« MediaWiki:Common.js » : différence entre les versions

De Encyclopédie-de-L'AFN_1830-1962
mAucun résumé des modifications
mAucun résumé des modifications
 
(4 versions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
//Ajoute des boutons à la barre d'outils
 
if($.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1 ) {
 
  if( !mw.user.options.get('usebetatoolbar')) {
/* Cette fonction ajoute un "onclick" sur chaque titre, qui lancera un appel à toogleTitle() lors d'un clic sur ceux ci */
    alert("Vous devez utiliser la barre d'outil améliorée pour profiter du gadget « Ajouts à la nouvelle barre d’outils améliorée ». Activez la dans vos préférences d'édition ou désactivez ce gadget.");
/*
  } else {
function ImplementToogleOnclick() {
    $(function() {
 
  for( var titleLevel = 1 ; titleLevel < 7 ; titleLevel++) {
      //Boutons de formatage : poem et changement de casse
      var titleList = document.getElementsByTagName('h' + titleLevel)
      $('#wpTextbox1').wikiEditor('addToToolbar', {
      var nb = titleList.length
        section: 'advanced',
      for( var b = 0 ; b < nb ; b++) {
        group: 'format',
          titleList[b].setAttribute('onclick', "toogleTitle(this)");
        tools: {
      }
          'poem': {
  }
            label: 'Poème',
}
            type: 'button',
addOnloadHook(ImplementToogleOnclick)
            icon: '//upload.wikimedia.org/wikipedia/commons/thumb/d/dd/P_writing_icon.svg/23px-P_writing_icon.svg.png',
*/
            action: {
/* Cette fonction, quand invoquée, fait disparaitre ou réaparaitre le contenu placé sous un titre jusqu'au prochain titre de niveau egal ou supérieur
              type: 'encapsulate',
(= un h3 s'arrete au prochain h2 ou h3 mais continuera s'il rencontre un h4 ou h5) */
              options: {
/*
                pre: '<poem>',
function toogleTitle(p_this) {
                peri: 'Texte du poème',
  var p_niveau = p_this.nodeName.substring(1,2) //le 1 de h1 (ou 2 de h2, etc.)
                post: '</poem>',
 
                ownline: true
  //construction de l'expression reguliere permettant le trouver le prochain titre de niveau égal ou supérieur
              }
  var stopMatch = "(h1"
            }
  for(var a = 2 ; a <= p_niveau ; a++) {
          },
     stopMatch += "|h"+a
          'toggleCase': {
            label: 'Modifier la casse',
            type: 'button',
            icon: '//upload.wikimedia.org/wikipedia/commons/thumb/d/de/Wynn.svg/23px-Wynn.svg.png',
            action: {
              type: 'callback',
              execute: function() {
                var context = $('img[rel="toggleCase"]').data('context');
                var selection = context.$textarea.textSelection('getSelection');
                if (!selection.collapsed) {
                  var str = selection.toString();
                  if (str == str.toUpperCase()) {
                    str = str.toLowerCase();
                  } else {
                    str = str.toUpperCase();
                  }
                  context.$textarea.textSelection('encapsulateSelection', {'pre': '', 'peri': str, 'post': '', 'replace': true});
                }
              }
            }
          }
        }
      });
      //Boutons d’insertion : modèle et guillemets
      $('#wpTextbox1').wikiEditor('addToToolbar', {
        section: 'advanced',
        group: 'insert',
        tools: {
          'template': {
            label: 'Modèle',
            type: 'button',
            icon: '//upload.wikimedia.org/wikipedia/commons/8/86/Wikieditor-template.png',
            action: {
              type: 'encapsulate',
              options: {
                pre: '{{',
                peri: 'Nom du modèle',
                post: '|}}'
              }
            }
          },
          'quote': {
            label: 'Citation',
            type: 'button',
            icon: '//upload.wikimedia.org/wikipedia/commons/a/ac/Norwegian_quote_sign.png',
            action: {
              type: 'encapsulate',
              options: {
                pre: '« ',
                peri: 'Texte',
                post: ' »'
              }
            }
          }
        }
      });
      //Ajoute une section wikisource avec le contenu de l'editool
      $('#wpTextbox1').wikiEditor('addToToolbar', {
        sections: {
          'wikisource': {
            type: 'booklet',
            label: 'Wikisource',
            pages: {
              'wiki': {
                layout: 'characters',
                label: 'Syntaxe wiki',
                characters: []
              }
            }
          }
        }
      });
      var section = $('.section-wikisource .page-wiki div');
      var links = $('.mw-editTools .plainlinks p').eq(0);
      links.find('a').each(function() {
        var button = $('<span>');
        button.text($(this).text());
        button.attr('rel', $(this).text());
        button.attr('onclick', $(this).attr('onclick'));
        button.css('font-size', '1em');
        //button.click($(this).attr('onclick'));
        section.append(button);
      });
     });
   }
   }
  stopMatch += ")"
  reg = new RegExp(stopMatch, "i" )
 
   //Ajoute un bouton index dans l'espace principal
   //on ajoute une classe (neko_toogle_cache) au titre pour savoir s'il est en mode replié
   if(mw.config.get('wgNamespaceNumber') == 0 && $.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1 ) {
   if( p_this.className != "neko_toogle_cache") { //il faut  replier
    $(function() {
    p_this.className = "neko_toogle_cache"
      $('#wpTextbox1').wikiEditor('addToToolbar', {
    var display_to_put = "none"
        section: 'advanced',
  } else { //il faut faire déplier
        group: 'insert',
    p_this.className = ""
        tools: {
    var display_to_put = "block"
          'pages': {
            label: 'Pages',
            type: 'button',
            icon: '//upload.wikimedia.org/wikipedia/commons/6/6a/Nuvola_apps_icons.png',
            action: {
              type: 'encapsulate',
              options: {
                pre: '<pages index="',
                peri: 'Nom du fac-similé',
                post: '" from= to= fromsection= tosection= header=1 />',
                ownline: true
              }
            }
          }
        }
      });
    });
   }
   }
 
   //Ajoute la capacité d'afficher et de masquer les en-têtes et pied de pages dans l'espace page.
   var nextSiblingNode = p_this.nextSibling
   if(mw.config.get('wgNamespaceNumber') == 104 && $.inArray(mw.config.get('wgAction'), ['edit', 'submit']) !== -1) {
 
    $(function() {
   while( nextSiblingNode ) {
      $('#wpTextbox1').wikiEditor('addToToolbar', {
    if( nextSiblingNode.nodeName.match(reg) ) break; //on a atteint le titre "bloquant" suivant = stop
         section: 'main',
 
        groups: {
    if( nextSiblingNode.style) { //certains nodes sont des nodes texte et n'ont pas de style.
          'nav':{
         nextSiblingNode.style.display = display_to_put
            tools: {
        if( nextSiblingNode.className = "neko_toogle_cache") nextSiblingNode.className = "" // x
              'header-footer': {
    }
                label: 'Afficher l’en-tête et pied de page',
    nextSiblingNode = nextSiblingNode.nextSibling //on passe au voisin suivant
                type: 'button',
                icon: '//upload.wikimedia.org/wikipedia/commons/b/bc/Farm-Fresh_layout_header.png',
                action: {
                  type: 'callback',
                  execute: function() {
                    if($('#prp_header').css('display') == 'none') {
                      $('#prp_header').css({'display': 'block'});
                      $('#prp_footer').css({'display': 'block'});
                    } else {
                      $('#prp_header').css({'display': 'none'});
                      $('#prp_footer').css({'display': 'none'});
                    }
                  }
                }
              }
            }
          }
        }
      });
    });
   }
   }
}
}
*/

Dernière version du 12 mai 2018 à 16:42

/* Cette fonction ajoute un "onclick" sur chaque titre, qui lancera un appel à toogleTitle() lors d'un clic sur ceux ci */
/*
function ImplementToogleOnclick() {

   for( var titleLevel = 1 ; titleLevel < 7 ; titleLevel++) {
      var titleList = document.getElementsByTagName('h' + titleLevel)
      var nb = titleList.length
      for( var b = 0 ; b < nb ; b++) {
          titleList[b].setAttribute('onclick', "toogleTitle(this)");
      }
   }
}
addOnloadHook(ImplementToogleOnclick)
*/
/* Cette fonction, quand invoquée, fait disparaitre ou réaparaitre le contenu placé sous un titre jusqu'au prochain titre de niveau egal ou supérieur
(= un h3 s'arrete au prochain h2 ou h3 mais continuera s'il rencontre un h4 ou h5) */
/*
function toogleTitle(p_this) {
  var p_niveau = p_this.nodeName.substring(1,2) //le 1 de h1 (ou 2 de h2, etc.)

  //construction de l'expression reguliere permettant le trouver le prochain titre de niveau égal ou supérieur
  var stopMatch = "(h1"
  for(var a = 2 ; a <= p_niveau ; a++)  {
    stopMatch += "|h"+a
  }
  stopMatch += ")"
  reg = new RegExp(stopMatch, "i" )

  //on ajoute une classe (neko_toogle_cache) au titre pour savoir s'il est en mode replié
  if( p_this.className != "neko_toogle_cache") { //il faut  replier
     p_this.className = "neko_toogle_cache"
     var display_to_put = "none"
  } else { //il faut faire déplier
     p_this.className = ""
     var display_to_put = "block"
  }

  var nextSiblingNode = p_this.nextSibling

  while( nextSiblingNode ) {
     if(  nextSiblingNode.nodeName.match(reg) ) break; //on a atteint le titre "bloquant" suivant = stop

     if( nextSiblingNode.style) { //certains nodes sont des nodes texte et n'ont pas de style.
        nextSiblingNode.style.display = display_to_put
        if( nextSiblingNode.className = "neko_toogle_cache") nextSiblingNode.className = "" // x
     }
     nextSiblingNode = nextSiblingNode.nextSibling //on passe au voisin suivant
  }
}
*/