MediaWiki:Common.js

From dataZoa Wiki
Revision as of 11:12, 30 September 2016 by RB (Talk | contribs)

Jump to: navigation, search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences
/* Any JavaScript here will be loaded for all users on every page load. */
 
//the below does work!!
$(document).ready(function(){
$("h2").click(function(){
alert("The h2 was clicked.");
});
});
 
//basic function, wrapped in document.ready -- this works!
function thisAlert() {$(document).ready(function(){
alert('this is an alert');
});
}
 
//function triggered by the presence of a particular id
$(document).ready(function() {
if($('#mylist').length > 0) {
alert('yes')
};
});
 
//internal load function => this ultimately does not work because I can't call the function
function testLoad() {$(document).ready(function(){
$.ajax({
    url:'http://docwiki.datazoa.com/Test_Origin_Text',
    type:'get',
    dataType:'html',
    success:function(data) {
         alert('testLoad was successful!');}
    })
});
}
 
//modified internal load, triggered by an id (as above)
$(document).ready(function() {
if($('#loadfunction').length > 0) {
$.ajax({
    url:'http://docwiki.datazoa.com/Test_Origin_Text',
    type:'get',
    dataType:'html',
    success:function(data) {
         alert('testLoad was successful!');}
    })
};
});
 
//internal load with full script
$(document).ready(function() {
if($('#myList').length > 0) {
$.ajax({
    url:'http://docwiki.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"
						}
                                        }
    })
};
});
 
//external load with full script
$(document).ready(function() {
if($('#externalList').length > 0) {
$.ajax({
    url:'https://www.datazoa.com/publish/gettingdata-01-1.asp',
    type:'get',
    dataType:'html',
    success:function(data) {
         var _html= jQuery(data);
         list = _html.find('Gdib GCfl'); // 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("externalList").appendChild(node); // append li to ul with id="externalList"
						}
                                        }
    })
};
});
 
//external load function
function extLoad() {$(document).ready(function(){
$.ajax({
    url:'https://www.datazoa.com/publish/gettingdata-01-1.asp',
    type:'get',
    dataType:'html',
    success:function(data) {
         alert('extLoad was successful!');}
    })
});
}