diff --git a/editors/js/ckeditor-3.0.js b/editors/js/ckeditor-3.0.js index d2cf300..89664ca 100644 --- a/editors/js/ckeditor-3.0.js +++ b/editors/js/ckeditor-3.0.js @@ -208,9 +208,18 @@ Drupal.wysiwyg.editor.instance.ckeditor = { // @todo Don't know if we need this yet. return content; }, + insert: function(content) { content = this.prepareContent(content); CKEDITOR.instances[this.field].insertHtml(content); + }, + + setContent: function (content) { + CKEDITOR.instances[this.field].setData(content); + }, + + getContent: function () { + return CKEDITOR.instances[this.field].getData(); } }; diff --git a/editors/js/fckeditor-2.6.js b/editors/js/fckeditor-2.6.js index 4ee2cff..114c49b 100644 --- a/editors/js/fckeditor-2.6.js +++ b/editors/js/fckeditor-2.6.js @@ -175,6 +175,16 @@ Drupal.wysiwyg.editor.instance.fckeditor = { var instance = FCKeditorAPI.GetInstance(this.field); // @see FCK.InsertHtml(), FCK.InsertElement() instance.InsertHtml(content); + }, + + getContent: function () { + var instance = FCKeditorAPI.GetInstance(this.field); + return instance.GetData(); + }, + + setContent: function (content) { + var instance = FCKeditorAPI.GetInstance(this.field); + instance.SetHTML(content); } }; diff --git a/editors/js/jwysiwyg.js b/editors/js/jwysiwyg.js index ae47853..c7ebbcf 100644 --- a/editors/js/jwysiwyg.js +++ b/editors/js/jwysiwyg.js @@ -22,4 +22,18 @@ Drupal.wysiwyg.editor.detach.jwysiwyg = function(context, params) { $field.show(); }; +Drupal.wysiwyg.editor.instance.jwysiwyg = { + insert: function (content) { + $('#' + this.field).wysiwyg('insertHtml', content); + }, + + setContent: function (content) { + $('#' + this.field).wysiwyg('setContent', content); + }, + + getContent: function () { + return $('#' + this.field).wysiwyg('getContent'); + } +}; + })(jQuery); diff --git a/editors/js/markitup.js b/editors/js/markitup.js index 6691811..efa0bcd 100644 --- a/editors/js/markitup.js +++ b/editors/js/markitup.js @@ -26,4 +26,18 @@ Drupal.wysiwyg.editor.detach.markitup = function(context, params) { } }; +Drupal.wysiwyg.editor.instance.markitup = { + insert: function (content) { + $.markItUp({ replaceWith: content }); + }, + + setContent: function (content) { + $('#' + this.field).val(content); + }, + + getContent: function () { + return $('#' + this.field).val(); + } +}; + })(jQuery); diff --git a/editors/js/nicedit.js b/editors/js/nicedit.js index d5d9795..d2d8df2 100644 --- a/editors/js/nicedit.js +++ b/editors/js/nicedit.js @@ -89,6 +89,14 @@ Drupal.wysiwyg.editor.instance.nicedit = { // Only fragment children are inserted. range.insertNode(fragment); } + }, + + setContent: function (content) { + nicEditors.findEditor(this.field).setContent(content); + }, + + getContent: function () { + return nicEditors.findEditor(this.field).getContent(); } }; diff --git a/editors/js/none.js b/editors/js/none.js index 3402024..4c3f603 100644 --- a/editors/js/none.js +++ b/editors/js/none.js @@ -65,6 +65,14 @@ Drupal.wysiwyg.editor.instance.none = { else { editor.value += content; } + }, + + setContent: function (content) { + $('#' + this.field).val(content); + }, + + getContent: function () { + return $('#' + this.field).val(); } }; diff --git a/editors/js/openwysiwyg.js b/editors/js/openwysiwyg.js index 89a5337..3719a99 100644 --- a/editors/js/openwysiwyg.js +++ b/editors/js/openwysiwyg.js @@ -65,4 +65,56 @@ Drupal.wysiwyg.editor.detach.openwysiwyg = function(context, params) { } }; +/** + * Instance methods for openWYSIWYG. + */ +Drupal.wysiwyg.editor.instance.openwysiwyg = { + insert: function (content) { + alert(Drupal.t('Sorry, inserting content is not supported on openWYSIWYG.')); + }, + + setContent: function (content) { + // Based on openWYSIWYG's _generate() method. + var doc = WYSIWYG.getEditorWindow(this.field).document; + if (WYSIWYG.config[this.field].ReplaceLineBreaks) { + content = content.replace(/\n\r|\n/ig, '
'); + } + if (WYSIWYG.viewTextMode[this.field]) { + var html = document.createTextNode(content); + doc.body.innerHTML = ''; + doc.body.appendChild(html); + } + else { + doc.open(); + doc.write(content); + doc.close(); + } + }, + + getContent: function () { + // Based on openWYSIWYG's updateTextarea() method. + var content = ''; + var doc = WYSIWYG.getEditorWindow(this.field).document; + if (WYSIWYG.viewTextMode[this.field]) { + if (WYSIWYG_Core.isMSIE) { + content = doc.body.innerText; + } + else { + var range = doc.body.ownerDocument.createRange(); + range.selectNodeContents(doc.body); + content = range.toString(); + } + } + else { + content = doc.body.innerHTML; + } + content = WYSIWYG.stripURLPath(this.field, content); + content = WYSIWYG_Core.replaceRGBWithHexColor(content); + if (WYSIWYG.config[this.field].ReplaceLineBreaks) { + content = content.replace(/(\r\n)|(\n)/ig, ''); + } + return content; + } +}; + })(jQuery); diff --git a/editors/js/tinymce-3.js b/editors/js/tinymce-3.js index b04a4ce..969bff6 100644 --- a/editors/js/tinymce-3.js +++ b/editors/js/tinymce-3.js @@ -177,7 +177,7 @@ Drupal.wysiwyg.editor.instance.tinymce = { }, openDialog: function(dialog, params) { - var instanceId = this.isFullscreen() ? 'mce_fullscreen' : this.field; + var instanceId = this.getInstanceId(); var editor = tinyMCE.get(instanceId); editor.windowManager.open({ file: dialog.url + '/' + instanceId, @@ -188,8 +188,7 @@ Drupal.wysiwyg.editor.instance.tinymce = { }, closeDialog: function(dialog) { - var instanceId = this.isFullscreen() ? 'mce_fullscreen' : this.field; - var editor = tinyMCE.get(instanceId); + var editor = tinyMCE.get(this.getInstanceId()); editor.windowManager.close(dialog); }, @@ -224,13 +223,25 @@ Drupal.wysiwyg.editor.instance.tinymce = { insert: function(content) { content = this.prepareContent(content); - var instanceId = this.isFullscreen() ? 'mce_fullscreen' : this.field; - tinyMCE.execInstanceCommand(instanceId, 'mceInsertContent', false, content); + tinyMCE.execInstanceCommand(this.getInstanceId(), 'mceInsertContent', false, content); + }, + + setContent: function (content) { + content = this.prepareContent(content); + tinyMCE.execInstanceCommand(this.getInstanceId(), 'mceSetContent', false, content); + }, + + getContent: function () { + return tinyMCE.get(this.getInstanceId()).getContent(); }, isFullscreen: function() { // TinyMCE creates a completely new instance for fullscreen mode. return tinyMCE.activeEditor.id == 'mce_fullscreen' && tinyMCE.activeEditor.getParam('fullscreen_editor_id') == this.field; + }, + + getInstanceId: function () { + return this.isFullscreen() ? 'mce_fullscreen' : this.field; } }; diff --git a/editors/js/whizzywig-56.js b/editors/js/whizzywig-56.js index 229a70b..168d5a8 100644 --- a/editors/js/whizzywig-56.js +++ b/editors/js/whizzywig-56.js @@ -80,10 +80,7 @@ Drupal.wysiwyg.editor.attach.whizzywig = function(context, params, settings) { // Attach editor. makeWhizzyWig(params.field, (settings.buttons ? settings.buttons : 'all')); // Whizzywig fails to detect and set initial textarea contents. - var instance = $('#whizzy' + params.field).get(0); - if (instance) { - instance.contentWindow.document.body.innerHTML = tidyD($field.val()); - } + $('#whizzy' + params.field).contents().find('body').html(tidyD($field.val())); }; /** @@ -91,28 +88,14 @@ Drupal.wysiwyg.editor.attach.whizzywig = function(context, params, settings) { */ Drupal.wysiwyg.editor.detach.whizzywig = function(context, params) { var detach = function (index) { - var id = whizzies[index]; - var instance = $('#whizzy' + id).get(0); - if (!instance) { - return; - } - var editingArea = instance.contentWindow.document; - var $field = $('#' + id); - // Whizzywig shows the original textarea in source mode. - if ($field.css('display') == 'block') { - editingArea.body.innerHTML = $field.val(); - } - + var id = whizzies[index], $field = $('#' + id), instance = Drupal.wysiwyg.instances[id]; // Save contents of editor back into textarea. - $field.val(tidyH(editingArea)); + $field.val(instance.getContent()); // Remove editor instance. $('#' + id + '-whizzywig').remove(); whizzies.splice(index, 1); - // Restore original textarea styling. - var originalValues = Drupal.wysiwyg.instances[id]; - $field.removeAttr('style'); - $field.attr('style', originalValues.originalStyle); + $field.removeAttr('style').attr('style', instance.originalStyle); }; if (typeof params != 'undefined') { @@ -130,4 +113,36 @@ Drupal.wysiwyg.editor.detach.whizzywig = function(context, params) { } }; +/** + * Instance methods for Whizzywig. + */ +Drupal.wysiwyg.editor.instance.whizzywig = { + insert: function (content) { + insHTML(content); + }, + + setContent: function (content) { + // Whizzywig shows the original textarea in source mode. + if ($field.css('display') == 'block') { + $('#' + this.field).val(content); + } + else { + var doc = $('#whizzy' + this.field).contents()[0]; + doc.open(); + doc.write(content); + doc.close(); + } + }, + + getContent: function () { + // Whizzywig's tidyH() expects a document node. Clone the editing iframe's + // document so tidyH() won't mess with it if this gets called while editing. + var clone = $($('#whizzy' + this.field).contents()[0].documentElement).clone()[0].ownerDocument; + // Whizzywig shows the original textarea in source mode so update the body. + if ($field.css('display') == 'block') { + clone.body.innerHTML = $('#' + this.field).val(); + } + return tidyH(clone); + } +}; })(jQuery); diff --git a/editors/js/whizzywig-60.js b/editors/js/whizzywig-60.js index dc995f6..a6d59bd 100644 --- a/editors/js/whizzywig-60.js +++ b/editors/js/whizzywig-60.js @@ -29,10 +29,7 @@ Drupal.wysiwyg.editor.attach.whizzywig = function(context, params, settings) { // Attach editor. makeWhizzyWig(params.field, (settings.buttons ? settings.buttons : 'all')); // Whizzywig fails to detect and set initial textarea contents. - var instance = $('#whizzy' + params.field).get(0); - if (instance) { - instance.contentWindow.document.body.innerHTML = tidyD($field.val()); - } + $('#whizzy' + params.field).contents().find('body').html(tidyD($field.val())); }; /** @@ -40,31 +37,17 @@ Drupal.wysiwyg.editor.attach.whizzywig = function(context, params, settings) { */ Drupal.wysiwyg.editor.detach.whizzywig = function(context, params) { var detach = function (index) { - var id = whizzies[index]; - var instance = $('#whizzy' + id).get(0); - if (!instance) { - return; - } - var editingArea = instance.contentWindow.document; - var $field = $('#' + id); - // Whizzywig shows the original textarea in source mode. - if ($field.css('display') == 'block') { - editingArea.body.innerHTML = $field.val(); - } - + var id = whizzies[index], $field = $('#' + id), instance = Drupal.wysiwyg.instances[id]; // Save contents of editor back into textarea. - $field.val(tidyH(editingArea)); + $field.val(instance.getContent()); // Move original textarea back to its previous location. - $container = $('#CONTAINER' + id); + var $container = $('#CONTAINER' + id); $field.insertBefore($container); // Remove editor instance. $container.remove(); whizzies.splice(index, 1); - // Restore original textarea styling. - var originalValues = Drupal.wysiwyg.instances[id]; - $field.removeAttr('style'); - $field.attr('style', originalValues.originalStyle); + $field.removeAttr('style').attr('style', instance.originalStyle); } if (typeof params != 'undefined') { @@ -82,4 +65,36 @@ Drupal.wysiwyg.editor.detach.whizzywig = function(context, params) { } }; +/** + * Instance methods for Whizzywig. + */ +Drupal.wysiwyg.editor.instance.whizzywig = { + insert: function (content) { + insHTML(content); + }, + + setContent: function (content) { + // Whizzywig shows the original textarea in source mode. + if ($field.css('display') == 'block') { + $('#' + this.field).val(content); + } + else { + var doc = $('#whizzy' + this.field).contents()[0]; + doc.open(); + doc.write(content); + doc.close(); + } + }, + + getContent: function () { + // Whizzywig's tidyH() expects a document node. Clone the editing iframe's + // document so tidyH() won't mess with it if this gets called while editing. + var clone = $($('#whizzy' + this.field).contents()[0].documentElement).clone()[0].ownerDocument; + // Whizzywig shows the original textarea in source mode so update the body. + if ($field.css('display') == 'block') { + clone.body.innerHTML = $('#' + this.field).val(); + } + return tidyH(clone); + } +}; })(jQuery); diff --git a/editors/js/whizzywig.js b/editors/js/whizzywig.js index e98bc4d..f41c154 100644 --- a/editors/js/whizzywig.js +++ b/editors/js/whizzywig.js @@ -71,10 +71,7 @@ Drupal.wysiwyg.editor.attach.whizzywig = function(context, params, settings) { // Attach editor. makeWhizzyWig(params.field, (settings.buttons ? settings.buttons : 'all')); // Whizzywig fails to detect and set initial textarea contents. - var instance = $('#whizzy' + params.field).get(0); - if (instance) { - instance.contentWindow.document.body.innerHTML = tidyD($field.val()); - } + $('#whizzy' + params.field).contents().find('body').html(tidyD($field.val())); }; /** @@ -82,30 +79,14 @@ Drupal.wysiwyg.editor.attach.whizzywig = function(context, params, settings) { */ Drupal.wysiwyg.editor.detach.whizzywig = function(context, params) { var detach = function (index) { - var id = whizzies[index]; - var instance = $('#whizzy' + id).get(0); - if (!instance) { - return; - } - var body = instance.contentWindow.document.body; - var $field = $('#' + id); - // Whizzywig shows the original textarea in source mode. - if ($field.css('display') == 'block') { - body.innerHTML = $field.val(); - } - body.innerHTML = tidyH(body.innerHTML); - + var id = whizzies[index], $field = $('#' + id), instance = Drupal.wysiwyg.instances[id]; // Save contents of editor back into textarea. - $field.val(window.get_xhtml ? get_xhtml(body) : body.innerHTML); - $field.val($field.val().replace(location.href + '#', '#')); + $field.val(instance.getContent()); // Remove editor instance. $('#' + id + '-whizzywig').remove(); whizzies.splice(index, 1); - // Restore original textarea styling. - var originalValues = Drupal.wysiwyg.instances[id]; - $field.removeAttr('style'); - $field.attr('style', originalValues.originalStyle); + $field.removeAttr('style').attr('style', instance.originalStyle); }; if (typeof params != 'undefined') { @@ -123,4 +104,44 @@ Drupal.wysiwyg.editor.detach.whizzywig = function(context, params) { } }; +/** + * Instance methods for Whizzywig. + */ +Drupal.wysiwyg.editor.instance.whizzywig = { + insert: function (content) { + insHTML(content); + }, + + setContent: function (content) { + var $field = $('#' + this.field); + // Whizzywig shows the original textarea in source mode. + if ($field.css('display') == 'block') { + $field.val(content); + } + else { + var doc = $('#whizzy' + this.field).contents()[0]; + doc.open(); + doc.write(content); + doc.close(); + } + }, + + getContent: function () { + var $field = $('#' + this.field), + // Whizzywig shows the original textarea in source mode. + content = ($field.css('display') == 'block' ? + $field.val() : $('#whizzy' + this.field).contents().find('body').html() + ); + + content = tidyH(content); + // Whizzywig's get_xhtml() addon, if defined, expects a DOM node. + if ($.isFunction(window.get_xhtml)) { + var pre = document.createElement('pre'); + pre.innerHTML = content; + content = get_xhtml(pre); + } + return content.replace(location.href + '#', '#'); + } +}; + })(jQuery); diff --git a/editors/js/wymeditor.js b/editors/js/wymeditor.js index ed66784..2a3708a 100644 --- a/editors/js/wymeditor.js +++ b/editors/js/wymeditor.js @@ -44,12 +44,24 @@ Drupal.wysiwyg.editor.detach.wymeditor = function (context, params) { Drupal.wysiwyg.editor.instance.wymeditor = { insert: function (content) { + this.getInstance().insert(content); + }, + + setContent: function (content) { + this.getInstance().html(content); + }, + + getContent: function (content) { + return this.getInstance().xhtml(); + }, + + getInstance: function () { var $field = $('#' + this.field); var index = $field.data(WYMeditor.WYM_INDEX); if (typeof index != 'undefined') { - var instance = WYMeditor.INSTANCES[index]; - instance.insert(content); + return WYMeditor.INSTANCES[index]; } + return null; } }; diff --git a/editors/js/yui.js b/editors/js/yui.js index ad8be36..dd72a61 100644 --- a/editors/js/yui.js +++ b/editors/js/yui.js @@ -32,4 +32,19 @@ Drupal.wysiwyg.editor.detach.yui = function(context, params) { } }; +Drupal.wysiwyg.editor.instance.yui = { + insert: function (content) { + YAHOO.widget.EditorInfo.getEditorById(this.field).cmd_inserthtml(content); + }, + + setContent: function (content) { + YAHOO.widget.EditorInfo.getEditorById(this.field).setEditorHTML(content); + }, + + getContent: function () { + var instance = YAHOO.widget.EditorInfo.getEditorById(this.field); + return instance.cleanHTML(instance.getEditorHTML(content)); + } +}; + })(jQuery); diff --git a/wysiwyg.js b/wysiwyg.js index 72ca156..43300dc 100644 --- a/wysiwyg.js +++ b/wysiwyg.js @@ -187,6 +187,7 @@ Drupal.wysiwyg.toggleWysiwyg = function (event) { Drupal.wysiwyg.editor.attach.none(context, params); Drupal.wysiwyg.instances[params.field] = Drupal.wysiwyg.editor.instance.none; Drupal.wysiwyg.instances[params.field].editor = 'none'; + Drupal.wysiwyg.instances[params.field].field = params.field; $(this).html(Drupal.settings.wysiwyg.enable).blur(); } else {