1 /* Import theme specific language pack */
2 tinyMCE.importPluginLanguagePack('searchreplace', 'en,sv,zh_cn,fa,fr_ca,fr,de,pl,pt_br,cs,nl,da,he,no,hu');
4 function TinyMCE_searchreplace_getInfo() {
6 longname : 'Search/Replace',
7 author : 'Moxiecode Systems',
8 authorurl : 'http://tinymce.moxiecode.com',
9 infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_searchreplace.html',
10 version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
14 function TinyMCE_searchreplace_getControlHTML(control_name) {
15 switch (control_name) {
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>';
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>';
27 * Executes the search/replace commands.
29 function TinyMCE_searchreplace_execCommand(editor_id, element, command, user_interface, value) {
30 function defValue(key, default_value) {
31 value[key] = typeof(value[key]) == "undefined" ? default_value : value[key];
34 function replaceSel(search_str, str) {
35 // Get current selection
36 if (!tinyMCE.isMSIE) {
37 var sel = instance.contentWindow.getSelection();
38 var rng = sel.getRangeAt(0);
40 var rng = instance.contentWindow.document.selection.createRange();
43 // Replace current one
44 if (!tinyMCE.isMSIE) {
45 var doc = instance.contentWindow.document;
47 // This way works when the replace doesn't contain the search string
48 if (str.indexOf(search_str) == -1) {
50 rng.insertNode(rng.createContextualFragment(str));
53 // Insert content ugly way! Needed to move selection to after replace item
54 doc.execCommand("insertimage", false, "#mce_temp_url#");
55 var elm = tinyMCE.getElementByAttributeValue(doc.body, "img", "src", "#mce_temp_url#");
56 elm.parentNode.replaceChild(doc.createTextNode(str), elm);
60 rng.item(0).outerHTML = str;
66 var instance = tinyMCE.getInstanceById(editor_id);
71 // Setup defualt values
72 defValue("editor_id", editor_id);
73 defValue("searchstring", "");
74 defValue("replacestring", null);
75 defValue("replacemode", "none");
76 defValue("casesensitive", false);
77 defValue("backwards", false);
78 defValue("wrap", false);
79 defValue("wholeword", false);
80 defValue("inline", "yes");
84 case "mceResetSearch":
85 tinyMCE.lastSearchRng = null;
91 var template = new Array();
93 if (value['replacestring'] != null) {
94 template['file'] = '../../plugins/searchreplace/replace.htm'; // Relative to theme
95 template['width'] = 320;
96 template['height'] = 120;
97 template['width'] += tinyMCE.getLang('lang_searchreplace_replace_delta_width', 0);
98 template['height'] += tinyMCE.getLang('lang_searchreplace_replace_delta_height', 0);
100 template['file'] = '../../plugins/searchreplace/search.htm'; // Relative to theme
101 template['width'] = 310;
102 template['height'] = 105;
103 template['width'] += tinyMCE.getLang('lang_searchreplace_search_delta_width', 0);
104 template['height'] += tinyMCE.getLang('lang_searchreplace_replace_delta_height', 0);
107 tinyMCE.openWindow(template, value);
109 var win = tinyMCE.getInstanceById(editor_id).contentWindow;
110 var doc = tinyMCE.getInstanceById(editor_id).contentWindow.document;
111 var body = tinyMCE.getInstanceById(editor_id).contentWindow.document.body;
114 if (body.innerHTML == "") {
115 alert(tinyMCE.getLang('lang_searchreplace_notfound'));
119 // Handle replace current
120 if (value['replacemode'] == "current") {
121 replaceSel(value['string'], value['replacestring']);
124 value['replacemode'] = "none";
125 tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false);
130 if (tinyMCE.isMSIE) {
131 var rng = tinyMCE.lastSearchRng ? tinyMCE.lastSearchRng : doc.selection.createRange();
134 if (value['wholeword'])
137 if (value['casesensitive'])
140 // Handle replace all mode
141 if (value['replacemode'] == "all") {
142 while (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {
143 rng.scrollIntoView();
146 replaceSel(value['string'], value['replacestring']);
149 alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));
153 if (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {
154 rng.scrollIntoView();
156 rng.collapse(value['backwards']);
157 tinyMCE.lastSearchRng = rng;
159 alert(tinyMCE.getLang('lang_searchreplace_notfound'));
161 if (value['replacemode'] == "all") {
162 while (win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false))
163 replaceSel(value['string'], value['replacestring']);
165 alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));
169 if (!win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false))
170 alert(tinyMCE.getLang('lang_searchreplace_notfound'));
175 case "mceSearchReplace":
176 value['replacestring'] = "";
178 tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false);
182 // Pass to next handler in chain
186 function TinyMCE_searchreplace_handleNodeChange(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {