re-added binary
[citadel.git] / webcit / tiny_mce / plugins / searchreplace / editor_plugin_src.js
1 /* Import theme specific language pack */\r
2 tinyMCE.importPluginLanguagePack('searchreplace', 'en,sv,zh_cn,fa,fr_ca,fr,de,pl,pt_br,cs,nl,da,he,no,hu');\r
3 \r
4 function TinyMCE_searchreplace_getInfo() {\r
5         return {\r
6                 longname : 'Search/Replace',\r
7                 author : 'Moxiecode Systems',\r
8                 authorurl : 'http://tinymce.moxiecode.com',\r
9                 infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_searchreplace.html',\r
10                 version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion\r
11         };\r
12 };\r
13 \r
14 function TinyMCE_searchreplace_getControlHTML(control_name)     {\r
15         switch (control_name) {\r
16                 case "search":\r
17                         return '<a href="javascript:tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mceSearch\',true);" 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
18 \r
19                 case "replace":\r
20                         return '<a href="javascript:tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mceSearchReplace\',true);" 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
21         }\r
22 \r
23         return "";\r
24 }\r
25 \r
26 /**\r
27  * Executes     the     search/replace commands.\r
28  */\r
29 function TinyMCE_searchreplace_execCommand(editor_id, element, command, user_interface, value) {\r
30         function defValue(key, default_value) {\r
31                 value[key] = typeof(value[key]) == "undefined" ? default_value : value[key];\r
32         }\r
33 \r
34         function replaceSel(search_str, str) {\r
35                 // Get current selection\r
36                 if (!tinyMCE.isMSIE) {\r
37                         var sel = instance.contentWindow.getSelection();\r
38                         var rng = sel.getRangeAt(0);\r
39                 } else {\r
40                         var rng = instance.contentWindow.document.selection.createRange();\r
41                 }\r
42 \r
43                 // Replace current one\r
44                 if (!tinyMCE.isMSIE) {\r
45                         var doc = instance.contentWindow.document;\r
46 \r
47                         // This way works when the replace doesn't contain the search string\r
48                         if (str.indexOf(search_str) == -1) {\r
49                                 rng.deleteContents();\r
50                                 rng.insertNode(rng.createContextualFragment(str));\r
51                                 rng.collapse(false);\r
52                         } else {\r
53                                 // Insert content ugly way! Needed to move selection to after replace item\r
54                                 doc.execCommand("insertimage", false, "#mce_temp_url#");\r
55                                 var elm = tinyMCE.getElementByAttributeValue(doc.body, "img", "src", "#mce_temp_url#");\r
56                                 elm.parentNode.replaceChild(doc.createTextNode(str), elm);\r
57                         }\r
58                 } else {\r
59                         if (rng.item)\r
60                                 rng.item(0).outerHTML = str;\r
61                         else\r
62                                 rng.pasteHTML(str);\r
63                 }\r
64         }\r
65 \r
66         var instance = tinyMCE.getInstanceById(editor_id);\r
67 \r
68         if (!value)\r
69                 value = new Array();\r
70 \r
71         // Setup defualt values\r
72         defValue("editor_id", editor_id);\r
73         defValue("searchstring", "");\r
74         defValue("replacestring", null);\r
75         defValue("replacemode", "none");\r
76         defValue("casesensitive", false);\r
77         defValue("backwards", false);\r
78         defValue("wrap", false);\r
79         defValue("wholeword", false);\r
80         defValue("inline", "yes");\r
81 \r
82         // Handle commands\r
83         switch (command) {\r
84                 case "mceResetSearch":\r
85                         tinyMCE.lastSearchRng = null;\r
86                         return true;\r
87 \r
88                 case "mceSearch":\r
89                         if (user_interface) {\r
90                                 // Open search dialog\r
91                                 var template = new Array();\r
92 \r
93                                 if (value['replacestring'] != null) {\r
94                                         template['file'] = '../../plugins/searchreplace/replace.htm'; // Relative to theme\r
95                                         template['width'] = 320;\r
96                                         template['height'] = 120;\r
97                                         template['width'] += tinyMCE.getLang('lang_searchreplace_replace_delta_width', 0);\r
98                                         template['height'] += tinyMCE.getLang('lang_searchreplace_replace_delta_height', 0);\r
99                                 } else {\r
100                                         template['file'] = '../../plugins/searchreplace/search.htm'; // Relative to theme\r
101                                         template['width'] = 310;\r
102                                         template['height'] = 105;\r
103                                         template['width'] += tinyMCE.getLang('lang_searchreplace_search_delta_width', 0);\r
104                                         template['height'] += tinyMCE.getLang('lang_searchreplace_replace_delta_height', 0);\r
105                                 }\r
106 \r
107                                 tinyMCE.openWindow(template, value);\r
108                         } else {\r
109                                 var win = tinyMCE.getInstanceById(editor_id).contentWindow;\r
110                                 var doc = tinyMCE.getInstanceById(editor_id).contentWindow.document;\r
111                                 var body = tinyMCE.getInstanceById(editor_id).contentWindow.document.body;\r
112 \r
113                                 // Whats the point\r
114                                 if (body.innerHTML == "") {\r
115                                         alert(tinyMCE.getLang('lang_searchreplace_notfound'));\r
116                                         return true;\r
117                                 }\r
118 \r
119                                 // Handle replace current\r
120                                 if (value['replacemode'] == "current") {\r
121                                         replaceSel(value['string'], value['replacestring']);\r
122 \r
123                                         // Search next one\r
124                                         value['replacemode'] = "none";\r
125                                         tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false);\r
126 \r
127                                         return true;\r
128                                 }\r
129 \r
130                                 if (tinyMCE.isMSIE) {\r
131                                         var rng = tinyMCE.lastSearchRng ? tinyMCE.lastSearchRng : doc.selection.createRange();\r
132                                         var flags = 0;\r
133 \r
134                                         if (value['wholeword'])\r
135                                                 flags = flags | 2;\r
136 \r
137                                         if (value['casesensitive'])\r
138                                                 flags = flags | 4;\r
139 \r
140                                         // Handle replace all mode\r
141                                         if (value['replacemode'] == "all") {\r
142                                                 while (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {\r
143                                                         rng.scrollIntoView();\r
144                                                         rng.select();\r
145                                                         rng.collapse(false);\r
146                                                         replaceSel(value['string'], value['replacestring']);\r
147                                                 }\r
148 \r
149                                                 alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));\r
150                                                 return true;\r
151                                         }\r
152 \r
153                                         if (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {\r
154                                                 rng.scrollIntoView();\r
155                                                 rng.select();\r
156                                                 rng.collapse(value['backwards']);\r
157                                                 tinyMCE.lastSearchRng = rng;\r
158                                         } else\r
159                                                 alert(tinyMCE.getLang('lang_searchreplace_notfound'));\r
160                                 } else {\r
161                                         if (value['replacemode'] == "all") {\r
162                                                 while (win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false))\r
163                                                         replaceSel(value['string'], value['replacestring']);\r
164 \r
165                                                 alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));\r
166                                                 return true;\r
167                                         }\r
168 \r
169                                         if (!win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false))\r
170                                                 alert(tinyMCE.getLang('lang_searchreplace_notfound'));\r
171                                 }\r
172                         }\r
173                         return true;\r
174 \r
175                 case "mceSearchReplace":\r
176                         value['replacestring'] = "";\r
177 \r
178                         tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false);\r
179                         return true;\r
180         }\r
181 \r
182         // Pass to next handler in chain\r
183         return false;\r
184 }\r
185 \r
186 function TinyMCE_searchreplace_handleNodeChange(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {\r
187         return true;\r
188 }\r