]> code.citadel.org Git - citadel.git/blobdiff - webcit/tiny_mce/plugins/searchreplace/editor_plugin_src.js
* Upgraded TinyMCE to v2.0.1; CLEAR YOUR CACHE NOW
[citadel.git] / webcit / tiny_mce / plugins / searchreplace / editor_plugin_src.js
diff --git a/webcit/tiny_mce/plugins/searchreplace/editor_plugin_src.js b/webcit/tiny_mce/plugins/searchreplace/editor_plugin_src.js
new file mode 100644 (file)
index 0000000..7a7dde7
--- /dev/null
@@ -0,0 +1,195 @@
+/* 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
+ */\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
+               }\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
+function TinyMCE_searchreplace_handleNodeChange(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {\r
+       return true;\r
+}\r