From bd901c35e2a8c62ab44b0d0e53eeb30aae289782 Mon Sep 17 00:00:00 2001 From: John Baab Date: Mon, 23 Jan 2017 11:48:47 -0500 Subject: [PATCH] Expanded Exec Command Options Added InsertHTML support for IE and insertFontPoint for all browsers. --- src/bootstrap-wysiwyg.js | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/bootstrap-wysiwyg.js b/src/bootstrap-wysiwyg.js index 75c52fa..4f0a7a3 100644 --- a/src/bootstrap-wysiwyg.js +++ b/src/bootstrap-wysiwyg.js @@ -121,12 +121,12 @@ var command = commandArr[ 0 ]; // If the command has an argument and its value matches this button. == used for string/number comparison - if ( commandArr.length > 1 && document.queryCommandEnabled( command ) && document.queryCommandValue( command ) === commandArr[ 1 ] ) { + if (commandArr.length > 1 && document.queryCommandSupported(command) && document.queryCommandEnabled(command) && document.queryCommandValue(command) === commandArr[1]) { self.addClass( options.activeToolbarClass ); } // Else if the command has no arguments and it is active - else if ( commandArr.length === 1 && document.queryCommandEnabled( command ) && document.queryCommandState( command ) ) { + else if (commandArr.length === 1 && document.queryCommandSupported(command) && document.queryCommandEnabled(command) && document.queryCommandState(command)) { self.addClass( options.activeToolbarClass ); } @@ -145,10 +145,13 @@ var parts = commandWithArgs.split( "-" ); - if ( parts.length === 1 ) { + if ( parts.length === 1 && document.queryCommandSupported(command) ) { document.execCommand( command, false, args ); } else if ( parts[ 0 ] === "format" && parts.length === 2 ) { document.execCommand( "formatBlock", false, parts[ 1 ] ); + } else if (parts.length === 1 && command === 'insertHTML') { + //Custom insertHTML for IE + this.insertHTML(args, editor); } ( editor ).trigger( "change" ); @@ -234,6 +237,27 @@ } }; + Wysiwyg.prototype.insertFontPoint = function (value, editor, options, toolbarBtnSelector) { + var self = this; + editor.focus(); + + self.execCommand('fontSize 7', null, editor, options, toolbarBtnSelector); + editor.find('font[size="7"]').removeAttr('size').css('font-size', value + 'pt'); + }; + + Wysiwyg.prototype.insertHTML = function (html, editor) { + editor.focus(); + + var el = document.createElement("div"); + el.innerHTML = html; + var frag = document.createDocumentFragment(), node; + while ((node = el.firstChild)) { + frag.appendChild(node); + } + + this.selectedRange.insertNode(frag); + }; + Wysiwyg.prototype.insertFiles = function( files, options, editor, toolbarBtnSelector ) { var self = this; editor.focus(); @@ -268,6 +292,14 @@ if ( editor.data( options.commandRole ) === "html" ) { self.toggleHtmlEdit( editor ); + } + else if (editor.data(options.commandRole).indexOf('fontPoint') >= 0) { + //alert($(this).data(options.commandRole)); + var commandArr = $(this).data(options.commandRole).split(' '); + commandArr.shift(); + var args = commandArr.join(' ') + (''); + + self.insertFontPoint(args, editor, options, toolbarBtnSelector); } else { self.execCommand( $( this ).data( options.commandRole ), null, editor, options, toolbarBtnSelector ); }