annotate WebContent/jscripts/tiny_mce/plugins/searchreplace/js/searchreplace.js @ 5:0be9d53a6967

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