MediaWiki:Mobile.js

/* Any JavaScript here will be loaded for users using the mobile site */

/* a bug prevents Mobile.css from loading, this fixes it */ mw.loader.using('mobile.site.styles')

// ================================================================================ // Page specific JS/CSS // ================================================================================

//Define vars var mwSkin = mw.config.get("skin") var pageTypes = {}; pageTypes.globalJS = 'MediaWiki:Common.js/' + mw.config.get("wgPageName"); pageTypes.globalCSS = 'MediaWiki:Common.css/' + mw.config.get("wgPageName"); pageTypes.skinJS = 'MediaWiki:' + mwSkin + '.js/' + mw.config.get("wgPageName"); pageTypes.skinCSS = 'MediaWiki:' + mwSkin + '.css/' + mw.config.get("wgPageName"); pageTypes.userJS = 'User:' + mw.config.get("wgUserName") + '/common.js/' + mw.config.get("wgPageName"); pageTypes.userCSS = 'User:' + mw.config.get("wgUserName") + '/common.css/' + mw.config.get("wgPageName"); pageTypes.userSkinJS = 'User:' + mw.config.get("wgUserName") + '/' + mwSkin + '.js/' + mw.config.get("wgPageName"); pageTypes.userSkinCSS = 'User:' + mw.config.get("wgUserName") + '/' + mwSkin + '.css/' + mw.config.get("wgPageName");

function checkPage(type, exist) { if (exist == null) { new mw.Api.get({           action: 'parse',            page: type,            prop: ""        }).done(function (data) {            checkPage(type, true)        }).fail(function (data) {            checkPage(type, false)        }); }   else if (exist) { if (getTypeByValue(type).endsWith("JS")) { mw.loader.load('/w/index.php?title=' + pageEnc(type) + '&action=raw&ctype=text/javascript'); }       else { mw.loader.load('/w/index.php?title=' + pageEnc(type) + '&action=raw&ctype=text/css', 'text/css'); }       checkNextPage(type) }   else if (!exist) { checkNextPage(type) } }

function checkNextPage(type) { switch (type) { case pageTypes.globalJS: checkPage(pageTypes.globalCSS); break; case pageTypes.globalCSS: checkPage(pageTypes.skinJS); break; case pageTypes.skinJS: checkPage(pageTypes.skinCSS); break; case pageTypes.skinCSS: if (mw.config.get("wgUserName") != null) { checkPage(pageTypes.userJS); }           break; case pageTypes.userJS: if (mw.config.get("wgUserName") != null) { checkPage(pageTypes.userCSS); }           break; case pageTypes.userCSS: if (mw.config.get("wgUserName") != null) { checkPage(pageTypes.userSkinJS); }           break; case pageTypes.userSkinJS: if (mw.config.get("wgUserName") != null) { checkPage(pageTypes.userSkinCSS); }           break; } }

function pageEnc(string) { return encodeURIComponent(string); }

function getTypeByValue(value) { return Object.keys(pageTypes).find(function (key) { return pageTypes[key] === value }); }

//Check page specific files onApiReady(function {    checkPage(pageTypes.globalJS); });

function onApiReady(callback) { if (mw.Api != null) { setTimeout(callback, 0); } else { setTimeout(onApiReady.bind(null, callback), 0); } }

// Fix for user dropdown menu $("body.skin-timeless #user-tools h2").on('click', function {   if ($(window).width >= 851) {        var display = $('#personal-inner, #menus-cover').css("display") != "none" && $('#personal-inner, #menus-cover').css("display") != null        if(display) $('#personal-inner, #menus-cover').css("display", "none");        else        $('#personal-inner, #menus-cover').attr('style', "display: block !important");    } }); $('#site-navigation h2').on('click', function {   if ($(window).width < 851) {        $('#site-navigation .sidebar-inner, #menus-cover').fadeToggle(toggleTime);    }    if ($(window).width >= 851) {        var display = $('#personal-inner, #menus-cover').css("display") != "none" && $('#personal-inner, #menus-cover').css("display") != null        if(display) $('#personal-inner, #menus-cover').css("display", "none");        else        $('#personal-inner, #menus-cover').attr('style', "display: block !important");    } }); $('#site-tools h2').on('click', function {   if ($(window).width < 851) {        $('#site-tools .sidebar-inner, #menus-cover').fadeToggle(toggleTime);    }    if ($(window).width >= 851) {        var display = $('#site-tools .sidebar-inner, #menus-cover').css("display") != "none" && $('#personal-inner, #menus-cover').css("display") != null        if(display) $('#site-tools .sidebar-inner, #menus-cover').css("display", "none");        else        $('#site-tools .sidebar-inner, #menus-cover').attr('style', "display: block !important");    } }); $('#ca-more').on('click', function {   $('#page-tools .sidebar-inner').css('top', $('#ca-more').offset.top + 25);    if ($(window).width >= 851) {        var display = $('#page-tools .sidebar-inner, #menus-cover').css("display") != "none" && $('#personal-inner, #menus-cover').css("display") != null        if(display) $('#page-tools .sidebar-inner, #menus-cover').css("display", "none");        else        $('#page-tools .sidebar-inner, #menus-cover').attr('style', "display: block !important");    } }); $('#ca-languages').on('click', function {   $('#other-languages .sidebar-inner').css('top', $('#ca-languages').offset.top + 25);    if ($(window).width >= 851) {        var display = $('#other-languages .sidebar-inner, #menus-cover').css("display") != "none" && $('#personal-inner, #menus-cover').css("display") != null        if(display) $('#other-languages .sidebar-inner, #menus-cover').css("display", "none");        else        $('#other-languages .sidebar-inner, #menus-cover').attr('style', "display: block !important");    } }); $(".mw-echo-notifications-badge").off("click")