[ Index ] |
|
Code source de Typo3 4.1.3 |
1 /*************************************************************** 2 * Copyright notice 3 * 4 * (c) 2003 dynarch.com. Authored by Mihai Bazon, sponsored by www.americanbible.org. 5 * (c) 2004, 2005, 2006 Stanislas Rolland <stanislas.rolland(arobas)fructifor.ca> 6 * All rights reserved 7 * 8 * This script is part of the TYPO3 project. The TYPO3 project is 9 * free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * (at your option) any later version. 13 * 14 * The GNU General Public License can be found at 15 * http://www.gnu.org/copyleft/gpl.html. 16 * A copy is found in the textfile GPL.txt and important notices to the license 17 * from the author is found in LICENSE.txt distributed with these scripts. 18 * 19 * 20 * This script is distributed in the hope that it will be useful, 21 * but WITHOUT ANY WARRANTY; without even the implied warranty of 22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 * GNU General Public License for more details. 24 * 25 * This script is a modified version of a script published under the htmlArea License. 26 * A copy of the htmlArea License may be found in the textfile HTMLAREA_LICENSE.txt. 27 * 28 * This copyright notice MUST APPEAR in all copies of the script! 29 ***************************************************************/ 30 /* 31 * Spell Checker Plugin for TYPO3 htmlArea RTE 32 * 33 * TYPO3 CVS ID: $Id: spell-check-ui.js 1462 2006-05-05 20:35:09Z stanrolland $ 34 */ 35 36 // internationalization file was already loaded in parent ;-) 37 var SpellChecker = window.opener.SpellChecker; 38 var i18n = SpellChecker.I18N; 39 40 // initial_dictonary, charset and pspell_mode added by Stanislas Rolland 2004-09-16 41 var initial_dictionary = SpellChecker.f_dictionary; 42 var pspell_charset = SpellChecker.f_charset; 43 var pspell_mode = SpellChecker.f_pspell_mode; 44 45 var editor = SpellChecker.editor; 46 var frame = null; 47 var currentElement = null; 48 var wrongWords = null; 49 var modified = false; 50 var allWords = {}; 51 var fixedWords = []; 52 var suggested_words = {}; 53 54 var to_p_dict = []; // List of words to add to personal dictionary 55 var to_r_list = []; // List of words to add to replacement list 56 57 function makeCleanDoc(leaveFixed) { 58 // document.getElementById("status").innerHTML = 'Please wait: rendering valid HTML'; 59 var words = wrongWords.concat(fixedWords); 60 for (var i = words.length; --i >= 0;) { 61 var el = words[i]; 62 if (!(leaveFixed && /HA-spellcheck-fixed/.test(el.className))) { 63 el.parentNode.insertBefore(el.firstChild, el); 64 el.parentNode.removeChild(el); 65 } else 66 el.className = "HA-spellcheck-fixed"; 67 } 68 return window.opener.HTMLArea.getHTML(frame.contentWindow.document.body, false, editor); 69 }; 70 71 function recheckClicked() { 72 document.getElementById("status").innerHTML = i18n["Please wait: changing dictionary to"] + ': "' + document.getElementById("f_dictionary").value + '".'; 73 var field = document.getElementById("f_content"); 74 field.value = makeCleanDoc(true); 75 field.form.submit(); 76 }; 77 78 function saveClicked() { 79 if (modified) { 80 editor.setHTML(makeCleanDoc(false)); 81 } 82 if ((to_p_dict.length || to_r_list.length) && SpellChecker.enablePersonalDicts) { 83 var data = {}; 84 for (var i = 0;i < to_p_dict.length;i++) { 85 data['to_p_dict[' + i + ']'] = to_p_dict[i]; 86 } 87 for (var i = 0;i < to_r_list.length;i++) { 88 data['to_r_list[' + i + '][0]'] = to_r_list[i][0]; 89 data['to_r_list[' + i + '][1]'] = to_r_list[i][1]; 90 } 91 data['cmd'] = 'learn'; 92 data['enablePersonalDicts'] = SpellChecker.enablePersonalDicts; 93 data['userUid'] = SpellChecker.userUid; 94 data['dictionary'] = SpellChecker.f_dictionary; 95 data['pspell_charset'] = SpellChecker.f_charset; 96 data['pspell_mode'] = SpellChecker.f_pspell_mode; 97 window.opener.HTMLArea._postback('plugins/SpellChecker/spell-check-logic.php', data); 98 } 99 window.close(); 100 return false; 101 }; 102 103 function cancelClicked() { 104 var ok = true; 105 if (modified) { 106 ok = confirm(i18n["QUIT_CONFIRMATION"]); 107 } 108 if (ok) { 109 window.close(); 110 } 111 return false; 112 }; 113 114 function replaceWord(el) { 115 var replacement = document.getElementById("v_replacement").value; 116 var this_word_modified = (el.innerHTML != replacement); 117 if (this_word_modified) 118 modified = true; 119 if (el) { 120 el.className = el.className.replace(/\s*HA-spellcheck-(hover|fixed)\s*/g, " "); 121 } 122 el.className += " HA-spellcheck-fixed"; 123 el.__msh_fixed = true; 124 if (!this_word_modified) { 125 return false; 126 } 127 to_r_list.push([el.innerHTML, replacement]); 128 el.innerHTML = replacement; 129 }; 130 131 function replaceClicked() { 132 replaceWord(currentElement); 133 var start = currentElement.__msh_id; 134 var index = start; 135 do { 136 ++index; 137 if (index == wrongWords.length) index = 0; 138 }while((index != start) && wrongWords[index].__msh_fixed); 139 if (index == start) { 140 index = 0; 141 alert(i18n["Finished list of mispelled words"]); 142 } 143 wrongWords[index].__msh_wordClicked(true); 144 return false; 145 }; 146 147 function revertClicked() { 148 document.getElementById("v_replacement").value = currentElement.__msh_origWord; 149 replaceWord(currentElement); 150 currentElement.className = "HA-spellcheck-error HA-spellcheck-current"; 151 return false; 152 }; 153 154 function replaceAllClicked() { 155 var replacement = document.getElementById("v_replacement").value; 156 var ok = true; 157 var spans = allWords[currentElement.__msh_origWord]; 158 if (spans.length == 0) { 159 alert("An impossible condition just happened. Call FBI. ;-)"); 160 } else if (spans.length == 1) { 161 replaceClicked(); 162 return false; 163 } 164 /* 165 var message = "The word \"" + currentElement.__msh_origWord + "\" occurs " + spans.length + " times.\n"; 166 if (replacement == currentElement.__msh_origWord) { 167 ok = confirm(message + "Ignore all occurrences?"); 168 } else { 169 ok = confirm(message + "Replace all occurrences with \"" + replacement + "\"?"); 170 } 171 */ 172 if (ok) { 173 for (var i = 0; i < spans.length; ++i) { 174 if (spans[i] != currentElement) { 175 replaceWord(spans[i]); 176 } 177 } 178 // replace current element the last, so that we jump to the next word ;-) 179 replaceClicked(); 180 } 181 return false; 182 }; 183 184 function ignoreClicked() { 185 document.getElementById("v_replacement").value = currentElement.__msh_origWord; 186 replaceClicked(); 187 return false; 188 }; 189 190 function ignoreAllClicked() { 191 document.getElementById("v_replacement").value = currentElement.__msh_origWord; 192 replaceAllClicked(); 193 return false; 194 }; 195 196 function learnClicked() { 197 to_p_dict.push(currentElement.__msh_origWord); 198 return ignoreAllClicked(); 199 }; 200 201 function initDocument() { 202 __dlg_translate(i18n); 203 __dlg_init(); 204 var param = window.dialogArguments; 205 editor = param['editor']; 206 HTMLArea = param['HTMLArea']; 207 modified = false; 208 document.title = i18n["Spell Checker"]; 209 frame = document.getElementById("i_framecontent"); 210 var field = document.getElementById("f_content"); 211 field.value = HTMLArea.getHTML(editor._doc.body, false, editor); 212 document.getElementById("f_init").value = "0"; 213 document.getElementById("f_dictionary").value = initial_dictionary; 214 document.getElementById("f_charset").value = pspell_charset; 215 document.getElementById("f_pspell_mode").value = pspell_mode; 216 document.getElementById("f_user_uid").value = SpellChecker.userUid; 217 document.getElementById("f_personal_dicts").value = SpellChecker.enablePersonalDicts; 218 field.form.submit(); 219 220 // assign some global event handlers 221 var select = document.getElementById("v_suggestions"); 222 select.onchange = function() { 223 document.getElementById("v_replacement").value = this.value; 224 }; 225 HTMLArea._addEvent(select, "dblclick", replaceClicked); 226 227 document.getElementById("b_replace").onclick = replaceClicked; 228 if (SpellChecker.enablePersonalDicts) document.getElementById("b_learn").onclick = learnClicked; 229 else document.getElementById("b_learn").style.display = 'none'; 230 document.getElementById("b_replall").onclick = replaceAllClicked; 231 document.getElementById("b_ignore").onclick = ignoreClicked; 232 document.getElementById("b_ignall").onclick = ignoreAllClicked; 233 document.getElementById("b_recheck").onclick = recheckClicked; 234 document.getElementById("b_revert").onclick = revertClicked; 235 document.getElementById("b_info").onclick = displayInfo; 236 237 document.getElementById("b_ok").onclick = saveClicked; 238 document.getElementById("b_cancel").onclick = cancelClicked; 239 240 select = document.getElementById("v_dictionaries"); 241 select.onchange = function() { 242 document.getElementById("f_dictionary").value = this.value; 243 }; 244 }; 245 246 function getAbsolutePos(el) { 247 var r = { x: el.offsetLeft, y: el.offsetTop }; 248 if (el.offsetParent) { 249 var tmp = getAbsolutePos(el.offsetParent); 250 r.x += tmp.x; 251 r.y += tmp.y; 252 } 253 return r; 254 }; 255 256 function wordClicked(scroll) { 257 var self = this; 258 if (scroll) (function() { 259 var pos = getAbsolutePos(self); 260 var ws = { x: frame.offsetWidth - 4, 261 y: frame.offsetHeight - 4 }; 262 var wp = { x: frame.contentWindow.document.body.scrollLeft, 263 y: frame.contentWindow.document.body.scrollTop }; 264 pos.x -= Math.round(ws.x/2); 265 if (pos.x < 0) pos.x = 0; 266 pos.y -= Math.round(ws.y/2); 267 if (pos.y < 0) pos.y = 0; 268 frame.contentWindow.scrollTo(pos.x, pos.y); 269 })(); 270 if (currentElement) { 271 var a = allWords[currentElement.__msh_origWord]; 272 currentElement.className = currentElement.className.replace(/\s*HA-spellcheck-current\s*/g, " "); 273 for (var i = 0; i < a.length; ++i) { 274 var el = a[i]; 275 if (el != currentElement) { 276 el.className = el.className.replace(/\s*HA-spellcheck-same\s*/g, " "); 277 } 278 } 279 } 280 currentElement = this; 281 this.className += " HA-spellcheck-current"; 282 var a = allWords[currentElement.__msh_origWord]; 283 for (var i = 0; i < a.length; ++i) { 284 var el = a[i]; 285 if (el != currentElement) { 286 el.className += " HA-spellcheck-same"; 287 } 288 } 289 // document.getElementById("b_replall").disabled = (a.length <= 1); 290 // document.getElementById("b_ignall").disabled = (a.length <= 1); 291 var txt; 292 var txt2; 293 if (a.length == 1) { 294 txt = i18n["One occurrence"]; 295 txt2 = i18n["was found."]; 296 } else if (a.length == 2) { 297 txt = i18n["Two occurrences"]; 298 txt2 = i18n["were found."]; 299 } else { 300 txt = a.length + " " + i18n["occurrences"]; 301 txt2 = i18n["were found."]; 302 } 303 var suggestions = suggested_words[this.__msh_origWord]; 304 if (suggestions) suggestions = suggestions.split(/,/); 305 else suggestions = []; 306 var select = document.getElementById("v_suggestions"); 307 document.getElementById("statusbar").innerHTML = txt + " " + i18n["of the word"] + 308 ' "<b>' + currentElement.__msh_origWord + '</b>"' + " " + txt2; 309 for (var i = select.length; --i >= 0;) { 310 select.remove(i); 311 } 312 for (var i = 0; i < suggestions.length; ++i) { 313 var txt = suggestions[i]; 314 var option = document.createElement("option"); 315 option.value = txt; 316 option.appendChild(document.createTextNode(txt)); 317 select.appendChild(option); 318 } 319 document.getElementById("v_currentWord").innerHTML = this.__msh_origWord; 320 if (suggestions.length > 0) { 321 select.selectedIndex = 0; 322 select.onchange(); 323 } else { 324 document.getElementById("v_replacement").value = this.innerHTML; 325 } 326 select.style.display = "none"; 327 select.style.display = "block"; 328 return false; 329 }; 330 331 function wordMouseOver() { 332 this.className += " HA-spellcheck-hover"; 333 }; 334 335 function wordMouseOut() { 336 this.className = this.className.replace(/\s*HA-spellcheck-hover\s*/g, " "); 337 }; 338 339 function displayInfo() { 340 var info = frame.contentWindow.spellcheck_info; 341 if (!info) 342 alert(i18n["No information available"]); 343 else { 344 var txt = i18n["Document information"] + "\n" ; 345 for (var i in info) { 346 txt += "\n" + i18n[i] + " : " + info[i]; 347 } 348 txt += " " + i18n["seconds"]; 349 alert(txt); 350 } 351 return false; 352 }; 353 354 function finishedSpellChecking() { 355 // initialization of global variables 356 currentElement = null; 357 wrongWords = null; 358 allWords = {}; 359 fixedWords = []; 360 suggested_words = frame.contentWindow.suggested_words; 361 362 document.getElementById("status").innerHTML = i18n["HTMLArea Spell Checker"]; 363 var doc = frame.contentWindow.document; 364 var spans = doc.getElementsByTagName("span"); 365 var sps = []; 366 var id = 0; 367 for (var i = 0; i < spans.length; ++i) { 368 var el = spans[i]; 369 if (/HA-spellcheck-error/.test(el.className)) { 370 sps.push(el); 371 el.__msh_wordClicked = wordClicked; 372 el.onclick = function(ev) { 373 ev || (ev = window.event); 374 ev && HTMLArea._stopEvent(ev); 375 return this.__msh_wordClicked(false); 376 }; 377 el.onmouseover = wordMouseOver; 378 el.onmouseout = wordMouseOut; 379 el.__msh_id = id++; 380 var txt = (el.__msh_origWord = el.firstChild.data); 381 el.__msh_fixed = false; 382 if (typeof allWords[txt] == "undefined") { 383 allWords[txt] = [el]; 384 } else { 385 allWords[txt].push(el); 386 } 387 } else if (/HA-spellcheck-fixed/.test(el.className)) { 388 fixedWords.push(el); 389 } 390 } 391 wrongWords = sps; 392 if (sps.length == 0) { 393 if (!modified) { 394 alert(i18n["NO_ERRORS_CLOSING"]); 395 window.close(); 396 } else { 397 alert(i18n["NO_ERRORS"]); 398 } 399 return false; 400 } 401 (currentElement = sps[0]).__msh_wordClicked(true); 402 var as = doc.getElementsByTagName("a"); 403 for (var i = as.length; --i >= 0;) { 404 var a = as[i]; 405 a.onclick = function() { 406 if (confirm(i18n["CONFIRM_LINK_CLICK"] + ":\n" + 407 this.href + "\n" + i18n["I will open it in a new page."])) { 408 window.open(this.href); 409 } 410 return false; 411 }; 412 } 413 var dicts = doc.getElementById("HA-spellcheck-dictionaries"); 414 if (dicts) { 415 dicts.parentNode.removeChild(dicts); 416 dicts = dicts.innerHTML.split(/,/); 417 var select = document.getElementById("v_dictionaries"); 418 for (var i = select.length; --i >= 0;) { 419 select.remove(i); 420 } 421 var selectedOptionIndex = 0; 422 for (var i = 0; i < dicts.length; ++i) { 423 var txt = dicts[i]; 424 var option = document.createElement("option"); 425 if (/^@(.*)$/.test(txt)) { 426 txt = RegExp.$1; 427 selectedOptionIndex = i; 428 if (HTMLArea.is_ie) option.selected = true; 429 document.getElementById("f_dictionary").value = txt; 430 } 431 option.value = txt; 432 option.appendChild(document.createTextNode(txt)); 433 select.appendChild(option); 434 } 435 select.selectedIndex = selectedOptionIndex; 436 } 437 };
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Nov 25 17:13:16 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |