searchreplace.js
3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
function init() {
tinyMCEPopup.resizeToInnerSize();
// start with appropiate tab
var task = (tinyMCE.getWindowArg("replacestring") != null) ? "replace" : "search";
mcTabs.displayTab(task + '_tab', task +'_panel');
manageReplaceButtons();
var formObj = document.forms[0];
formObj[task + "_panel_searchstring"].value = tinyMCE.getWindowArg("searchstring");
formObj["replace_panel_replacestring"].value = (tinyMCE.getWindowArg("replacestring") != null) ? tinyMCE.getWindowArg("replacestring") : "";
formObj[task + "_panel_casesensitivebox"].checked = tinyMCE.getWindowArg("casesensitive");
formObj[task + "_panel_backwardsu"].checked = tinyMCE.getWindowArg("backwards");
formObj[task + "_panel_backwardsd"].checked = !tinyMCE.getWindowArg("backwards");
tinyMCEPopup.execCommand("mceResetSearch", false, {dummy : ""}, false);
}
function searchNext(replacemode) {
// "search" or "replace" mode of operation?
var task = (document.getElementById("search_tab").className == "current") ? "search" : "replace";
var formObj = document.forms[0];
if (task == "replace") {
// Whats the point?
if (formObj[task + "_panel_searchstring"].value == "" || formObj[task + "_panel_searchstring"].value == formObj[task + "_panel_replacestring"].value)
return;
}
// Do search
tinyMCEPopup.execCommand('mceSearch', false, {
string : formObj[task + "_panel_searchstring"].value,
replacestring : formObj["replace_panel_replacestring"].value,
replacemode : replacemode,
casesensitive : formObj[task + "_panel_casesensitivebox"].checked,
backwards : false
}, false);
window.focus();
}
function cancelAction() {
tinyMCEPopup.close();
}
function manageReplaceButtons() {
// "search" or "replace" mode of operation?
var task = (document.getElementById("search_tab").className == "current") ? "search" : "replace";
document.getElementById("replace_buttons").style.visibility = (task == "replace") ? "visible" : "hidden";
}
function copyValues(link) {
// check if tab is already active
var tab = link;
while (tab.tagName && tab.tagName.toLowerCase() != "li") tab = tab.parentNode;
if (tab.className) return false; // tab is already active -> no need to copy any values!
// copy values from one panel to the other (if they exist there)
var from_panel_name = tab.id.match(/^search/i) ? "replace_panel" : "search_panel";
var to_panel_name = (from_panel_name == "search_panel") ? "replace_panel" : "search_panel";
// find all elements with IDs to copy their values
var elms = document.getElementById(from_panel_name).getElementsByTagName("*");
for (var i = 0; i < elms.length; i++) {
if (elms[i].id && elms[i].id != "") {
var checked = "undefined";
if (elms[i].type.toLowerCase() == "checkbox" || elms[i].type.toLowerCase() == "radio")
checked = elms[i].checked;
// copy values if element exists in other panel
var to_elm_name = to_panel_name + elms[i].id.substring(from_panel_name.length, elms[i].id.length);
var to_elm = document.getElementById(to_elm_name);
if (to_elm) {
if (checked != "undefined")
to_elm.checked = checked;
else
to_elm.value = elms[i].value;
}
}
}
return false;
}