Select Git revision
application.js
application.js 10.03 KiB
/**
* This function changes the b and i tags to strong and em tags respectively
*
* @param {string} inputhtml Input HTML to be parsed
*/
function clean_up_html_tags(inputhtml) {
return inputhtml
.replace("<b>", "<strong>")
.replace("</b>", "</strong>")
.replace("<i>", "<em>")
.replace("</i>", "</em>")
.replace("</font>", "</span>")
.replace("<font color=\"", "<span style=\"color: ");
}
/**
* jQuery document ready function
*/
$(document).ready(function () {
// Set default paragraph separator to p tag instead of br
document.execCommand("defaultParagraphSeparator", false, "p");
// Clear out values to start with
$('#input-textarea').text('');
$('#input-textarea').val('');
$('#input-textarea').on('input propertychange', function () {
});
// Update code button in the center of form
$('#update-code').click(function () {
let outputprehtml = $('#input-textarea').html();
$('#output-pre').text(clean_up_html_tags(outputprehtml));
});
// Colour picker needs to be set twice in case they don't change the colour
$("#color-picker")
.click(function () {
document.execCommand('foreColor', false, $("#color-picker").val());
return true;
})
.change(function () {
document.execCommand('foreColor', false, $("#color-picker").val());
return true;
});
// Create list of buttons used to style the input like bold, italic etc
var buttonList = [{
// Bold button
'type': 'icon',
'icon': 'bold',
'name': 'Bold',
'id': 'bold',
'title': 'Bold',
'onclick': function () {
document.execCommand('bold', false, '');
return true;
}
},
{
// Italic button
'type': 'icon',
'icon': 'italic',
'name': 'Italic',
'id': 'italic',
'title': 'Italic',
'onclick': function () {