Difference between revisions of "MediaWiki:Common.js"
From dataZoa Wiki
Line 56: | Line 56: | ||
}); | }); | ||
} | } | ||
+ | |||
+ | // 160926 added to remove sidebar Tools | ||
+ | |||
+ | 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', 'Upload file', 'http://en.wikipedia.org/wiki/Special:Upload' ); | ||
+ | } | ||
+ | |||
+ | jQuery( CustomizeModificationsOfSidebar ); |
Revision as of 08:07, 26 September 2016
/* Any JavaScript here will be loaded for all users on every page load. */ $( function () { //the below doesn't work, or, I don't know how to call the function var hello_friend = function() { window.alert("hello friend!"); } //the below does work!! $(document).ready(function(){ $("h2").click(function(){ alert("The h2 was clicked."); }); }); //here's a try at JQuery load $(document).ready(function(){ $("button").click(function(){ //when the button is clicked $("#loadjs").load("demo_test.txt"); //replace whatever is in div1 with the contents of demo_test.txt }); }); // Paste snippet here. // Paste as many as you like, only one "$( function () { ... } );" wrapper is needed! } ); //testing to see whether I can load any function function someAlert() { alert("this is a javascript function being called!"); } //my JQuery_Test_Load as a function function testLoad() { $(document).ready(function(){ jQuery.ajax({ url:'http://wiki.datazoa.com/Test_Origin_Text', type:'get', dataType:'html', success:function(data) { var _html= jQuery(data); list = _html.find('li'); // gets me an object (maybe?) with four elements for (i = 0; i <= list.length; i++) { console.log(list[i].innerHTML); //I get an error on HTML but it still seems to output correctly var node = document.createElement("li"); // create a <li> node var textnode = document.createTextNode(list[i].innerHTML); //create a text node node.appendChild(textnode); // append text to li document.getElementById("myList").appendChild(node); // append li to ul with id="myList" } } }); //console.log(myList.html()); }); } // 160926 added to remove sidebar Tools 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', 'Upload file', 'http://en.wikipedia.org/wiki/Special:Upload' ); } jQuery( CustomizeModificationsOfSidebar );