2 * $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
\r
5 * @copyright Copyright © 2004-2007, Moxiecode Systems AB, All rights reserved.
\r
8 tinyMCE.importPluginLanguagePack('searchreplace');
\r
10 var TinyMCE_SearchReplacePlugin = {
\r
11 getInfo : function() {
\r
13 longname : 'Search/Replace',
\r
14 author : 'Moxiecode Systems AB',
\r
15 authorurl : 'http://tinymce.moxiecode.com',
\r
16 infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/searchreplace',
\r
17 version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
\r
21 initInstance : function (inst) {
\r
22 inst.addShortcut('ctrl', 'f', 'lang_searchreplace_search_desc', 'mceSearch', true);
\r
23 // No CTRL+R for "replace" because browsers will reload page instead of executing plugin
\r
26 getControlHTML : function (cn) {
\r
29 return tinyMCE.getButtonHTML(cn, 'lang_searchreplace_search_desc', '{$pluginurl}/images/search.gif','mceSearch', true);
\r
32 return tinyMCE.getButtonHTML(cn, 'lang_searchreplace_replace_desc', '{$pluginurl}/images/replace.gif', 'mceSearchReplace', true);
\r
38 execCommand : function (editor_id, element, command, user_interface, value) {
\r
39 var inst = tinyMCE.getInstanceById(editor_id), selectedText = inst.selection.getSelectedText(), rng;
\r
41 function defValue(key, default_value) {
\r
42 value[key] = typeof(value[key]) == "undefined" ? default_value : value[key];
\r
45 function replaceSel(search_str, str, back) {
\r
46 if (!inst.selection.isCollapsed()) {
\r
47 if (tinyMCE.isRealIE)
\r
48 inst.selection.getRng().duplicate().pasteHTML(str); // Needs to be duplicated due to selection bug in IE
\r
50 inst.execCommand('mceInsertContent', false, str);
\r
57 defValue("editor_id", editor_id);
\r
58 defValue("searchstring", selectedText);
\r
59 defValue("replacestring", null);
\r
60 defValue("replacemode", "none");
\r
61 defValue("casesensitive", false);
\r
62 defValue("backwards", false);
\r
63 defValue("wrap", false);
\r
64 defValue("wholeword", false);
\r
65 defValue("inline", "yes");
\r
66 defValue("resizable", "no");
\r
70 if (user_interface) {
\r
71 var template = new Array();
\r
73 template['file'] = '../../plugins/searchreplace/searchreplace.htm';
\r
74 template['width'] = 380;
\r
75 template['height'] = 155 + (tinyMCE.isNS7 ? 20 : 0) + (tinyMCE.isMSIE ? 15 : 0);
\r
76 template['width'] += tinyMCE.getLang('lang_searchreplace_delta_width', 0);
\r
77 template['height'] += tinyMCE.getLang('lang_searchreplace_delta_height', 0);
\r
79 inst.selection.collapse(true);
\r
81 tinyMCE.openWindow(template, value);
\r
83 var win = tinyMCE.getInstanceById(editor_id).contentWindow;
\r
84 var doc = tinyMCE.getInstanceById(editor_id).contentWindow.document;
\r
85 var body = tinyMCE.getInstanceById(editor_id).contentWindow.document.body;
\r
86 var awin = value.win, found;
\r
88 if (body.innerHTML == "") {
\r
89 awin.alert(tinyMCE.getLang('lang_searchreplace_notfound'));
\r
93 if (value['replacemode'] == "current") {
\r
94 replaceSel(value['string'], value['replacestring'], value['backwards']);
\r
95 value['replacemode'] = "none";
\r
96 //tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value);
\r
100 inst.selection.collapse(value['backwards']);
\r
102 if (tinyMCE.isMSIE) {
\r
103 var rng = inst.selection.getRng();
\r
105 if (value['wholeword'])
\r
108 if (value['casesensitive'])
\r
111 if (!rng.findText) {
\r
112 awin.alert('This operation is currently not supported by this browser.');
\r
116 if (value['replacemode'] == "all") {
\r
119 while (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {
\r
121 rng.scrollIntoView();
\r
123 replaceSel(value['string'], value['replacestring'], value['backwards']);
\r
127 awin.alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));
\r
129 awin.alert(tinyMCE.getLang('lang_searchreplace_notfound'));
\r
134 if (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {
\r
135 rng.scrollIntoView();
\r
138 awin.alert(tinyMCE.getLang('lang_searchreplace_notfound'));
\r
140 if (value['replacemode'] == "all") {
\r
143 while (win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false)) {
\r
145 replaceSel(value['string'], value['replacestring'], value['backwards']);
\r
149 awin.alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));
\r
151 awin.alert(tinyMCE.getLang('lang_searchreplace_notfound'));
\r
156 if (!win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false))
\r
157 awin.alert(tinyMCE.getLang('lang_searchreplace_notfound'));
\r
163 case "mceSearchReplace" :
\r
164 value['replacestring'] = "";
\r
165 tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false);
\r
173 tinyMCE.addPlugin("searchreplace", TinyMCE_SearchReplacePlugin);