MediaWiki:Common.js

/* */

/* ######################################################################## */ /* ### JavaScript here is loaded for all users and all skins. ### */ /* ######################################################################## */ mw.loader.load( '/wiki/MediaWiki:JCarousel.js?action=raw&ctype=text/javascript' );

/* ######################################################################## */ /* ### SHARED CODE                                                     ### */ /* ### ### */ /* ### Description: Used by multiple modules                            ### */ /* ### Credit:     various                                             ### */ /* ######################################################################## */

/** * Removes lazy loading from all images contained in `lazyIcon`. * */ function removeLazyLoad(lazyIcon) { var lazyIconImages = lazyIcon.getElementsByTagName("img"); for (var i = 0; i < lazyIconImages.length; i++) { var iconSrc = lazyIconImages[i].getAttribute("data-src"); if (iconSrc !== null) lazyIconImages[i].setAttribute("src", iconSrc); lazyIconImages[i].className = ""; } }

/* ############################################################################# */ /* ### TICKER                                                               ### */ /* ###  ### */ /* ### Description: Displays a ticker, as in Template:Ticker             ### */ /* ### Credit:     unknown                                                  ### */ /* ###             User:FDekker                                             ### */ /* ############################################################################# */ $(function {   $(".ticker").each(function(_, ticker) { var step = 10; // How many pixels to move text each tick var tickerSpeed = 200; ticker = $(ticker); if (ticker.attr('data-speed') !== undefined) tickerSpeed = parseInt(ticker.attr('data-speed')); if (ticker.attr('data-step') !== undefined) step = parseInt(ticker.attr('data-step')); ticker.css("display", "block");

var wrapper = $(".tickerWrapper", ticker); wrapper.css("left", (step + ticker.width) + "px");

var text = $(".tickerText", ticker); var textWidth = text.outerWidth;

setInterval(function {           var offset =                (wrapper.position.left > -(textWidth + step))                    ? (wrapper.position.left - step) + "px"  // Move left                    : (ticker.width + step) + "px";  // Reset            wrapper.css("left", offset);        }, tickerSpeed); }); });

/* ################################################################################################################# * /* ### TICKER                                                                                                   ### * /* ###                                      ### * /* ### Description: Automatically sorts the table based on the column with                                       ### * /* ###             a class of "default-table-sort-key"                                                          ### * /* ### Credit:     meta.wikimedia.org/wiki/Help:Sorting#Using_JavaScript_to_trigger_client-side_table_sorting   ### * /* ###             User:Eckserah                                                                                ### * /* ################################################################################################################# */

jQuery( document ).ready( function( $ ) {   // wrapped in "mw.loader.using" so this doesn't execute until Tablesorter has loaded    mw.loader.using( 'jquery.tablesorter', function { //debugger; $('table.sortable').each(function(index, element) {			var defaultSortKey = $(element).find('th.default-table-sort-key');			if (defaultSortKey.length > 0) {				var defaultSortIndex = defaultSortKey.first.index;				//messy workaround				var json = {}				json[defaultSortIndex] = 'asc';				$(element).tablesorter( {sortList: [ json ]} );			}   	}); } ); } );

/* ############################################################################# */ /* ### Youtube lazy loading                                                 ### */ /* ###  ### */ /* ###              User:Eckserah                                            ### */ /* ############################################################################# */ (function($) {	var youtube = $(".youtube");

for (var i = 0; i < youtube.length; i++) { var source = "https://i.ytimg.com/vi/"+ $(youtube[i]).data('embed') +"/0.jpg"; var imgWidth = $(youtube[i]).data('embed-width'); var imgHeight = $(youtube[i]).data('embed-height'); var image = new Image; image.src = source; image.width = imgWidth; image.height = imgHeight; image.addEventListener("load", function {			youtube[i].prepend(image);		});

youtube[i].addEventListener( "click", function {			var iframe = document.createElement("iframe");

iframe.setAttribute("frameborder", "0"); iframe.setAttribute("width", imgWidth); iframe.setAttribute("height", imgHeight); iframe.setAttribute("allowfullscreen", "true"); iframe.setAttribute("src", "https://www.youtube.com/embed/"+ $(this).data('embed') +"?" + $(this).data('embed-query'));

this.innerHTML = ""; this.appendChild(iframe); });	}; }(jQuery));