diff --git a/deployment/serendipity_editor.js b/deployment/serendipity_editor.js index 8bcbec1a..b034053b 100644 --- a/deployment/serendipity_editor.js +++ b/deployment/serendipity_editor.js @@ -165,6 +165,92 @@ function serendipity_imageSelector_addToElement (str, el) function serendipity_imageSelector_addToBody (str, textarea) { + + // check for FCKEditor usage + if (typeof(FCKeditorAPI) != 'undefined') { + + // if here the blog uses FCK editor + var 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); + } 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 + var oEditor; + + 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) { + 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 + var oEditor; + + 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]; + } + + // the actual insert for the HTMLArea editor + 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 if(typeof(TinyMCE) != 'undefined') { + // for the TinyMCE editor we do not have a text mode insert + + //tinyMCE.execCommand('mceInsertContent', false, str); + tinyMCE.execInstanceCommand('serendipity[' + textarea + ']', 'mceInsertContent', false, str); + } else { + noWysiwygAdd(str, textarea); + } +} + +// The noWysiwygAdd JS function is the vanila serendipity_imageSelector_addToBody js function which works fine in NO WYSIWYG mode +// NOTE: the serendipity_imageSelector_addToBody could add any valid HTML string to the textarea +function noWysiwygAdd( str, textarea ) +{ + // default case: no wysiwyg editor eltarget = ''; if (document.forms['serendipityEntry'] && document.forms['serendipityEntry']['serendipity['+ textarea +']']) { eltarget = document.forms['serendipityEntry']['serendipity['+ textarea +']'] @@ -173,11 +259,11 @@ function serendipity_imageSelector_addToBody (str, textarea) } else { eltarget = document.forms[0].elements[0]; } - - wrapSelection(eltarget, str, ''); + eltarget.focus(); } + function serendipity_imageSelector_done(textarea) { var insert = ''; diff --git a/docs/NEWS b/docs/NEWS index edc2ffce..39586491 100644 --- a/docs/NEWS +++ b/docs/NEWS @@ -3,13 +3,14 @@ Version 1.3 () ------------------------------------------------------------------------ + * Patch popup-HTML-code insertion javascript to better inter- + operate with tinymce, xinha or fckeditor. Thanks to + Assen Tchorbadjiev. + * Updated WordPress imported to be able to import from a 2.3 structure (experimental). Also added WPXRSS import to the generic RSS importer. (garvinhicking) - * Patch PEAR.php for better detection, if already included. - Thanks to Assen Tchorbadjiev. - * Fix wrong entry timestamp used in comment feeds (garvinhicking) * Add experimental DB layer for "SQLRelay" database proxy extension, @@ -57,6 +58,10 @@ Version 1.3 () Version 1.2.1 () ------------------------------------------------------------------------ + + * Patch PEAR.php for better detection, if already included. + Thanks to Assen Tchorbadjiev. + * Fix admin entry list when no entries exist or meet filter criteria. (Don Chambers) diff --git a/serendipity_editor.js b/serendipity_editor.js index 8bcbec1a..b034053b 100644 --- a/serendipity_editor.js +++ b/serendipity_editor.js @@ -165,6 +165,92 @@ function serendipity_imageSelector_addToElement (str, el) function serendipity_imageSelector_addToBody (str, textarea) { + + // check for FCKEditor usage + if (typeof(FCKeditorAPI) != 'undefined') { + + // if here the blog uses FCK editor + var 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); + } 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 + var oEditor; + + 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) { + 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 + var oEditor; + + 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]; + } + + // the actual insert for the HTMLArea editor + 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 if(typeof(TinyMCE) != 'undefined') { + // for the TinyMCE editor we do not have a text mode insert + + //tinyMCE.execCommand('mceInsertContent', false, str); + tinyMCE.execInstanceCommand('serendipity[' + textarea + ']', 'mceInsertContent', false, str); + } else { + noWysiwygAdd(str, textarea); + } +} + +// The noWysiwygAdd JS function is the vanila serendipity_imageSelector_addToBody js function which works fine in NO WYSIWYG mode +// NOTE: the serendipity_imageSelector_addToBody could add any valid HTML string to the textarea +function noWysiwygAdd( str, textarea ) +{ + // default case: no wysiwyg editor eltarget = ''; if (document.forms['serendipityEntry'] && document.forms['serendipityEntry']['serendipity['+ textarea +']']) { eltarget = document.forms['serendipityEntry']['serendipity['+ textarea +']'] @@ -173,11 +259,11 @@ function serendipity_imageSelector_addToBody (str, textarea) } else { eltarget = document.forms[0].elements[0]; } - - wrapSelection(eltarget, str, ''); + eltarget.focus(); } + function serendipity_imageSelector_done(textarea) { var insert = '';