MediaWiki:Common.js

/* Any JavaScript here will be loaded for all users on every page load. */ // following script by w:user:joeyaa -- adds link to contribs for logged-out people's article/blog comments

$('.details span[title]').each(function{       var t = $(this),        title = $(this).attr("title");        t.html('Unregistered user (IP: ' + title + ')'); });

if (mwCustomEditButtons) { mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://upload.wikimedia.org/wikipedia/commons/thumb/4/40/Youtube_icon.svg/23px-Youtube_icon.svg.png", "speedTip": "Embed a YouTube Video", "tagOpen": " ", "tagClose": " ", "sampleText": "Video ID"}; mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images.wikia.com/central/images/c/c9/Button_strike.png", "speedTip": "Strike", "tagOpen": " ", "tagClose": " ", "sampleText": "Strike-through text"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABcAAAAWCAMAAAAcqPc3AAAAAXNSR0IArs4c6QAAAk9QTFRFAAAAgAAAAIAAgIAAAACAgACAAICAwMDAwNzApsrwAAAAQ1l4SGB7a3uQdYijhpixkKO9k6bAl6rEmq3HnrHLo7bQqLvVrb/YsMPds8bgus3nvc/owdTuxNjzydz20uT91+f+////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////QEBAQUFBQkJCQ0NDRERERUVFRkZGR0dHSEhISUlJSkpKS0tLTExMTU1NTk5OT09PUFBQUVFRUlJSU1NTVFRUVVVVVlZWV1dXWFhYWVlZWlpaW1tbXFxcXV1dXl5eX19fYGBgYWFhYmJiY2NjZGRkZWVlZmZmZ2dnaGhoaWlpampqa2trbGxsbW1tbm5ub29vcHBwcXFxcnJyc3NzdHR0dXV1dnZ2d3d3eHh4eXl5enp6e3t7fHx8fX19fn5+f39/gICAgYGBgoKCg4ODhISEhYWFhoaGh4eHiIiIiYmJioqKi4uLjIyMjY2Njo6Oj4+PkJCQkZGRkpKSk5OTlJSUlZWVlpaWl5eXmJiYmZmZmpqam5ubnJycnZ2dnp6en5+foKCgoaGhoqKio6OjpKSkpaWlpqamp6enqKioqampqqqqq6urrKysra2trq6ur6+vsLCwsbGxsrKys7OztLS0tbW1tra2t7e3uLi4ubm5urq6u7u7vLy8vb29vr6+v7+/wMDAwcHBwsLCw8PDxMTECL3QDwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GCQccCQrY7AcAAACHSURBVCjPfchZDsMgEATR+jfOhldsSLj/JdNJjIRHKE+IHhW5qSe/Whz52dKRU4Jk/ekxQrTU9x12S33bYLPUQ4Bgqa8rrJb6ssBiqc8zzJb6NMFUlEt9HGEsyqk+DMBwKKe6954TBa/+kFP/BPV7Tfm76rca/Fb9WuNY9UuLo3ddVz194vo3NB0oZdoKj8sAAAAASUVORK5CYII=", "speedTip": "Redirect", "tagOpen": "#REDIRECT ",		"tagClose": "", "sampleText": "Insert text"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images.wikia.com/clubpenguin/images/3/31/HighlightButton.png", "speedTip": "Highlight", "tagOpen": " ", "tagClose": " ", "sampleText": "Highlighted text here."};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images.wikia.com/central/images/5/56/Button_big.png", "speedTip": "Large Text", "tagOpen": " ", "tagClose": " ", "sampleText": "Insert Text Here"};

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images.wikia.com/central/images/5/58/Button_small.png", "speedTip": "Small Text", "tagOpen": " ", "tagClose": " ", "sampleText": "Insert Text Here" };

mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images.wikia.com/central/images/f/fd/Button_underline.png", "speedTip": " Underline Selected Text ", "tagOpen": " ", "tagClose": " ", "sampleText": "Insert text to underline!" };	mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABcAAAAWCAYAAAArdgcFAAAAAXNSR0IArs4c6QAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB90GCBEoGHtVh6UAAAAMaVRYdENvbW1lbnQAAAAAALyuspkAAAIYSURBVDjLtVW7ihRBFD13uvYxa2hmICIo4scIJgqCoOAPmAhGfoEYGGxiIisL/oCIoIEiGGhiZKDsKLg7jbrs4AxOd92HQVXPw77twqKVnOCcunWq7rkUmZnhP6w797YQBvuAmYGIXARwJO7j7jeEKI3xLjwaFytFr65qTKsai3j71k3cuHYFg8GgxTW4/eghrl+9jGdPn7gaM0MwSoct4mDnE0YHBxiPfyYvjmZv9yvK4R7KctihIQRmbXcj31DFIKJuw5oYqPoaMkNgjm6jAECUIcJuw8w0FxdXQ0QIIgwygxHN0LJ1ZYbEeombaVTzDdTXGBBULZ+GGc6dG1iXuQY139AMrgYwhLqOnW9elkMUYcV988lkkgyIIEZ2FIQgIl21sXn/7qGTmBrarkGE9OZd1s+eO4+NjWNu0S+fd7D/43t6c7cGchRzNmeYrV+4eAknT51e5jJubz3Am9cvoWpg0ZZGU/Ho7QUAMDNijC2OAGhOi6j4GjOEyJxanto8RwDCAo6xzRHBNMdV1NeAEIS5wzcgqnn62ndrhk3/oslp+WPjLAmak9DeOM+5uRoiQmARENJUNti4FxGIyBLX4Hz81deYITSNWVxFEVJWewRRcWPW6xVZW3RoCLT5+EXrm2NmqAhW19Y6h8dMUU0rrPf7Lv/81TuE0WjcWeDXNB46oVXt719dLxDevv/wzz/nlX7AmRPH8RuTxxRrcgmtcAAAAABJRU5ErkJggg==", "speedTip": "History table", "tagOpen": "{|class=\"wikitable sortable\"\n! scope=\"col\"| Catalog\n! scope=\"col\"| Available from\n! scope=\"col\"| Available until\n|-\n|catalog goes here\n|starting date\n|ending date\n|}", }; }

