Difference between revisions of "MediaWiki:Common.js"

From dataZoa Wiki
Jump to: navigation, search
Line 18: Line 18:
 
$('#editCheckBoxes').hide();
 
$('#editCheckBoxes').hide();
  
// script for loading get-dzdot
 
$(document).ready(function() {
 
if($('#get-dzdot').length > 0) {
 
$.ajax({
 
    url:'https://www.datazoa.com/publish/gettingpublicdata1.asp?onlydot=true',
 
    type:'get',
 
    dataType:'html',
 
    success:function(data) {
 
    _html= jQuery(data);
 
    //get the title
 
    h3 = _html.find('h3');
 
    var node = document.createElement("h3");
 
    var textnode = document.createTextNode(h3[0].textContent);
 
    node.appendChild(textnode);
 
    document.getElementById("get-dzdot").appendChild(node);
 
    //console.log(h3[0].textContent);
 
    //get the text
 
    items = _html.find("li");
 
    console.log(items.length)
 
    array  = [0,1,5,6,7]
 
    for (i = 0; i < array.length; i++) {
 
    item = items[array[i]].innerHTML;
 
  // item = item.replace(/<a href=\"/g,'[').replace(/\">/g,' ').replace(/<\/a>/g,']').replace(/<span class=\"Gfsxs Gfsi\"/g,'').replace(/<\/span>/g,'');
 
    //item = item + '<br />'
 
    console.log(item);
 
    var node = document.createElement("li");
 
    var textnode = document.createTextNode(item);
 
    node.appendChild(textnode);
 
    document.getElementById("get-dzdot").appendChild(textnode);
 
    }
 
 
    }
 
});
 
};
 
});
 
 
// script for loading multi-country data sources
 
$(document).ready(function() {
 
if($('#mcountry').length > 0) {
 
$.ajax({
 
    url:'https://www.datazoa.com/publish/gettingdata-01-3.asp',
 
    type:'get',
 
    dataType:'html',
 
    success:function(data) {
 
    _html= jQuery(data);
 
   
 
    //get what i need
 
    trs = _html.find('.DIsourcesite');
 
    console.log(trs.length);
 
    titles = _html.find('[class="Gdib GCfl"]');
 
    console.log(titles.length);
 
    tooltips = _html.find('.GCkeyTip');
 
    console.log(tooltips.length);
 
    tvs = _html.find('[class="GCfl Gdib"]');
 
    console.log(tvs.length);
 
   
 
    //set variables
 
    j = 1
 
    k = 0
 
    l = 0
 
 
    expression = /http\S+?\"/
 
    expression_tv = /www\S+?\"/
 
    expression_tt = /<b>[a-zA-Z\s\d\D]+?\">/
 
    patt = new RegExp(expression);
 
    patt_tv = new RegExp(expression_tv);
 
    patt_tt = new RegExp(expression_tt);
 
    //loop
 
    for (i = 0; i < trs.length; i++) {
 
    // get titles and links
 
    tr = trs[i].innerHTML
 
    if(tr.includes('Gdib GCfl')) {
 
        //title
 
        title = titles[j].textContent;
 
        title = title.replace("&amp;","&");
 
        //link url
 
        link = titles[j].getAttribute('onclick');
 
        link = patt.exec(link);
 
        link = String(link).replace("\"","");
 
        //testing
 
        console.log(title + " " + link);
 
        //add it to the document
 
        var node = document.createElement("span"); // create a <li> node
 
        var textnode = document.createElement("a");
 
        textnode.setAttribute('href', link);
 
        textnode.innerHTML = title;
 
        textnode.style.marginRight = "5px";
 
        node.appendChild(textnode); // append text to li
 
        document.getElementById("mcountry").appendChild(node); // append li to ul with id="myList"
 
        j += 1;
 
        }   
 
    //get tvs
 
    if(tr.includes('TVicon')) {
 
        tv = tvs[k].getAttribute('onclick');
 
        console.log(tv);
 
        tv = patt_tv.exec(tv);
 
        tv = String(tv).replace("\"","");
 
        console.log(tv);
 
        //add it to the document
 
        img_link = document.createElement("a");
 
        img_link.setAttribute('href',tv);
 
        img = document.createElement("img");
 
        img.src = 'http://datazoa.com/img/TVicon.png';
 
        img.style.marginRight = "5px";
 
        document.getElementById("mcountry").appendChild(img_link);
 
        document.getElementById("mcountry").appendChild(img); 
 
        k += 1;
 
        }
 
    //get tooltips
 
    if(tr.includes('GCkeyTip')) {
 
        tt = tooltips[l].outerHTML;
 
        console.log(l + " " + tt);
 
        tt = patt_tt.exec(tt);
 
        tt = String(tt).replace("\"","");
 
        console.log(tt);
 
        //add it to the document
 
        img_link = document.createElement("a");
 
        img_link.setAttribute('href',tt);
 
        img = document.createElement("img");
 
        img.src = 'https://www.datazoa.com/img/Key.png';
 
        document.getElementById("mcountry").appendChild(img_link);
 
        document.getElementById("mcountry").appendChild(img); 
 
        l += 1;
 
        }   
 
    //create a new line
 
    br = document.createElement("br");
 
    document.getElementById("mcountry").appendChild(br); 
 
    } 
 
 
    }
 
});
 
};
 
});
 
  
 
