[ Index ] |
|
Code source de Seagull 0.6.1 |
1 /** 2 * $RCSfile: editor_plugin_src.js,v $ 3 * $Revision: 1.27 $ 4 * $Date: 2006/02/13 15:09:28 $ 5 * 6 * @author Moxiecode 7 * @copyright Copyright © 2004-2006, Moxiecode Systems AB, All rights reserved. 8 */ 9 10 /* Import theme specific language pack */ 11 tinyMCE.importPluginLanguagePack('searchreplace', 'en,tr,sv,zh_cn,fa,fr_ca,fr,de,pl,pt_br,cs,nl,da,he,nb,hu,ru,ru_KOI8-R,ru_UTF-8,nn,fi,cy,es,is,zh_tw,zh_tw_utf8,sk'); 12 13 var TinyMCE_SearchReplacePlugin = { 14 getInfo : function() { 15 return { 16 longname : 'Search/Replace', 17 author : 'Moxiecode Systems', 18 authorurl : 'http://tinymce.moxiecode.com', 19 infourl : 'http://tinymce.moxiecode.com/tinymce/docs/plugin_searchreplace.html', 20 version : tinyMCE.majorVersion + "." + tinyMCE.minorVersion 21 }; 22 }, 23 24 initInstance : function(inst) { 25 inst.addShortcut('ctrl', 'f', 'lang_searchreplace_search_desc', 'mceSearch', true); 26 }, 27 28 getControlHTML : function(cn) { 29 switch (cn) { 30 case "search": 31 return tinyMCE.getButtonHTML(cn, 'lang_searchreplace_search_desc', '{$pluginurl}/images/search.gif', 'mceSearch', true); 32 case "replace": 33 return tinyMCE.getButtonHTML(cn, 'lang_searchreplace_replace_desc', '{$pluginurl}/images/replace.gif', 'mceSearchReplace', true); 34 } 35 return ""; 36 }, 37 38 /** 39 * Executes the search/replace commands. 40 */ 41 execCommand : function(editor_id, element, command, user_interface, value) { 42 var instance = tinyMCE.getInstanceById(editor_id); 43 44 function defValue(key, default_value) { 45 value[key] = typeof(value[key]) == "undefined" ? default_value : value[key]; 46 } 47 48 function replaceSel(search_str, str, back) { 49 instance.execCommand('mceInsertContent', false, str); 50 } 51 52 if (!value) 53 value = new Array(); 54 55 // Setup defualt values 56 defValue("editor_id", editor_id); 57 defValue("searchstring", ""); 58 defValue("replacestring", null); 59 defValue("replacemode", "none"); 60 defValue("casesensitive", false); 61 defValue("backwards", false); 62 defValue("wrap", false); 63 defValue("wholeword", false); 64 defValue("inline", "yes"); 65 66 // Handle commands 67 switch (command) { 68 case "mceResetSearch": 69 tinyMCE.lastSearchRng = null; 70 return true; 71 72 case "mceSearch": 73 if (user_interface) { 74 // Open search dialog 75 var template = new Array(); 76 77 if (value['replacestring'] != null) { 78 template['file'] = '../../plugins/searchreplace/replace.htm'; // Relative to theme 79 template['width'] = 320; 80 template['height'] = 100 + (tinyMCE.isNS7 ? 20 : 0); 81 template['width'] += tinyMCE.getLang('lang_searchreplace_replace_delta_width', 0); 82 template['height'] += tinyMCE.getLang('lang_searchreplace_replace_delta_height', 0); 83 } else { 84 template['file'] = '../../plugins/searchreplace/search.htm'; // Relative to theme 85 template['width'] = 310; 86 template['height'] = 105 + (tinyMCE.isNS7 ? 25 : 0); 87 template['width'] += tinyMCE.getLang('lang_searchreplace_search_delta_width', 0); 88 template['height'] += tinyMCE.getLang('lang_searchreplace_replace_delta_height', 0); 89 } 90 91 instance.execCommand('SelectAll'); 92 93 if (tinyMCE.isMSIE) { 94 var r = instance.selection.getRng(); 95 r.collapse(true); 96 r.select(); 97 } else 98 instance.selection.getSel().collapseToStart(); 99 100 tinyMCE.openWindow(template, value); 101 } else { 102 var win = tinyMCE.getInstanceById(editor_id).contentWindow; 103 var doc = tinyMCE.getInstanceById(editor_id).contentWindow.document; 104 var body = tinyMCE.getInstanceById(editor_id).contentWindow.document.body; 105 106 // Whats the point 107 if (body.innerHTML == "") { 108 alert(tinyMCE.getLang('lang_searchreplace_notfound')); 109 return true; 110 } 111 112 // Handle replace current 113 if (value['replacemode'] == "current") { 114 replaceSel(value['string'], value['replacestring'], value['backwards']); 115 116 // Search next one 117 value['replacemode'] = "none"; 118 tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false); 119 120 return true; 121 } 122 123 if (tinyMCE.isMSIE) { 124 var rng = tinyMCE.lastSearchRng ? tinyMCE.lastSearchRng : doc.selection.createRange(); 125 var flags = 0; 126 127 if (value['wholeword']) 128 flags = flags | 2; 129 130 if (value['casesensitive']) 131 flags = flags | 4; 132 133 if (!rng.findText) { 134 alert('This operation is currently not supported by this browser.'); 135 return true; 136 } 137 138 // Handle replace all mode 139 if (value['replacemode'] == "all") { 140 while (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) { 141 rng.scrollIntoView(); 142 rng.select(); 143 rng.collapse(false); 144 replaceSel(value['string'], value['replacestring'], value['backwards']); 145 } 146 147 alert(tinyMCE.getLang('lang_searchreplace_allreplaced')); 148 return true; 149 } 150 151 if (rng.findText(value['string'], value['backwards'] ? -1 : 1, flags)) { 152 rng.scrollIntoView(); 153 rng.select(); 154 rng.collapse(value['backwards']); 155 tinyMCE.lastSearchRng = rng; 156 } else 157 alert(tinyMCE.getLang('lang_searchreplace_notfound')); 158 } else { 159 if (value['replacemode'] == "all") { 160 while (win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false)) 161 replaceSel(value['string'], value['replacestring'], value['backwards']); 162 163 alert(tinyMCE.getLang('lang_searchreplace_allreplaced')); 164 return true; 165 } 166 167 if (!win.find(value['string'], value['casesensitive'], value['backwards'], value['wrap'], value['wholeword'], false, false)) 168 alert(tinyMCE.getLang('lang_searchreplace_notfound')); 169 } 170 } 171 return true; 172 173 case "mceSearchReplace": 174 value['replacestring'] = ""; 175 176 tinyMCE.execInstanceCommand(editor_id, 'mceSearch', user_interface, value, false); 177 return true; 178 } 179 180 // Pass to next handler in chain 181 return false; 182 } 183 }; 184 185 tinyMCE.addPlugin("searchreplace", TinyMCE_SearchReplacePlugin);
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 30 01:27:52 2007 | par Balluche grâce à PHPXref 0.7 |