« 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 |
||
| Ligne 53 : | Ligne 53 : | ||
// === External OOUI Dialog | // === External OOUI Dialog Déplaçable === | ||
mw.loader.using('oojs-ui-core').done(function () { | |||
// Création du WindowManager | if (typeof window.openExtDialog !== 'undefined') { | ||
return; // déjà initialisé | |||
} | |||
// Création du WindowManager | |||
window.extDialogWM = new OO.ui.WindowManager(); | window.extDialogWM = new OO.ui.WindowManager(); | ||
$(document.body).append(window.extDialogWM.$element); | $(document.body).append(window.extDialogWM.$element); | ||
// Définition de la classe du Dialog | |||
function ExternalIframeDialog(config) { | function ExternalIframeDialog(config) { | ||
ExternalIframeDialog.super.call(this, config); | ExternalIframeDialog.super.call(this, config); | ||
| Ligne 81 : | Ligne 86 : | ||
}; | }; | ||
// Fonction | // Fonction principale à appeler depuis les pages | ||
window.openExtDialog = function (url, title = 'Page externe', width = 1100, height = 750) { | window.openExtDialog = function (url, title = 'Page externe', width = 1100, height = 750) { | ||
var dialog = new ExternalIframeDialog({ size: 'large' }); | |||
dialog.setTitle(title); | |||
dialog.iframe.attr('src', url); | |||
window.extDialogWM.addWindows([dialog]); | |||
window.extDialogWM.openWindow(dialog, { | |||
width: width, | |||
height: height | |||
}); | |||
// Rendre draggable après ouverture | |||
setTimeout(function () { | |||
if (dialog.$element) { | |||
dialog.$element.draggable({ | dialog.$element.draggable({ | ||
handle: '.oo-ui-window-head', | handle: '.oo-ui-window-head', | ||
containment: 'window' | containment: 'window' | ||
}); | }); | ||
} | } | ||
}); | }, 600); | ||
}; | }; | ||
} | |||
console.log('[ExternalDialog] OOUI Dialog initialisé avec succès'); | |||
}); | |||
Version du 1 mai 2026 à 15:22
/* 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
}
}
*/
// === External OOUI Dialog Déplaçable ===
mw.loader.using('oojs-ui-core').done(function () {
if (typeof window.openExtDialog !== 'undefined') {
return; // déjà initialisé
}
// Création du WindowManager
window.extDialogWM = new OO.ui.WindowManager();
$(document.body).append(window.extDialogWM.$element);
// Définition de la classe du Dialog
function ExternalIframeDialog(config) {
ExternalIframeDialog.super.call(this, config);
}
OO.inheritClass(ExternalIframeDialog, OO.ui.Dialog);
ExternalIframeDialog.static.name = 'externalIframeDialog';
ExternalIframeDialog.prototype.initialize = function () {
ExternalIframeDialog.super.prototype.initialize.call(this);
this.iframe = $('<iframe>')
.attr({ frameborder: 0, allowfullscreen: true })
.css({ width: '100%', height: '100%', border: 'none' });
this.$body.append(this.iframe);
};
ExternalIframeDialog.prototype.getBodyHeight = function () {
return this.config.height || 700;
};
// Fonction principale à appeler depuis les pages
window.openExtDialog = function (url, title = 'Page externe', width = 1100, height = 750) {
var dialog = new ExternalIframeDialog({ size: 'large' });
dialog.setTitle(title);
dialog.iframe.attr('src', url);
window.extDialogWM.addWindows([dialog]);
window.extDialogWM.openWindow(dialog, {
width: width,
height: height
});
// Rendre draggable après ouverture
setTimeout(function () {
if (dialog.$element) {
dialog.$element.draggable({
handle: '.oo-ui-window-head',
containment: 'window'
});
}
}, 600);
};
console.log('[ExternalDialog] OOUI Dialog initialisé avec succès');
});