// js for changing the image
 
// js for changing the image
Line 163: Line 30:
 
image.style.height = "200px";
 
image.style.height = "200px";
 
}
 
}
 
 
  
 
// Load images from OUTSIDE the wiki -- needs some kludges...
 
// Load images from OUTSIDE the wiki -- needs some kludges...

Revision as of 07:46, 5 December 2016

/* Any JavaScript here will be loaded for all users on every page load. */
 
/* Global overrides for styling */
$('body').addClass('GbcWIKI');
$('#mw-head').addClass('GbcWIKI');
 
$('#mw-head').height('80px'); // horrible temporary kludge for chrome
 
$('#mw-page-base').addClass('GbcWIKI')
$('#mw-head-base').addClass('GbcWIKI')
 
/* stop wasting space */
$('#editpage-copywarn').hide();
$('.mw-editinginterface').hide();
$('.mw-translateinterface').hide();
$('#wpSummaryLabel').hide();
$('#wpSummary').hide();
$('#editCheckBoxes').hide();
 
 
// 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";
}
 
// Load images from OUTSIDE the wiki -- needs some kludges...
 
// 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'); } 
});
 
 
// workhorse for imgWhole, loads a foreign image (after page load, to avoid MediaWiki limitation)
// for elem, takes an attr called data-guts, which is a string that evals to an object, slaps it into the elem itself 
imgWholeFunc = function( elem ) {
	if ( undefined === elem.attr('style') ) { elem.attr('style',''); } // assert a style attr
	eval( "var guts = " + elem.data('guts')); // get the string for attr 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);
	}
}
 
 
// Model: <div class="imgWholeWrap1"><div class="imgWhole " data-guts="{ url: '...', xtraStyle: '...stylestr...'  }"></div></div>
// example to insert an icon from dataZoa.com: 
// <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" // where are the images from?
 
// generic
$('.imgWhole').each( function() { imgWholeFunc($(this)); });
$('.pageSnippet').each( function() { pageSnippetFunc($(this)); });
 
// for imgGlyph24 class 
// e.g. <div class="imgGlyph24 imgIdea"></div> to insert a lightbulb
//
$('.imgIdea').each( function() { $(this).attr("data-guts","{ url: '/img/3_idea24.png', title: 'A tip for you...', xtraStyle: '' }"); imgWholeFunc( $(this) ); });
$('.imgWarning').each( function() { $(this).attr("data-guts","{ url: '/img/58_warn24.png', title: 'Warning!', xtraStyle: '' }"); imgWholeFunc( $(this) ); });
$('.imgConcept').each( function() { $(this).attr("data-guts","{ url: '/img/81_BlueFlag24.png', title: 'Important Concept...', xtraStyle: '' }"); imgWholeFunc( $(this) ); });
$('.imgDisambiguate').each( function() { $(this).attr("data-guts","{ url: '/img/80_YellowFlag24.png', title: 'Disambiguate...', xtraStyle: '' }"); imgWholeFunc( $(this) ); });