Difference between revisions of "MediaWiki:Common.js"
From dataZoa Wiki
Line 216: | Line 216: | ||
elem.attr('style', elem.attr('style') + ' ' + guts.xtraStyle); | elem.attr('style', elem.attr('style') + ' ' + guts.xtraStyle); | ||
} | } | ||
− | } | + | } |
Revision as of 11:31, 11 November 2016
/* 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 -- still showing an error on list . . . $(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, simplified, with trigger $(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) { alert('externaltLoad was successful!');} }) }; }); //external load function -- this does not work, comes up as undefined, etc. 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!');} }) }); } // script for loading gettingdata-01-1.asp $(document).ready(function() { if($('#gettingdata-01-1').length > 0) { $.ajax({ url:'https://www.datazoa.com/publish/gettingdata-01-1.asp', type:'get', dataType:'html', success:function(data) { _html= jQuery(data); titles = _html.find('.Gdib.GCfl'); expression = /http\S+?\"/ patt = new RegExp(expression); //titles = $(".Gdib.GCfl"); for (i = 2; i < 33; i ++) { title = titles[i].innerHTML; link = titles[i].getAttribute('onclick'); if(title) { if(title.includes('img')){ //console.log("skip this line"); } else { console.log(title); title = title.replace("&","&"); res = patt.exec(link); res = String(res).replace("\"",""); var node = document.createElement("li"); // create a <li> node var textnode = document.createElement("a"); textnode.setAttribute('href', res); //textnode.setAttribute('title', title); textnode.innerHTML = title; //var textnode = document.createTextNode("[" + res + " " + title + "]"); //create a text node //var textnode = document.createTextNode("<a href=\"" + res + "\">" + title + "</a>"); //create a text node node.appendChild(textnode); // append text to li document.getElementById("gettingdata-01-1").appendChild(node); // append li to ul with id="myList" } } //alert('externalLoad was successful!'); } } }) }; }); // js for changing the image if($('.changeimage').length > 0) { var image = $('.changeimage'); image = image[0]; image.style.background = "url(https://www.datazoa.com/img/vert_data_table.png)"; image.style.backgroundPosition = "0px 0px"; //change the first number for horizontal positioning, the second number for vertical image.style.backgroundRepeat = "no-repeat"; image.style.width = "600px"; image.style.height = "200px"; } // js for imgSnippet (show a shifted part of a foreign image) // Model: <div class="imgSnippetWrap1"><div class="imgSnippet " data-styler="{ view: nnn, styler: '...stylestr...' }"></div></div> // Copy the View string from Decorator.asp //var g_althost = ''; // set to e.g. https://www.datahydra.com var g_althost = 'http://www.datahydra.com'; $('.imgSnippet').each( function() { var elem = $(this); eval( "var styler = " + elem.data('styler')); elem.attr('style', styler.style.replace(/SQ/g,"'").replace('/img/DocSamples',g_althost+'/img/DocSamples')); elem.addClass( 'decoratorView' + styler.view); // watermark reminder when under development if ( g_althost.toLowerCase().indexOf('datazoa.com') < 0 ) { elem.text(' ' + g_althost); elem.css('color','orange'); elem.css('font-weight','bold'); elem.css('font-size','xx-small'); } }); // js for imgWhole (put a foreign image in-line) // Model: <div class="imgWholeWrap1"><div class="imgWhole " data-guts="{ url: '...', xtraStyle: '...stylestr...' }"></div></div> // example: // <div class="imgWholeWrap1"><div class="imgWhole " data-guts="{ url: '/img/Hint.png', title: 'Hint example', xtraStyle: ' min-height: 16px; min-width: 16px;' }"></div></div> var g_imgWholeHost = "https://www.datazoa.com" $('.imgWhole').each( function() { imgWholeFunc($(this)); }); $('.imgIdea').each( function() { $(this).attr("data-guts","{ url: '/img/3_idea24.png.png', title: 'Here\'s a tip!', xtraStyle: '' }"); imgWholeFunc( $(this) ); }); $('.imgWarning').each( function() { $(this).attr("data-guts","{ url: '/img/58_warn24.png.png', title: 'Warning!', xtraStyle: '' }"); imgWholeFunc( $(this) ); }); imgWholeFunc = function( elem ) { if ( undefined === elem.attr('style') ) { elem.attr('style',''); } eval( "var guts = " + elem.data('guts')); if ( undefined !== guts ) { elem.attr('title', guts.title); elem.attr('style', elem.attr('style') + ' ' + 'background: transparent url(' + g_imgWholeHost + guts.url + ') scroll 0px 0px; background-repeat: no-repeat; '); elem.attr('style', elem.attr('style') + ' ' + guts.xtraStyle); } }