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
4 function TinyMCE_searchreplace_getInfo() {
\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
14 function TinyMCE_searchreplace_getControlHTML(control_name) {
\r
15 switch (control_name) {
\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
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
29 * Executes the search/replace commands.
\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
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
42 var rng = instance.contentWindow.document.selection.createRange();
\r
45 // Replace current one
\r
46 if (!tinyMCE.isMSIE) {
\r
47 var doc = instance.contentWindow.document;
\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
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
62 rng.item(0).outerHTML = str;
\r
68 var instance = tinyMCE.getInstanceById(editor_id);
\r
71 value = new Array();
\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
86 case "mceResetSearch":
\r
87 tinyMCE.lastSearchRng = null;
\r
91 if (user_interface) {
\r
92 // Open search dialog
\r
93 var template = new Array();
\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
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
109 tinyMCE.openWindow(template, value);
\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
116 if (body.innerHTML == "") {
\r
117 alert(tinyMCE.getLang('lang_searchreplace_notfound'));
\r
121 // Handle replace current
\r
122 if (value['replacemode'] == "current") {
\r
123 replaceSel(value['string'], value['replacestring']);
\r
126 value['replacemode'] = "none";
\r
127 tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false);
\r
132 if (tinyMCE.isMSIE) {
\r
133 var rng = tinyMCE.lastSearchRng ? tinyMCE.lastSearchRng : doc.selection.createRange();
\r
136 if (value['wholeword'])
\r
139 if (value['casesensitive'])
\r
142 if (!rng.findText) {
\r
143 alert('This operation is currently not supported by this browser.');
\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
152 rng.collapse(false);
\r
153 replaceSel(value['string'], value['replacestring']);
\r
156 alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));
\r
160 if (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {
\r
161 rng.scrollIntoView();
\r
163 rng.collapse(value['backwards']);
\r
164 tinyMCE.lastSearchRng = rng;
\r
166 alert(tinyMCE.getLang('lang_searchreplace_notfound'));
\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
172 alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));
\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
182 case "mceSearchReplace":
\r
183 value['replacestring'] = "";
\r
185 tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false);
\r
189 // Pass to next handler in chain
\r
193 function TinyMCE_searchreplace_handleNodeChange(editor_id, node, undo_index, undo_levels, visual_aid, any_selection) {
\r