MediaWiki:Common.js: Difference between revisions

From Research Computing Center Wiki
Jump to navigation Jump to search
(Created page with "/////////////////////////////////////////////////////// // Codesnippet to make your sidebaritems expandable // // Use this code ONLY for monobook-Style. // ///////...")
 
No edit summary
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
///////////////////////////////////////////////////////
function ModifySidebar( action, section, name, link ) {
// Codesnippet to make your sidebaritems expandable  //
try {
// Use this code ONLY for monobook-Style.            //
switch ( section ) {
///////////////////////////////////////////////////////
case 'languages':
var target = 'p-lang';
$(document).ready(function(){
break;
case 'toolbox':
  //set the default expanded Items by their headline
var target = 'p-tb';
  var defaultExpandItems= ['Navigation', 'Orga'];
break;
  //set the basic-name for the cookies, which save the current state of expanding
case 'navigation':
  var expandCookieName = "disdance_project_wiki_nav_expanded_";
var target = 'p-navigation';
break;
  var maxHeights=[]
default:
  var expandeds=[];
var target = 'p-' + section;
  var labels=[];
break;
  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){
if ( action == 'add' ) {
    var id=$(target).parent().attr('id');
var node = document.getElementById( target )
    //You can change the expires-parameter to save the Cookie longer/shorter than 7 days like in this Code
  .getElementsByTagName( 'div' )[0]
    $.cookie(expandCookieName+id,'false', { expires: 7});
  .getElementsByTagName( 'ul' )[0];
    var str = labels[id]+"  ►";
 
    $(target).next('div').animate({'height':'0px'});
var aNode = document.createElement( 'a' );
    $(target).html(str);  
var liNode = document.createElement( 'li' );
 
aNode.appendChild( document.createTextNode( name ) );
aNode.setAttribute( 'href', link );
liNode.appendChild( aNode );
liNode.className = 'plainlinks';
node.appendChild( liNode );
}
}
 
function maximize(target){
if ( action == 'remove' ) {
    var id=$(target).parent().attr('id');
var list = document.getElementById( target )
    //You can change the expires-parameter to save the Cookie longer/shorter than 7 days like in this Code
  .getElementsByTagName( 'div' )[0]
    $.cookie(expandCookieName+id,'true', { expires: 7});
  .getElementsByTagName( 'ul' )[0];
    var str = labels[id]+"  ▼";
 
    var  newHeight = maxHeights[id];
var listelements = list.getElementsByTagName( 'li' );
    $(target).next('div').animate({'height':newHeight+'px'});
 
    $(target).html(str);  
for ( var i = 0; i < listelements.length; i++ ) {
if (
listelements[i].getElementsByTagName( 'a' )[0].innerHTML == name ||
listelements[i].getElementsByTagName( 'a' )[0].href == link
)
{
list.removeChild( listelements[i] );
}
}
}
}
 
function toggleNav(e){
} catch( e ) {
    var id=$(e.target).parent().attr('id');
// let's just ignore what's happened
    expandeds[id]=!expandeds[id];
return;
    if(expandeds[id]==true){
}
      maximize(e.target);
}
    }  
 
    else{
function CustomizeModificationsOfSidebar() {
      minimize(e.target);
// adds [[Special:CategoryTree]] to toolbox
    }
//ModifySidebar( 'add', 'toolbox', 'CategoryTree', 'http://en.wikipedia.org/wiki/Special:CategoryTree' );
}
// removes [[Special:Upload]] from toolbox
ModifySidebar( 'remove', 'toolbox', 'Related changes', 'https://wiki.gacrc.uga.edu/wiki/Special:RecentChangesLinked/MediaWiki:Sidebar' );
///////////////////////////////////////////////////////
ModifySidebar( 'remove', 'toolbox', 'What links here', 'https://wiki.gacrc.uga.edu/wiki/Special:WhatLinksHere/MediaWiki:Sidebar' );
///////////////////////////////////////////////////////
//ModifySidebar( 'remove', 'toolbox', 'Special pages', 'https://wiki.gacrc.uga.edu/wiki/Special:SpecialPages' );
ModifySidebar( 'remove', 'toolbox', 'Permanent link', 'https://wiki.gacrc.uga.edu/index.php?title=MediaWiki:Sidebar&oldid=2915' );
//ModifySidebar( 'remove', 'toolbox', 'Upload file', 'https://wiki.gacrc.uga.edu/wiki/Special:Upload' );
 
};
addOnloadHook( CustomizeModificationsOfSidebar )

Latest revision as of 22:23, 27 April 2015

function ModifySidebar( action, section, name, link ) {
try {
switch ( section ) {
	case 'languages':
		var target = 'p-lang';
		break;
	case 'toolbox':
		var target = 'p-tb';
		break;
	case 'navigation':
		var target = 'p-navigation';
		break;
	default:
		var target = 'p-' + section;
		break;
}

if ( action == 'add' ) {
	var node = document.getElementById( target )
					   .getElementsByTagName( 'div' )[0]
					   .getElementsByTagName( 'ul' )[0];

	var aNode = document.createElement( 'a' );
	var liNode = document.createElement( 'li' );

	aNode.appendChild( document.createTextNode( name ) );
	aNode.setAttribute( 'href', link );
	liNode.appendChild( aNode );
	liNode.className = 'plainlinks';
	node.appendChild( liNode );
}

if ( action == 'remove' ) {
	var list = document.getElementById( target )
					   .getElementsByTagName( 'div' )[0]
					   .getElementsByTagName( 'ul' )[0];

	var listelements = list.getElementsByTagName( 'li' );

	for ( var i = 0; i < listelements.length; i++ ) {
		if (
			listelements[i].getElementsByTagName( 'a' )[0].innerHTML == name ||
			listelements[i].getElementsByTagName( 'a' )[0].href == link
		)
		{
			list.removeChild( listelements[i] );
		}
	}
}

} catch( e ) {
// let's just ignore what's happened
return;
}
}

function CustomizeModificationsOfSidebar() {
// adds [[Special:CategoryTree]] to toolbox
//ModifySidebar( 'add', 'toolbox', 'CategoryTree', 'http://en.wikipedia.org/wiki/Special:CategoryTree' );
// removes [[Special:Upload]] from toolbox
ModifySidebar( 'remove', 'toolbox', 'Related changes', 'https://wiki.gacrc.uga.edu/wiki/Special:RecentChangesLinked/MediaWiki:Sidebar' );
ModifySidebar( 'remove', 'toolbox', 'What links here', 'https://wiki.gacrc.uga.edu/wiki/Special:WhatLinksHere/MediaWiki:Sidebar' );
//ModifySidebar( 'remove', 'toolbox', 'Special pages', 'https://wiki.gacrc.uga.edu/wiki/Special:SpecialPages' );
ModifySidebar( 'remove', 'toolbox', 'Permanent link', 'https://wiki.gacrc.uga.edu/index.php?title=MediaWiki:Sidebar&oldid=2915' );
//ModifySidebar( 'remove', 'toolbox', 'Upload file', 'https://wiki.gacrc.uga.edu/wiki/Special:Upload' );

};
addOnloadHook( CustomizeModificationsOfSidebar )