MediaWiki:RailgunClient.min.js

/** * @fileOverview This file defines the Railgun client, the basic framework * behind the Railgun user script. Railgun provides a set of additional * features for the Wikia Rail and is designed for personal usage on all * wikia.com wikis. * * Railgun Wiki:   http://railgunscript.wikia.com/wiki/Railgun_Wiki * Contact Author: http://community.wikia.com/wiki/Message_Wall:Mathmagician * * @author © Jeff Bradford, 2012 * @version 2.2.1 */ $(function{var c=false;try{if(-1===window.location.href.indexOf(".wikia.com")){console.log("[Railgun]: Script onload cancelled. Not a wikia.com domain.");return}else{if("string"!==typeof wgUserName){console.log("[Railgun]: Script onload cancelled. User is not logged in.");return}else{if("string"!==typeof skin||("oasis"!=skin&&"wikia"!=skin)){console.log("[Railgun]: Script onload cancelled. Non-supported skin:",skin);return}else{if(0===$("#WikiaRail").length){var a=$(".WikiaRail");if(1===a.length){a.attr("id","WikiaRail")}else{console.log("[Railgun]: Script onload cancelled. #WikiaRail not found in document.");return}}else{if("http://wikimarks.wikia.com"==wgServer&&2==wgNamespaceNumber&&wgTitle==wgUserName+"/Wikimarks"){console.log("[Railgun]: Script onload cancelled. Noninterference with Wikimarks editor.");return}else{if(!window.localStorage){console.log("[Railgun]: Script onload cancelled. Your browser does not support localStorage.");return}}}}}}c=true;Railgun={};(function(j){var f="http://railgunscript.wikia.com";var e="http://mathmagician.wikia.com";if("Mathmagician"===wgUserName&&e===wgServer){f=e}var i="2.2.1";var g="24 July 2012";function d{console.log("[Railgun]: - Printing framework data -");console.log("[Railgun]: Railgun.domain:",f);console.log("[Railgun]: Railgun.version:",i);console.log("[Railgun]: Railgun.updated:",g);console.log("");console.log("[Railgun]: - Printing config data -");console.log("[Railgun]:",Railgun.Config);console.log("");Railgun.Storage.contents}function h{console.log("[Railgun]: - Railgun API Overview -");console.log("api                            // prints an API overview");console.log("clear                           // WARNING! deletes all data in storage");console.log("getItem(key)                      // returns a value from storage");console.log("info                            // prints framework, config and storage data");console.log("init([anything])                  // initialize Railgun, [w/o modules package]");console.log("insert(id, content[, header])     // inserts a module into the siderail");console.log("register(id, name, init[, destr]) // registers a module with the framework");console.log("removeItem(key)                   // deletes a single value from storage");console.log("setItem(key, value)               // saves data to storage");console.log("swapElements(jQuery, jQuery)      // swaps 2 element's locations in the DOM")}function l(v,t){if(0===v.length||0===t.length){return}var u=v.first;var s=t.first;var p=u.parent;var m=s.parent;var r=u.index;var o=s.index;var n=(p[0]==m[0]);var q=r-o;if(n&&0===q){}else{if(n&&1===q){u.after(s)}else{if(n&&-1===q){s.after(u)}else{if(0===o){u.after(s);m.prepend(u)}else{var w=s.prev;u.after(s);w.after(u)}}}}}function k(o){function n{$("#railgun-client-stylesheet").remove;var q=f+"/wiki/MediaWiki:RailgunClient.min.css?action=raw&ctype=text/css";if(Railgun.Config.isDebug){q+="&maxage=0&smaxage=0"}$(document.head).append('');$("#railgun-modules-stylesheet").remove;$(document.head).append('');var p=$(".UserProfileAchievementsModule");if(0!==p.length){p.first.addClass("UserAchievements");p.last.addClass("MoreAchievements")}Railgun.Storage.init}function m{try{n}catch(p){console.log("[Railgun]: Warning. Exception thrown during initialization:",p)}}if("undefined"===typeof o){$.getScript(Railgun.Config.modulesJS).done(function{m}).fail(function{console.log("[Railgun]: Warning. Modules package failed to load. Proceeding with initialization sequence. Your modulesJS file is:",Railgun.Config.modulesJS);m})}else{console.log("[Railgun]: You have opted to initialize Railgun without loading a modules package.");m}}j.domain=f;j.version=i;j.updated=g;j.api=h;j.info=d;j.swapElements=l;j.init=k}(Railgun));Railgun.Config={};(function(h){var f=false;var g=false;var e=Railgun.domain+"/wiki/MediaWiki:RailgunModules.min.js?action=raw&ctype=text/javascript";var d=Railgun.domain+"/wiki/MediaWiki:RailgunModules.min.css?action=raw&ctype=text/css";if("boolean"!==typeof h.isDebug){h.isDebug=false}if("boolean"!==typeof h.isDelay){h.isDelay=false}if("string"!==typeof h.modulesJS){h.modulesJS=e;if(h.isDebug){if(-1===h.modulesJS.indexOf("smaxage=0")){h.modulesJS+="&maxage=0&smaxage=0"}else{if(-1===h.modulesJS.indexOf("maxage=0")){h.modulesJS+="&maxage=0"}}}}if("string"!==typeof h.modulesCSS){h.modulesCSS=d;if(h.isDebug){if(-1===h.modulesCSS.indexOf("smaxage=0")){h.modulesCSS+="&maxage=0&smaxage=0"}else{if(-1===h.modulesCSS.indexOf("maxage=0")){h.modulesCSS+="&maxage=0"}}}}Railgun.Config=h}("object"==typeof RailgunConfig?RailgunConfig:{}));Railgun.Storage={};(function(k){var f=null;var g=null;var j=null;function e(q){if(Railgun.Config.isDebug){console.log("[Railgun]: Client issuing "+q.instruction+" request to the server:",q)}f.contentWindow.postMessage(JSON.stringify(q),Railgun.domain)}function m{$(window).on("message",l);e({instruction:"init",isDebug:Railgun.Config.isDebug})}function l(q){q=q.originalEvent;if(q.origin!==Railgun.domain){return}var r=JSON.parse(q.data);if("init"===r.instruction){g=r.serverStatus||{};j=r.storageState||{};Railgun.ShowHideSiderail.init;Railgun.ModuleManager.init}else{j=r.storageState}}function d{console.log("[Railgun]: - Printing storage data -");console.log("[Railgun]:",j)}function p(q){if("object"===typeof j){return j[q]}return false}function i(q,r){e({instruction:"setItem",key:q,value:r})}function n(q){e({instruction:"removeItem",key:q})}function h{e({instruction:"clear"})}function o{var q=' '}else{q+='/wiki/RailgunServerCached?action=render"> '}$("#railgun-iframe").remove;$(document.body).append(q);f=document.getElementById("railgun-iframe");$(f).on("load",m)}k.init=o;k.getItem=p;k.setItem=i;k.removeItem=n;k.clear=h;k.contents=d}(Railgun.Storage));Railgun.ShowHideSiderail={};(function(g){var i='';var e='';function f{Railgun.Storage.setItem("siderailHidden",false);$(".WikiaRail, .WikiaMainContent, .catlinks").removeClass("railgun-no-siderail");$("#railgun-siderail-left-arrow").css("display","none");$("#railgun-siderail-right-arrow").css("display","block")}function d{Railgun.Storage.setItem("siderailHidden",true);$(".WikiaRail, .WikiaMainContent, .catlinks").addClass("railgun-no-siderail");$("#railgun-siderail-left-arrow").css("display","block");$("#railgun-siderail-right-arrow").css("display","none")}function h{var j=Railgun.Storage.getItem("siderailHidden")?true:false;$("#railgun-siderail-left-arrow, #railgun-siderail-right-arrow").remove;$(".WikiaFooter .toolbar").prepend(i+e);$("#railgun-siderail-left-arrow").click(f);$("#railgun-siderail-right-arrow").click(d);if(j){$(".WikiaRail, .WikiaMainContent, .catlinks").addClass("railgun-no-siderail");$("#railgun-siderail-left-arrow").css("display","block");$("#railgun-siderail-right-arrow").css("display","none")}else{$("#railgun-siderail-left-arrow").css("display","none");$("#railgun-siderail-right-arrow").css("display","block")}}g.init=h}(Railgun.ShowHideSiderail));Railgun.ModuleManager={};(function(F){var D=["WikiaPagesOnWikiModule","WikiaActivityModule","RelatedVideosModule","LatestPhotosModule","WikiaBlogListingBox","ChatModule","HotSpotsModule","CommunityCornerModule","UserAchievements","MoreAchievements","FollowedPagesModule","WikiaLatestEarnedBadgesModule"];var j={WikiaPagesOnWikiModule:"Add a Page",WikiaActivityModule:"Recent Wiki Activity",RelatedVideosModule:"Related Videos",LatestPhotosModule:"Latest Photos",WikiaBlogListingBox:"Popular Blog Posts",ChatModule:"Chat",HotSpotsModule:"Hot Spots",CommunityCornerModule:"Community Messages",UserAchievements:"User Achievements",MoreAchievements:"More Achievements",FollowedPagesModule:"Pages I'm following",WikiaLatestEarnedBadgesModule:"Recent Earned Badges"};var y=[];var i={};var A={};var u={};var r=false;var s=undefined;var q=undefined;var E=null;var p=null;var B=[];var x=null;function z(G){return(-1!==D.indexOf(G))}function C(I,K){var J='';var H="";if("string"===typeof K){H=" "+K+" "}var G=J+H+I+" ";$("#WikiaRail").prepend(G)}function g{if("null"!==typeof x){$("#"+x+" a.railgun-module-detach-a").click}x=$(this).parent.parent.addClass("railgun-module-anchor-topright").css("position","fixed").attr("id");Railgun.setItem("anchor_moduleId",x);var G=$('detach');G.click(v);$(this).replaceWith(G)}function v{x=null;Railgun.removeItem("anchor_moduleId");$(this).parent.parent.removeClass("railgun-module-anchor-topright").css("position","static");var G=$('anchor');G.click(g);$(this).replaceWith(G)}function h{$("#WikiaRail > *").each(function{var G=$(this);if(G.hasClass("rmm-switch")){}else{if(G.hasClass("rmm-component")){G.removeClass("rmm-mode-off-hidden")}else{G.addClass("rmm-mode-on-hidden")}}})}function f{$("#WikiaRail > *").each(function{var G=$(this);if(G.hasClass("rmm-switch")){}else{if(G.hasClass("rmm-component")){G.addClass("rmm-mode-off-hidden")}else{G.removeClass("rmm-mode-on-hidden")}}})}function m{var G=' Railgun Module Manager Open ';$("#WikiaRail").append(G);$("#rmm-switch-button").click(function{if(r=!r){h;$("#rmm-switch-button").text("Close")}else{f;$("#rmm-switch-button").text("Open")}})}function k{var N="railgunscript";if("Mathmagician"===wgUserName&&"http://mathmagician.wikia.com"===wgServer){N="mathmagician"}var P='anchor</a>');H.click(g);$("#"+N).children(".railgun-module-header").append(H)}}function d(K,H,J,I){var G=false;if("string"!=typeof K){if(Railgun.Config.isDebug){console.log("[Railgun]: Warning. Misuse of register, @param id must be a string, but the value provided was id =",K)}G=true}if("string"!=typeof H){if(Railgun.Config.isDebug){console.log("[Railgun]: Warning. Misuse of register, @param name must be a string, but the value provided was name =",H)}G=true}if("function"!=typeof J){if(Railgun.Config.isDebug){console.log("[Railgun]: Warning. Misuse of register, @param init must be a function, but the value provided was init =",J)}G=true}if("undefined"!=typeof I&&"function"!=typeof I){if(Railgun.Config.isDebug){console.log("[Railgun]: Warning. Misuse of register, @param destr must be undefined or of type function, but the value provided was destr =",I)}G=true}if(G){return}y[y.length]=K;i[K]=H;A[K]=J;u[K]=I}function w{p=Railgun.Storage.getItem("inst_modulesUninstalled")||{};x=Railgun.Storage.getItem("anchor_moduleId")||"";if(r){f}$(".rmm-component, .rmm-switch").remove;for(var G=0;G<D.length;G++){$("."+D[G]).attr("id",D[G])}for(var G=0;G<y.length;G++){var H=y[G];if(!p[H]){A[H]}}k;t;m;l}F.insert=e;F.register=d;F.init=w}(Railgun.ModuleManager))}catch(b){console.log("[Railgun]: Warning. A pre-initialization exception was thrown:",b)}try{if("boolean"===typeof c&&c){Railgun.getItem=Railgun.Storage.getItem;Railgun.setItem=Railgun.Storage.setItem;Railgun.removeItem=Railgun.Storage.removeItem;Railgun.clear=Railgun.Storage.clear;Railgun.insert=Railgun.ModuleManager.insert;Railgun.register=Railgun.ModuleManager.register;if(!Railgun.Config.isDelay){Railgun.init}}}catch(b){if("object"!==typeof Railgun){console.log("[Railgun]: Warning. Railgun namespace is undefined.",b)}else{if("object"!==typeof Railgun.Config){console.log("[Railgun]: Warning. Railgun.Config namespace is undefined.",b)}else{if("object"!==typeof Railgun.Storage){console.log("[Railgun]: Warning. Railgun.Storage namespace is undefined.",b)}else{if("object"!==typeof Railgun.ShowHideSiderail){console.log("[Railgun]: Warning. Railgun.ShowHideSiderail namespace is undefined.",b)}else{if("object"!==typeof Railgun.ModuleManager){console.log("[Railgun]: Warning. Railgun.ModuleManager namespace is undefined.",b)}else{console.log("[Railgun]: Warning. Railgun failed to initialize, but all namespaces are defined.",b)}}}}}}});