Upgrade TinyMCE to v3.4.5
[citadel.git] / webcit / tiny_mce / plugins / searchreplace / editor_plugin_src.js
old mode 100755 (executable)
new mode 100644 (file)
index cd2f3a8..4c87e8f
 /**\r
- * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $\r
+ * editor_plugin_src.js\r
  *\r
- * @author Moxiecode\r
- * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.\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
 \r
-tinyMCE.importPluginLanguagePack('searchreplace');\r
-\r
-var TinyMCE_SearchReplacePlugin = {\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
-       initInstance : function (inst) {\r
-               inst.addShortcut('ctrl', 'f', 'lang_searchreplace_search_desc', 'mceSearch', true);\r
-               // No CTRL+R for "replace" because browsers will reload page instead of executing plugin\r
-       },\r
-\r
-       getControlHTML : function (cn) {\r
-               switch (cn) {\r
-                       case "search" :\r
-                               return tinyMCE.getButtonHTML(cn, 'lang_searchreplace_search_desc', '{$pluginurl}/images/search.gif','mceSearch', true);\r
-\r
-                       case "replace" :\r
-                               return tinyMCE.getButtonHTML(cn, 'lang_searchreplace_replace_desc', '{$pluginurl}/images/replace.gif', 'mceSearchReplace', true);\r
-               }\r
-\r
-               return "";\r
-       },\r
-\r
-       execCommand : function (editor_id, element, command, user_interface, value) {\r
-               var inst = tinyMCE.getInstanceById(editor_id), selectedText = inst.selection.getSelectedText(), rng;\r
-\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, back) {\r
-                       if (!inst.selection.isCollapsed()) {\r
-                               if (tinyMCE.isRealIE)\r
-                                       inst.selection.getRng().duplicate().pasteHTML(str); // Needs to be duplicated due to selection bug in IE\r
-                               else\r
-                                       inst.execCommand('mceInsertContent', false, str);\r
-                       }\r
-               }\r
-\r
-               if (!value)\r
-                       value = [];\r
-\r
-               defValue("editor_id", editor_id);\r
-               defValue("searchstring", selectedText);\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
-               defValue("resizable", "no");\r
-\r
-               switch (command) {\r
-                       case "mceSearch" :\r
-                               if (user_interface) {\r
-                                       var template = new Array();\r
-\r
-                                       template['file'] = '../../plugins/searchreplace/searchreplace.htm';\r
-                                       template['width'] = 380;\r
-                                       template['height'] = 155 + (tinyMCE.isNS7 ? 20 : 0) + (tinyMCE.isMSIE ? 15 : 0);\r
-                                       template['width'] += tinyMCE.getLang('lang_searchreplace_delta_width', 0);\r
-                                       template['height'] += tinyMCE.getLang('lang_searchreplace_delta_height', 0);\r
-\r
-                                       inst.selection.collapse(true);\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
-                                       var awin = value.win, found;\r
-\r
-                                       if (body.innerHTML == "") {\r
-                                               awin.alert(tinyMCE.getLang('lang_searchreplace_notfound'));\r
-                                               return true;\r
-                                       }\r
-\r
-                                       if (value['replacemode'] == "current") {\r
-                                               replaceSel(value['string'], value['replacestring'], value['backwards']);\r
-                                               value['replacemode'] = "none";\r
-                                               //tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value);\r
-                                               //return true;\r
-                                       }\r
-\r
-                                       inst.selection.collapse(value['backwards']);\r
-\r
-                                       if (tinyMCE.isMSIE) {\r
-                                               var rng = inst.selection.getRng();\r
-                                               var flags = 0;\r
-                                               if (value['wholeword'])\r
-                                                       flags = flags | 2;\r
-\r
-                                               if (value['casesensitive'])\r
-                                                       flags = flags | 4;\r
-\r
-                                               if (!rng.findText) {\r
-                                                       awin.alert('This operation is currently not supported by this browser.');\r
-                                                       return true;\r
-                                               }\r
-\r
-                                               if (value['replacemode'] == "all") {\r
-                                                       found = false;\r
-\r
-                                                       while (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {\r
-                                                               found = true;\r
-                                                               rng.scrollIntoView();\r
-                                                               rng.select();\r
-                                                               replaceSel(value['string'], value['replacestring'], value['backwards']);\r
-                                                       }\r
-\r
-                                                       if (found)\r
-                                                               awin.alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));\r
-                                                       else\r
-                                                               awin.alert(tinyMCE.getLang('lang_searchreplace_notfound'));\r
-\r
-                                                       return true;\r
-                                               }\r
-\r
-                                               if (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {\r
-                                                       rng.scrollIntoView();\r
-                                                       rng.select();\r
-                                               } else\r
-                                                       awin.alert(tinyMCE.getLang('lang_searchreplace_notfound'));\r
-                                       } else {\r
-                                               if (value['replacemode'] == "all") {\r
-                                                       found = false;\r
-\r
-                                                       while (win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false)) {\r
-                                                               found = true;\r
-                                                               replaceSel(value['string'], value['replacestring'], value['backwards']);\r
-                                                       }\r
-\r
-                                                       if (found)\r
-                                                               awin.alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));\r
-                                                       else\r
-                                                               awin.alert(tinyMCE.getLang('lang_searchreplace_notfound'));\r
-\r
-                                                       return true;\r
-                                               }\r
-\r
-                                               if (!win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false))\r
-                                                       awin.alert(tinyMCE.getLang('lang_searchreplace_notfound'));\r
-                                       }\r
-                               }\r
-\r
-                               return true;\r
-\r
-                       case "mceSearchReplace" :\r
-                               value['replacestring'] = "";\r
-                               tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false);\r
-                               return true;\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
-               return false;\r
-       }\r
-};\r
-\r
-tinyMCE.addPlugin("searchreplace", TinyMCE_SearchReplacePlugin);
\ No newline at end of file
+       // Register plugin\r
+       tinymce.PluginManager.add('searchreplace', tinymce.plugins.SearchReplacePlugin);\r
+})();
\ No newline at end of file