|
|
Line 1: |
Line 1: |
| /* Any JavaScript here will be loaded for all users on every page load. */ | | /* Any JavaScript here will be loaded for all users on every page load. */ |
|
| |
|
| |
|
| |
|
| |
| /**
| |
| * Some fonctions handling classes (used by boîtes déroulantes navbox)
| |
| * isClass et whichClass from http://fr.wikibooks.org/w/index.php?title=MediaWiki:Common.js&oldid=140211
| |
| * hasClass, addClass, removeClass et eregReplace from http://drupal.org.in/doc/misc/drupal.js.source.html
| |
| * see implementation of .classList http://www.w3.org/TR/2008/WD-html5-diff-20080122/#htmlelement-extensions
| |
| */
| |
|
| |
| function isClass(element, classe) {
| |
| return hasClass(element, classe);
| |
| }
| |
|
| |
| function whichClass(element, classes) {
| |
| var s=" "+element.className+" ";
| |
| for(var i=0;i<classes.length;i++)
| |
| if (s.indexOf(" "+classes[i]+" ")>=0) return i;
| |
| return -1;
| |
| }
| |
|
| |
| function hasClass(node, className) {
| |
| if (node.className == className) {
| |
| return true;
| |
| }
| |
| var reg = new RegExp('(^| )'+ className +'($| )')
| |
| if (reg.test(node.className)) {
| |
| return true;
| |
| }
| |
| return false;
| |
| }
| |
|
| |
| function addClass(node, className) {
| |
| if (hasClass(node, className)) {
| |
| return false;
| |
| }
| |
| node.className += ' '+ className;
| |
| return true;
| |
| }
| |
|
| |
| function removeClass(node, className) {
| |
| if (!hasClass(node, className)) {
| |
| return false;
| |
| }
| |
| node.className = eregReplace('(^|\\s+)'+ className +'($|\\s+)', ' ', node.className);
| |
| return true;
| |
| }
| |
|
| |
| function eregReplace(search, replace, subject) {
| |
| return subject.replace(new RegExp(search,'g'), replace);
| |
| }
| |
|
| |
|
| |
|
| |
|
| |
| /**
| |
| * Navboxes
| |
| *
| |
| * [[Modèle:Méta palette de navigation]]
| |
| */
| |
|
| |
| var autoCollapse = 2;
| |
| var collapseCaption = '[ Hide ]';
| |
| var expandCaption = '[ Show ]';
| |
|
| |
| function collapseTable( tableIndex ) {
| |
| var Button = document.getElementById( "collapseButton" + tableIndex );
| |
| var Table = document.getElementById( "collapsibleTable" + tableIndex );
| |
| if ( !Table || !Button ) return false;
| |
|
| |
| var Rows = Table.getElementsByTagName( "tr" );
| |
|
| |
| if ( Button.firstChild.data == collapseCaption ) {
| |
| for ( var i = 1; i < Rows.length; i++ ) {
| |
| Rows[i].style.display = "none";
| |
| }
| |
| Button.firstChild.data = expandCaption;
| |
| } else {
| |
| for ( var i = 1; i < Rows.length; i++ ) {
| |
| Rows[i].style.display = Rows[0].style.display;
| |
| }
| |
| Button.firstChild.data = collapseCaption;
| |
| }
| |
| }
| |
|
| |
| function createCollapseButtons() {
| |
| var tableIndex = 0;
| |
| var NavigationBoxes = new Object();
| |
| var Tables = document.getElementsByTagName( "table" );
| |
|
| |
| for ( var i = 0; i < Tables.length; i++ ) {
| |
| if ( hasClass( Tables[i], "collapsible" ) ) {
| |
| NavigationBoxes[ tableIndex ] = Tables[i];
| |
| Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
| |
|
| |
| var Button = document.createElement( "span" );
| |
| var ButtonLink = document.createElement( "a" );
| |
| var ButtonText = document.createTextNode( collapseCaption );
| |
|
| |
| Button.style.styleFloat = "right";
| |
| Button.style.cssFloat = "right";
| |
| Button.style.fontWeight = "normal";
| |
| Button.style.textAlign = "right";
| |
| Button.style.width = "6em";
| |
|
| |
| ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
| |
| ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
| |
| ButtonLink.appendChild( ButtonText );
| |
|
| |
| Button.appendChild( ButtonLink );
| |
|
| |
| var Header = Tables[i].getElementsByTagName( "tr" )[0].getElementsByTagName( "th" )[0];
| |
| /* only add button and increment count if there is a header row to work with */
| |
| if (Header) {
| |
| Header.insertBefore( Button, Header.childNodes[0] );
| |
| tableIndex++;
| |
| }
| |
| }
| |
| }
| |
|
| |
| for (var i = 0; i < tableIndex; i++) {
| |
| if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) collapseTable( i );
| |
| }
| |
| }
| |
| addOnloadHook(createCollapseButtons);
| |
|
| |
|
| |
| /**
| |
| * [[Template:Navbox]]
| |
| */
| |
|
| |
| var NavigationBarShowDefault = 0;
| |
|
| |
| function toggleNavigationBar(indexNavigationBar) {
| |
| var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
| |
| var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
| |
|
| |
| if (!NavFrame || !NavToggle) return;
| |
|
| |
| // overwrite show/hide label with title attribute
| |
| // exemple : title="[down]/[up]"
| |
| var caption = [expandCaption, collapseCaption];
| |
| if (NavFrame.title && NavFrame.title.length > 0) {
| |
| caption = NavFrame.title.split("/");
| |
| if (caption.length < 2) caption.push(collapseCaption);
| |
| }
| |
|
| |
| // if shown now
| |
| if (NavToggle.firstChild.data == caption[1]) {
| |
| for ( var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
| |
| if (hasClass(NavChild, 'NavPic')) NavChild.style.display = 'none';
| |
| if (hasClass(NavChild, 'NavContent')) NavChild.style.display = 'none';
| |
| if (hasClass(NavChild, 'NavToggle')) NavChild.firstChild.data = caption[0];
| |
| }
| |
|
| |
| // if hidden now
| |
| } else if (NavToggle.firstChild.data == caption[0]) {
| |
| for ( var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
| |
| if (hasClass(NavChild, 'NavPic')) NavChild.style.display = 'block';
| |
| if (hasClass(NavChild, 'NavContent')) NavChild.style.display = 'block';
| |
| if (hasClass(NavChild, 'NavToggle')) NavChild.firstChild.data = caption[1];
| |
| }
| |
| }
| |
| }
| |
|
| |
| // adds show/hide-button to navigation bars
| |
| function createNavigationBarToggleButton() {
| |
| var indexNavigationBar = 0;
| |
| var NavFrame;
| |
| // iterate over all < div >-elements
| |
| for( var i=0; NavFrame = document.getElementsByTagName("div")[i]; i++ ) {
| |
| // if found a navigation bar
| |
| if (hasClass(NavFrame, "NavFrame")) {
| |
| indexNavigationBar++;
| |
| var NavToggle = document.createElement("a");
| |
| NavToggle.className = 'NavToggle';
| |
| NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
| |
| NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
| |
|
| |
| // overwrite show/hide label with title attribute
| |
| var caption = collapseCaption;
| |
| if (NavFrame.title && NavFrame.title.indexOf("/") > 0) {
| |
| caption = NavFrame.title.split("/")[1];
| |
| }
| |
|
| |
| var NavToggleText = document.createTextNode(caption);
| |
| NavToggle.appendChild(NavToggleText);
| |
|
| |
| // add NavToggle-Button as first div-element
| |
| // in <div class="NavFrame">
| |
| NavFrame.insertBefore( NavToggle, NavFrame.firstChild );
| |
| NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
| |
| }
| |
| }
| |
| // if more Navigation Bars found than Default: hide all
| |
| if (NavigationBarShowDefault < indexNavigationBar) {
| |
| for( var i=1; i<=indexNavigationBar; i++ ) {
| |
| toggleNavigationBar(i);
| |
| }
| |
| }
| |
| }
| |
| addOnloadHook(createNavigationBarToggleButton);
| |
|
| |
|
| |
| /*************************************************/
| |
|
| |
| /* Manage call to function() on submit action before sendind the page */
| |
|
| |
| function initeventpostform() {
| |
| if (wgAction == 'edit' || wgAction == 'submit') {
| |
| if (document.forms['editform'] == undefined || document.forms['editform'].elements['wpTextbox1'] == undefined) return;
| |
| document.forms['editform'].onsubmit = function() {
| |
| /* for agora pages: append section title link */
| |
| pgagora_insert_topsection();
| |
| /* other function */
| |
| }
| |
| }
| |
| }
| |
|
| |
| addOnloadHook(initeventpostform);
| |
|
| |
|
| |
|
| |
| /* Append an Agora link to Navigation menu (if connected) */
| |
|
| |
| function addlinkportletmenu() {
| |
| if (wgUserName != null)
| |
| addPortletLink("p-navigation", "https://www.boywiki.org/en/BoyWiki:Agora", "Agora", "n-agora", "A place to discuss the administration and editing of BoyWiki");
| |
| }
| |
|
| |
| addOnloadHook(addlinkportletmenu);
| |
|
| |
|
| |
|
| |
| /* For the 'dialogue' pages attribute the dialog class to body */
| |
| /* Used by css to colorize indentation in Agora */
| |
|
| |
| function attrib_class_dialog() {
| |
| /* only for Agora or discussion pages */
| |
| var bodyclass = document.body.className;
| |
| if (bodyclass.match(/page-BoyWiki_Agora/) || bodyclass.match(/ns-talk/))
| |
| document.body.className = bodyclass + ' dialog';
| |
| }
| |
|
| |
| addOnloadHook(attrib_class_dialog);
| |
|
| |
|
| |
|
| |
| /* Agora : if new sub-page created append a title section link (called by submit) */
| |
|
| |
| function pgagora_insert_topsection() {
| |
| /* only if agora new page and write permission */
| |
| if (wgAction != 'edit' && wgAction != 'submit') return true;
| |
| if (wgUserGroups == null || wgUserGroups.join(" ").match(/user|sysop|bureaucrat/) == null) return true;
| |
| if (wgPageName == null || wgPageName.match(/^BoyWiki:Agora\//) == null) return true;
| |
| if (wgTitle == null) return true;
| |
| if (wgArticleId != 0) return true;
| |
| if (document.forms['editform'].elements['wpSummary'] == undefined) return true;
| |
| if (document.getElementById('wpSummaryLabel').firstChild.firstChild.data.match(/Subject.*\/.*headline/) == null) return true;
| |
|
| |
| /* retrieve text */
| |
| var content = document.forms['editform'].elements['wpTextbox1'].value;
| |
| /* if title already present */
| |
| if (content.match(/^\n?=\[\[[^\]\/]*Agora\/[^\]]*\]\]=/)) return true;
| |
| /* otherwise copy subject sub-title */
| |
| var sujet = document.forms['editform'].elements['wpSummary'].value;
| |
| document.forms['editform'].elements['wpSummary'].value = "";
| |
| if (sujet.length) sujet = "=="+sujet+"==\n";
| |
| /* and insert title + subject at beginning of page */
| |
| var titre = "=[[BoyWiki:"+wgTitle+"|"+wgTitle+"]]=\n";
| |
| document.forms['editform'].elements['wpTextbox1'].value = titre + sujet + content;
| |
| return true;
| |
| }
| |
|
| |
| /*--------------------------------------------------------------------------------*/
| |
|
| |
|
| |
| /* Gestion tag <video> temporaire */
| |
|
| |
| function appendvideotag() {
| |
| if (wgAction == 'edit') return;
| |
|
| |
| var divs = document.getElementById('bodyContent').getElementsByTagName('div');
| |
| for (var i = 0; i < divs.length ; i++) {
| |
| if (divs[i].className == "video") {
| |
| var params = divs[i].getElementsByTagName('span')[0].innerHTML;
| |
| var text = divs[i].lastChild.innerHTML;
| |
| var style = divs[i].lastChild.getAttribute('style');
| |
| divs[i].innerHTML = '<video '+params+'>'+'</video><p style="'+style+'">'+text+'</p>';
| |
| }
| |
| }
| |
| }
| |
|
| |
| addOnloadHook (appendvideotag);
| |
|
| |
|
| |
| /*--------------------------------------------------------------------------------*/
| |
|
| |
|
| |
| /* Gestion tag <audio> temporaire */
| |
|
| |
| function appendaudiotag() {
| |
| if (wgAction == 'edit') return;
| |
|
| |
| var divs = document.getElementById('bodyContent').getElementsByTagName('div');
| |
| for (var i = 0; i < divs.length ; i++) {
| |
| if (divs[i].className == "audio") {
| |
| var params = divs[i].getElementsByTagName('span')[0].innerHTML;
| |
| var text = divs[i].lastChild.innerHTML;
| |
| var style = divs[i].lastChild.getAttribute('style');
| |
| divs[i].innerHTML = '<audio '+params+'>'+'</audio><p style="'+style+'">'+text+'</p>';
| |
| }
| |
| }
| |
| }
| |
|
| |
| addOnloadHook (appendaudiotag);
| |