src/crypto.c: possible fix for memory leak related
[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,nb,hu,ru,ru_KOI8-R,ru_UTF-8,nn,fi,cy,es,is,zh_tw,zh_tw_utf8,sk');\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                         var cmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mceSearch\',true);return false;';\r
18                         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
19 \r
20                 case "replace":\r
21                         var cmd = 'tinyMCE.execInstanceCommand(\'{$editor_id}\',\'mceSearchReplace\',true);return false;';\r
22                         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
23         }\r
24 \r
25         return "";\r
26 }\r
27 \r
28 /**\r
29  * Executes     the     search/replace commands.\r
30  */\r
31 function TinyMCE_searchreplace_execCommand(editor_id, element, command, user_interface, value) {\r
32         function defValue(key, default_value) {\r
33                 value[key] = typeof(value[key]) == "undefined" ? default_value : value[key];\r
34         }\r
35 \r
36         function replaceSel(search_str, str) {\r
37                 // Get current selection\r
38                 if (!tinyMCE.isMSIE) {\r
39                         var sel = instance.contentWindow.getSelection();\r
40                         var rng = sel.getRangeAt(0);\r
41                 } else {\r
42                         var rng = instance.contentWindow.document.selection.createRange();\r
43                 }\r
44 \r
45                 // Replace current one\r
46                 if (!tinyMCE.isMSIE) {\r
47                         var doc = instance.contentWindow.document;\r
48 \r
49                         // This way works when the replace doesn't contain the search string\r
50                         if (str.indexOf(search_str) == -1) {\r
51                                 rng.deleteContents();\r
52                                 rng.insertNode(rng.createContextualFragment(str));\r
53                                 rng.collapse(false);\r
54                         } else {\r
55                                 // Insert content ugly way! Needed to move selection to after replace item\r
56                                 doc.execCommand("insertimage", false, "#mce_temp_url#");\r
57                                 var elm = tinyMCE.getElementByAttributeValue(doc.body, "img", "src", "#mce_temp_url#");\r
58                                 elm.parentNode.replaceChild(doc.createTextNode(str), elm);\r
59                         }\r
60                 } else {\r
61                         if (rng.item)\r
62                                 rng.item(0).outerHTML = str;\r
63                         else\r
64                                 rng.pasteHTML(str);\r
65                 }\r
66         }\r
67 \r
68         var instance = tinyMCE.getInstanceById(editor_id);\r
69 \r
70         if (!value)\r
71                 value = new Array();\r
72 \r
73         // Setup defualt values\r
74         defValue("editor_id", editor_id);\r
75         defValue("searchstring", "");\r
76         defValue("replacestring", null);\r
77         defValue("replacemode", "none");\r
78         defValue("casesensitive", false);\r
79         defValue("backwards", false);\r
80         defValue("wrap", false);\r
81         defValue("wholeword", false);\r
82         defValue("inline", "yes");\r
83 \r
84         // Handle commands\r
85         switch (command) {\r
86                 case "mceResetSearch":\r
87                         tinyMCE.lastSearchRng = null;\r
88                         return true;\r
89 \r
90                 case "mceSearch":\r
91                         if (user_interface) {\r
92                                 // Open search dialog\r
93                                 var template = new Array();\r
94 \r
95                                 if (value['replacestring'] != null) {\r
96                                         template['file'] = '../../plugins/searchreplace/replace.htm'; // Relative to theme\r
97                                         template['width'] = 320;\r
98                                         template['height'] = 120 + (tinyMCE.isNS7 ? 20 : 0);\r
99                                         template['width'] += tinyMCE.getLang('lang_searchreplace_replace_delta_width', 0);\r
100                                         template['height'] += tinyMCE.getLang('lang_searchreplace_replace_delta_height', 0);\r
101                                 } else {\r
102                                         template['file'] = '../../plugins/searchreplace/search.htm'; // Relative to theme\r
103                                         template['width'] = 310;\r
104                                         template['height'] = 105 + (tinyMCE.isNS7 ? 25 : 0);\r
105                                         template['width'] += tinyMCE.getLang('lang_searchreplace_search_delta_width', 0);\r
106                                         template['height'] += tinyMCE.getLang('lang_searchreplace_replace_delta_height', 0);\r
107                                 }\r
108 \r
109                                 tinyMCE.openWindow(template, value);\r
110                         } else {\r
111                                 var win = tinyMCE.getInstanceById(editor_id).contentWindow;\r
112                                 var doc = tinyMCE.getInstanceById(editor_id).contentWindow.document;\r
113                                 var body = tinyMCE.getInstanceById(editor_id).contentWindow.document.body;\r
114 \r
115                                 // Whats the point\r
116                                 if (body.innerHTML == "") {\r
117                                         alert(tinyMCE.getLang('lang_searchreplace_notfound'));\r
118                                         return true;\r
119                                 }\r
120 \r
121                                 // Handle replace current\r
122                                 if (value['replacemode'] == "current") {\r
123                                         replaceSel(value['string'], value['replacestring']);\r
124 \r
125                                         // Search next one\r
126                                         value['replacemode'] = "none";\r
127                                         tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false);\r
128 \r
129                                         return true;\r
130                                 }\r
131 \r
132                                 if (tinyMCE.isMSIE) {\r
133                                         var rng = tinyMCE.lastSearchRng ? tinyMCE.lastSearchRng : doc.selection.createRange();\r
134                                         var flags = 0;\r
135 \r
136                                         if (value['wholeword'])\r
137                                                 flags = flags | 2;\r
138 \r
139                                         if (value['casesensitive'])\r
140                                                 flags = flags | 4;\r
141 \r
142                                         if (!rng.findText) {\r
143                                                 alert('This operation is currently not supported by this browser.');\r
144                                                 return true;\r
145                                         }\r
146 \r
147                                         // Handle replace all mode\r
148                                         if (value['replacemode'] == "all") {\r
149                                                 while (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {\r
150                                                         rng.scrollIntoView();\r
151                                                         rng.select();\r
152                                                         rng.collapse(false);\r
153                                                         replaceSel(value['string'], value['replacestring']);\r
154                                                 }\r
155 \r
156                                                 alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));\r
157                                                 return true;\r
158                                         }\r
159 \r
160                                         if (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {\r
161                                                 rng.scrollIntoView();\r
162                                                 rng.select();\r
163                                                 rng.collapse(value['backwards']);\r
164                                                 tinyMCE.lastSearchRng = rng;\r
165                                         } else\r
166                                                 alert(tinyMCE.getLang('lang_searchreplace_notfound'));\r
167                                 } else {\r
168                                         if (value['replacemode'] == "all") {\r
169                                                 while (win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false))\r
170                                                         replaceSel(value['string'], value['replacestring']);\r
171 \r
172                                                 alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));\r
173                                                 return true;\r
174                                         }\r
175 \r
176                                         if (!win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false))\r
177                                                 alert(tinyMCE.getLang('lang_searchreplace_notfound'));\r
178                                 }\r
179                         }\r
180                         return true;\r
181 \r
182                 case "mceSearchReplace":\r
183                         value['replacestring'] = "";\r
184 \r
185                         tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false);\r
186                         return true;\r
187         }\r
188 \r
189         // Pass to next handler in chain\r
190         return false;\r
191 }\r
192 \r
193 function TinyMCE_searchreplace_handleNodeChange(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {\r
194         return true;\r
195 }\r