2 * $Id: editor_plugin_src.js 126 2006-10-22 16:19:55Z spocke $
5 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved.
8 tinyMCE
.importPluginLanguagePack('searchreplace');
10 var TinyMCE_SearchReplacePlugin
= {
11 getInfo : function() {
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
) {
29 return tinyMCE
.getButtonHTML(cn
, 'lang_searchreplace_search_desc', '{$pluginurl}/images/search.gif','mceSearch', true);
32 return tinyMCE
.getButtonHTML(cn
, 'lang_searchreplace_replace_desc', '{$pluginurl}/images/replace.gif', 'mceSearchReplace', true);
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
);
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");
64 case "mceResetSearch" :
65 tinyMCE
.lastSearchRng
= null;
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');
81 var r
= inst
.selection
.getRng();
85 inst
.selection
.getSel().collapseToStart();
87 tinyMCE
.openWindow(template
, value
);
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'));
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);
104 if (tinyMCE
.isMSIE
) {
105 var rng
= tinyMCE
.lastSearchRng
? tinyMCE
.lastSearchRng
: doc
.selection
.createRange();
107 if (value
['wholeword'])
110 if (value
['casesensitive'])
114 alert('This operation is currently not supported by this browser.');
118 if (value
['replacemode'] == "all") {
119 while (rng
.findText(value
['string'], value
['backwards'] ? -1 : 1, flags
)) {
120 rng
.scrollIntoView();
123 replaceSel(value
['string'], value
['replacestring'], value
['backwards']);
126 alert(tinyMCE
.getLang('lang_searchreplace_allreplaced'));
130 if (rng
.findText(value
['string'], value
['backwards'] ? -1 : 1, flags
)) {
131 rng
.scrollIntoView();
133 rng
.collapse(value
['backwards']);
134 tinyMCE
.lastSearchRng
= rng
;
136 alert(tinyMCE
.getLang('lang_searchreplace_notfound'));
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'));
147 if (!win
.find(value
['string'], value
['casesensitive'], value
['backwards'], value
['wrap'], value
['wholeword'], false, false))
148 alert(tinyMCE
.getLang('lang_searchreplace_notfound'));
154 case "mceSearchReplace" :
155 value
['replacestring'] = "";
156 tinyMCE
.execInstanceCommand(editor_id
, 'mceSearch', user_interface
, value
, false);
164 tinyMCE
.addPlugin("searchreplace", TinyMCE_SearchReplacePlugin
);