Upgrade TinyMCE to v3.4.5
[citadel.git] / webcit / tiny_mce / plugins / searchreplace / editor_plugin_src.js
index 7a7dde7a8a7f0045b1c039ee9e544eb58ef49d9c..4c87e8fa79d0fdd12b5f577094f74c549db70266 100644 (file)
-/* Import theme        specific language pack */\r
-tinyMCE.importPluginLanguagePack('searchreplace', 'en,sv,zh_cn,fa,fr_ca,fr,de,pl,pt_br,cs,nl,da,he,nb,hu,ru,ru_KOI8-R,ru_UTF-8,nn,fi,cy,es,is,zh_tw,zh_tw_utf8,sk');\r
-\r
-function TinyMCE_searchreplace_getInfo() {\r
-       return {\r
-               longname : 'Search/Replace',\r
-               author : 'Moxiecode Systems',\r
-               authorurl : 'http://tinymce.moxiecode.com',\r
-               infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_searchreplace.html',\r
-               version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion\r
-       };\r
-};\r
-\r
-function TinyMCE_searchreplace_getControlHTML(control_name)    {\r
-       switch (control_name) {\r
-               case "search":\r
-                       var cmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mceSearch\',true);return false;';\r
-                       return '<a href="javascript:' + cmd + '" onclick="' + cmd + '" target="_self" onmousedown="return false;"><img id="{$editor_id}_search" src="{$pluginurl}/images/search.gif" title="{$lang_searchreplace_search_desc}" width="20" height="20" class="mceButtonNormal" onmouseover="tinyMCE.switchClass(this,\'mceButtonOver\');" onmouseout="tinyMCE.restoreClass(this);" onmousedown="tinyMCE.restoreAndSwitchClass(this,\'mceButtonDown\');" /></a>';\r
-\r
-               case "replace":\r
-                       var cmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mceSearchReplace\',true);return false;';\r
-                       return '<a href="javascript:' + cmd + '" onclick="' + cmd + '" target="_self" onmousedown="return false;"><img id="{$editor_id}_replace" src="{$pluginurl}/images/replace.gif" title="{$lang_searchreplace_replace_desc}" width="20" height="20" class="mceButtonNormal" onmouseover="tinyMCE.switchClass(this,\'mceButtonOver\');" onmouseout="tinyMCE.restoreClass(this);" onmousedown="tinyMCE.restoreAndSwitchClass(this,\'mceButtonDown\');" /></a>';\r
-       }\r
-\r
-       return "";\r
-}\r
-\r
 /**\r
- * Executes    the     search/replace commands.\r
+ * editor_plugin_src.js\r
+ *\r
+ * Copyright 2009, Moxiecode Systems AB\r
+ * Released under LGPL License.\r
+ *\r
+ * License: http://tinymce.moxiecode.com/license\r
+ * Contributing: http://tinymce.moxiecode.com/contributing\r
  */\r
