2
* $Id: editor_plugin_src.js 201 2007-02-12 15:56:56Z spocke $
5
* @copyright Copyright ďż˝ 2004-2007, 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://wiki.moxiecode.com/index.php/TinyMCE:Plugins/searchreplace',
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
if (!inst.selection.isCollapsed()) {
48
inst.selection.getRng().duplicate().pasteHTML(str); // Needs to be duplicated due to selection bug in IE
50
inst.execCommand('mceInsertContent', false, str);
57
defValue("editor_id", editor_id);
58
defValue("searchstring", selectedText);
59
defValue("replacestring", null);
60
defValue("replacemode", "none");
61
defValue("casesensitive", false);
62
defValue("backwards", false);
63
defValue("wrap", false);
64
defValue("wholeword", false);
65
defValue("inline", "yes");
66
defValue("resizable", "no");
71
var template = new Array();
73
template['file'] = '../../plugins/searchreplace/searchreplace.htm';
74
template['width'] = 380;
75
template['height'] = 155 + (tinyMCE.isNS7 ? 20 : 0) + (tinyMCE.isMSIE ? 15 : 0);
76
template['width'] += tinyMCE.getLang('lang_searchreplace_delta_width', 0);
77
template['height'] += tinyMCE.getLang('lang_searchreplace_delta_height', 0);
79
inst.selection.collapse(true);
81
tinyMCE.openWindow(template, value);
83
var win = tinyMCE.getInstanceById(editor_id).contentWindow;
84
var doc = tinyMCE.getInstanceById(editor_id).contentWindow.document;
85
var body = tinyMCE.getInstanceById(editor_id).contentWindow.document.body;
86
var awin = value.win, found;
88
if (body.innerHTML == "") {
89
awin.alert(tinyMCE.getLang('lang_searchreplace_notfound'));
93
if (value['replacemode'] == "current") {
94
replaceSel(value['string'], value['replacestring'], value['backwards']);
95
value['replacemode'] = "none";
96
//tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value);
100
inst.selection.collapse(value['backwards']);
102
if (tinyMCE.isMSIE) {
103
var rng = inst.selection.getRng();
105
if (value['wholeword'])
108
if (value['casesensitive'])
112
awin.alert('This operation is currently not supported by this browser.');
116
if (value['replacemode'] == "all") {
119
while (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {
121
rng.scrollIntoView();
123
replaceSel(value['string'], value['replacestring'], value['backwards']);
127
awin.alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));
129
awin.alert(tinyMCE.getLang('lang_searchreplace_notfound'));
134
if (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) {
135
rng.scrollIntoView();
138
awin.alert(tinyMCE.getLang('lang_searchreplace_notfound'));
140
if (value['replacemode'] == "all") {
143
while (win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false)) {
145
replaceSel(value['string'], value['replacestring'], value['backwards']);
149
awin.alert(tinyMCE.getLang('lang_searchreplace_allreplaced'));
151
awin.alert(tinyMCE.getLang('lang_searchreplace_notfound'));
156
if (!win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false))
157
awin.alert(tinyMCE.getLang('lang_searchreplace_notfound'));
163
case "mceSearchReplace" :
164
value['replacestring'] = "";
165
tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false);
173
tinyMCE.addPlugin("searchreplace", TinyMCE_SearchReplacePlugin);
b'\\ No newline at end of file'