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

Location:
plugins/dcCKEditor/js
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • plugins/dcCKEditor/js/ckeditor-plugins/dclink/plugin.js

    r2962 r3880  
     1/*global CKEDITOR, dotclear, $ */ 
     2'use strict'; 
     3 
    14(function() { 
    2      CKEDITOR.plugins.add('dclink', { 
    3           icons: 'dclink', 
    4           init: function(editor) { 
    5                editor.addCommand('dcLinkCommand', { 
    6                     exec: function(editor) { 
    7                          if (editor.getSelection().getSelectedElement()!=null 
    8                              || editor.getSelection().getNative().toString().replace(/\s*/,'')!='') { 
    9                               $.toolbarPopup('popup_link.php?plugin_id=dcCKEditor'); 
    10                          } 
    11                     } 
    12                }); 
     5  CKEDITOR.plugins.add('dclink', { 
     6    icons: 'dclink', 
     7    init: function(editor) { 
     8      editor.addCommand('dcLinkCommand', { 
     9        exec: function(editor) { 
     10          if (editor.getSelection().getSelectedElement() != null || 
     11            editor.getSelection().getNative().toString().replace(/\s*/, '') != '') { 
     12            $.toolbarPopup('popup_link.php?plugin_id=dcCKEditor'); 
     13          } 
     14        } 
     15      }); 
    1316 
    14                editor.ui.addButton('dcLink', { 
    15                     label: dotclear.msg.link_title, 
    16                     command: 'dcLinkCommand', 
    17                     toolbar: 'insert' 
    18                }); 
     17      editor.ui.addButton('dcLink', { 
     18        label: dotclear.msg.link_title, 
     19        command: 'dcLinkCommand', 
     20        toolbar: 'insert' 
     21      }); 
    1922 
    20                editor.on('doubleclick',function(e) { 
    21                     var element = CKEDITOR.plugins.link.getSelectedLink(editor) || e.data.element; 
    22                     if (!element.isReadOnly()) { 
    23                          if (element.is('a') 
    24                              && !element.hasClass('media-link') // link to original media @see js/popup_media.js 
    25                              && !element.hasClass('ref-post')) {    // link to an entry @see js/popup_posts.js 
     23      editor.on('doubleclick', function(e) { 
     24        const element = CKEDITOR.plugins.link.getSelectedLink(editor) || e.data.element; 
     25        if (!element.isReadOnly()) { 
     26          if (element.is('a') && 
     27            !element.hasClass('media-link') && // link to original media @see js/popup_media.js 
     28            !element.hasClass('ref-post')) { // link to an entry @see js/popup_posts.js 
    2629 
    27                               editor.getSelection().selectElement(element); 
     30            editor.getSelection().selectElement(element); 
    2831 
    29                               var popup_url = 'popup_link.php?plugin_id=dcCKEditor'; 
    30                               if (element.getAttribute('href')) { 
    31                                    popup_url += '&href='+element.getAttribute('href'); 
    32                               } 
    33                               if (element.getAttribute('hreflang')) { 
    34                                    popup_url += '&hreflang='+element.getAttribute('hreflang'); 
    35                               } 
    36                               if (element.getAttribute('title')) { 
    37                                    popup_url += '&title='+element.getAttribute('title'); 
    38                               } 
     32            let popup_url = 'popup_link.php?plugin_id=dcCKEditor'; 
     33            if (element.getAttribute('href')) { 
     34              popup_url += '&href=' + element.getAttribute('href'); 
     35            } 
     36            if (element.getAttribute('hreflang')) { 
     37              popup_url += '&hreflang=' + element.getAttribute('hreflang'); 
     38            } 
     39            if (element.getAttribute('title')) { 
     40              popup_url += '&title=' + element.getAttribute('title'); 
     41            } 
    3942 
    40                               $.toolbarPopup(popup_url); 
    41                               return false; 
    42                          } 
    43                     } 
    44                }); 
    45           } 
    46      }); 
     43            $.toolbarPopup(popup_url); 
     44            return false; 
     45          } 
     46        } 
     47      }); 
     48    } 
     49  }); 
    4750})(); 
  • plugins/dcCKEditor/js/ckeditor-plugins/entrylink/plugin.js

    r2901 r3880  
     1/*global CKEDITOR, dotclear, $ */ 
     2'use strict'; 
     3 
    14(function() { 
    2      CKEDITOR.plugins.add('entrylink', { 
    3           icons: 'entrylink', 
    4           init: function(editor) { 
    5                popup_params = { 'width': 760, 'height': 500}; 
     5  CKEDITOR.plugins.add('entrylink', { 
     6    icons: 'entrylink', 
     7    init: function(editor) { 
     8      const popup_params = { 
     9        'width': 760, 
     10        'height': 500 
     11      }; 
    612 
    7                editor.addCommand('entryLinkCommand', { 
    8                     exec: function(editor) { 
    9                          if (editor.getSelection().getNative().toString().replace(/\s*/,'')!='') { 
    10                               $.toolbarPopup('popup_posts.php?popup=1&plugin_id=dcCKEditor', popup_params); 
    11                          } 
    12                     } 
    13                }); 
     13      editor.addCommand('entryLinkCommand', { 
     14        exec: function(editor) { 
     15          if (editor.getSelection().getNative().toString().replace(/\s*/, '') != '') { 
     16            $.toolbarPopup('popup_posts.php?popup=1&plugin_id=dcCKEditor', popup_params); 
     17          } 
     18        } 
     19      }); 
    1420 
    15                editor.ui.addButton('EntryLink', { 
    16                     label: dotclear.msg.post_link_title, 
    17                     command: 'entryLinkCommand', 
    18                     toolbar: 'insert' 
    19                }); 
     21      editor.ui.addButton('EntryLink', { 
     22        label: dotclear.msg.post_link_title, 
     23        command: 'entryLinkCommand', 
     24        toolbar: 'insert' 
     25      }); 
    2026 
    21                editor.on('doubleclick',function(e) { 
    22                     var element = CKEDITOR.plugins.link.getSelectedLink(editor) || e.data.element; 
    23                     if (!element.isReadOnly()) { 
    24                          if (element.is('a') 
    25                              && !element.hasClass('media-link') 
    26                              && element.hasClass('ref-post')) { // link to original media @see js/popup_media.js 
    27                               editor.getSelection().selectElement(element); 
     27      editor.on('doubleclick', function(e) { 
     28        const element = CKEDITOR.plugins.link.getSelectedLink(editor) || e.data.element; 
     29        if (!element.isReadOnly()) { 
     30          if (element.is('a') && !element.hasClass('media-link') && element.hasClass('ref-post')) { 
     31            // link to original media @see js/popup_media.js 
     32            editor.getSelection().selectElement(element); 
    2833 
    29                               $.toolbarPopup('popup_posts.php?popup=1&plugin_id=dcCKEditor', popup_params); 
    30                               return false; 
    31                          } 
    32                     } 
    33                }); 
    34           } 
    35      }); 
     34            $.toolbarPopup('popup_posts.php?popup=1&plugin_id=dcCKEditor', popup_params); 
     35            return false; 
     36          } 
     37        } 
     38      }); 
     39    } 
     40  }); 
    3641})(); 
  • plugins/dcCKEditor/js/ckeditor-plugins/img/plugin.js

    r2869 r3880  
     1/*global CKEDITOR, dotclear */ 
     2'use strict'; 
     3 
    14(function() { 
    2      CKEDITOR.plugins.add('img', { 
    3           init: function(editor) { 
    4                editor.addCommand('dcImgCommand', new CKEDITOR.dialogCommand('imgDialog')); 
     5  CKEDITOR.plugins.add('img', { 
     6    init: function(editor) { 
     7      editor.addCommand('dcImgCommand', new CKEDITOR.dialogCommand('imgDialog')); 
    58 
    6                CKEDITOR.dialog.add('imgDialog', this.path+'dialogs/img.js'); 
     9      CKEDITOR.dialog.add('imgDialog', this.path + 'dialogs/img.js'); 
    710 
    8                editor.ui.addButton('img', { 
    9                     label: dotclear.msg.img_title, 
    10                     command: 'dcImgCommand', 
    11                     toolbar: 'insert', 
    12                     icon: this.path + 'icons/img.png' 
    13                }); 
    14           } 
    15      }); 
     11      editor.ui.addButton('img', { 
     12        label: dotclear.msg.img_title, 
     13        command: 'dcImgCommand', 
     14        toolbar: 'insert', 
     15        icon: this.path + 'icons/img.png' 
     16      }); 
     17    } 
     18  }); 
    1619})(); 
  • plugins/dcCKEditor/js/ckeditor-plugins/media/plugin.js

    r2835 r3880  
     1/*global CKEDITOR, dotclear, $ */ 
     2'use strict'; 
     3 
    14(function() { 
    2      CKEDITOR.plugins.add('media', { 
    3           icons: 'media', 
    4           init: function(editor) { 
    5                popup_params = { 'width': 760, 'height': 500}; 
     5  CKEDITOR.plugins.add('media', { 
     6    icons: 'media', 
     7    init: function(editor) { 
     8      const popup_params = { 
     9        'width': 760, 
     10        'height': 500 
     11      }; 
    612 
    7                editor.addCommand('mediaCommand', { 
    8                     exec: function(editor) { 
    9                          $.toolbarPopup('media.php?popup=1&plugin_id=dcCKEditor', popup_params); 
    10                     } 
    11                }); 
     13      editor.addCommand('mediaCommand', { 
     14        exec: function() { 
     15          $.toolbarPopup('media.php?popup=1&plugin_id=dcCKEditor', popup_params); 
     16        } 
     17      }); 
    1218 
    13                editor.ui.addButton('Media', { 
    14                     label: dotclear.msg.img_select_title, 
    15                     command: 'mediaCommand', 
    16                     toolbar: 'insert' 
    17                }); 
     19      editor.ui.addButton('Media', { 
     20        label: dotclear.msg.img_select_title, 
     21        command: 'mediaCommand', 
     22        toolbar: 'insert' 
     23      }); 
    1824 
    19                editor.on('doubleclick',function(e) { 
    20                     var element = CKEDITOR.plugins.link.getSelectedLink(editor) || e.data.element; 
    21                     if (!element.isReadOnly()) { 
    22                          if (element.is('img') || (element.is('a') && element.hasClass('media-link'))) { 
    23                               $.toolbarPopup('media.php?popup=1&plugin_id=dcCKEditor', popup_params); 
    24                               return false; 
    25                          } 
    26                     } 
    27                }); 
    28           } 
    29      }); 
     25      editor.on('doubleclick', function(e) { 
     26        const element = CKEDITOR.plugins.link.getSelectedLink(editor) || e.data.element; 
     27        if (!element.isReadOnly()) { 
     28          if (element.is('img') || (element.is('a') && element.hasClass('media-link'))) { 
     29            $.toolbarPopup('media.php?popup=1&plugin_id=dcCKEditor', popup_params); 
     30            return false; 
     31          } 
     32        } 
     33      }); 
     34    } 
     35  }); 
    3036})(); 
  • plugins/dcCKEditor/js/ckeditor-skins/dotclear/skin.js

    r2738 r3880  
     1/*global CKEDITOR */ 
     2'use strict'; 
     3 
    14CKEDITOR.skin.name = 'dotclear'; 
    25 
  • plugins/dcCKEditor/js/popup_link.js

    r3709 r3880  
    88 
    99  $('#link-insert-ok').click(function() { 
    10     var insert_form = $('#link-insert-form').get(0); 
     10    const insert_form = $('#link-insert-form').get(0); 
    1111    if (insert_form == undefined) { 
    1212      return; 
    1313    } 
    1414 
    15     var editor_name = window.opener.$.getEditorName(), 
    16       editor = window.opener.CKEDITOR.instances[editor_name], 
    17       link = '', 
    18       selected_element; 
     15    const editor_name = window.opener.$.getEditorName(); 
     16    const editor = window.opener.CKEDITOR.instances[editor_name]; 
     17    let link = ''; 
     18    let selected_element; 
    1919    if (editor.getSelection().getSelectedElement() != null) { 
    2020      selected_element = editor.getSelection().getSelectedElement(); 
  • plugins/dcCKEditor/js/popup_media.js

    r3725 r3880  
    88 
    99  $('#media-insert-ok').click(function() { 
    10     var insert_form = $('#media-insert-form').get(0); 
     10    const insert_form = $('#media-insert-form').get(0); 
    1111    if (insert_form === undefined) { 
    1212      return; 
    1313    } 
    1414 
    15     var editor_name = window.opener.$.getEditorName(), 
    16       editor = window.opener.CKEDITOR.instances[editor_name], 
    17       type = insert_form.elements.type.value, 
    18       media_align_grid = { 
    19         left: 'float: left; margin: 0 1em 1em 0;', 
    20         right: 'float: right; margin: 0 0 1em 1em;', 
    21         center: 'margin: 0 auto; display: table;' 
    22       }; 
     15    const editor_name = window.opener.$.getEditorName(); 
     16    const editor = window.opener.CKEDITOR.instances[editor_name]; 
     17    const type = insert_form.elements.type.value; 
     18    const media_align_grid = { 
     19      left: 'float: left; margin: 0 1em 1em 0;', 
     20      right: 'float: right; margin: 0 0 1em 1em;', 
     21      center: 'margin: 0 auto; display: table;' 
     22    }; 
    2323 
    2424    if (type == 'image') { 
    2525      if (editor.mode == 'wysiwyg') { 
    2626 
    27         var align = $('input[name="alignment"]:checked', insert_form).val(); 
    28         var media_legend = $('input[name="legend"]:checked', insert_form).val(); 
    29         var img_description = $('input[name="description"]', insert_form).val(); 
    30         var style = ''; 
    31         var template = ''; 
    32         var template_figure = [ 
     27        const align = $('input[name="alignment"]:checked', insert_form).val(); 
     28        let media_legend = $('input[name="legend"]:checked', insert_form).val(); 
     29        const img_description = $('input[name="description"]', insert_form).val(); 
     30        let style = ''; 
     31        let template = ''; 
     32        let template_figure = [ 
    3333          '', 
    3434          '' 
    3535        ]; 
    36         var template_link = [ 
     36        let template_link = [ 
    3737          '', 
    3838          '' 
    3939        ]; 
    40         var template_image = ''; 
     40        let template_image = ''; 
    4141 
    4242        if (media_legend != '' && media_legend != 'title' && media_legend != 'none') { 
     
    5858          template_figure[1] = template_figure[1] + '</figure>'; 
    5959        } 
    60         template_image = '<img class="media" src="{imgSrc}" alt="{imgAlt}"' + style + '/>'; 
     60        template_image = `<img class="media" src="{imgSrc}" alt="{imgAlt}"${style}/>`; 
    6161        if ($('input[name="insertion"]:checked', insert_form).val() == 'link') { 
    6262          // With a link to original 
     
    6666        template = template_figure[0] + template_link[0] + template_image + template_link[1] + template_figure[1]; 
    6767 
    68         var block = new window.opener.CKEDITOR.template(template); 
    69         var params = {}; 
     68        let block = new window.opener.CKEDITOR.template(template); 
     69        let params = {}; 
    7070 
    7171        // Set parameters for template 
     
    8686 
    8787        // Insert element 
    88         var figure = window.opener.CKEDITOR.dom.element.createFromHtml( 
     88        const figure = window.opener.CKEDITOR.dom.element.createFromHtml( 
    8989          block.output(params), editor.document 
    9090        ); 
    9191        editor.insertElement(figure); 
    9292      } 
     93 
    9394    } else if (type == 'mp3') { 
    9495      // Audio media 
    95       var player_audio = $('#public_player').val(); 
    96       var align_audio = $('input[name="alignment"]:checked', insert_form).val(); 
     96      let player_audio = $('#public_player').val(); 
     97      const align_audio = $('input[name="alignment"]:checked', insert_form).val(); 
    9798 
    9899      if (align_audio != undefined && align_audio != 'none') { 
    99         player_audio = '<div style="' + media_align_grid[align_audio] + '">' + player_audio + '</div>'; 
     100        player_audio = `<div style="${media_align_grid[align_audio]}">${player_audio}</div>`; 
    100101      } 
    101102      editor.insertElement(window.opener.CKEDITOR.dom.element.createFromHtml(player_audio)); 
     103 
    102104    } else if (type == 'flv') { 
    103105      // Video media 
    104       var oplayer = $('<div>' + $('#public_player').val() + '</div>'); 
    105       var flashvars = $('[name=FlashVars]', oplayer).val(); 
     106      const oplayer = $(`<div>${$('#public_player').val()}</div>`); 
     107      let flashvars = $('[name=FlashVars]', oplayer).val(); 
    106108 
    107       var align_video = $('input[name="alignment"]:checked', insert_form).val(); 
     109      const align_video = $('input[name="alignment"]:checked', insert_form).val(); 
    108110 
    109       var title = insert_form.elements.title.value; 
     111      const title = insert_form.elements.title.value; 
    110112      if (title) { 
    111         flashvars = 'title=' + encodeURI(title) + '&amp;' + flashvars; 
     113        flashvars = `title=${encodeURI(title)}&amp;${flashvars}`; 
    112114      } 
    113115 
    114       var vw = $('#video_w').val(); 
    115       var vh = $('#video_h').val(); 
     116      const vw = $('#video_w').val(); 
     117      const vh = $('#video_h').val(); 
    116118 
    117119      if (vw > 0) { 
     
    135137 
    136138      $('[name=FlashVars]', oplayer).val(flashvars); 
    137       var player_video = oplayer.html(); 
     139      let player_video = oplayer.html(); 
    138140 
    139141      if (align_video != undefined && align_video != 'none') { 
    140         player_video = '<div style="' + media_align_grid[align_video] + '">' + player_video + '</div>'; 
     142        player_video = `<div style="${media_align_grid[align_video]}">${player_video}</div>`; 
    141143      } 
    142144      editor.insertElement(window.opener.CKEDITOR.dom.element.createFromHtml(player_video)); 
     145 
    143146    } else { 
    144147      // Unknown media type 
    145       var link = '<a href="'; 
    146       link += window.opener.$.stripBaseURL($('input[name="url"]', insert_form).val()); 
    147       link += '">' + window.opener.CKEDITOR.tools.htmlEncodeAttr(insert_form.elements.title.value) + '</a>'; 
    148       var element = window.opener.CKEDITOR.dom.element.createFromHtml(link); 
     148      const url = window.opener.$.stripBaseURL($('input[name="url"]', insert_form).val()); 
     149      const text = window.opener.CKEDITOR.tools.htmlEncodeAttr(insert_form.elements.title.value); 
     150      const element = window.opener.CKEDITOR.dom.element.createFromHtml(`<a href="${url}">${text}</a>`); 
    149151 
    150152      editor.insertElement(element); 
  • plugins/dcCKEditor/js/popup_posts.js

    r3709 r3880  
    99  $('#form-entries tr>td.maximal>a').click(function(e) { 
    1010    e.preventDefault(); 
    11     var editor_name = window.opener.$.getEditorName(), 
    12       editor = window.opener.CKEDITOR.instances[editor_name], 
    13       link = '', 
    14       selected_text = editor.getSelection().getNative().toString(); 
     11    const editor_name = window.opener.$.getEditorName(); 
     12    const editor = window.opener.CKEDITOR.instances[editor_name]; 
     13    let link = ''; 
     14    const selected_text = editor.getSelection().getNative().toString(); 
    1515 
    1616    if (editor.mode == 'wysiwyg') { 
    1717      link = '<a class="ref-post" href="' + window.opener.$.stripBaseURL($(this).attr('title')) + '">' + selected_text + '</a>'; 
    18       var element = window.opener.CKEDITOR.dom.element.createFromHtml(link); 
     18      const element = window.opener.CKEDITOR.dom.element.createFromHtml(link); 
    1919      editor.insertElement(element); 
    2020    } 
Note: See TracChangeset for help on using the changeset viewer.

Sites map