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