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