comparison 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
comparison
equal deleted inserted replaced
4:c32080f364c6 5:0be9d53a6967
1 tinyMCEPopup.requireLangPack();
2
3 var SearchReplaceDialog = {
4 init : function(ed) {
5 var t = this, f = document.forms[0], m = tinyMCEPopup.getWindowArg("mode");
6
7 t.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 mcTabs.onChange.add(function(tab_id, panel_id) {
15 t.switchMode(tab_id.substring(0, tab_id.indexOf('_')));
16 });
17 },
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
49 if (tinymce.isIE) {
50 r = ed.getDoc().selection.createRange();
51 }
52
53 if (s == '')
54 return;
55
56 function fix() {
57 // Correct Firefox graphics glitches
58 // TODO: Verify if this is actually needed any more, maybe it was for very old FF versions?
59 r = se.getRng().cloneRange();
60 ed.getDoc().execCommand('SelectAll', false, null);
61 se.setRng(r);
62 };
63
64 function replace() {
65 ed.selection.setContent(rs); // Needs to be duplicated due to selection bug in IE
66 };
67
68 // IE flags
69 if (ca)
70 fl = fl | 4;
71
72 switch (a) {
73 case 'all':
74 // Move caret to beginning of text
75 ed.execCommand('SelectAll');
76 ed.selection.collapse(true);
77
78 if (tinymce.isIE) {
79 ed.focus();
80 r = ed.getDoc().selection.createRange();
81
82 while (r.findText(s, b ? -1 : 1, fl)) {
83 r.scrollIntoView();
84 r.select();
85 replace();
86 fo = 1;
87
88 if (b) {
89 r.moveEnd("character", -(rs.length)); // Otherwise will loop forever
90 }
91 }
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)
102 tinyMCEPopup.alert(ed.getLang('searchreplace_dlg.allreplaced'));
103 else
104 tinyMCEPopup.alert(ed.getLang('searchreplace_dlg.notfound'));
105
106 return;
107
108 case 'current':
109 if (!ed.selection.isCollapsed())
110 replace();
111
112 break;
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) {
123 ed.focus();
124 r = ed.getDoc().selection.createRange();
125
126 if (r.findText(s, b ? -1 : 1, fl)) {
127 r.scrollIntoView();
128 r.select();
129 } else
130 tinyMCEPopup.alert(ed.getLang('searchreplace_dlg.notfound'));
131
132 tinyMCEPopup.storeSelection();
133 } else {
134 if (!w.find(s, ca, b, false, false, false, false))
135 tinyMCEPopup.alert(ed.getLang('searchreplace_dlg.notfound'));
136 else
137 fix();
138 }
139 }
140 };
141
142 tinyMCEPopup.onInit.add(SearchReplaceDialog.init, SearchReplaceDialog);