Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expanded Exec Command Options #111

Open
wants to merge 1 commit into
base: 2.0-dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions src/bootstrap-wysiwyg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

Expand All @@ -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" );
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 );
}
Expand Down