Legend:
- Unmodified
- Added
- Removed
-
plugins/dcLegacyEditor/js/jsToolBar/jsToolBar.wysiwyg.js
r3736 r3880 64 64 jsToolBar.prototype.syncContents = function(from) { 65 65 from = from || 'textarea'; 66 varThis = this;66 const This = this; 67 67 if (from == 'textarea') { 68 68 initContent(); 69 69 } else { 70 70 this.validBlockquote(); 71 varhtml = this.applyHtmlFilters(this.ibody.innerHTML);71 let html = this.applyHtmlFilters(this.ibody.innerHTML); 72 72 if (html == '<br />') { 73 73 html = '<p></p>'; … … 86 86 This.ibody.innerHTML = This.applyWysiwygFilters(This.textarea.value); 87 87 if (This.ibody.createTextRange) { //cursor at the begin for IE 88 varIErange = This.ibody.createTextRange();88 const IErange = This.ibody.createTextRange(); 89 89 IErange.execCommand("SelectAll"); 90 90 IErange.collapse(); … … 92 92 } 93 93 } else { 94 varidoc = This.iwin.document;95 varpara = idoc.createElement('p');94 const idoc = This.iwin.document; 95 const para = idoc.createElement('p'); 96 96 para.appendChild(idoc.createElement('br')); 97 97 while (idoc.body.hasChildNodes()) { … … 108 108 }; 109 109 jsToolBar.prototype.applyHtmlFilters = function(str) { 110 for ( varfn in this.htmlFilters) {110 for (let fn in this.htmlFilters) { 111 111 str = this.htmlFilters[fn].call(this, str); 112 112 } … … 115 115 jsToolBar.prototype.wysiwygFilters = {}; 116 116 jsToolBar.prototype.applyWysiwygFilters = function(str) { 117 for ( varfn in this.wysiwygFilters) {117 for (let fn in this.wysiwygFilters) { 118 118 str = this.wysiwygFilters[fn].call(this, str); 119 119 } … … 143 143 */ 144 144 jsToolBar.prototype.initWindow = function() { 145 varThis = this;145 const This = this; 146 146 147 147 this.iframe = document.createElement('iframe'); … … 160 160 161 161 function initIframe() { 162 vardoc = This.iframe.contentWindow.document;162 const doc = This.iframe.contentWindow.document; 163 163 if (!doc) { 164 164 setTimeout(initIframe, 1); … … 167 167 168 168 doc.open(); 169 var html = 170 '<html>\n' + 171 '<head>\n' + 172 '<link rel="stylesheet" href="style/default.css" type="text/css" media="screen" />' + 173 '<style type="text/css">' + This.iframe_css + '</style>\n' + 174 (This.base_url != '' ? '<base href="' + This.base_url + '" />' : '') + 175 '</head>\n' + 176 '<body>\n' + 177 '</body>\n' + 178 '</html>'; 169 const html = 170 `<html> 171 <head> 172 <link rel="stylesheet" href="style/default.css" type="text/css" media="screen" /> 173 <style type="text/css">${This.iframe_css}</style> 174 ${This.base_url != '' ? `<base href="${This.base_url}" />` : ''} 175 </head> 176 <body></body> 177 </html>`; 179 178 180 179 doc.write(html); … … 212 211 } 213 212 214 for ( varevt in This.iwinEvents) {215 varevent = This.iwinEvents[evt];213 for (let evt in This.iwinEvents) { 214 const event = This.iwinEvents[evt]; 216 215 This.addIwinEvent(This.iframe.contentWindow.document, event.type, event.fn, This); 217 216 } … … 227 226 }; 228 227 jsToolBar.prototype.addIwinEvent = function(target, type, fn, scope) { 229 varmyFn = function(e) {228 const myFn = function(e) { 230 229 fn.call(scope, e); 231 230 }; … … 260 259 } 261 260 262 varThis = this;261 const This = this; 263 262 264 263 function setLink(title, link) { 265 varli = document.createElement('li');266 vara;264 const li = document.createElement('li'); 265 let a; 267 266 if (link) { 268 267 a = document.createElement('a'); … … 307 306 this.iwin.document.designMode = 'on'; 308 307 } catch (e) {} // Firefox needs this 309 varThis = this;308 const This = this; 310 309 setTimeout(function() { 311 310 This.iframe.contentWindow.focus(); … … 326 325 }; 327 326 jsToolBar.prototype.resizeDragMove = function(event) { 328 var new_height = (this.dragStartH + event.clientY - this.dragStartY) + 'px';327 const new_height = `${this.dragStartH + event.clientY - this.dragStartY}px`; 329 328 if (this.iframe != undefined) { 330 329 this.iframe.style.height = new_height; … … 338 337 */ 339 338 jsToolBar.prototype.insertNode = function(node) { 340 varrange;339 let range; 341 340 342 341 if (this.iwin.getSelection) { // Gecko 343 varsel = this.iwin.getSelection();342 const sel = this.iwin.getSelection(); 344 343 range = sel.getRangeAt(0); 345 344 … … 366 365 } else { // IE 367 366 // lambda element 368 varp = this.iwin.document.createElement('div');367 const p = this.iwin.document.createElement('div'); 369 368 p.appendChild(node); 370 369 range = this.iwin.document.selection.createRange(); … … 381 380 */ 382 381 jsToolBar.prototype.getSelectedNode = function() { 383 varsel;382 let sel; 384 383 var content; 385 384 if (this.iwin.getSelection) { // Gecko 386 385 sel = this.iwin.getSelection(); 387 varrange = sel.getRangeAt(0);386 const range = sel.getRangeAt(0); 388 387 content = range.cloneContents(); 389 388 } else { // IE 390 389 sel = this.iwin.document.selection; 391 vard = this.iwin.document.createElement('div');390 const d = this.iwin.document.createElement('div'); 392 391 d.innerHTML = sel.createRange().htmlText; 393 392 content = this.iwin.document.createDocumentFragment(); 394 for ( vari = 0; i < d.childNodes.length; i++) {393 for (let i = 0; i < d.childNodes.length; i++) { 395 394 content.appendChild(d.childNodes[i].cloneNode(true)); 396 395 } … … 405 404 return this.iwin.getSelection().toString(); 406 405 } else { // IE 407 varrange = this.iwin.document.selection.createRange();406 const range = this.iwin.document.selection.createRange(); 408 407 return range.text; 409 408 } … … 411 410 412 411 jsToolBar.prototype.replaceNodeByContent = function(node) { 413 varcontent = this.iwin.document.createDocumentFragment();414 for ( vari = 0; i < node.childNodes.length; i++) {412 const content = this.iwin.document.createDocumentFragment(); 413 for (let i = 0; i < node.childNodes.length; i++) { 415 414 content.appendChild(node.childNodes[i].cloneNode(true)); 416 415 } … … 419 418 420 419 jsToolBar.prototype.getBlockLevel = function() { 421 var blockElts = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']; 422 423 var range, commonAncestorContainer; 420 const blockElts = ['p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6']; 421 422 let range; 423 let commonAncestorContainer; 424 424 if (this.iwin.getSelection) { //gecko 425 varselection = this.iwin.getSelection();425 const selection = this.iwin.getSelection(); 426 426 range = selection.getRangeAt(0); 427 427 commonAncestorContainer = range.commonAncestorContainer; … … 434 434 } 435 435 436 varancestorTagName = commonAncestorContainer.tagName.toLowerCase();436 let ancestorTagName = commonAncestorContainer.tagName.toLowerCase(); 437 437 while (arrayIndexOf(blockElts, ancestorTagName) == -1 && ancestorTagName != 'body') { 438 438 commonAncestorContainer = commonAncestorContainer.parentNode; … … 443 443 }; 444 444 jsToolBar.prototype.adjustBlockLevelCombo = function() { 445 varblockLevel = this.getBlockLevel();445 const blockLevel = this.getBlockLevel(); 446 446 if (blockLevel !== null) 447 447 this.toolNodes.blocks.value = blockLevel.tagName.toLowerCase(); … … 471 471 */ 472 472 jsToolBar.prototype.tagsoup2xhtml = function(html) { 473 for ( varreg in this.simpleCleanRegex) {473 for (let reg in this.simpleCleanRegex) { 474 474 html = html.replace(this.simpleCleanRegex[reg][0], this.simpleCleanRegex[reg][1]); 475 475 } … … 488 488 489 489 /* IE laisse souvent des attributs sans guillemets */ 490 varmyRegexp = /<[^>]+((\s+\w+\s*=\s*)([^"'][\w~@+$,%\/:.#?=&;!*()-]*))[^>]*?>/;491 varmyQuoteFn = function(str, val1, val2, val3) {492 vartamponRegex = new RegExp(regexpEscape(val1));490 const myRegexp = /<[^>]+((\s+\w+\s*=\s*)([^"'][\w~@+$,%\/:.#?=&;!*()-]*))[^>]*?>/; 491 const myQuoteFn = function(str, val1, val2, val3) { 492 const tamponRegex = new RegExp(regexpEscape(val1)); 493 493 return str.replace(tamponRegex, val2 + '"' + val3 + '"'); 494 494 }; … … 508 508 509 509 /* Trim only if there's no pre tag */ 510 varpattern_pre = /<pre>[\s\S]*<\/pre>/gi;510 const pattern_pre = /<pre>[\s\S]*<\/pre>/gi; 511 511 if (!pattern_pre.test(html)) { 512 512 html = html.replace(/^\s+/gm, ''); … … 517 517 }; 518 518 jsToolBar.prototype.validBlockquote = function() { 519 varblockElts = ['address', 'blockquote', 'dl', 'div', 'fieldset', 'form', 'h1',519 const blockElts = ['address', 'blockquote', 'dl', 'div', 'fieldset', 'form', 'h1', 520 520 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'ol', 'p', 'pre', 'table', 'ul' 521 521 ]; 522 varBQs = this.iwin.document.getElementsByTagName('blockquote');523 varbqChilds;524 varp;525 526 for ( varbq = 0; bq < BQs.length; bq++) {522 const BQs = this.iwin.document.getElementsByTagName('blockquote'); 523 let bqChilds; 524 let p; 525 526 for (let bq = 0; bq < BQs.length; bq++) { 527 527 bqChilds = BQs[bq].childNodes; 528 varfrag = this.iwin.document.createDocumentFragment();529 for ( vari = (bqChilds.length - 1); i >= 0; i--) {528 let frag = this.iwin.document.createDocumentFragment(); 529 for (let i = (bqChilds.length - 1); i >= 0; i--) { 530 530 if (bqChilds[i].nodeType == 1 && // Node.ELEMENT_NODE 531 531 arrayIndexOf(blockElts, bqChilds[i].tagName.toLowerCase()) >= 0) { … … 561 561 562 562 jsToolBar.prototype.removeTextFormating = function(html) { 563 for ( varreg in this.removeFormatRegexp) {563 for (let reg in this.removeFormatRegexp) { 564 564 html = html.replace(this.removeFormatRegexp[reg][0], this.removeFormatRegexp[reg][1]); 565 565 } … … 576 576 fn: function(opt) { 577 577 if (opt == 'none') { 578 varblockLevel = this.getBlockLevel();578 const blockLevel = this.getBlockLevel(); 579 579 if (blockLevel !== null) { 580 580 this.replaceNodeByContent(blockLevel); … … 611 611 612 612 jsToolBar.prototype.elements.quote.fn.wysiwyg = function() { 613 varn = this.getSelectedNode();614 varq = this.iwin.document.createElement('q');613 const n = this.getSelectedNode(); 614 const q = this.iwin.document.createElement('q'); 615 615 q.appendChild(n); 616 616 this.insertNode(q); … … 618 618 619 619 jsToolBar.prototype.elements.code.fn.wysiwyg = function() { 620 varn = this.getSelectedNode();621 varcode = this.iwin.document.createElement('code');620 const n = this.getSelectedNode(); 621 const code = this.iwin.document.createElement('code'); 622 622 code.appendChild(n); 623 623 this.insertNode(code); … … 625 625 626 626 jsToolBar.prototype.elements.mark.fn.wysiwyg = function() { 627 varn = this.getSelectedNode();628 varmark = this.iwin.document.createElement('mark');627 const n = this.getSelectedNode(); 628 const mark = this.iwin.document.createElement('mark'); 629 629 mark.appendChild(n); 630 630 this.insertNode(mark); … … 632 632 633 633 jsToolBar.prototype.elements.br.fn.wysiwyg = function() { 634 varn = this.iwin.document.createElement('br');634 const n = this.iwin.document.createElement('br'); 635 635 this.insertNode(n); 636 636 }; 637 637 638 638 jsToolBar.prototype.elements.blockquote.fn.wysiwyg = function() { 639 varn = this.getSelectedNode();640 varq = this.iwin.document.createElement('blockquote');639 const n = this.getSelectedNode(); 640 const q = this.iwin.document.createElement('blockquote'); 641 641 q.appendChild(n); 642 642 this.insertNode(q); … … 659 659 660 660 jsToolBar.prototype.elements.link.fn.wysiwyg = function() { 661 var href, hreflang; 662 var range, commonAncestorContainer; 661 let href; 662 let hreflang; 663 let range; 664 let commonAncestorContainer; 663 665 if (this.iwin.getSelection) { //gecko 664 varselection = this.iwin.getSelection();666 const selection = this.iwin.getSelection(); 665 667 range = selection.getRangeAt(0); 666 668 commonAncestorContainer = range.commonAncestorContainer; … … 673 675 } 674 676 675 varancestorTagName = commonAncestorContainer.tagName.toLowerCase();677 let ancestorTagName = commonAncestorContainer.tagName.toLowerCase(); 676 678 while (ancestorTagName != 'a' && ancestorTagName != 'body') { 677 679 commonAncestorContainer = commonAncestorContainer.parentNode; … … 707 709 708 710 // Create link 709 varn = this.getSelectedNode();710 vara = this.iwin.document.createElement('a');711 const n = this.getSelectedNode(); 712 const a = this.iwin.document.createElement('a'); 711 713 a.href = href; 712 714 if (hreflang) a.setAttribute('hreflang', hreflang); … … 723 725 jsToolBar.prototype.elements.removeFormat.disabled = !jsToolBar.prototype.can_wwg; 724 726 jsToolBar.prototype.elements.removeFormat.fn.xhtml = function() { 725 varhtml = this.textarea.value;727 let html = this.textarea.value; 726 728 html = this.removeTextFormating(html); 727 729 this.textarea.value = html; 728 730 }; 729 731 jsToolBar.prototype.elements.removeFormat.fn.wysiwyg = function() { 730 varhtml = this.iwin.document.body.innerHTML;732 let html = this.iwin.document.body.innerHTML; 731 733 html = this.removeTextFormating(html); 732 734 this.iwin.document.body.innerHTML = html; … … 738 740 return aArray.indexOf(aValue); 739 741 } else { 740 varindex = -1;741 varl = aArray.length;742 for ( vari = 0; i < l; i++) {742 let index = -1; 743 const l = aArray.length; 744 for (let i = 0; i < l; i++) { 743 745 if (aArray[i] === aValue) { 744 746 index = i; … … 755 757 return true; 756 758 } else if (obj.attachEvent) { 757 varr = obj.attachEvent("on" + evType, fn);759 const r = obj.attachEvent("on" + evType, fn); 758 760 return r; 759 761 } else { … … 767 769 return true; 768 770 } else if (obj.detachEvent) { 769 varr = obj.detachEvent("on" + evType, fn);771 const r = obj.detachEvent("on" + evType, fn); 770 772 return r; 771 773 } else {
Note: See TracChangeset
for help on using the changeset viewer.