commit | author | age
|
d9344f
|
1 |
tinyMCEPopup.requireLangPack();
|
S |
2 |
|
|
3 |
var SearchReplaceDialog = {
|
|
4 |
init : function(ed) {
|
a9251b
|
5 |
var t = this, f = document.forms[0], m = tinyMCEPopup.getWindowArg("mode");
|
d9344f
|
6 |
|
a9251b
|
7 |
t.switchMode(m);
|
d9344f
|
8 |
|
S |
9 |
f[m + '_panel_searchstring'].value = tinyMCEPopup.getWindowArg("search_string");
|
|
10 |
|
|
11 |
// Focus input field
|
|
12 |
f[m + '_panel_searchstring'].focus();
|
a9251b
|
13 |
|
T |
14 |
mcTabs.onChange.add(function(tab_id, panel_id) {
|
|
15 |
t.switchMode(tab_id.substring(0, tab_id.indexOf('_')));
|
|
16 |
});
|
d9344f
|
17 |
},
|
S |
18 |
|
|
19 |
switchMode : function(m) {
|
|
20 |
var f, lm = this.lastMode;
|
|
21 |
|
|
22 |
if (lm != m) {
|
|
23 |
f = document.forms[0];
|
|
24 |
|
|
25 |
if (lm) {
|
|
26 |
f[m + '_panel_searchstring'].value = f[lm + '_panel_searchstring'].value;
|
|
27 |
f[m + '_panel_backwardsu'].checked = f[lm + '_panel_backwardsu'].checked;
|
|
28 |
f[m + '_panel_backwardsd'].checked = f[lm + '_panel_backwardsd'].checked;
|
|
29 |
f[m + '_panel_casesensitivebox'].checked = f[lm + '_panel_casesensitivebox'].checked;
|
|
30 |
}
|
|
31 |
|
|
32 |
mcTabs.displayTab(m + '_tab', m + '_panel');
|
|
33 |
document.getElementById("replaceBtn").style.display = (m == "replace") ? "inline" : "none";
|
|
34 |
document.getElementById("replaceAllBtn").style.display = (m == "replace") ? "inline" : "none";
|
|
35 |
this.lastMode = m;
|
|
36 |
}
|
|
37 |
},
|
|
38 |
|
|
39 |
searchNext : function(a) {
|
|
40 |
var ed = tinyMCEPopup.editor, se = ed.selection, r = se.getRng(), f, m = this.lastMode, s, b, fl = 0, w = ed.getWin(), wm = ed.windowManager, fo = 0;
|
|
41 |
|
|
42 |
// Get input
|
|
43 |
f = document.forms[0];
|
|
44 |
s = f[m + '_panel_searchstring'].value;
|
|
45 |
b = f[m + '_panel_backwardsu'].checked;
|
|
46 |
ca = f[m + '_panel_casesensitivebox'].checked;
|
|
47 |
rs = f['replace_panel_replacestring'].value;
|
|
48 |
|
a9251b
|
49 |
if (tinymce.isIE) {
|
T |
50 |
r = ed.getDoc().selection.createRange();
|
|
51 |
}
|
|
52 |
|
29da64
|
53 |
if (s == '')
|
A |
54 |
return;
|
|
55 |
|
d9344f
|
56 |
function fix() {
|
S |
57 |
// Correct Firefox graphics glitches
|
a9251b
|
58 |
// TODO: Verify if this is actually needed any more, maybe it was for very old FF versions?
|
d9344f
|
59 |
r = se.getRng().cloneRange();
|
S |
60 |
ed.getDoc().execCommand('SelectAll', false, null);
|
|
61 |
se.setRng(r);
|
|
62 |
};
|
|
63 |
|
|
64 |
function replace() {
|
a9251b
|
65 |
ed.selection.setContent(rs); // Needs to be duplicated due to selection bug in IE
|
d9344f
|
66 |
};
|
S |
67 |
|
|
68 |
// IE flags
|
|
69 |
if (ca)
|
|
70 |
fl = fl | 4;
|
|
71 |
|
|
72 |
switch (a) {
|
|
73 |
case 'all':
|
29da64
|
74 |
// Move caret to beginning of text
|
A |
75 |
ed.execCommand('SelectAll');
|
|
76 |
ed.selection.collapse(true);
|
|
77 |
|
d9344f
|
78 |
if (tinymce.isIE) {
|
a9251b
|
79 |
ed.focus();
|
T |
80 |
r = ed.getDoc().selection.createRange();
|
|
81 |
|
d9344f
|
82 |
while (r.findText(s, b ? -1 : 1, fl)) {
|
S |
83 |
r.scrollIntoView();
|
|
84 |
r.select();
|
|
85 |
replace();
|
|
86 |
fo = 1;
|
69d05c
|
87 |
|
A |
88 |
if (b) {
|
|
89 |
r.moveEnd("character", -(rs.length)); // Otherwise will loop forever
|
|
90 |
}
|
d9344f
|
91 |
}
|
S |
92 |
|
|
93 |
tinyMCEPopup.storeSelection();
|
|
94 |
} else {
|
|
95 |
while (w.find(s, ca, b, false, false, false, false)) {
|
|
96 |
replace();
|
|
97 |
fo = 1;
|
|
98 |
}
|
|
99 |
}
|
|
100 |
|
|
101 |
if (fo)
|
29da64
|
102 |
tinyMCEPopup.alert(ed.getLang('searchreplace_dlg.allreplaced'));
|
d9344f
|
103 |
else
|
29da64
|
104 |
tinyMCEPopup.alert(ed.getLang('searchreplace_dlg.notfound'));
|
d9344f
|
105 |
|
S |
106 |
return;
|
|
107 |
|
|
108 |
case 'current':
|
29da64
|
109 |
if (!ed.selection.isCollapsed())
|
A |
110 |
replace();
|
|
111 |
|
d9344f
|
112 |
break;
|
S |
113 |
}
|
|
114 |
|
|
115 |
se.collapse(b);
|
|
116 |
r = se.getRng();
|
|
117 |
|
|
118 |
// Whats the point
|
|
119 |
if (!s)
|
|
120 |
return;
|
|
121 |
|
|
122 |
if (tinymce.isIE) {
|
a9251b
|
123 |
ed.focus();
|
T |
124 |
r = ed.getDoc().selection.createRange();
|
|
125 |
|
d9344f
|
126 |
if (r.findText(s, b ? -1 : 1, fl)) {
|
S |
127 |
r.scrollIntoView();
|
|
128 |
r.select();
|
|
129 |
} else
|
29da64
|
130 |
tinyMCEPopup.alert(ed.getLang('searchreplace_dlg.notfound'));
|
d9344f
|
131 |
|
S |
132 |
tinyMCEPopup.storeSelection();
|
|
133 |
} else {
|
|
134 |
if (!w.find(s, ca, b, false, false, false, false))
|
29da64
|
135 |
tinyMCEPopup.alert(ed.getLang('searchreplace_dlg.notfound'));
|
d9344f
|
136 |
else
|
S |
137 |
fix();
|
|
138 |
}
|
|
139 |
}
|
|
140 |
};
|
|
141 |
|
|
142 |
tinyMCEPopup.onInit.add(SearchReplaceDialog.init, SearchReplaceDialog);
|