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