/* // ************************************************** // Experimental javascript countdown timer (Splarka) // Version 0.0.3 // ************************************************** // // Usage example: // //  Only January 01 2007 00 begin_of_the_skype_highlighting              01 2007 //00      end_of_the_skype_highlighting:00:00 PST until New years. // //  Javascript disabled. function updatetimer(i) { var now = new Date; var then = timers[i].eventdate; var diff = count=Math.floor((then.getTime-now.getTime)/1000); // catch bad date strings if(isNaN(diff)) { timers[i].firstChild.nodeValue = '** ' + timers[i].eventdate + ' **' ; return; } // determine plus/minus if(diff<0) { diff = -diff; var tpm = '+'; } else { var tpm = ''; } // calcuate the diff var left = (diff%60) + ' seconds'; diff=Math.floor(diff/60); if(diff > 0) left = (diff%60) + ' minutes ' + left; diff=Math.floor(diff/60); if(diff > 0) left = (diff%24) + ' hours ' + left; diff=Math.floor(diff/24); if(diff > 0) left = diff + ' days ' + left timers[i].firstChild.nodeValue = tpm + left; // a setInterval is more efficient, but calling setTimeout // makes errors break the script rather than infinitely recurse timeouts[i] = setTimeout('updatetimer(' + i + ')',1000); } function checktimers { //hide 'nocountdown' and show 'countdown' var nocountdowns = getElementsByClassName(document, 'span', 'nocountdown'); for(var i in nocountdowns) nocountdowns[i].style.display = 'none' var countdowns = getElementsByClassName(document, 'span', 'countdown'); for(var i in countdowns) countdowns[i].style.display = 'inline' //set up global objects timers and timeouts. timers = getElementsByClassName(document, 'span', 'countdowndate'); //global timeouts = new Array; // generic holder for the timeouts, global if(timers.length == 0) return; for(var i in timers) { timers[i].eventdate = new Date(timers[i].firstChild.nodeValue); updatetimer(i); //start it up  } } addOnloadHook(checktimers); // ************************************************** // - end -  Experimental javascript countdown timer // ************************************************** /* for title templates */ // rewriteTitle; // ************************************************** // "Username" template - from Bloons wiki // ************************************************** $(function { if (typeof wgUserName != 'undefined') {     $('.insertusername').html(wgUserName);  } }); /* hoverimage */ $(function {	$('div.fadein img').css('opacity','0.7');	$('div.fadein img').mouseover(function { $(this).animate({opacity:1},800); }).mouseout(function { $(this).animate({opacity:0.7},800); }); }); // ============================================================ // displayTimer - 2/1/11 // ============================================================ //Add a clock to the WikiHeader //Modified from work by Patrick Westerhoff [poke]: //http://bulbapedia.bulbagarden.net/wiki/MediaWiki:Monobook.js hookEvent( 'load', displayTimer ); function displayTimer {   if ( typeof( timerDisplay ) !== 'undefined' && timerDisplay === false ) return; var date; if (skin == 'oasis') {   var timerParent = document.getElementById( 'WikiHeader' ).getElementsByTagName( 'div' )[0]; }   if (skin == 'monobook') {   var timerParent = document.getElementById( 'p-personal' ).getElementsByTagName( 'ul' )[0]; }   var timerLink   = document.createElement( 'a' ); var timerObj   = document.createElement( 'li' ); timerLink.href              = '/wiki/' + wgPageName + '?action=purge'; timerLink.title             = 'Purge the server cache and update the contents of this page.' timerObj.id                 = 'displayTimer'; timerObj.style.textTransform = 'none'; timerObj.style.fontWeight   = 'bold'; timerObj.style.fontSize     = '100%'; timerObj.appendChild( timerLink ); timerParent.insertBefore( timerObj, timerParent.firstChild ); if (skin == 'oasis') {       $('#displayTimer').css({'position': "inherit", 'right': "175px", 'top': "-28px"}); }   var month = new Array(12); month[0] = "Jan"; month[1] = "Feb"; month[2] = "Mar"; month[3] = "Apr"; month[4] = "May"; month[5] = "Jun"; month[6] = "Jul"; month[7] = "Aug"; month[8] = "Sep"; month[9] = "Oct"; month[10] = "Nov"; month[11] = "Dec"; function actualizeUTC {       timerDate           = new Date; timerLink.innerHTML = ( timerDate.getUTCDate    < 10 ? '0' : '' ) + timerDate.getUTCDate     + ' ' + ( timerDate.getUTCMonth   < 10 ?  :   ) + month[timerDate.getUTCMonth] + ' ' + ( timerDate.getUTCFullYear < 10 ? '0' : '' ) + timerDate.getUTCFullYear + ' ' + ( timerDate.getUTCHours   < 10 ? '0' : '' ) + timerDate.getUTCHours    + ':' + ( timerDate.getUTCMinutes < 10 ? '0' : '' ) + timerDate.getUTCMinutes  + ':' + ( timerDate.getUTCSeconds < 10 ? '0' : '' ) + timerDate.getUTCSeconds  + ' (UTC)'; }   function actualizeCustom {       timerDate           = new Date; timerDate.setMinutes ( timerDate.getMinutes + timerDate.getTimezoneOffset + timerTimezone * 60 ); timerLink.innerHTML = ( timerDate.getDate    < 10 ? '0' : '' ) + timerDate.getDate     + ' ' + ( timerDate.getMonth   < 10 ?  :   ) + month[timerDate.getMonth] + ' ' + ( timerDate.getFullYear < 10 ? '0' : '' ) + timerDate.getFullYear + ' ' + ( timerDate.getHours   < 10 ? '0' : '' ) + timerDate.getHours    + ':' + ( timerDate.getMinutes < 10 ? '0' : '' ) + timerDate.getMinutes  + ':' + ( timerDate.getSeconds < 10 ? '0' : '' ) + timerDate.getSeconds + ' (UTC' + ( timerTimezone < 0 ? '' : '+' ) + timerTimezone + ')'; }   // start if ( typeof( timerTimezone ) !== 'number' ) {       actualizeUTC; setInterval( actualizeUTC, 1000 ); }   else {       actualizeCustom; setInterval( actualizeCustom, 1000 ); } } // BEGIN JavaScript title rewrite -- jQuery version and new wikia skin fixes by Grunny function rewriteTitle { if( typeof( window.SKIP_TITLE_REWRITE ) != 'undefined' && window.SKIP_TITLE_REWRITE ) { return; }	if( $('#title-meta').length == 0 ) { return; }	var newTitle = $('#title-meta').html; if( skin == "oasis" ) { $('header.WikiaPageHeader > h1').html(' ' + newTitle + ' '); $('header.WikiaPageHeader > h1').attr('style','text-align:' + $('#title-align').html + ';'); } else { $('.firstHeading').html(' ' + newTitle + ' '); $('.firstHeading').attr('style','text-align:' + $('#title-align').html + ';'); } } // END JavaScript title rewrite addOnloadHook(rewriteTitle); // interactive CP buttons function changeBgImage (image, id) { var element = document.getElementById(id); element.style.backgroundImage = "url("+image+")"; } function changeBgImage (image, id) { var element = document.getElementById(id); element.style.backgroundImage = "url("+image+")"; } /* hiding the TOC for template:hidetoc */ if ($(".hidetoc").length > 0) { $(document).ready(function {		$("#toc").addClass("tochidden");		$("#toc td > ul").css("display","none");		$("#toc .toctoggle a").text("show");	}); }

