Dotclear


Ignore:
Timestamp:
09/18/18 20:22:10 (7 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Use let and const rather than var (ES2015/ES6), use template string where is more efficient

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/dcLegacyEditor/js/jsToolBar/jsToolBar.js

    r3735 r3880  
    2424 */ 
    2525 
    26 var jsToolBar = function(textarea) { 
     26const jsToolBar = function(textarea) { 
    2727  if (!document.createElement) { 
    2828    return; 
     
    5959      this.handle = document.createElement('div'); 
    6060      this.handle.className = 'jstHandle'; 
    61       var dragStart = this.resizeDragStart; 
    62       var This = this; 
     61      const dragStart = this.resizeDragStart; 
     62      const This = this; 
    6363      this.handle.addEventListener('mousedown', function(event) { 
    6464        dragStart.call(This, event); 
     
    7373}; 
    7474 
    75 var jsButton = function(title, fn, scope, className, accesskey) { 
     75const jsButton = function(title, fn, scope, className, accesskey) { 
    7676  this.title = title || null; 
    7777  this.fn = fn || function() {}; 
     
    8383  if (!this.scope) return null; 
    8484 
    85   var button = document.createElement('button'); 
     85  const button = document.createElement('button'); 
    8686  button.setAttribute('type', 'button'); 
    8787  if (this.className) button.className = this.className; 
    8888  button.title = this.title; 
    8989  if (this.accesskey) button.accessKey = this.accesskey; 
    90   var span = document.createElement('span'); 
     90  const span = document.createElement('span'); 
    9191  span.appendChild(document.createTextNode(this.title)); 
    9292  button.appendChild(span); 
     
    9696  } 
    9797  if (typeof(this.fn) == 'function') { 
    98     var This = this; 
     98    const This = this; 
    9999    button.onclick = function() { 
    100100      try { 
     
    107107}; 
    108108 
    109 var jsSpace = function(id) { 
     109const jsSpace = function(id) { 
    110110  this.id = id || null; 
    111111  this.width = null; 
    112112}; 
    113113jsSpace.prototype.draw = function() { 
    114   var span = document.createElement('span'); 
     114  const span = document.createElement('span'); 
    115115  if (this.id) span.id = this.id; 
    116116  span.appendChild(document.createTextNode(String.fromCharCode(160))); 
     
    121121}; 
    122122 
    123 var jsCombo = function(title, options, scope, fn, className) { 
     123const jsCombo = function(title, options, scope, fn, className) { 
    124124  this.title = title || null; 
    125125  this.options = options || null; 
     
    131131  if (!this.scope || !this.options) return null; 
    132132 
    133   var select = document.createElement('select'); 
     133  const select = document.createElement('select'); 
    134134  if (this.className) select.className = this.className; 
    135135  select.title = this.title; 
    136136 
    137   for (var o in this.options) { 
     137  for (let o in this.options) { 
    138138    //var opt = this.options[o]; 
    139     var option = document.createElement('option'); 
     139    const option = document.createElement('option'); 
    140140    option.value = o; 
    141141    option.appendChild(document.createTextNode(this.options[o])); 
     
    143143  } 
    144144 
    145   var This = this; 
     145  const This = this; 
    146146  select.onchange = function() { 
    147147    try { 
     
    177177 
    178178  button: function(toolName) { 
    179     var tool = this.elements[toolName]; 
     179    const tool = this.elements[toolName]; 
    180180    if (typeof tool.fn[this.mode] != 'function') return null; 
    181     var b = new jsButton(tool.title, tool.fn[this.mode], this, 'jstb_' + toolName, tool.accesskey); 
     181    const b = new jsButton(tool.title, tool.fn[this.mode], this, 'jstb_' + toolName, tool.accesskey); 
    182182    if (tool.icon != undefined) { 
    183183      b.icon = tool.icon; 
     
    186186  }, 
    187187  space: function(toolName) { 
    188     var tool = new jsSpace(toolName); 
     188    const tool = new jsSpace(toolName); 
    189189    if (this.elements[toolName].format != undefined && !this.elements[toolName].format[this.mode]) return null; 
    190190    if (this.elements[toolName].width !== undefined) { 
     
    194194  }, 
    195195  combo: function(toolName) { 
    196     var tool = this.elements[toolName]; 
     196    const tool = this.elements[toolName]; 
    197197 
    198198    if (tool[this.mode] != undefined) { 
    199199 
    200       var length = tool[this.mode].list.length; 
     200      const length = tool[this.mode].list.length; 
    201201 
    202202      if (typeof tool[this.mode].fn != 'function' || length == 0) { 
    203203        return null; 
    204204      } else { 
    205         var options = {}; 
    206         for (var i = 0; i < length; i++) { 
    207           var opt = tool[this.mode].list[i]; 
     205        let options = {}; 
     206        for (let i = 0; i < length; i++) { 
     207          const opt = tool[this.mode].list[i]; 
    208208          options[opt] = tool.options[opt]; 
    209209        } 
     
    224224 
    225225    // Draw toolbar elements 
    226     var b, tool, newTool; 
    227  
    228     for (var i in this.elements) { 
     226    let b; 
     227    let tool; 
     228    let newTool; 
     229 
     230    for (let i in this.elements) { 
    229231      b = this.elements[i]; 
    230232 
    231       var disabled = 
     233      const disabled = 
    232234        b.type == undefined || b.type == '' || 
    233235        (b.disabled != undefined && b.disabled) || 
     
    262264    suffix = suffix || ''; 
    263265 
    264     var start, end, sel, scrollPos, subst, res; 
     266    let start; 
     267    let end; 
     268    let sel; 
     269    let scrollPos; 
     270    let subst; 
     271    let res; 
    265272 
    266273    if (typeof(document.selection) != "undefined") { 
     
    305312  stripBaseURL: function(url) { 
    306313    if (this.base_url != '') { 
    307       var pos = url.indexOf(this.base_url); 
     314      const pos = url.indexOf(this.base_url); 
    308315      if (pos == 0) { 
    309316        url = url.substr(this.base_url.length); 
     
    321328}; 
    322329jsToolBar.prototype.resizeDragStart = function(event) { 
    323   var This = this; 
     330  const This = this; 
    324331  this.dragStartY = event.clientY; 
    325332  this.resizeSetStartH(); 
     
    364371      else 
    365372        try { 
    366           this.singleTag('<' + opt + '>', '</' + opt + '>'); 
     373          this.singleTag(`<${opt}>`, `</${opt}>`); 
    367374        } catch (e) {} 
    368375      this.toolNodes.blocks.value = 'nonebis'; 
     
    688695    this.encloseSelection('', '', function(str) { 
    689696      if (str) { 
    690         return '<img src="' + src + '" alt="' + str + '" />'; 
     697        return `<img src="${src}" alt="${str}" />`; 
    691698      } else { 
    692         return '<img src="' + src + '" alt="" />'; 
     699        return `<img src="${src}" alt="" />`; 
    693700      } 
    694701    }); 
     
    700707    this.encloseSelection('', '', function(str) { 
    701708      if (str) { 
    702         return '((' + src + '|' + str + '))'; 
     709        return `((${src}|${str}))`; 
    703710      } else { 
    704         return '((' + src + '))'; 
     711        return `((${src}))`; 
    705712      } 
    706713    }); 
Note: See TracChangeset for help on using the changeset viewer.

Sites map