Dotclear


Ignore:
Timestamp:
02/18/18 18:16:29 (8 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

use strict and no more linter warnings/errors as far as possible, switch from inline js to separate loaded file

Location:
plugins/tags/js
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • plugins/tags/js/ckeditor-tags-plugin.js

    r2939 r3709  
     1/*global $, dotclear, CKEDITOR */ 
     2'use strict'; 
     3 
    14(function() { 
    2      CKEDITOR.plugins.add('dctags', { 
    3           init: function(editor) { 
    4                editor.addCommand('dcTagsCommand', { 
    5                     exec: function(editor) { 
    6                          if (editor.getSelection().getNative().toString().replace(/\s*/,'')!='') { 
    7                               var str = editor.getSelection().getNative().toString().replace(/\s*/,''); 
    8                               var url = dotclear.msg.tag_url; 
    9                               window.dc_tag_editor.addMeta(str); 
    10                               var link = '<a href="'+$.stripBaseURL(url+'/'+str)+'">'+str+'</a>'; 
    11                               var element = CKEDITOR.dom.element.createFromHtml(link); 
    12                               editor.insertElement(element); 
    13                          } 
    14                     } 
    15                }); 
     5  CKEDITOR.plugins.add('dctags', { 
     6    init: function(editor) { 
     7      editor.addCommand('dcTagsCommand', { 
     8        exec: function(editor) { 
     9          if (editor.getSelection().getNative().toString().replace(/\s*/, '') != '') { 
     10            var str = editor.getSelection().getNative().toString().replace(/\s*/, ''); 
     11            var url = dotclear.msg.tag_url; 
     12            window.dc_tag_editor.addMeta(str); 
     13            var link = '<a href="' + $.stripBaseURL(url + '/' + str) + '">' + str + '</a>'; 
     14            var element = CKEDITOR.dom.element.createFromHtml(link); 
     15            editor.insertElement(element); 
     16          } 
     17        } 
     18      }); 
    1619 
    17                editor.ui.addButton('dcTags', { 
    18                     label: dotclear.msg.tag_title, 
    19                     command: 'dcTagsCommand', 
    20                     toolbar: 'insert', 
    21                     icon: this.path + 'tag.png' 
    22                }); 
    23           } 
    24      }); 
     20      editor.ui.addButton('dcTags', { 
     21        label: dotclear.msg.tag_title, 
     22        command: 'dcTagsCommand', 
     23        toolbar: 'insert', 
     24        icon: this.path + 'tag.png' 
     25      }); 
     26    } 
     27  }); 
    2528})(); 
  • plugins/tags/js/legacy-post.js

    r2924 r3709  
     1/*global dotclear, jsToolBar */ 
     2'use strict'; 
     3 
    14// Toolbar button for tags 
    25jsToolBar.prototype.elements.tagSpace = { 
    3      type: 'space', 
    4      format:{ 
    5           wysiwyg:true, 
    6           wiki:true, 
    7           xhtml:true, 
    8           markdown:true 
    9      } 
     6  type: 'space', 
     7  format: { 
     8    wysiwyg:  true, 
     9    wiki:     true, 
     10    xhtml:    true, 
     11    markdown: true 
     12  } 
    1013}; 
    1114 
    12 jsToolBar.prototype.elements.tag = {type: 'button', title: 'Keyword', fn:{} }; 
     15jsToolBar.prototype.elements.tag = { 
     16  type: 'button', 
     17  title: 'Keyword', 
     18  fn: {} 
     19}; 
    1320jsToolBar.prototype.elements.tag.context = 'post'; 
    1421jsToolBar.prototype.elements.tag.icon = 'index.php?pf=tags/img/tag-add.png'; 
    1522jsToolBar.prototype.elements.tag.fn.wiki = function() { 
    16      this.encloseSelection('','',function(str) { 
    17           if (str == '') { window.alert(dotclear.msg.no_selection); return ''; } 
    18           if (str.indexOf(',') != -1) { 
    19                return str; 
    20           } else { 
    21                window.dc_tag_editor.addMeta(str); 
    22                return '['+str+'|tag:'+str+']'; 
    23           } 
    24      }); 
     23  this.encloseSelection('', '', function(str) { 
     24    if (str == '') { 
     25      window.alert(dotclear.msg.no_selection); 
     26      return ''; 
     27    } 
     28    if (str.indexOf(',') != -1) { 
     29      return str; 
     30    } else { 
     31      window.dc_tag_editor.addMeta(str); 
     32      return '[' + str + '|tag:' + str + ']'; 
     33    } 
     34  }); 
    2535}; 
    2636jsToolBar.prototype.elements.tag.fn.markdown = function() { 
    27      var url = this.elements.tag.url; 
    28      this.encloseSelection('','',function(str) { 
    29           if (str == '') { window.alert(dotclear.msg.no_selection); return ''; } 
    30           if (str.indexOf(',') != -1) { 
    31                return str; 
    32           } else { 
    33                window.dc_tag_editor.addMeta(str); 
    34                return '['+str+']('+this.stripBaseURL(url+'/'+str)+')'; 
    35           } 
    36      }); 
     37  var url = this.elements.tag.url; 
     38  this.encloseSelection('', '', function(str) { 
     39    if (str == '') { 
     40      window.alert(dotclear.msg.no_selection); 
     41      return ''; 
     42    } 
     43    if (str.indexOf(',') != -1) { 
     44      return str; 
     45    } else { 
     46      window.dc_tag_editor.addMeta(str); 
     47      return '[' + str + '](' + this.stripBaseURL(url + '/' + str) + ')'; 
     48    } 
     49  }); 
    3750}; 
    3851jsToolBar.prototype.elements.tag.fn.xhtml = function() { 
    39      var url = this.elements.tag.url; 
    40      this.encloseSelection('','',function(str) { 
    41           if (str == '') { window.alert(dotclear.msg.no_selection); return ''; } 
    42           if (str.indexOf(',') != -1) { 
    43                return str; 
    44           } else { 
    45                window.dc_tag_editor.addMeta(str); 
    46                return '<a href="'+this.stripBaseURL(url+'/'+str)+'">'+str+'</a>'; 
    47           } 
    48      }); 
     52  var url = this.elements.tag.url; 
     53  this.encloseSelection('', '', function(str) { 
     54    if (str == '') { 
     55      window.alert(dotclear.msg.no_selection); 
     56      return ''; 
     57    } 
     58    if (str.indexOf(',') != -1) { 
     59      return str; 
     60    } else { 
     61      window.dc_tag_editor.addMeta(str); 
     62      return '<a href="' + this.stripBaseURL(url + '/' + str) + '">' + str + '</a>'; 
     63    } 
     64  }); 
    4965}; 
    5066jsToolBar.prototype.elements.tag.fn.wysiwyg = function() { 
    51      var t = this.getSelectedText(); 
     67  var t = this.getSelectedText(); 
    5268 
    53      if (t == '') { window.alert(dotclear.msg.no_selection); return; } 
    54      if (t.indexOf(',') != -1) { return; } 
     69  if (t == '') { 
     70    window.alert(dotclear.msg.no_selection); 
     71    return; 
     72  } 
     73  if (t.indexOf(',') != -1) { 
     74    return; 
     75  } 
    5576 
    56      var n = this.getSelectedNode(); 
    57      var a = document.createElement('a'); 
    58      a.href = this.stripBaseURL(this.elements.tag.url+'/'+t); 
    59      a.appendChild(n); 
    60      this.insertNode(a); 
    61      window.dc_tag_editor.addMeta(t); 
     77  var n = this.getSelectedNode(); 
     78  var a = document.createElement('a'); 
     79  a.href = this.stripBaseURL(this.elements.tag.url + '/' + t); 
     80  a.appendChild(n); 
     81  this.insertNode(a); 
     82  window.dc_tag_editor.addMeta(t); 
    6283}; 
  • plugins/tags/js/post.js

    r2924 r3709  
     1/*global $, dotclear, metaEditor, editor_tags_options */ 
     2'use strict'; 
     3 
    14$(function() { 
    2      $('#edit-entry').onetabload(function() { 
    3           var tags_edit = $('#tags-edit'); 
    4           var post_id = $('#id'); 
    5           var meta_field = null; 
     5  $('#edit-entry').onetabload(function() { 
     6    var tags_edit = $('#tags-edit'); 
     7    var post_id = $('#id'); 
     8    var meta_field = null; 
     9    var mEdit = null; 
    610 
    7           if (tags_edit.length > 0) { 
    8                post_id = (post_id.length > 0) ? post_id.get(0).value : false; 
    9                if (post_id == false) { 
    10                     meta_field = $('<input type="hidden" name="post_tags" />'); 
    11                     meta_field.val($('#post_tags').val()); 
    12                } 
    13                var mEdit = new metaEditor(tags_edit,meta_field,'tag',editor_tags_options); 
    14                mEdit.meta_url = 'plugin.php?p=tags&m=tag_posts&amp;tag='; 
    15                mEdit.displayMeta('tag',post_id); 
     11    if (tags_edit.length > 0) { 
     12      post_id = (post_id.length > 0) ? post_id.get(0).value : false; 
     13      if (post_id == false) { 
     14        meta_field = $('<input type="hidden" name="post_tags" />'); 
     15        meta_field.val($('#post_tags').val()); 
     16      } 
     17      mEdit = new metaEditor(tags_edit, meta_field, 'tag', editor_tags_options); 
     18      mEdit.meta_url = 'plugin.php?p=tags&m=tag_posts&amp;tag='; 
     19      mEdit.displayMeta('tag', post_id); 
    1620 
    17                // mEdit object reference for toolBar 
    18                window.dc_tag_editor = mEdit; 
    19           } 
     21      // mEdit object reference for toolBar 
     22      window.dc_tag_editor = mEdit; 
     23    } 
    2024 
    21           $('#post_meta_input').autocomplete(mEdit.service_uri, { 
    22                extraParams: { 
    23                     'f': 'searchMeta', 
    24                     'metaType': 'tag' 
    25                }, 
    26                delay: 1000, 
    27                multiple: true, 
    28                multipleSeparator: ", ", 
    29                matchSubset: false, 
    30                matchContains: true, 
    31                parse: function(xml) { 
    32                     var results = []; 
    33                     $(xml).find('meta').each(function(){ 
    34                          results[results.length] = { 
    35                               data: { 
    36                                    "id": $(this).text(), 
    37                                    "count": $(this).attr("count"), 
    38                                    "percent":  $(this).attr("roundpercent") 
    39                               }, 
    40                               result: $(this).text() 
    41                          }; 
    42                     }); 
    43                     return results; 
    44                }, 
    45                formatItem: function(tag) { 
    46                     return tag.id + ' <em>(' + 
    47                     dotclear.msg.tags_autocomplete. 
    48                          replace('%p',tag.percent). 
    49                          replace('%e',tag.count + ' ' + 
    50                               (tag.count > 1 ? 
    51                               dotclear.msg.entries : 
    52                               dotclear.msg.entry) 
    53                          ) + 
    54                     ')</em>'; 
    55                }, 
    56                formatResult: function(tag) { 
    57                     return tag.result; 
    58                } 
    59           }); 
    60      }); 
     25    $('#post_meta_input').autocomplete(mEdit.service_uri, { 
     26      extraParams: { 
     27        'f': 'searchMeta', 
     28        'metaType': 'tag' 
     29      }, 
     30      delay: 1000, 
     31      multiple: true, 
     32      multipleSeparator: ', ', 
     33      matchSubset: false, 
     34      matchContains: true, 
     35      parse: function(xml) { 
     36        var results = []; 
     37        $(xml).find('meta').each(function() { 
     38          results[results.length] = { 
     39            data: { 
     40              'id': $(this).text(), 
     41              'count': $(this).attr('count'), 
     42              'percent': $(this).attr('roundpercent') 
     43            }, 
     44            result: $(this).text() 
     45          }; 
     46        }); 
     47        return results; 
     48      }, 
     49      formatItem: function(tag) { 
     50        return tag.id + ' <em>(' + 
     51          dotclear.msg.tags_autocomplete. 
     52        replace('%p', tag.percent). 
     53        replace('%e', tag.count + ' ' + 
     54            (tag.count > 1 ? 
     55              dotclear.msg.entries : 
     56              dotclear.msg.entry) 
     57          ) + 
     58          ')</em>'; 
     59      }, 
     60      formatResult: function(tag) { 
     61        return tag.result; 
     62      } 
     63    }); 
     64  }); 
    6165 
    62      $('h5 .s-tags').toggleWithLegend($('.s-tags').not('label'),{ 
    63           user_pref: 'post_tags', 
    64           legend_click: true 
    65      }); 
     66  $('h5 .s-tags').toggleWithLegend($('.s-tags').not('label'), { 
     67    user_pref: 'post_tags', 
     68    legend_click: true 
     69  }); 
    6670 
    6771}); 
  • plugins/tags/js/posts_actions.js

    r2546 r3709  
     1/*global $, dotclear, metaEditor, editor_tags_options */ 
     2'use strict'; 
     3 
    14$(function() { 
    25     var tag_field = $('#new_tags'); 
     
    2225     $('#post_meta_input').autocomplete(mEdit.service_uri, { 
    2326          extraParams: { 
    24                'f': 'searchMeta', 
     27               'f':        'searchMeta', 
    2528               'metaType': 'tag' 
    2629          }, 
     
    3437                    results[results.length] = { 
    3538                         data: { 
    36                               "id": $(this).text(), 
    37                               "count": $(this).attr("count"), 
    38                               "percent":  $(this).attr("roundpercent") 
     39                              'id':      $(this).text(), 
     40                              'count':   $(this).attr('count'), 
     41                              'percent': $(this).attr('roundpercent') 
    3942                         }, 
    4043                         result: $(this).text() 
Note: See TracChangeset for help on using the changeset viewer.

Sites map