« 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
 
(20 versions intermédiaires par le même utilisateur non affichées)
Ligne 1 : Ligne 1 :
/* Tout JavaScript ici sera chargé avec chaque page accédée par n’importe quel utilisateur. */
/**
* Extra buttons in toolbar
* @stats [[File:Krinkle_InsertWikiEditorButton.js]]
*/
jQuery.getScript('//meta.wikimedia.org/w/index.php?title=User:Krinkle/Scripts/InsertWikiEditorButton.js&action=raw&ctype=text/javascript', function () {
        // Insérer début de page
        krInsertWikiEditorButton({
                "id": "mw-customeditbutton-myspecialbutton",
                "icon": "http://upload.wikimedia.org/wikipedia/commons/thumb/a/a4/Gnome-face-smile.svg/22px-Gnome-face-smile.svg.png",
                "label": "Insère un début de page",
                "insertBefore": "{{ORI-COMMUN}}",
                "insertAfter": "{{RETOUR}}",
                "sampleText": "[[Catégorie:choisir]]"
        });
        // Monkey
        /*
                krInsertWikiEditorButton({
                "id": "mw-customeditbutton-myspecialbutton",
                "icon": "http://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/Gnome-face-monkey.svg/22px-Gnome-face-monkey.svg.png",
                "label": "Insert monkey",
                "insertBefore": "[[File:Gnome-face-monkey.svg|21px|",
                "insertAfter": "]]",
                "sampleText": "Happy face"
        });
        */
});


$j('#wpTextbox1').wikiEditor('addToToolbar', {
        section: 'emoticons', // id de la section du nouveau menu
        group: 'faces',  // id du groupe du nouveau menu
        tools: {
                'heading': { //id du nouveau menu
                        label: 'wikieditor-toolbar-tool-heading',
                        type: 'select',
                        list: {
                                'heading-2' : { //id de la 1ere entré du menu
                                        label: 'Titre 2', //label de la 1ere entré du menu
                                        action: {
                                                // même contenu que pour un bouton normal
                krInsertWikiEditorButton({
                "id": "mw-customeditbutton-myspecialbutton",
                "icon": "http://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/Gnome-face-monkey.svg/22px-Gnome-face-monkey.svg.png",
                "label": "Modèle CHANTIER",
                "insertBefore": "{{CHANTIER}}",
                "insertAfter": "",
                "sampleText": ""
        });


/* 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)
                                'heading-5' : { //id de la 2e entré du menu
      var nb = titleList.length
                                        label: 'Titre 3', //label de la 2e entré du menu
      for( var b = 0 ; b < nb ; b++) {
                                        action: {
          titleList[b].setAttribute('onclick', "toogleTitle(this)");
                                                // même contenu
      }
                krInsertWikiEditorButton({
  }
                "id": "mw-customeditbutton-myspecialbutton",
}
                "icon": "http://upload.wikimedia.org/wikipedia/commons/thumb/1/1b/Gnome-face-monkey.svg/22px-Gnome-face-monkey.svg.png",
addOnloadHook(ImplementToogleOnclick)
                "label": "Modèle RETOUR",
*/
                "insertBefore": "{{RETOUR}}",
/* 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
                "insertAfter": "",
(= un h3 s'arrete au prochain h2 ou h3 mais continuera s'il rencontre un h4 ou h5) */
                "sampleText": ""
/*
        });
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
  }
}
*/

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
  }
}
*/