« Utilisateur:Dodoïste/monobook.js » : différence entre les versions
Jump to navigation
Jump to search
(Nouvelle page : →* * Pour [[Modèle:Boîte déroulante|Modèle:Boîte déroulante]] : var NavigationBarShowDefault = 0; function toggleNavigationBar(indexNavigationBar) { var NavToggle ...) |
Aucun résumé des modifications |
||
Ligne 1 : | Ligne 1 : | ||
/** Collapsible tables ********************************************************* |
|||
/** |
|||
* |
|||
* Pour [[Modèle:Boîte déroulante|Modèle:Boîte déroulante]] |
|||
* Description: Allows tables to be collapsed, showing only the header. See |
|||
* [[Wikipedia:NavFrame]]. |
|||
* Maintainers: [[User:R. Koot]] |
|||
* Changed for better usability by [[User:Cacycle]] |
|||
*/ |
*/ |
||
var NavigationBarShowDefault = 0; |
|||
function toggleNavigationBar(indexNavigationBar) { |
|||
var NavToggle = document.getElementById("NavToggle" + indexNavigationBar); |
|||
var NavFrame = document.getElementById("NavFrame" + indexNavigationBar); |
|||
if (!NavFrame || !NavToggle) return; |
|||
var autoCollapseTest = 2; |
|||
// surcharge des libellés dérouler/enrouler grâce a l'attribut title |
|||
var expandCaptionTest = '<a class="collapseButtonContent"><a class="collapseButtonShow"> </a>afficher</a>'; |
|||
// exemple : title="[déroulade]/[enroulade]" |
|||
var collapseCaptionTest = '<a class="collapseButtonContent"><a class="collapseButtonHide"> </a>masquer</a>'; |
|||
var caption = [expandCaption, collapseCaption]; |
|||
var expandTitle = 'Afficher le contenu masqué'; |
|||
if (NavFrame.title && NavFrame.title.length > 0) { |
|||
var collapseTitle = 'Masquer le contenu'; |
|||
caption = NavFrame.title.split("/"); |
|||
if (caption.length < 2) caption.push(collapseCaption); |
|||
// detect MS-IE < 7 |
|||
if (window.showModalDialog && window.clipboardData && window.createPopup) { |
|||
// ignore MS-IE >= 7 in compatibility mode |
|||
var agent = navigator.userAgent.match(/(MSIE)\W+(\d+\.\d+)/i); |
|||
if ( (agent == null) || (parseFloat(agent[2]) < 7) ) { |
|||
expandCaptionTest = '<a class="collapseButtonContent"><a class="collapseButtonShowIE6"> </a>afficher</a>'; |
|||
collapseCaptionTest = '<a class="collapseButtonContent"><a class="collapseButtonHideIE6"> </a>masquer</a>'; |
|||
} |
} |
||
} |
|||
// 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]; |
|||
} |
|||
collapseTableTest = function( tableIndex ) |
|||
// if hidden now |
|||
{ |
|||
} else if (NavToggle.firstChild.data == caption[0]) { |
|||
var Button = document.getElementById( "collapseButton" + tableIndex ); |
|||
for ( var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) { |
|||
var Table = document.getElementById( "collapsibleTable" + tableIndex ); |
|||
if (hasClass(NavChild, 'NavPic')) NavChild.style.display = 'block'; |
|||
if (hasClass(NavChild, 'NavContent')) NavChild.style.display = 'block'; |
|||
if ( !Table || !Button ) return false; |
|||
if (hasClass(NavChild, 'NavToggle')) NavChild.firstChild.data = caption[1]; |
|||
var Rows = Table.rows; |
|||
if ( Button.title == collapseTitle ) { |
|||
for ( var i = 1; i < Rows.length; i++ ) { |
|||
Rows[i].style.display = "none"; |
|||
} |
|||
Button.innerHTML = expandCaptionTest; |
|||
Button.title = expandTitle; |
|||
} else { |
|||
for ( var i = 1; i < Rows.length; i++ ) { |
|||
Rows[i].style.display = Rows[0].style.display; |
|||
} |
|||
Button.innerHTML = collapseCaptionTest; |
|||
Button.title = collapseTitle; |
|||
} |
} |
||
window.getSelection().removeAllRanges(); |
|||
} |
|||
} |
|||
} |
|||
// 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 + ');'); |
|||
function createCollapseButtonsTest() |
|||
// surcharge des libellés dérouler/enrouler grâce a l'attribut title |
|||
{ |
|||
var caption = collapseCaption; |
|||
var tableIndex = 0; |
|||
if (NavFrame.title && NavFrame.title.indexOf("/") > 0) { |
|||
var NavigationBoxes = new Object(); |
|||
caption = NavFrame.title.split("/")[1]; |
|||
var Tables = document.getElementsByTagName( "table" ); |
|||
} |
|||
for ( var i = 0; i < Tables.length; i++ ) { |
|||
var NavToggleText = document.createTextNode(caption); |
|||
if ( hasClass( Tables[i], "collapsible" ) ) { |
|||
NavToggle.appendChild(NavToggleText); |
|||
// only add button and increment count if there is a header row to work with |
|||
// add NavToggle-Button as first div-element |
|||
var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0]; |
|||
if (!HeaderRow) continue; |
|||
// in |
|||
var Header = HeaderRow.getElementsByTagName( "th" )[0]; |
|||
<div class="NavFrame"> |
|||
if (!Header) continue; |
|||
NavFrame.insertBefore( NavToggle, NavFrame.firstChild ); |
|||
NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar); |
|||
// insert space-balancing empty a left of the title |
|||
var a = document.createElement('a'); |
|||
a.className = 'collapseButtonBalance'; |
|||
Header.insertBefore(a, Header.lastChild); |
|||
NavigationBoxes[ tableIndex ] = Tables[i]; |
|||
Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex ); |
|||
// Styles are declared in Common.css |
|||
Header.innerHTML += '<a href="#" id="collapseButton' + tableIndex + '" class="collapseButtonTest" onclick="javascript:collapseTableTest(' + tableIndex + '); return false;" title="' + collapseTitle + '">' + collapseCaptionTest + '</a>'; |
|||
tableIndex++; |
|||
} |
|||
} |
} |
||
} |
|||
for ( var i = 0; i < tableIndex; i++ ) { |
|||
// if more Navigation Bars found than Default: hide all |
|||
if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapseTest && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) { |
|||
if (NavigationBarShowDefault < indexNavigationBar) { |
|||
collapseTableTest( i ); |
|||
} |
|||
else if ( hasClass( NavigationBoxes[i], "innercollapse" ) ) { |
|||
var element = NavigationBoxes[i]; |
|||
while (element = element.parentNode) { |
|||
if ( hasClass( element, "outercollapse" ) ) { |
|||
collapseTableTest ( i ); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
} |
} |
||
} |
|||
addOnloadHook(createCollapseButtonsTest); |
|||
} |
|||
addOnloadHook(createNavigationBarToggleButton);</div> |
Dernière version du 30 septembre 2009 à 09:20
/** Collapsible tables ********************************************************* * * Description: Allows tables to be collapsed, showing only the header. See * [[Wikipedia:NavFrame]]. * Maintainers: [[User:R. Koot]] * Changed for better usability by [[User:Cacycle]] */ var autoCollapseTest = 2; var expandCaptionTest = '<a class="collapseButtonContent"><a class="collapseButtonShow"> </a>afficher</a>'; var collapseCaptionTest = '<a class="collapseButtonContent"><a class="collapseButtonHide"> </a>masquer</a>'; var expandTitle = 'Afficher le contenu masqué'; var collapseTitle = 'Masquer le contenu'; // detect MS-IE < 7 if (window.showModalDialog && window.clipboardData && window.createPopup) { // ignore MS-IE >= 7 in compatibility mode var agent = navigator.userAgent.match(/(MSIE)\W+(\d+\.\d+)/i); if ( (agent == null) || (parseFloat(agent[2]) < 7) ) { expandCaptionTest = '<a class="collapseButtonContent"><a class="collapseButtonShowIE6"> </a>afficher</a>'; collapseCaptionTest = '<a class="collapseButtonContent"><a class="collapseButtonHideIE6"> </a>masquer</a>'; } } collapseTableTest = function( tableIndex ) { var Button = document.getElementById( "collapseButton" + tableIndex ); var Table = document.getElementById( "collapsibleTable" + tableIndex ); if ( !Table || !Button ) return false; var Rows = Table.rows; if ( Button.title == collapseTitle ) { for ( var i = 1; i < Rows.length; i++ ) { Rows[i].style.display = "none"; } Button.innerHTML = expandCaptionTest; Button.title = expandTitle; } else { for ( var i = 1; i < Rows.length; i++ ) { Rows[i].style.display = Rows[0].style.display; } Button.innerHTML = collapseCaptionTest; Button.title = collapseTitle; } window.getSelection().removeAllRanges(); } function createCollapseButtonsTest() { 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" ) ) { // only add button and increment count if there is a header row to work with var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0]; if (!HeaderRow) continue; var Header = HeaderRow.getElementsByTagName( "th" )[0]; if (!Header) continue; // insert space-balancing empty a left of the title var a = document.createElement('a'); a.className = 'collapseButtonBalance'; Header.insertBefore(a, Header.lastChild); NavigationBoxes[ tableIndex ] = Tables[i]; Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex ); // Styles are declared in Common.css Header.innerHTML += '<a href="#" id="collapseButton' + tableIndex + '" class="collapseButtonTest" onclick="javascript:collapseTableTest(' + tableIndex + '); return false;" title="' + collapseTitle + '">' + collapseCaptionTest + '</a>'; tableIndex++; } } for ( var i = 0; i < tableIndex; i++ ) { if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapseTest && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) { collapseTableTest( i ); } else if ( hasClass( NavigationBoxes[i], "innercollapse" ) ) { var element = NavigationBoxes[i]; while (element = element.parentNode) { if ( hasClass( element, "outercollapse" ) ) { collapseTableTest ( i ); break; } } } } } addOnloadHook(createCollapseButtonsTest);