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 ]} );			}   	}); } ); } );

/* ############################################################################# */ /* ### CLIPBOARD                                                            ### */ /* ###  ### */ /* ### Credit:      JoJo\'s Bizarre Encyclopedia (https://jojowiki.com)      ### */ /* ###             User:Eckserah                                            ### */ /* ############################################################################# */

(function($, document) {   var _notice = '\nThis content comes from the Independent Fallout Wiki (https://fallout.wiki/), and must be attributed to its authors if you are using it on another wiki or web page. Do not copy paste this into your site without giving credit, as specified in the license.'     , _init = function {        if (mw.config.get('wgUserGroups', []).length < 2) {            $('#mw-content-text').on('cut copy', _copyevent);            $(document.body).on('paste', '[contenteditable],input,textarea', _pasteevent);        }    }      , _copyevent = function(e) {        var text, $target;        $target = $(e.target);        if ($target.closest('.ace_editor').length > 0) {            return;        } else if ($target.is('input,textarea')) {            if (e.type == 'cut') {                return;            }            text = $target.val.substring(e.target.selectionStart, e.target.selectionEnd); } else { text = document.getSelection.toString; }       if (text.length < 40) { return; }       text = text + _notice; (e.originalEvent.clipboardData || window.clipboardData).setData('text/plain', text); e.preventDefault; console.log('Content to be copied modified. Report any problems to Vish.'); }    , _pasteevent = function(e) { var paste, selection, input, startPos, endPos, text; paste = (e.originalEvent.clipboardData || window.clipboardData).getData('text/plain'); if (paste.indexOf(_notice) == -1) { return; }       paste = paste.replace(_notice, ''); if ($(event.target).is('[contenteditable]')) { selection = window.getSelection; if (!selection.rangeCount) { return false; }           selection.deleteFromDocument; selection.getRangeAt(0).insertNode(document.createTextNode(paste)); } else { input = event.target; if (input.selectionStart !== undefined) { startPos = input.selectionStart; endPos = input.selectionEnd; text = $(input).val; text = text.substring(0, startPos) + paste + text.substring(endPos); $(input).val(text); endPos = startPos + paste.length; input.setSelectionRange(endPos, endPos); }       }        console.log('Content to paste modified.'); e.preventDefault; };   $(_init); } )(jQuery, document);

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

for (var i = 0; i < youtube.length; i++) { var source = "https://img.youtube.com/vi/"+ $(youtube[i]).data('embed') +"/sddefault.jpg";

var image = new Image; debugger; image.src = source; image.addEventListener("load", function {					youtube[i].appendChild(image);		});

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

iframe.setAttribute("frameborder", "0"); iframe.setAttribute("width", $(this).data('embed-width')); iframe.setAttribute("height", $(this).data('embed-height')); 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));