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

De Adadov.net wiki
Aucun résumé des modifications
Aucun résumé des modifications
Ligne 1 : Ligne 1 :
/** Dynamic Navigation Bars (experimental) *************************************
///////////////////////////////////////////////////////
  *
// Codesnippet to make your sidebaritems expandable //
* From English Wikipedia, 2008-09-15
// Use this code ONLY for monobook-Style.           //
*
///////////////////////////////////////////////////////
*  Description: See [[Wikipedia:NavFrame]].
*  Maintainers: UNMAINTAINED
*/


// set up the words in your language
$(document).ready(function(){
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';


// shows and hides content and picture (if available) of navigation bars
  //set the default expanded Items by their headline
// Parameters:
  var defaultExpandItems= ['Navigation', 'Orga'];
//    indexNavigationBar: the index of navigation bar to be toggled
  //set the basic-name for the cookies, which save the current state of expanding
function toggleNavigationBar( indexNavigationBar ) {
  var expandCookieName = "disdance_project_wiki_nav_expanded_";
var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );


if( !NavFrame || !NavToggle ) {
  var maxHeights=[]
return false;
  var expandeds=[];
}
  var labels=[];
  initNav();
}
function initNav(){
    $('#p-logo').css({'position':'relative', 'display':'block'});;
    $('.generated-sidebar h5,#p-tb h5 ').each(function(i){
     
          var id = $(this).parent().attr('id');         
          maxHeights[id]=$(this).next('div').height();
          var str = $(this).html();
          labels[id]=str;   
         
          if ($.cookie(expandCookieName+id)=='false'  ){             
                expandeds[id]=false;
                minimize( $(this));
               
        } else if ($.cookie(expandCookieName+id)=='true'  ){
                expandeds[id]=true;
                maximize( $(this));
       
        } else if (defaultExpandItems.indexOf(str)==-1){
                expandeds[id]=false;
                minimize( $(this));
        } else {
                expandeds[id]=true;
                maximize( $(this));
        }
        $(this).css({'cursor':'pointer'});
        $(this).click(toggleNav);
    });
}


// if shown now
function minimize(target){
if( NavToggle.firstChild.data == NavigationBarHide ) {
    var id=$(target).parent().attr('id');
for( var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
    //You can change the expires-parameter to save the Cookie longer/shorter than 7 days like in this Code
if ( hasClass( NavChild, 'NavPic' ) ) {
    $.cookie(expandCookieName+id,'false', { expires: 7});
NavChild.style.display = 'none';
    var str = labels[id]+"  ►";
}
    $(target).next('div').animate({'height':'0px'});
if ( hasClass( NavChild, 'NavContent' ) ) {
    $(target).html(str);   
NavChild.style.display = 'none';
}
}
}
NavToggle.firstChild.data = NavigationBarShow;


// if hidden now
function maximize(target){
} else if( NavToggle.firstChild.data == NavigationBarShow ) {
    var id=$(target).parent().attr('id');
for( var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
    //You can change the expires-parameter to save the Cookie longer/shorter than 7 days like in this Code
if( hasClass( NavChild, 'NavPic' ) ) {
    $.cookie(expandCookieName+id,'true', { expires: 7});
NavChild.style.display = 'block';
    var str = labels[id]+"  ▼";
}
    var  newHeight = maxHeights[id];
if( hasClass( NavChild, 'NavContent' ) ) {
    $(target).next('div').animate({'height':newHeight+'px'});
NavChild.style.display = 'block';
    $(target).html(str);  
}
}
NavToggle.firstChild.data = NavigationBarHide;
}
}
}


// adds show/hide-button to navigation bars
function toggleNav(e){
function createNavigationBarToggleButton() {
    var id=$(e.target).parent().attr('id');
var indexNavigationBar = 0;
    expandeds[id]=!expandeds[id];
// iterate over all < div >-elements
    if(expandeds[id]==true){  
var divs = document.getElementsByTagName( 'div' );
      maximize(e.target);
for( var i = 0; NavFrame = divs[i]; i++ ) {
    }
// if found a navigation bar
    else{
if( hasClass( NavFrame, 'NavFrame' ) ) {
      minimize(e.target);
indexNavigationBar++;
    }
var NavToggle = document.createElement( 'a' );
}
NavToggle.className = 'NavToggle';
NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
NavToggle.setAttribute( 'href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');' );


var NavToggleText = document.createTextNode( NavigationBarHide );
///////////////////////////////////////////////////////
for( var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
///////////////////////////////////////////////////////
if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
if( NavChild.style.display == 'none' ) {
NavToggleText = document.createTextNode( NavigationBarShow );
break;
}
}
}
 
NavToggle.appendChild( NavToggleText );
// Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
for( var j = 0; j < NavFrame.childNodes.length; j++ ) {
if( hasClass( NavFrame.childNodes[j], 'NavHead' ) ) {
NavFrame.childNodes[j].appendChild( NavToggle );
}
}
NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
}
}
}
addOnloadHook( createNavigationBarToggleButton );

Version du 17 avril 2012 à 22:18

///////////////////////////////////////////////////////
// Codesnippet to make your sidebaritems expandable  //
// Use this code ONLY for monobook-Style.            //
///////////////////////////////////////////////////////

$(document).ready(function(){

  //set the default expanded Items by their headline
  var defaultExpandItems= ['Navigation', 'Orga'];
  //set the basic-name for the cookies, which save the current state of expanding
  var expandCookieName = "disdance_project_wiki_nav_expanded_";

  var maxHeights=[]
  var expandeds=[];
  var labels=[];
  initNav();
}
function initNav(){
    $('#p-logo').css({'position':'relative', 'display':'block'});;
    $('.generated-sidebar h5,#p-tb h5 ').each(function(i){
       
          var id = $(this).parent().attr('id');           
          maxHeights[id]=$(this).next('div').height();
          var str = $(this).html();
          labels[id]=str;     
          
          if ($.cookie(expandCookieName+id)=='false'  ){               
                expandeds[id]=false;
                minimize( $(this));
                
         } else if ($.cookie(expandCookieName+id)=='true'  ){
                expandeds[id]=true;
                maximize( $(this));
        
         } else if (defaultExpandItems.indexOf(str)==-1){
                expandeds[id]=false;
                minimize( $(this));
         } else {
                expandeds[id]=true;
                maximize( $(this));
         }
         $(this).css({'cursor':'pointer'});
         $(this).click(toggleNav);
    });
}

function minimize(target){
    var id=$(target).parent().attr('id');
    //You can change the expires-parameter to save the Cookie longer/shorter than 7 days like in this Code
    $.cookie(expandCookieName+id,'false', { expires: 7});
    var str = labels[id]+"  ►";
    $(target).next('div').animate({'height':'0px'});
    $(target).html(str);    
}

function maximize(target){
    var id=$(target).parent().attr('id');
    //You can change the expires-parameter to save the Cookie longer/shorter than 7 days like in this Code
    $.cookie(expandCookieName+id,'true', { expires: 7});
    var str = labels[id]+"  ▼";
    var  newHeight = maxHeights[id];
    $(target).next('div').animate({'height':newHeight+'px'});
    $(target).html(str);    
}

function toggleNav(e){
    var id=$(e.target).parent().attr('id');
    expandeds[id]=!expandeds[id];
    if(expandeds[id]==true){ 
       maximize(e.target);
    } 
    else{ 
       minimize(e.target);
    }
} 

///////////////////////////////////////////////////////
///////////////////////////////////////////////////////