|
|
|
@ -23,13 +23,16 @@ define(['jquery'], |
|
|
|
options, |
|
|
|
toolbarBtnSelector, |
|
|
|
updateToolbar = function () { |
|
|
|
if (options.activeToolbarClass) { |
|
|
|
var actCls = options.activeToolbarClass; |
|
|
|
if (actCls) { |
|
|
|
$(options.toolbarSelector).find(toolbarBtnSelector).each(function () { |
|
|
|
var command = $(this).data(options.commandRole); |
|
|
|
if (document.queryCommandState(command)) { |
|
|
|
$(this).addClass(options.activeToolbarClass); |
|
|
|
var el = $(this); |
|
|
|
var command = el.data(options.commandRole); |
|
|
|
var doc = editor.get(0).ownerDocument; |
|
|
|
if (doc.queryCommandState(command)) { |
|
|
|
el.addClass(actCls); |
|
|
|
} else { |
|
|
|
$(this).removeClass(options.activeToolbarClass); |
|
|
|
el.removeClass(actCls); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
@ -38,7 +41,9 @@ define(['jquery'], |
|
|
|
var commandArr = commandWithArgs.split(' '), |
|
|
|
command = commandArr.shift(), |
|
|
|
args = commandArr.join(' ') + (valueArg || ''); |
|
|
|
document.execCommand(command, 0, args); |
|
|
|
//document.execCommand("insertHTML", false, "<span class='own-class'>"+ document.getSelection()+"</span>");
|
|
|
|
editor.get(0).ownerDocument.execCommand("styleWithCSS", false, true); |
|
|
|
editor.get(0).ownerDocument.execCommand(command, 0, args); |
|
|
|
updateToolbar(); |
|
|
|
}, |
|
|
|
/* |
|
|
|
@ -106,13 +111,24 @@ define(['jquery'], |
|
|
|
bindToolbar = function (toolbar, options) { |
|
|
|
toolbar.find(toolbarBtnSelector).unbind().click(function () { |
|
|
|
restoreSelection(); |
|
|
|
editor.focus(); |
|
|
|
//editor.focus(); // cause defocus on selects
|
|
|
|
editor.get(0).ownerDocument.execCommand($(this).data(options.commandRole)); |
|
|
|
saveSelection(); |
|
|
|
}); |
|
|
|
toolbar.find('[data-toggle=dropdown]').click(restoreSelection); |
|
|
|
|
|
|
|
toolbar.find('input[type=text][data-' + options.commandRole + ']').on('webkitspeechchange change', function () { |
|
|
|
var dName = '[data-' + options.commandRole + ']'; |
|
|
|
toolbar.find('select'+dName).on('webkitspeechchange change', function(){ |
|
|
|
var newValue = this.value; |
|
|
|
restoreSelection(); |
|
|
|
if (newValue) { |
|
|
|
editor.focus(); |
|
|
|
execCommand($(this).data(options.commandRole), newValue); |
|
|
|
} |
|
|
|
console.log('change isolated2 ', newValue); |
|
|
|
saveSelection(); |
|
|
|
}); |
|
|
|
toolbar.find('input[type=text]'+dName,', select'+dName).on('webkitspeechchange change', function () { |
|
|
|
console.log('on changed ', newValue); |
|
|
|
var newValue = this.value; /* ugly but prevents fake double-calls due to selection restoration */ |
|
|
|
this.value = ''; |
|
|
|
restoreSelection(); |
|
|
|
@ -122,8 +138,10 @@ define(['jquery'], |
|
|
|
} |
|
|
|
saveSelection(); |
|
|
|
}).on('focus', function () { |
|
|
|
console.log('on focus '); |
|
|
|
var input = $(this); |
|
|
|
if (!input.data(options.selectionMarker)) { |
|
|
|
console.log('i have no ', options.selectionMarker); |
|
|
|
markSelection(input, options.selectionColor); |
|
|
|
input.focus(); |
|
|
|
} |
|
|
|
@ -161,7 +179,8 @@ define(['jquery'], |
|
|
|
return this; |
|
|
|
} |
|
|
|
options = $.extend({}, $.fn.wysiwyg.defaults, userOptions); |
|
|
|
toolbarBtnSelector = 'a[data-' + options.commandRole + '],button[data-' + options.commandRole + '],input[type=button][data-' + options.commandRole + ']'; |
|
|
|
var dName = '[data-' + options.commandRole + ']'; |
|
|
|
toolbarBtnSelector = 'a'+dName+',button'+dName+',input[type=button]'+dName+', select'+dName; |
|
|
|
//bindHotkeys(options.hotKeys);
|
|
|
|
if (options.dragAndDropImages) { |
|
|
|
initFileDrops(); |
|
|
|
@ -183,6 +202,7 @@ define(['jquery'], |
|
|
|
return this; |
|
|
|
}; |
|
|
|
$.fn.wysiwyg.defaults = { |
|
|
|
/* |
|
|
|
hotKeys: { |
|
|
|
'ctrl+b meta+b': 'bold', |
|
|
|
'ctrl+i meta+i': 'italic', |
|
|
|
@ -196,6 +216,7 @@ define(['jquery'], |
|
|
|
'shift+tab': 'outdent', |
|
|
|
'tab': 'indent' |
|
|
|
}, |
|
|
|
*/ |
|
|
|
toolbarSelector: '[data-role=editor-toolbar]', |
|
|
|
commandRole: 'edit', |
|
|
|
activeToolbarClass: 'btn-info', |
|
|
|
|