includes/clientside/tinymce/plugins/searchreplace/js/searchreplace.js
changeset 335 67bd3121a12e
child 459 31c23016ab62
equal deleted inserted replaced
334:c72b545f1304 335:67bd3121a12e
       
     1 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 
       
    12 	switchMode : function(m) {
       
    13 		var f, lm = this.lastMode;
       
    14 
       
    15 		if (lm != m) {
       
    16 			f = document.forms[0];
       
    17 
       
    18 			if (lm) {
       
    19 				f[m + '_panel_searchstring'].value = f[lm + '_panel_searchstring'].value;
       
    20 				f[m + '_panel_backwardsu'].checked = f[lm + '_panel_backwardsu'].checked;
       
    21 				f[m + '_panel_backwardsd'].checked = f[lm + '_panel_backwardsd'].checked;
       
    22 				f[m + '_panel_casesensitivebox'].checked = f[lm + '_panel_casesensitivebox'].checked;
       
    23 			}
       
    24 
       
    25 			mcTabs.displayTab(m + '_tab',  m + '_panel');
       
    26 			document.getElementById("replace_buttons").style.visibility = (m == "replace") ? "visible" : "hidden";
       
    27 			this.lastMode = m;
       
    28 		}
       
    29 	},
       
    30 
       
    31 	searchNext : function(a) {
       
    32 		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;
       
    33 
       
    34 		// Get input
       
    35 		f = document.forms[0];
       
    36 		s = f[m + '_panel_searchstring'].value;
       
    37 		b = f[m + '_panel_backwardsu'].checked;
       
    38 		ca = f[m + '_panel_casesensitivebox'].checked;
       
    39 		rs = f['replace_panel_replacestring'].value;
       
    40 
       
    41 		function fix() {
       
    42 			// Correct Firefox graphics glitches
       
    43 			r = se.getRng().cloneRange();
       
    44 			ed.getDoc().execCommand('SelectAll', false, null);
       
    45 			se.setRng(r);
       
    46 		};
       
    47 
       
    48 		function replace() {
       
    49 			if (tinymce.isIE)
       
    50 				ed.selection.getRng().duplicate().pasteHTML(rs); // Needs to be duplicated due to selection bug in IE
       
    51 			else
       
    52 				ed.getDoc().execCommand('InsertHTML', false, rs);
       
    53 		};
       
    54 
       
    55 		// IE flags
       
    56 		if (ca)
       
    57 			fl = fl | 4;
       
    58 
       
    59 		switch (a) {
       
    60 			case 'all':
       
    61 				if (tinymce.isIE) {
       
    62 					while (r.findText(s, b ? -1 : 1, fl)) {
       
    63 						r.scrollIntoView();
       
    64 						r.select();
       
    65 						replace();
       
    66 						fo = 1;
       
    67 					}
       
    68 
       
    69 					tinyMCEPopup.storeSelection();
       
    70 				} else {
       
    71 					while (w.find(s, ca, b, false, false, false, false)) {
       
    72 						replace();
       
    73 						fo = 1;
       
    74 					}
       
    75 				}
       
    76 
       
    77 				if (fo)
       
    78 					wm.alert(ed.getLang('searchreplace_dlg.allreplaced'));
       
    79 				else
       
    80 					wm.alert(ed.getLang('searchreplace_dlg.notfound'));
       
    81 
       
    82 				return;
       
    83 
       
    84 			case 'current':
       
    85 				replace();
       
    86 				break;
       
    87 		}
       
    88 
       
    89 		se.collapse(b);
       
    90 		r = se.getRng();
       
    91 
       
    92 		if (tinymce.isIE) {
       
    93 			if (r.findText(s, b ? -1 : 1, fl)) {
       
    94 				r.scrollIntoView();
       
    95 				r.select();
       
    96 			} else
       
    97 				wm.alert(ed.getLang('searchreplace_dlg.notfound'));
       
    98 
       
    99 			tinyMCEPopup.storeSelection();
       
   100 		} else {
       
   101 			if (!w.find(s, ca, b, false, false, false, false))
       
   102 				wm.alert(ed.getLang('searchreplace_dlg.notfound'));
       
   103 			else
       
   104 				fix();
       
   105 		}
       
   106 	}
       
   107 };
       
   108 
       
   109 tinyMCEPopup.onInit.add(SearchReplaceDialog.init, SearchReplaceDialog);