/* fixing links to Club Penguin's RSS for Template:ClubPenguinRSS */ /* a big credit for Mathmagician for making the script loop */ (function {	function cpBlogLink {		if ($(".cprss-links > .wikiaRssPlaceholder > .wikiaRss > ul").length > 0) {			$(".cprss-links > .wikiaRssPlaceholder > .wikiaRss > ul > li > a").each(function { $(this).attr("href", "http://www.clubpenguin.com/" + $(this).attr("href")); });		} else {			// if condition was false, check again 1 second later			window.setTimeout(cpBlogLink, 1000);		}	}

$(cpBlogLink);

});

/* add Tempalte:No license when the uploader skips the license selection */

$(document).ready(function {	$('select[name="wpLicense"]#wpLicense > option:contains(None selected)').attr("value","No license"); });

/* auto-download an example logo for Club Penguin Wiki:Logo Design */ // full support info at http://caniuse.com/download

$("a#wiki-logo-blank").attr("download","example_logo.png");

/* irc installation - code by Super Miron */ if (mw.config.get("wgUserName")) { $(".irc").html(" "); }

/* chat log search */

// when link is pressed $("a#chatlogs-search-button").mouseover(function {	if ($("input#chatlogs-search-box").val.length > 0) {		var google = "https://www.google.com/#q=site:",			site = encodeURIComponent("http://clubpenguin.wikia.com/wiki/Club_Penguin_Wiki:Chat/Logs/"),			string = encodeURIComponent($("input#chatlogs-search-box").val.replace(/ /g, "+")),			searchPage = google + site + "+" + string;		$(this).attr("href", searchPage);	} }); // when enter is pressed (on the text box) $("input#chatlogs-search-box").on("keypress", function(k) {	if (k.keyCode == 13 && $("input#chatlogs-search-box").val.length > 0) {		// if enter is pressed		$("a#chatlogs-search-button")[0].click;	} });

/* settings for DynamicImages - make gif images animated */

DynamicImages = { gifGalleryImages: true, gifImages: true, svgGalleryImages: false }

/*	import codes from other wiki pages before adding, it's recommended to move the pages to a	subpage of Common.js	also, make sure that you separate each page from the array with a comma

importArticles({	type: "script",	articles: [		"u:dev:PurgeButton/code.js",		"u:dev:AjaxRC/code.js",		"u:dev:ShowHide/code.js",		"u:dev:UserTags/code.js",		"u:zh.pad.wikia.com:MediaWiki:CountDown.js",		"u:dev:DupImageList/code.js",		"MediaWiki:Common.js/closeThread.js",		"MediaWiki:Common.js/ThreadAdminBadges-load.js",		"u:dev:DynamicImages/code.js"	] }, {	type: "style",	articles: [		"u:zh.pad.wikia.com:MediaWiki:CountDown.css"	] });

/* add to Template:Expansion a link to the incompleted section */ var headings = $("#mw-content-text *").filter("h1,h2,h3,h4,h5,h6"); for (hI = 0; hI < $(headings).length; hI++) { if ($(headings[hI]).next.hasClass("section-stub") == true) { $(headings[hI]).next.find(".mbox-text > .expand").html('expanding it'); } }

/* Special:CSS modifications for interfaceeditors and admins */ if (mw.config.get("wgCanonicalSpecialPageName") == "CSS" && (mw.config.get("wgUserGroups").indexOf("sysop") > -1 || mw.config.get("wgUserGroups").indexOf("interfaceeditor"))) { $(".css-editor-container .ace_indent-guide").css("opacity", "0.25"); $('a[accesskey="a"]').attr("target", "_blank"); // open history in a new ticket }

/* verbatim-independent script for playing Template:EmbedMusic */ /* syntax: ID */

// set function function EmbedMusic { if (		$("#mw-content-text span.EmbedMusic").length > 0 && // music fragments exist		Number($("#mw-content-text span.EmbedMusic").first.text) != NaN && // music has a valid input		[2, 3, 10, 500].indexOf(mw.config.get("wgNamespaceNumber")) > -1 // namespace: ["User", "User talk", "Template", "User blog"]	) { $("#mw-content-text span.EmbedMusic").first.replaceWith(			'' +			'' +			' '		); } else if ($("#mw-content-text span.EmbedMusic").length > 0) { console.log("Your music ID input for Template:EmbedMusic was not valid. Please try again."); } }

if (mw.config.get("wgAction") == "edit") { // when ?action=edit $("body").on("DOMNodeInserted", ".WikiaArticle", function {		EmbedMusic;	}); } else { // not in the editor EmbedMusic; }

/* adding SVG section to the article Color */

if (mw.config.get("wgPageName") == "Color" && typeof window.SVGAElement !== "undefined") { // page is Color and the client supports SVG $.getJSON("/api.php?action=query&format=json&prop=revisions&titles=MediaWiki:ArticleColorInteractive&rvprop=content&cb=" + new Date.getTime, function(data) {		var a = data.query.pages;		for (var pageid in a) {			var content = a[pageid].revisions[0]["*"];			$("table#color-table").after( ' Interactive Color Preview \n' + content );			$("svg#colors-cp-interactive").css({ "display": "block", "margin": "auto" });			$("svg#colors-cp-interactive .color-svg-icon-container").mouseover(function { var fill = $(this).find(".color-svg-icon").css("fill"); $("svg#colors-cp-interactive .color-svg-target").each(function {					$(this).css("fill", fill);				}); });		}	}); }

/* remove extra breaks from featured blog posts on the main page */

if (mw.config.get("wgPageName") == "Club_Penguin_Wiki") { $(".WikiaBlogListingPost blockquote p").each(function {		if ($(this).html == " ") {			$(this).remove;		}	}); $(".WikiaBlogListingPost blockquote br + br").remove; }