-function TinyMCE_searchreplace_execCommand(editor_id, element, command,        user_interface, value) {\r
-       function defValue(key, default_value) {\r
-               value[key] = typeof(value[key]) == "undefined" ? default_value : value[key];\r
-       }\r
-\r
-       function replaceSel(search_str, str) {\r
-               // Get current selection\r
-               if (!tinyMCE.isMSIE) {\r
-                       var sel = instance.contentWindow.getSelection();\r
-                       var rng = sel.getRangeAt(0);\r
-               } else {\r
-                       var rng = instance.contentWindow.document.selection.createRange();\r
-               }\r
-\r
-               // Replace current one\r
-               if (!tinyMCE.isMSIE) {\r
-                       var doc = instance.contentWindow.document;\r
 \r
-                       // This way works when the replace doesn't contain the search string\r
-                       if (str.indexOf(search_str) == -1) {\r
-                               rng.deleteContents();\r
-                               rng.insertNode(rng.createContextualFragment(str));\r
-                               rng.collapse(false);\r
-                       } else {\r
-                               // Insert content ugly way! Needed to move selection to after replace item\r
-                               doc.execCommand("insertimage", false, "#mce_temp_url#");\r
-                               var elm = tinyMCE.getElementByAttributeValue(doc.body, "img", "src", "#mce_temp_url#");\r
-                               elm.parentNode.replaceChild(doc.createTextNode(str), elm);\r
-                       }\r
-               } else {\r
-                       if (rng.item)\r
-                               rng.item(0).outerHTML = str;\r
-                       else\r
-                               rng.pasteHTML(str);\r
+(function() {\r
+       tinymce.create('tinymce.plugins.SearchReplacePlugin', {\r
+               init : function(ed, url) {\r
+                       function open(m) {\r
+                               // Keep IE from writing out the f/r character to the editor\r
+                               // instance while initializing a new dialog. See: #3131190\r
+                               window.focus();\r
+\r
+                               ed.windowManager.open({\r
+                                       file : url + '/searchreplace.htm',\r
+                                       width : 420 + parseInt(ed.getLang('searchreplace.delta_width', 0)),\r
+                                       height : 170 + parseInt(ed.getLang('searchreplace.delta_height', 0)),\r
+                                       inline : 1,\r
+                                       auto_focus : 0\r
+                               }, {\r
+                                       mode : m,\r
+                                       search_string : ed.selection.getContent({format : 'text'}),\r
+                                       plugin_url : url\r
+                               });\r
+                       };\r
+\r
+                       // Register commands\r
+                       ed.addCommand('mceSearch', function() {\r
+                               open('search');\r
+                       });\r
+\r
+                       ed.addCommand('mceReplace', function() {\r
+                               open('replace');\r
+                       });\r
+\r
+                       // Register buttons\r
+                       ed.addButton('search', {title : 'searchreplace.search_desc', cmd : 'mceSearch'});\r
+                       ed.addButton('replace', {title : 'searchreplace.replace_desc', cmd : 'mceReplace'});\r
+\r
+                       ed.addShortcut('ctrl+f', 'searchreplace.search_desc', 'mceSearch');\r
+               },\r
+\r
+               getInfo : function() {\r
+                       return {\r
+                               longname : 'Search/Replace',\r
+                               author : 'Moxiecode Systems AB',\r
+                               authorurl : 'http://tinymce.moxiecode.com',\r
+                               infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/searchreplace',\r
+                               version : tinymce.majorVersion + "." + tinymce.minorVersion\r
+                       };\r
                }\r
-       }\r
-\r
-       var instance = tinyMCE.getInstanceById(editor_id);\r
-\r
-       if (!value)\r
-               value = new Array();\r
-\r
-       // Setup defualt values\r
-       defValue("editor_id", editor_id);\r
-       defValue("searchstring", "");\r
-       defValue("replacestring", null);\r
-       defValue("replacemode", "none");\r
-       defValue("casesensitive", false);\r
-       defValue("backwards", false);\r
-       defValue("wrap", false);\r
-       defValue("wholeword", false);\r
-       defValue("inline", "yes");\r
-\r
-       // Handle commands\r
-       switch (command) {\r
-               case "mceResetSearch":\r
-                       tinyMCE.lastSearchRng = null;\r
-                       return true;\r
-\r
-               case "mceSearch":\r
-                       if (user_interface) {\r
-                               // Open search dialog\r
-                               var template = new Array();\r
-\r
-                               if (value['replacestring'] != null) {\r
-                                       template['file'] = '../../plugins/searchreplace/replace.htm'; // Relative to theme\r
-                                       template['width'] = 320;\r
-                                       template['height'] = 120 + (tinyMCE.isNS7 ? 20 : 0);\r
-                                       template['width'] += tinyMCE.getLang('lang_searchreplace_replace_delta_width', 0);\r
-                                       template['height'] += tinyMCE.getLang('lang_searchreplace_replace_delta_height', 0);\r
-                               } else {\r
-                                       template['file'] = '../../plugins/searchreplace/search.htm'; // Relative to theme\r
-                                       template['width'] = 310;\r
-                                       template['height'] = 105 + (tinyMCE.isNS7 ? 25 : 0);\r
-                                       template['width'] += tinyMCE.getLang('lang_searchreplace_search_delta_width', 0);\r
-                                       template['height'] += tinyMCE.getLang('lang_searchreplace_replace_delta_height', 0);\r
-                               }\r
-\r
-                               tinyMCE.openWindow(template, value);\r
-                       } else {\r
-                               var win = tinyMCE.getInstanceById(editor_id).contentWindow;\r
-                               var doc = tinyMCE.getInstanceById(editor_id).contentWindow.document;\r
-                               var body = tinyMCE.getInstanceById(editor_id).contentWindow.document.body;\r
-\r
-                               // Whats the point\r
-                               if (body.innerHTML == "") {\r
-                                       alert(tinyMCE.getLang('lang_searchreplace_notfound'));\r
-                                       return true;\r
-                               }\r
-\r
-                               // Handle replace current\r
-                               if (value['replacemode'] == "current") {\r
-                                       replaceSel(value['string'], value['replacestring']);\r
-\r
-                                       // Search next one\r
-                                       value['replacemode'] = "none";\r
-                                       tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false);\r
-\r
-                                       return true;\r
-                               }\r
-\r
-                               if (tinyMCE.isMSIE) {\r
-                                       var rng = tinyMCE.lastSearchRng ? tinyMCE.lastSearchRng : doc.selection.createRange();\r
-                                       var flags = 0;\r
-\r
-                                       if (value['wholeword'])\r
-                                               flags = flags | 2;\r
-\r
-                                       if (value['casesensitive'])\r
-                                               flags = flags | 4;\r
-\r
-                                       if (!rng.findText) {\r
-                                               alert('This operation is currently not supported by this browser.');\r
-                                               return true;\r
-                                       }\r
-\r
-                                       // Handle replace all mode\r
-                                       if (value['replacemode'] == "all") {\r
-                                               while (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {\r
-                                                       rng.scrollIntoView();\r
-                                                       rng.select();\r
-                                                       rng.collapse(false);\r
-                                                       replaceSel(value['string'], value['replacestring']);\r
-                                               }\r
-\r
-                                               alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));\r
-                                               return true;\r
-                                       }\r
-\r
-                                       if (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {\r
-                                               rng.scrollIntoView();\r
-                                               rng.select();\r
-                                               rng.collapse(value['backwards']);\r
-                                               tinyMCE.lastSearchRng = rng;\r
-                                       } else\r
-                                               alert(tinyMCE.getLang('lang_searchreplace_notfound'));\r
-                               } else {\r
-                                       if (value['replacemode'] == "all") {\r
-                                               while (win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false))\r
-                                                       replaceSel(value['string'], value['replacestring']);\r
-\r
-                                               alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));\r
-                                               return true;\r
-                                       }\r
-\r
-                                       if (!win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false))\r
-                                               alert(tinyMCE.getLang('lang_searchreplace_notfound'));\r
-                               }\r
-                       }\r
-                       return true;\r
-\r
-               case "mceSearchReplace":\r
-                       value['replacestring'] = "";\r
-\r
-                       tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false);\r
-                       return true;\r
-       }\r
-\r
-       // Pass to next handler in chain\r
-       return false;\r
-}\r
+       });\r
 \r
-function TinyMCE_searchreplace_handleNodeChange(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {\r
-       return true;\r
-}\r
+       // Register plugin\r
+       tinymce.PluginManager.add('searchreplace', tinymce.plugins.SearchReplacePlugin);\r
+})();
\ No newline at end of file