[ Index ] |
|
Code source de Plume CMS 1.2.2 |
1 jsToolBar.prototype.can_wwg = (document.designMode != undefined); 2 jsToolBar.prototype.iframe = null; 3 jsToolBar.prototype.iwin = null; 4 jsToolBar.prototype.ibody = null; 5 jsToolBar.prototype.iframe_css = null; 6 7 /* Editor methods 8 -------------------------------------------------------- */ 9 jsToolBar.prototype.drawToolBar = jsToolBar.prototype.draw; 10 jsToolBar.prototype.draw = function(mode) { 11 mode = mode || 'xhtml'; 12 13 if (this.can_wwg) { 14 this.mode = 'wysiwyg'; 15 this.drawToolBar('wysiwyg'); 16 this.initWindow(); 17 } else { 18 this.drawToolBar(mode); 19 } 20 }; 21 22 jsToolBar.prototype.switchMode = function(mode) { 23 mode = mode || 'xhtml'; 24 25 if (mode == 'xhtml') { 26 this.draw(mode); 27 } else { 28 if (this.wwg_mode) { 29 this.syncContents('iframe'); 30 } 31 this.removeEditor(); 32 this.textarea.style.display = ''; 33 this.drawToolBar(mode); 34 } 35 }; 36 37 jsToolBar.prototype.syncContents = function(from) { 38 from = from || 'textarea'; 39 var This = this; 40 if (from == 'textarea') { 41 initContent(); 42 } else { 43 this.validBlockquote(); 44 var html = this.tagsoup2xhtml(this.ibody.innerHTML); 45 if (html == '<br />') { html = '<p></p>'; } 46 this.textarea.value = html; 47 } 48 49 function initContent() { 50 if (!This.iframe.contentWindow.document || !This.iframe.contentWindow.document.body) { 51 setTimeout(initContent, 1); 52 return; 53 } 54 This.ibody = This.iframe.contentWindow.document.body; 55 56 if (This.textarea.value != '' && This.textarea.value != '<p></p>') { 57 This.ibody.innerHTML = This.textarea.value; 58 if (This.ibody.createTextRange) { //cursor at the begin for IE 59 var IErange = This.ibody.createTextRange(); 60 IErange.execCommand("SelectAll"); 61 IErange.collapse(); 62 IErange.select(); 63 } 64 } else if (window.navigator.product != undefined && 65 window.navigator.product == 'Gecko') { 66 This.ibody.innerHTML = '<p><br _moz_editor_blogus_node="TRUE" _moz_dirty=""></p>'; 67 } else { 68 var idoc = This.iwin.document; 69 var para = idoc.createElement('p'); 70 para.appendChild(idoc.createTextNode('')); 71 while (idoc.body.hasChildNodes()) { 72 idoc.body.removeChild(idoc.body.lastChild); 73 } 74 idoc.body.appendChild(para); 75 } 76 } 77 }; 78 79 jsToolBar.prototype.switchEdit = function() { 80 if (this.wwg_mode) { 81 this.textarea.style.display = ''; 82 this.iframe.style.display = 'none'; 83 this.syncContents('iframe'); 84 this.drawToolBar('xhtml'); 85 this.wwg_mode = false; 86 this.focusEditor(); 87 } else { 88 this.iframe.style.display = ''; 89 this.textarea.style.display = 'none'; 90 this.syncContents('textarea'); 91 this.drawToolBar('wysiwyg'); 92 this.wwg_mode = true; 93 this.focusEditor(); 94 } 95 this.setSwitcher(); 96 }; 97 98 /** Creates iframe for editor, inits a blank document 99 */ 100 jsToolBar.prototype.initWindow = function() { 101 var This = this; 102 103 var container = document.createElement('div'); 104 105 this.iframe = document.createElement('iframe'); 106 container.appendChild(this.iframe); 107 108 this.textarea.parentNode.insertBefore(this.iframe,this.textarea.nextSibling); 109 110 this.switcher = document.createElement('ul'); 111 this.switcher.className = 'jstSwitcher'; 112 this.editor.appendChild(this.switcher); 113 114 this.iframe.height = this.textarea.offsetHeight + 0; 115 this.iframe.width = this.textarea.offsetWidth + 0; 116 117 if (this.textarea.tabIndex != undefined) { 118 this.iframe.tabIndex = this.textarea.tabIndex; 119 } 120 121 function initIframe() { 122 var doc = This.iframe.contentWindow.document; 123 if (!doc) { 124 setTimeout(initIframe,1); 125 return false; 126 } 127 128 doc.open(); 129 var html = 130 '<html>\n'+ 131 '<head>\n'+ 132 '<style type="text/css">'+This.iframe_css+'</style>\n'+ 133 (This.base_url != '' ? '<base href="'+This.base_url+'" />' : '')+ 134 '</head>\n'+ 135 '<body>\n'+ 136 '</body>\n'+ 137 '</html>'; 138 139 doc.write(html); 140 doc.close(); 141 if (document.all) { // for IE 142 doc.designMode = 'on'; 143 } 144 145 This.iwin = This.iframe.contentWindow; 146 147 This.syncContents('textarea'); 148 149 if (This.wwg_mode == undefined) { 150 This.wwg_mode = true; 151 } 152 153 if (This.wwg_mode) { 154 This.textarea.style.display = 'none'; 155 } else { 156 This.iframe.style.display = 'none'; 157 } 158 159 // update textarea on submit 160 if (This.textarea.form) { 161 chainHandler(This.textarea.form,'onsubmit', function() { 162 if (This.wwg_mode) { 163 This.syncContents('iframe'); 164 } 165 }); 166 } 167 168 for (var evt in This.iwinEvents) { 169 var event = This.iwinEvents[evt]; 170 addEvent(This.iwin.document, event.type, function(){event.fn.apply(This, arguments)}, true); 171 } 172 173 This.setSwitcher(); 174 This.focusEditor(); 175 176 return true; 177 } 178 setTimeout(initIframe,1); 179 }; 180 jsToolBar.prototype.iwinEvents = { 181 block1: { 182 type: 'mouseup', 183 fn: function(){ this.adjustBlockLevelCombo() } 184 }, 185 block2: { 186 type: 'keyup', 187 fn: function(){ this.adjustBlockLevelCombo() } 188 } 189 } 190 191 /** Insert a mode switcher after editor area 192 */ 193 jsToolBar.prototype.switcher_visual_title = 'visual'; 194 jsToolBar.prototype.switcher_source_title = 'source'; 195 jsToolBar.prototype.setSwitcher = function() { 196 while (this.switcher.hasChildNodes()) { 197 this.switcher.removeChild(this.switcher.firstChild); 198 } 199 200 var This = this; 201 function setLink(title,link) { 202 var li = document.createElement('li'); 203 if (link) { 204 var a = document.createElement('a'); 205 a.href = '#'; 206 a.editor = This; 207 a.onclick = function() { this.editor.switchEdit(); return false; }; 208 a.appendChild(document.createTextNode(title)); 209 } else { 210 a = document.createTextNode(title); 211 } 212 213 li.appendChild(a); 214 This.switcher.appendChild(li); 215 } 216 217 setLink(this.switcher_visual_title,!this.wwg_mode); 218 setLink(this.switcher_source_title,this.wwg_mode); 219 }; 220 221 /** Removes editor area and mode switcher 222 */ 223 jsToolBar.prototype.removeEditor = function() { 224 if (this.iframe != null) { 225 this.iframe.parentNode.removeChild(this.iframe); 226 this.iframe = null; 227 } 228 229 if (this.switcher != undefined && this.switcher.parentNode != undefined) { 230 this.switcher.parentNode.removeChild(this.switcher); 231 } 232 }; 233 234 /** Focus on the editor area 235 */ 236 jsToolBar.prototype.focusEditor = function() { 237 if (this.wwg_mode) { 238 this.iwin.document.designMode = 'on'; // Firefox needs this 239 var This = this; 240 setTimeout(function() {This.iframe.contentWindow.focus()},1); 241 } else { 242 this.textarea.focus(); 243 } 244 }; 245 246 /** Resizer 247 */ 248 jsToolBar.prototype.resizeSetStartH = function() { 249 if (this.wwg_mode && this.iframe != undefined) { 250 this.dragStartH = this.iframe.offsetHeight; 251 return; 252 } 253 this.dragStartH = this.textarea.offsetHeight + 0; 254 }; 255 jsToolBar.prototype.resizeDragMove = function(event) { 256 var new_height = (this.dragStartH+event.clientY-this.dragStartY)+'px'; 257 if (this.iframe != undefined) { 258 this.iframe.style.height = new_height; 259 } 260 this.textarea.style.height = new_height; 261 }; 262 263 /* Editing methods 264 -------------------------------------------------------- */ 265 /** Replaces current selection by given node 266 */ 267 jsToolBar.prototype.insertNode = function(node) { 268 var range; 269 270 if (this.iwin.getSelection) { // Gecko 271 var sel = this.iwin.getSelection(); 272 range = sel.getRangeAt(0); 273 274 // deselect all ranges 275 sel.removeAllRanges(); 276 277 // empty range 278 range.deleteContents(); 279 280 // Insert node 281 range.insertNode(node); 282 283 range.selectNodeContents(node); 284 range.setEndAfter(node); 285 if (range.endContainer.childNodes.length > range.endOffset && 286 range.endContainer.nodeType != Node.TEXT_NODE) { 287 range.setEnd(range.endContainer.childNodes[range.endOffset], 0); 288 } else { 289 range.setEnd(range.endContainer.childNodes[0]); 290 } 291 sel.addRange(range); 292 293 sel.collapseToEnd(); 294 } else { // IE 295 // lambda element 296 var p = this.iwin.document.createElement('div'); 297 p.appendChild(node); 298 range = this.iwin.document.selection.createRange(); 299 range.execCommand('delete'); 300 // insert innerHTML from element 301 range.pasteHTML(p.innerHTML); 302 range.collapse(false); 303 range.select(); 304 } 305 this.iwin.focus(); 306 }; 307 308 /** Returns a document fragment with selected nodes 309 */ 310 jsToolBar.prototype.getSelectedNode = function() { 311 //this.focusEditor(); // inutile 312 313 if (this.iwin.getSelection) { // Gecko 314 var sel = this.iwin.getSelection(); 315 var range = sel.getRangeAt(0); 316 var content = range.cloneContents(); 317 } else { // IE 318 var sel = this.iwin.document.selection; 319 var d = this.iwin.document.createElement('div'); 320 d.innerHTML = sel.createRange().htmlText; 321 var content = this.iwin.document.createDocumentFragment(); 322 for (var i=0; i < d.childNodes.length; i++) { 323 content.appendChild(d.childNodes[i].cloneNode(true)); 324 } 325 } 326 return content; 327 }; 328 329 /** Returns string representation for selected node 330 */ 331 jsToolBar.prototype.getSelectedText = function() { 332 //this.focusEditor(); // inutile 333 334 if (this.iwin.getSelection) { // Gecko 335 return this.iwin.getSelection().toString(); 336 } else { // IE 337 var range = this.iwin.document.selection.createRange(); 338 return range.text; 339 } 340 }; 341 342 jsToolBar.prototype.getBlockLevel = function() { 343 var blockElts = ['p','h1','h2','h3','h4','h5','h6']; 344 345 var range, commonAncestorContainer; 346 if (this.iwin.getSelection) { //gecko 347 var selection = this.iwin.getSelection(); 348 range = selection.getRangeAt(0); 349 commonAncestorContainer = range.commonAncestorContainer; 350 while (commonAncestorContainer.nodeType != 1) { 351 commonAncestorContainer = commonAncestorContainer.parentNode; 352 } 353 } else { //ie 354 range = this.iwin.document.selection.createRange(); 355 commonAncestorContainer = range.parentElement(); 356 } 357 358 var ancestorTagName = commonAncestorContainer.tagName.toLowerCase(); 359 while (arrayIndexOf(blockElts, ancestorTagName)==-1 && ancestorTagName!='body') { 360 commonAncestorContainer = commonAncestorContainer.parentNode; 361 ancestorTagName = commonAncestorContainer.tagName.toLowerCase(); 362 } 363 if (ancestorTagName == 'body') return ''; 364 else return ancestorTagName; 365 } 366 jsToolBar.prototype.adjustBlockLevelCombo = function() { 367 var blockLevel = this.getBlockLevel(); 368 if (blockLevel!='') this.toolNodes.blocks.value = blockLevel; 369 else { 370 if (this.mode == 'wysiwyg') this.toolNodes.blocks.value = 'none'; 371 if (this.mode == 'xhtml') this.toolNodes.blocks.value = 'nonebis'; 372 } 373 } 374 375 /** HTML code cleanup 376 -------------------------------------------------------- */ 377 jsToolBar.prototype.simpleCleanRegex = new Array( 378 /* Remove every tags we don't need */ 379 [/<meta[\w\W]*?>/gim,''], 380 [/<style[\w\W]*?>[\w\W]*?<\/style>/gim, ''], 381 [/<\/?font[\w\W]*?>/gim, ''], 382 383 384 /* Replacements */ 385 [/<(\/?)(B|b|STRONG)([\s>\/])/g, "<$1strong$3"], 386 [/<(\/?)(I|i|EM)([\s>\/])/g, "<$1em$3"], 387 [/<IMG ([^>]*?[^\/])>/gi, "<img $1 />"], 388 [/<INPUT ([^>]*?[^\/])>/gi, "<input $1 />"], 389 [/<COL ([^>]*?[^\/])>/gi, "<col $1 />"], 390 [/<AREA ([^>]*?[^\/])>/gi, "<area $1 />"], 391 [/<PARAM ([^>]*?[^\/])>/gi, "<param $1 />"], 392 [/<(\/?)U([\s>\/])/gi, "<$1ins$2"], 393 [/<(\/?)STRIKE([\s>\/])/gi, "<$1del$2"], 394 [/<span style="font-weight: normal;">([\w\W]*?)<\/span>/gm, "$1"], 395 [/<span style="font-weight: bold;">([\w\W]*?)<\/span>/gm, "<strong>$1</strong>"], 396 [/<span style="font-style: italic;">([\w\W]*?)<\/span>/gm, "<em>$1</em>"], 397 [/<span style="text-decoration: underline;">([\w\W]*?)<\/span>/gm, "<ins>$1</ins>"], 398 [/<span style="text-decoration: line-through;">([\w\W]*?)<\/span>/gm, "<del>$1</del>"], 399 [/<span style="text-decoration: underline line-through;">([\w\W]*?)<\/span>/gm, "<del><ins>$1</ins></del>"], 400 [/<span style="(font-weight: bold; ?|font-style: italic; ?){2}">([\w\W]*?)<\/span>/gm, "<strong><em>$2</em></strong>"], 401 [/<span style="(font-weight: bold; ?|text-decoration: underline; ?){2}">([\w\W]*?)<\/span>/gm, "<ins><strong>$2</strong></ins>"], 402 [/<span style="(font-weight: italic; ?|text-decoration: underline; ?){2}">([\w\W]*?)<\/span>/gm, "<ins><em>$2</em></ins>"], 403 [/<span style="(font-weight: bold; ?|text-decoration: line-through; ?){2}">([\w\W]*?)<\/span>/gm, "<del><strong>$2</strong></del>"], 404 [/<span style="(font-weight: italic; ?|text-decoration: line-through; ?){2}">([\w\W]*?)<\/span>/gm, "<del><em>$2</em></del>"], 405 [/<span style="(font-weight: bold; ?|font-style: italic; ?|text-decoration: underline; ?){3}">([\w\W]*?)<\/span>/gm, "<ins><strong><em>$2</em></strong></ins>"], 406 [/<span style="(font-weight: bold; ?|font-style: italic; ?|text-decoration: line-through; ?){3}">([\w\W]*?)<\/span>/gm, "<del><strong><em>$2</em></strong></del>"], 407 [/<span style="(font-weight: bold; ?|font-style: italic; ?|text-decoration: underline line-through; ?){3}">([\w\W]*?)<\/span>/gm, "<del><ins><strong><em>$2</em></strong></ins></del>"], 408 [/<strong style="font-weight: normal;">([\w\W]*?)<\/strong>/gm, "$1"], 409 [/<([a-z]+) style="font-weight: normal;">([\w\W]*?)<\/\1>/gm, "<$1>$2</$1>"], 410 [/<([a-z]+) style="font-weight: bold;">([\w\W]*?)<\/\1>/gm, "<$1><strong>$2</strong></$1>"], 411 [/<([a-z]+) style="font-style: italic;">([\w\W]*?)<\/\1>/gm, "<$1><em>$2</em></$1>"], 412 [/<([a-z]+) style="text-decoration: underline;">([\w\W]*?)<\/\1>/gm, "<ins><$1>$2</$1></ins>"], 413 [/<([a-z]+) style="text-decoration: line-through;">([\w\W]*?)<\/\1>/gm, "<del><$1>$2</$1></del>"], 414 [/<([a-z]+) style="text-decoration: underline line-through;">([\w\W]*?)<\/\1>/gm, "<del><ins><$1>$2</$1></ins></del>"], 415 [/<([a-z]+) style="(font-weight: bold; ?|font-style: italic; ?){2}">([\w\W]*?)<\/\1>/gm, "<$1><strong><em>$3</em></strong></$1>"], 416 [/<([a-z]+) style="(font-weight: bold; ?|text-decoration: underline; ?){2}">([\w\W]*?)<\/\1>/gm, "<ins><$1><strong>$3</strong></$1></ins>"], 417 [/<([a-z]+) style="(font-weight: italic; ?|text-decoration: underline; ?){2}">([\w\W]*?)<\/\1>/gm, "<ins><$1><em>$3</em></$1></ins>"], 418 [/<([a-z]+) style="(font-weight: bold; ?|text-decoration: line-through; ?){2}">([\w\W]*?)<\/\1>/gm, "<del><$1><strong>$3</strong></$1></del>"], 419 [/<([a-z]+) style="(font-weight: italic; ?|text-decoration: line-through; ?){2}">([\w\W]*?)<\/\1>/gm, "<del><$1><em>$3</em></$1></del>"], 420 [/<([a-z]+) style="(font-weight: bold; ?|font-style: italic; ?|text-decoration: underline; ?){3}">([\w\W]*?)<\/\1>/gm, "<ins><$1><strong><em>$3</em></strong></$1></ins>"], 421 [/<([a-z]+) style="(font-weight: bold; ?|font-style: italic; ?|text-decoration: line-through; ?){3}">([\w\W]*?)<\/\1>/gm, "<del><$1><strong><em>$3</em></strong></$1></del>"], 422 [/<([a-z]+) style="(font-weight: bold; ?|font-style: italic; ?|text-decoration: underline line-through; ?){3}">([\w\W]*?)<\/\1>/gm, "<del><ins><$1><strong><em>$3</em></strong></$1></ins></del>"], 423 /* mise en forme identique contigue */ 424 [/<\/(strong|em|ins|del|q|code)>(\s*?)<\1>/gim, "$2"], 425 [/<(br|BR)>/g, "<br />"], 426 /* opera est trop strict ;)) */ 427 [/([^\s])\/>/g, "$1 />"], 428 /* br intempestifs de fin de block */ 429 [/<br \/>\s*<\/(h1|h2|h3|h4|h5|h6|ul|ol|li|p|blockquote|div)/gi, "</$1"], 430 [/<\/(h1|h2|h3|h4|h5|h6|ul|ol|li|p|blockquote)>([^\n\u000B\r\f])/gi, "</$1>\n$2"], 431 [/<(hr|HR)( style="width: 100%; height: 2px;")?>/g, "<hr />"] 432 ); 433 434 /** Cleanup HTML code 435 */ 436 jsToolBar.prototype.tagsoup2xhtml = function(html) { 437 for (var reg in this.simpleCleanRegex) { 438 html = html.replace(this.simpleCleanRegex[reg][0], this.simpleCleanRegex[reg][1]); 439 } 440 /* tags vides */ 441 /* note : on tente de ne pas tenir compte des commentaires html, ceux-ci 442 permettent entre autre d'inserer des commentaires conditionnels pour ie */ 443 while ( /(<[^\/!]>|<[^\/!][^>]*[^\/]>)\s*<\/[^>]*[^-]>/.test(html) ) { 444 html = html.replace(/(<[^\/!]>|<[^\/!][^>]*[^\/]>)\s*<\/[^>]*[^-]>/g, ""); 445 } 446 447 /* tous les tags en minuscule */ 448 html = html.replace(/<(\/?)([A-Z0-9]+)/g, 449 function(match0, match1, match2) { 450 return "<" + match1 + match2.toLowerCase(); 451 }); 452 453 /* IE laisse souvent des attributs sans guillemets */ 454 var myRegexp = /<[^>]+((\s+\w+\s*=\s*)([^"'][\w\/]*))[^>]*?>/; 455 while ( myRegexp.test(html)) { 456 html = html.replace( 457 myRegexp, 458 function (str, val1, val2, val3){ 459 var tamponRegex = new RegExp(val1); 460 return str.replace(tamponRegex, val2+'"'+val3+'"'); 461 } 462 ) 463 } 464 465 /* les navigateurs rajoutent une unite aux longueurs css nulles */ 466 /* note: a ameliorer ! */ 467 while ( /(<[^>]+style=(["'])[^>]+[\s:]+)0(pt|px)(\2|\s|;)/.test(html)) { 468 html = html.replace(/(<[^>]+style=(["'])[^>]+[\s:]+)0(pt|px)(\2|\s|;)/gi, "$1"+"0$4"); 469 } 470 471 /* correction des fins de lignes : le textarea edite contient des \n 472 * le wysiwyg des \r\n , et le textarea mis a jour SANS etre affiche des \r\n ! */ 473 html = html.replace(/\r\n/g,"\n"); 474 475 /* Trim */ 476 html = html.replace(/^\s+/gm,''); 477 html = html.replace(/\s+$/gm,''); 478 479 return html; 480 }; 481 jsToolBar.prototype.validBlockquote = function() { 482 var blockElts = ['address','blockquote','dl','div','fieldset','form','h1', 483 'h2','h3','h4','h5','h6','hr','ol','p','pre','table','ul']; 484 var BQs = this.iwin.document.getElementsByTagName('blockquote'); 485 var bqChilds; 486 487 for (var bq = 0; bq < BQs.length; bq++) { 488 bqChilds = BQs[bq].childNodes; 489 var frag = this.iwin.document.createDocumentFragment(); 490 for (var i = (bqChilds.length-1); i >= 0; i--) { 491 if (bqChilds[i].nodeType == 1 && // Node.ELEMENT_NODE 492 arrayIndexOf(blockElts, bqChilds[i].tagName.toLowerCase()) >= 0) 493 { 494 if (frag.childNodes.length > 0) { 495 var p = this.iwin.document.createElement('p'); 496 p.appendChild(frag); 497 BQs[bq].replaceChild(p, bqChilds[i+1]); 498 frag = this.iwin.document.createDocumentFragment(); 499 } 500 } else { 501 if (frag.childNodes.length > 0) BQs[bq].removeChild(bqChilds[i+1]); 502 frag.insertBefore(bqChilds[i].cloneNode(true), frag.firstChild); 503 } 504 } 505 if (frag.childNodes.length > 0) { 506 var p = this.iwin.document.createElement('p'); 507 p.appendChild(frag); 508 BQs[bq].replaceChild(p, bqChilds[0]); 509 } 510 } 511 } 512 513 /* Removing text formating */ 514 jsToolBar.prototype.removeFormatRegexp = new Array( 515 [/(<[a-z][^>]*)margin\s*:[^;]*;/mg, "$1"], 516 [/(<[a-z][^>]*)margin-bottom\s*:[^;]*;/mg, "$1"], 517 [/(<[a-z][^>]*)margin-left\s*:[^;]*;/mg, "$1"], 518 [/(<[a-z][^>]*)margin-right\s*:[^;]*;/mg, "$1"], 519 [/(<[a-z][^>]*)margin-top\s*:[^;]*;/mg, "$1"], 520 521 [/(<[a-z][^>]*)padding\s*:[^;]*;/mg, "$1"], 522 [/(<[a-z][^>]*)padding-bottom\s*:[^;]*;/mg, "$1"], 523 [/(<[a-z][^>]*)padding-left\s*:[^;]*;/mg, "$1"], 524 [/(<[a-z][^>]*)padding-right\s*:[^;]*;/mg, "$1"], 525 [/(<[a-z][^>]*)padding-top\s*:[^;]*;/mg, "$1"], 526 527 [/(<[a-z][^>]*)font\s*:[^;]*;/mg, "$1"], 528 [/(<[a-z][^>]*)font-family\s*:[^;]*;/mg, "$1"], 529 [/(<[a-z][^>]*)font-size\s*:[^;]*;/mg, "$1"], 530 [/(<[a-z][^>]*)font-style\s*:[^;]*;/mg, "$1"], 531 [/(<[a-z][^>]*)font-variant\s*:[^;]*;/mg, "$1"], 532 [/(<[a-z][^>]*)font-weight\s*:[^;]*;/mg, "$1"], 533 534 [/(<[a-z][^>]*)color\s*:[^;]*;/mg, "$1"] 535 ); 536 537 jsToolBar.prototype.removeTextFormating = function(html) { 538 for (var reg in this.removeFormatRegexp) { 539 html = html.replace(this.removeFormatRegexp[reg][0], this.removeFormatRegexp[reg][1]); 540 } 541 542 html = this.tagsoup2xhtml(html); 543 html = html.replace(/style="\s*?"/mgi,''); 544 return html; 545 }; 546 547 /** Toolbar elements 548 -------------------------------------------------------- */ 549 jsToolBar.prototype.elements.blocks.options.none.fn.wysiwyg = function() { 550 // rajouter de quoi supprimer le paragraphe ou header 551 this.iwin.focus(); 552 }; 553 jsToolBar.prototype.elements.blocks.options.p.fn.wysiwyg = function() { 554 this.iwin.document.execCommand('formatblock',false,'<p>'); 555 this.iwin.focus(); 556 }; 557 jsToolBar.prototype.elements.blocks.options.h1.fn.wysiwyg = function() { 558 this.iwin.document.execCommand('formatblock',false,'<h1>'); 559 this.iwin.focus(); 560 }; 561 jsToolBar.prototype.elements.blocks.options.h2.fn.wysiwyg = function() { 562 this.iwin.document.execCommand('formatblock',false,'<h2>'); 563 this.iwin.focus(); 564 }; 565 jsToolBar.prototype.elements.blocks.options.h3.fn.wysiwyg = function() { 566 this.iwin.document.execCommand('formatblock',false,'<h3>'); 567 this.iwin.focus(); 568 }; 569 jsToolBar.prototype.elements.blocks.options.h4.fn.wysiwyg = function() { 570 this.iwin.document.execCommand('formatblock',false,'<h4>'); 571 this.iwin.focus(); 572 }; 573 jsToolBar.prototype.elements.blocks.options.h5.fn.wysiwyg = function() { 574 this.iwin.document.execCommand('formatblock',false,'<h5>'); 575 this.iwin.focus(); 576 }; 577 jsToolBar.prototype.elements.blocks.options.h6.fn.wysiwyg = function() { 578 this.iwin.document.execCommand('formatblock',false,'<h6>'); 579 this.iwin.focus(); 580 }; 581 582 jsToolBar.prototype.elements.strong.fn.wysiwyg = function() { 583 //this.focusEditor();// pas besoin de sortir l'artillerie pour ces cas, plutot this.iwin.focus(), et c'est plus logique aprés le traitement 584 this.iwin.document.execCommand('bold', false, null); 585 this.iwin.focus(); 586 }; 587 588 jsToolBar.prototype.elements.em.fn.wysiwyg = function() { 589 this.iwin.document.execCommand('italic', false, null); 590 this.iwin.focus(); 591 }; 592 593 jsToolBar.prototype.elements.ins.fn.wysiwyg = function() { 594 this.iwin.document.execCommand('underline', false, null); 595 this.iwin.focus(); 596 }; 597 598 jsToolBar.prototype.elements.del.fn.wysiwyg = function() { 599 this.iwin.document.execCommand('strikethrough', false, null); 600 this.iwin.focus(); 601 }; 602 603 jsToolBar.prototype.elements.quote.fn.wysiwyg = function() { 604 var n = this.getSelectedNode(); 605 var q = this.iwin.document.createElement('q'); 606 q.appendChild(n); 607 this.insertNode(q); 608 }; 609 610 jsToolBar.prototype.elements.code.fn.wysiwyg = function() { 611 var n = this.getSelectedNode(); 612 var code = this.iwin.document.createElement('code'); 613 code.appendChild(n); 614 this.insertNode(code); 615 }; 616 617 jsToolBar.prototype.elements.br.fn.wysiwyg = function() { 618 var n = this.iwin.document.createElement('br'); 619 this.insertNode(n); 620 }; 621 622 jsToolBar.prototype.elements.blockquote.fn.wysiwyg = function() { 623 var n = this.getSelectedNode(); 624 var q = this.iwin.document.createElement('blockquote'); 625 q.appendChild(n); 626 this.insertNode(q); 627 }; 628 629 jsToolBar.prototype.elements.pre.fn.wysiwyg = function() { 630 this.iwin.document.execCommand('formatblock',false,'<pre>'); 631 this.iwin.focus(); 632 }; 633 634 jsToolBar.prototype.elements.ul.fn.wysiwyg = function() { 635 this.iwin.document.execCommand('insertunorderedlist',false,null); 636 this.iwin.focus(); 637 }; 638 639 jsToolBar.prototype.elements.ol.fn.wysiwyg = function() { 640 this.iwin.document.execCommand('insertorderedlist',false,null); 641 this.iwin.focus(); 642 }; 643 644 jsToolBar.prototype.elements.link.fn.wysiwyg = function() { 645 var href, hreflang; 646 var range, commonAncestorContainer; 647 if (this.iwin.getSelection) { //gecko 648 var selection = this.iwin.getSelection(); 649 range = selection.getRangeAt(0); 650 commonAncestorContainer = range.commonAncestorContainer; 651 while (commonAncestorContainer.nodeType != 1) { 652 commonAncestorContainer = commonAncestorContainer.parentNode; 653 } 654 } else { //ie 655 range = this.iwin.document.selection.createRange(); 656 commonAncestorContainer = range.parentElement(); 657 } 658 659 var ancestorTagName = commonAncestorContainer.tagName.toLowerCase(); 660 while (ancestorTagName!='a' && ancestorTagName!='body') { 661 commonAncestorContainer = commonAncestorContainer.parentNode; 662 ancestorTagName = commonAncestorContainer.tagName.toLowerCase(); 663 } 664 665 // Update or remove link? 666 if (ancestorTagName == 'a') { 667 href = commonAncestorContainer.href || ''; 668 hreflang = commonAncestorContainer.hreflang || ''; 669 } 670 671 href = window.prompt(this.elements.link.href_prompt,href); 672 673 // Remove link 674 if (ancestorTagName == 'a' && href=='') { 675 this.iwin.document.execCommand('unlink',false,null); 676 this.iwin.focus(); 677 return; 678 } 679 if (!href) return; // user cancel 680 681 hreflang = window.prompt(this.elements.link.hreflang_prompt, hreflang); 682 683 // Update link 684 if (ancestorTagName == 'a' && href) { 685 commonAncestorContainer.setAttribute('href', href); 686 if (hreflang) { 687 commonAncestorContainer.setAttribute('hreflang', hreflang); 688 } else { 689 commonAncestorContainer.removeAttribute('hreflang'); 690 } 691 return; 692 } 693 694 // Create link 695 var n = this.getSelectedNode(); 696 var a = this.iwin.document.createElement('a'); 697 a.href = href; 698 if (hreflang) a.setAttribute('hreflang',hreflang); 699 a.appendChild(n); 700 this.insertNode(a); 701 }; 702 703 704 705 // Remove format and Toggle 706 jsToolBar.prototype.elements.removeFormat = { 707 type: 'button', 708 title: 'Remove text formating', 709 fn: {} 710 } 711 jsToolBar.prototype.elements.removeFormat.disabled = !jsToolBar.prototype.can_wwg; 712 jsToolBar.prototype.elements.removeFormat.fn.xhtml = function() { 713 var html = this.textarea.value; 714 html = this.removeTextFormating(html); 715 this.textarea.value = html; 716 } 717 jsToolBar.prototype.elements.removeFormat.fn.wysiwyg = function() { 718 var html = this.iwin.document.body.innerHTML; 719 html = this.removeTextFormating(html); 720 this.iwin.document.body.innerHTML = html; 721 }; 722 /** Utilities 723 -------------------------------------------------------- */ 724 function arrayIndexOf(aArray, aValue){ 725 if (typeof Array.indexOf == 'function') { 726 return aArray.indexOf(aValue); 727 } else { 728 var index = -1; 729 var l = aArray.length; 730 for (var i = 0; i < l ; i++) { 731 if (aArray[i] === aValue) { 732 index = i; 733 break; 734 } 735 } 736 return index; 737 } 738 } 739 function addEvent(obj, evType, fn, useCapture) { 740 if (obj.addEventListener){ 741 obj.addEventListener(evType, fn, useCapture); 742 return true; 743 } else if (obj.attachEvent){ 744 var r = obj.attachEvent("on"+evType, fn); 745 return r; 746 } else { 747 return false; 748 } 749 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 11:57:01 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |