MediaWiki:Common.js

// Wikia's own WikiaScriptLoader isn't automatically included in other skins such as monobook. // Presumably this is because they no longer support them. This checks to see if WikiaScriptLoader // function reference has been declared, and if it has not, it creates it. Backwards compatibility // for everybody! - Blame User:Tierrie @ DA Wiki if this works. Blame someone else if it breaks. // Note: This script is copied from DragonAge.Wikia.com

if(typeof WikiaScriptLoader === 'undefined') { var WikiaScriptLoader=WikiaScriptLoader?WikiaScriptLoader:function{var b=navigator.userAgent.toLowerCase;this.useDOMInjection=b.indexOf("opera")!=-1||b.indexOf("firefox")!=-1&&b.indexOf("/4.0b")==-1;this.isIE=b.indexOf("opera")==-1&&b.indexOf("msie")!=-1;this.headNode=document.getElementsByTagName("HEAD")[0]}; WikiaScriptLoader.prototype={loadScript:function(b,c){this.useDOMInjection?this.loadScriptDOMInjection(b,c):this.loadScriptDocumentWrite(b,c)},loadScriptDOMInjection:function(b,c){var a=document.createElement("script");a.type="text/javascript";a.src=b;var d=function{a.onloadDone=true;typeof c=="function"&&c};a.onloadDone=false;a.onload=d;a.onreadystatechange=function{a.readyState=="loaded"&&!a.onloadDone&&d};this.headNode.appendChild(a)},loadScriptDocumentWrite:function(b,c){document.write('<\/script>');var a=function{typeof c=="function"&&c};typeof c=="function"&&this.addHandler(window,"load",a)},loadScriptAjax:function(b,c){var a=this,d=this.getXHRObject;d.onreadystatechange=function{if(d.readyState==4){var e=d.responseText;if(a.isIE)eval(e);else{var f=document.createElement("script");f.type="text/javascript";f.text=e;a.headNode.appendChild(f)}typeof c=="function"&&c}};d.open("GET",b,true);d.send("")},loadCSS:function(b,c){var a=document.createElement("link"); a.rel="stylesheet";a.type="text/css";a.media=c||"";a.href=b;this.headNode.appendChild(a)},addHandler:function(b,c,a){if(window.addEventListener)window.addEventListener(c,a,false);else window.attachEvent&&window.attachEvent("on"+c,a)},getXHRObject:function{var b=false;try{b=new XMLHttpRequest}catch(c){for(var a=["Msxml2.XMLHTTP.6.0","Msxml2.XMLHTTP.3.0","Msxml2.XMLHTTP","Microsoft.XMLHTTP"],d=a.length,e=0;e<d;e++){try{b=new ActiveXObject(a[e])}catch(f){continue}break}}return b}};window.wsl=new WikiaScriptLoader; }

/* * ADVANCED AJAX AUTO-REFRESHING ARTICLES * Code originally by "pcj" of Wowpedia * Maintenance, cleanup, style and bug fixes by Grunny (http://community.wikia.com/wiki/User:Grunny) */ var	ajaxIndicator = 'http://images2.wikia.nocookie.net/dev/images/8/82/Facebook_throbber.gif', ajaxTimer, ajaxRefresh = 60000, refreshText = 'Auto-refresh page', refreshHover = 'Enable auto-refreshing of this page', doRefresh = true; if ( !window.ajaxPages ) { var ajaxPages = new Array( 'Special:RecentChanges','Special:WikiActivity' ); } if ( !window.ajaxCallAgain ) { var ajaxCallAgain = []; } if( typeof AjaxRCRefreshText == "string" ) { refreshText = AjaxRCRefreshText; } if( typeof AjaxRCRefreshHoverText == "string" ) { refreshHover = AjaxRCRefreshHoverText; } /** * Sets the cookie * @param c_name string Name of the cookie * @param value string 'on' or 'off' * @param expiredays integer Expiry time of the cookie in days */ function setCookie( c_name, value, expiredays ) { var exdate = new Date; exdate.setDate( exdate.getDate + expiredays); document.cookie = c_name + "=" + escape(value) + ( ( expiredays === null ) ? "" : ";expires=" + exdate.toGMTString ); } /** * Gets the cookie * @param c_name string Cookie name * @return The cookie name or empty string */ function getCookie( c_name ) { if ( document.cookie.length > 0 ) { var c_start = document.cookie.indexOf( c_name + "=" ); if ( c_start !== -1 ) { c_start = c_start + c_name.length + 1; var c_end = document.cookie.indexOf( ";", c_start ); if ( c_end === -1 ) { c_end = document.cookie.length; }			return unescape( document.cookie.substring( c_start, c_end ) ); }	}	return ""; } /** * Main function to start the Auto-refresh process */ function preloadAJAXRL { var	ajaxRLCookie = ( getCookie( "ajaxload-" + wgPageName ) == "on" ) ? true : false, appTo = ( $( '#WikiaPageHeader' ).length ) ? $( '#WikiaPageHeader' ) : ( $( '#AdminDashboardHeader' ).length ? $( '#AdminDashboardHeader > h1' ) : $( '.firstHeading' ) ); appTo.append( ' ' + refreshText + ':   ' ); $( '#ajaxLoadProgress' ).ajaxSend( function ( event, xhr, settings ) {		if ( location.href == settings.url ) {			$( this ).show;		}	} ).ajaxComplete ( function ( event, xhr, settings ) {		var	$collapsibleElements = $( '#mw-content-text' ).find( '.mw-collapsible' );		if ( location.href == settings.url ) {			$( this ).hide;			for ( var i = 0; i < ajaxCallAgain.length; i++ ) {				ajaxCallAgain[i];			}			if ( $collapsibleElements.length ) {				$collapsibleElements.makeCollapsible;			}			if ( mw.config.get( 'wgNamespaceNumber' ) === -1 && mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Recentchanges' ) {				mw.special.recentchanges.init;			}		}	} ); $( '#ajaxToggle' ).click( toggleAjaxReload ); $( '#ajaxToggle' ).attr( 'checked', ajaxRLCookie); if ( getCookie( "ajaxload-" + wgPageName ) == "on" ) { loadPageData; } } /** * Turn refresh on and off by toggling the checkbox */ function toggleAjaxReload { if ( $( '#ajaxToggle' ).prop( 'checked' ) === true ) { setCookie( "ajaxload-" + wgPageName, "on", 30 ); doRefresh = true; loadPageData; } else { setCookie( "ajaxload-" + wgPageName, "off", 30 ); doRefresh = false; clearTimeout( ajaxTimer ); } } /** * Does the actual refresh */ function loadPageData { var cC = '#mw-content-text'; $( cC ).load( location.href + " " + cC + " > *", function ( data ) {		if ( doRefresh ) {			ajaxTimer = setTimeout( loadPageData, ajaxRefresh );		}	} ); } /** * Load the script on specific pages */ $( function {	for ( var x = 0; x < ajaxPages.length; x++ ) {		if ( wgPageName == ajaxPages[x] && $( '#ajaxToggle' ).length === 0 ) {			preloadAJAXRL;		}	} } );

// http://dev.wikia.com/wiki/BotoneraPopups importScriptURI('http://dev.wikia.com/wiki/BotoneraPopups/Code/en.js?action=raw&ctype=text/javascript&templates=expand'); importStylesheetPage('BotoneraPopups/code.css', 'dev');

// Lists all duplicate images on UW-Template:Duplicate Images importScriptPage('DupImageList/code.js', 'dev');

// jQuery-UI v1.8.23 importScriptURI('http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js');

// Template:ShowInfo JavaScript importScriptPage('Template:ShowInfo/Script.js'); monoBookText = 'MonoBook'; oasisText = 'Wikia';

importArticles({   type: 'style',    articles: [        'Template:Questinfo/Stylesheet.css',        'Template:Ambox/code.css',        'Template:Forum/code.css',        'Template:BioStyle.css',        'Template:ShowInfo/Style.css',        'Template:BookInfo/Style.css',        'Template:AidesInfo/Style.css',        'Template:h1/Style.css',        'Template:SkillInfo/Style.css',        'Template:NPCInfo/Style.css',        'Template:NPCprod/Style.css'    ] }, {    type: 'script',    articles: [        'w:c:dev:SkinSwitchButton/code.js',        'Template:NPCprod/Script.js',        'Template:TGnfo/Script.js',        'Template:AidesInfo/Script.js',        'Template:DiscoveryInfo/Script.js',        'UW-Templates:Script.js'    ] });

$('table.uisortable').children('tbody').addClass('ui-sortable'); $('.ui-sortable').sortable; $('.ui-sortable').disableSelection; $('.ui-draggable').draggable;

/****************************** Temporarily Unused Script

// w:c:dev:ShowHide importScriptPage('ShowHide/code.js', 'dev');

Updated @ November 23, 2012