1 /* Import theme specific language pack */
2 tinyMCE.importPluginLanguagePack('searchreplace', 'en,sv,zh_cn,fa,fr_ca,fr,de,pl,pt_br,cs,nl');
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);" 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);" 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;
98 template['file'] = '../../plugins/searchreplace/search.htm'; // Relative to theme
99 template['width'] = 310;
100 template['height'] = 105;
103 tinyMCE.openWindow(template, value);
105 var win = tinyMCE.getInstanceById(editor_id).contentWindow;
106 var doc = tinyMCE.getInstanceById(editor_id).contentWindow.document;
107 var body = tinyMCE.getInstanceById(editor_id).contentWindow.document.body;
110 if (body.innerHTML == "") {
111 alert(tinyMCE.getLang('lang_searchreplace_notfound'));
115 // Handle replace current
116 if (value['replacemode'] == "current") {
117 replaceSel(value['string'], value['replacestring']);
120 value['replacemode'] = "none";
121 tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false);
126 if (tinyMCE.isMSIE) {
127 var rng = tinyMCE.lastSearchRng ? tinyMCE.lastSearchRng : doc.selection.createRange();
130 if (value['wholeword'])
133 if (value['casesensitive'])
136 // Handle replace all mode
137 if (value['replacemode'] == "all") {
138 while (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {
139 rng.scrollIntoView();
142 replaceSel(value['string'], value['replacestring']);
145 alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));
149 if (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {
150 rng.scrollIntoView();
152 rng.collapse(value['backwards']);
153 tinyMCE.lastSearchRng = rng;
155 alert(tinyMCE.getLang('lang_searchreplace_notfound'));
157 if (value['replacemode'] == "all") {
158 while (win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false))
159 replaceSel(value['string'], value['replacestring']);
161 alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));
165 if (!win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false))
166 alert(tinyMCE.getLang('lang_searchreplace_notfound'));
171 case "mceSearchReplace":
172 value['replacestring'] = "";
174 tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false);
178 // Pass to next handler in chain
182 function TinyMCE_searchreplace_handleNodeChange(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {