User:Aristoi/common.js

From Wikimedia Commons, the free media repository
Jump to navigation Jump to search
Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
// bouton pour convertir les auteurs en creator //
$.typo = {
  todo: new Array(),
  add: function(fonction) {
    this.todo.push(fonction);
  },
  exec: function() {
    var txt = $('#wpTextbox1').val();
    for(var i in this.todo) {
      txt = this.todo[i](txt);
    }
    $('#wpTextbox1').val(txt);
  },
  editForm: function() {
    if($('#wpTextbox1').length == 0)
      return;
    if(mw.user.options.get('usebetatoolbar')) {
      mw.loader.using('ext.wikiEditor', function() {
        $('#wpTextbox1').wikiEditor('addToToolbar', {
          section: 'advanced',
          group: 'format',
          tools: {
            'typo': {
              label: 'Corrections',
              type: 'button',
              icon: '//upload.wikimedia.org/wikipedia/commons/8/82/Toolbaricon_regular_T.png'
            }
          }
        });
        $('img[rel="typo"]').mouseup(function() {
          $.typo.exec();
        });
      });
    } else {
      $("#toolbar").append('<img id="typo-button" width="23" height="22" border="0" src="//upload.wikimedia.org/wikipedia/commons/9/9f/Button_defaultsort.png" alt="Corrections" title="Corrections" style="cursor: pointer;">');
      $('#typo-button').mouseup(function() {
        $.typo.exec();
      });
    }
  }
}
 
if($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1 ) {
$(function() {
  //typo
  $.typo.add(function(str) {
    // s:fr:Auteur: -> creator
    str = str.replace(/\[\[s:fr:Auteur:([^\|\]]*)(\|([^\]]*))?\]\]/g, "{{Creator:$1}}");
    str = str.replace(/\[\[:no:([^\|\]]*)(\|([^\]]*))?\]\]/g, "{{Creator:$1}}");
    str = str.replace(/Source=http:\/\/www\.archive\.org\/details\/([a-zA-Z0-9]*)/g, "Source={{IA|$1}}");

    return $.trim(str);
  });
 
  $.typo.editForm();
});
}


 mw.util.addPortletLink('p-tb', 'javascript:importScript("MediaWiki:VisualFileChange.js");', 'Lancer une tâche générale', 't-AjaxQuickDeleteOnDemand');