From ab3f3efcebe622a3b2465bf4482f538c1cd6c535 Mon Sep 17 00:00:00 2001 From: Ian Date: Thu, 30 May 2013 21:08:14 +0300 Subject: [PATCH] upport master->2.0 default/serendipity_editor.js CKEDITOR and mode switches in func serendipity_imageSelector_addToBody still did not touch my changes within noWysiwygAdd() --- templates/default/admin/serendipity_editor.js | 84 +++++++++++++++---- 1 file changed, 68 insertions(+), 16 deletions(-) diff --git a/templates/default/admin/serendipity_editor.js b/templates/default/admin/serendipity_editor.js index 6cc9e1c0..cf15742c 100644 --- a/templates/default/admin/serendipity_editor.js +++ b/templates/default/admin/serendipity_editor.js @@ -134,44 +134,96 @@ function serendipity_imageSelector_addToElement (str, id) { // "Transfer" value from media db popup to textarea, including wysiwyg // This gets textarea="body"/"extended" and tries to insert into the textarea named serendipity[body]/serendipity[extended] -function serendipity_imageSelector_addToBody (str, textarea) { +function serendipity_imageSelector_addToBody (str, textarea) +{ var oEditor; - if (typeof(FCKeditorAPI) != 'undefined') { + + // check for CKEDITOR usage + if (typeof(CKEDITOR) != 'undefined') { + + // if here the blog uses CKEDITOR + oEditor = isinstance; // build-in by ckeditor plugin + + if (oEditor.mode == "wysiwyg") { + // if here the editior is in WYSIWYG mode so use the insert html function + oEditor.insertHtml(str); + // CKEDITOR.editor.mode = "source" disables function buttons, so using the fallback is redundant and could even confuse + } + + // check for FCKEditor usage + } else if (typeof(FCKeditorAPI) != 'undefined') { + + // if here the blog uses FCK editor oEditor = FCKeditorAPI.GetInstance('serendipity[' + textarea + ']') ; if (oEditor.EditMode == FCK_EDITMODE_WYSIWYG) { + // if here the editior is in WYSIWYG mode so use the insert html function oEditor.InsertHtml(str); - return; - } - } else if(typeof(xinha_editors) != 'undefined') { - if (typeof(xinha_editors['serendipity[' + textarea + ']']) != 'undefined') { - oEditor = xinha_editors['serendipity['+ textarea +']']; + } else { + // if here just insert the text to the textarea ( named with the value of textarea variable ) + noWysiwygAdd( str, textarea ); } + } else if(typeof(xinha_editors) != 'undefined') { + + // if here the blog uses Xinha editor + if (typeof(xinha_editors['serendipity[' + textarea + ']']) != 'undefined') { + // this is good for the two default editors (body & extended) + oEditor = xinha_editors['serendipity['+ textarea +']']; + } else if (typeof(xinha_editors[textarea]) != 'undefined') { + // this should work in any other cases than previous one + oEditor = xinha_editors[textarea]; + } else { + // this is the last chance to retrieve the instance of the editor ! + // editor has not been registered by the name of it's textarea + // so we must iterate over editors to find the good one + for (var editorName in xinha_editors) { + if ('serendipity[' + textarea + ']' == xinha_editors[editorName]._textArea.name) { + oEditor = xinha_editors[editorName]; + break; + } + } + } + + // the actual insert for the xinha editor if (oEditor) { - oEditor.insertHTML(str); - return; + if (oEditor._editMode != 'textmode') { + // if here the editior is in WYSIWYG mode so use the insert html function + oEditor.insertHTML(str); + } else { + // if here just insert the text to the textarea ( named with the value of textarea variable ) + noWysiwygAdd(str, textarea); + } + } else { + noWysiwygAdd(str, textarea); } } else if(typeof(HTMLArea) != 'undefined') { + // if here the blog uses HTMLArea editor if (textarea == 'body' && typeof(editorbody) != 'undefined') { oEditor = editorbody; } else if (textarea == 'extended' && typeof(editorextended) != 'undefined') { oEditor = editorextended; } else if (typeof(htmlarea_editors) != 'undefined' && typeof(htmlarea_editors[textarea]) != 'undefined') { - oEditor = htmlarea_editors[textarea]; + oEditor = htmlarea_editors[textarea]; } + // the actual insert for the HTMLArea editor if (oEditor._editMode != 'textmode') { + // if here the editor is in WYSIWYG mode so use the insert html function oEditor.insertHTML(str); - return; - } + } else { + // if here just insert the text to the textarea ( named with the value of textarea variable ) + noWysiwygAdd(str, textarea); + } + } else if(typeof(TinyMCE) != 'undefined') { + // for the TinyMCE editor we do not have a text mode insert tinyMCE.execInstanceCommand('serendipity[' + textarea + ']', 'mceInsertContent', false, str); - return; + + } else { + noWysiwygAdd(str, textarea); } - - noWysiwygAdd(str, textarea); } // The noWysiwygAdd JS function is the vanila serendipity_imageSelector_addToBody js function @@ -427,4 +479,4 @@ function invertSelection() { // Purely cosmetic function to highlight/dehighlight a comment by toggling the class comment_selected function highlightComment(id, checkvalue) { jQuery('#'+id).toggleClass('comment_selected'); -} \ No newline at end of file +}