upz, forgot to take out comments
[boxroom-stian.git] / public / javascripts / tiny_mce / plugins / searchreplace / editor_plugin_src.js
blobf8aee25c60a09e6b4b9d697aad55efd1a132b665
1 /**
2 * $Id: editor_plugin_src.js 126 2006-10-22 16:19:55Z spocke $
4 * @author Moxiecode
5 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
6 */
8 tinyMCE.importPluginLanguagePack('searchreplace');
10 var TinyMCE_SearchReplacePlugin = {
11 getInfo : function() {
12 return {
13 longname : 'Search/Replace',
14 author : 'Moxiecode Systems AB',
15 authorurl : 'http://tinymce.moxiecode.com',
16 infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_searchreplace.html',
17 version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion
21 initInstance : function (inst) {
22 inst.addShortcut('ctrl', 'f', 'lang_searchreplace_search_desc', 'mceSearch', true);
23 // No CTRL+R for "replace" because browsers will reload page instead of executing plugin
26 getControlHTML : function (cn) {
27 switch (cn) {
28 case "search" :
29 return tinyMCE.getButtonHTML(cn, 'lang_searchreplace_search_desc', '{$pluginurl}/images/search.gif','mceSearch', true);
31 case "replace" :
32 return tinyMCE.getButtonHTML(cn, 'lang_searchreplace_replace_desc', '{$pluginurl}/images/replace.gif', 'mceSearchReplace', true);
35 return "";
38 execCommand : function (editor_id, element, command, user_interface, value) {
39 var inst = tinyMCE.getInstanceById(editor_id), selectedText = inst.selection.getSelectedText(), rng;
41 function defValue(key, default_value) {
42 value[key] = typeof(value[key]) == "undefined" ? default_value : value[key];
45 function replaceSel(search_str, str, back) {
46 inst.execCommand('mceInsertContent', false, str);
49 if (!value)
50 value = [];
52 defValue("editor_id", editor_id);
53 defValue("searchstring", selectedText);
54 defValue("replacestring", null);
55 defValue("replacemode", "none");
56 defValue("casesensitive", false);
57 defValue("backwards", false);
58 defValue("wrap", false);
59 defValue("wholeword", false);
60 defValue("inline", "yes");
61 defValue("resizable", "no");
63 switch (command) {
64 case "mceResetSearch" :
65 tinyMCE.lastSearchRng = null;
66 return true;
68 case "mceSearch" :
69 if (user_interface) {
70 var template = new Array();
72 template['file'] = '../../plugins/searchreplace/searchreplace.htm';
73 template['width'] = 380;
74 template['height'] = 155 + (tinyMCE.isNS7 ? 20 : 0) + (tinyMCE.isMSIE ? 15 : 0);
75 template['width'] += tinyMCE.getLang('lang_searchreplace_delta_width', 0);
76 template['height'] += tinyMCE.getLang('lang_searchreplace_delta_height', 0);
78 inst.execCommand('SelectAll');
80 if (tinyMCE.isMSIE) {
81 var r = inst.selection.getRng();
82 r.collapse(true);
83 r.select();
84 } else
85 inst.selection.getSel().collapseToStart();
87 tinyMCE.openWindow(template, value);
88 } else {
89 var win = tinyMCE.getInstanceById(editor_id).contentWindow;
90 var doc = tinyMCE.getInstanceById(editor_id).contentWindow.document;
91 var body = tinyMCE.getInstanceById(editor_id).contentWindow.document.body;
92 if (body.innerHTML == "") {
93 alert(tinyMCE.getLang('lang_searchreplace_notfound'));
94 return true;
97 if (value['replacemode'] == "current") {
98 replaceSel(value['string'], value['replacestring'], value['backwards']);
99 value['replacemode'] = "none";
100 tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false);
101 return true;
104 if (tinyMCE.isMSIE) {
105 var rng = tinyMCE.lastSearchRng ? tinyMCE.lastSearchRng : doc.selection.createRange();
106 var flags = 0;
107 if (value['wholeword'])
108 flags = flags | 2;
110 if (value['casesensitive'])
111 flags = flags | 4;
113 if (!rng.findText) {
114 alert('This operation is currently not supported by this browser.');
115 return true;
118 if (value['replacemode'] == "all") {
119 while (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {
120 rng.scrollIntoView();
121 rng.select();
122 rng.collapse(false);
123 replaceSel(value['string'], value['replacestring'], value['backwards']);
126 alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));
127 return true;
130 if (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {
131 rng.scrollIntoView();
132 rng.select();
133 rng.collapse(value['backwards']);
134 tinyMCE.lastSearchRng = rng;
135 } else
136 alert(tinyMCE.getLang('lang_searchreplace_notfound'));
138 } else {
139 if (value['replacemode'] == "all") {
140 while (win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false))
141 replaceSel(value['string'], value['replacestring'], value['backwards']);
143 alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));
144 return true;
147 if (!win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false))
148 alert(tinyMCE.getLang('lang_searchreplace_notfound'));
152 return true;
154 case "mceSearchReplace" :
155 value['replacestring'] = "";
156 tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false);
157 return true;
160 return false;
164 tinyMCE.addPlugin("searchreplace", TinyMCE_SearchReplacePlugin);