MediaWiki:Common.js/mobile.js

MuseWiki, wiki for the band Muse
< MediaWiki:Common.js
Revision as of 13:59, 13 July 2009 by Crazybobbles (talk | contribs) (Created page with '//<source lang="JavaScript"> /** Mobile browser helper link ************************************************ * * Adds a link to the mobile-optimized gateway at en.m.wikimedia…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
//<source lang="JavaScript">

/** Mobile browser helper link ************************************************
 *
 *  Adds a link to the mobile-optimized gateway at en.m.wikimedia.org
 *  for viewers on iPhone, iPod Touch, Palm Pre, and Android devices.
 *  This is to drive more test traffic there for now;
 *  it's still in development but very usable for reading!
 *
 *  You can turn off the redirect by setting the cookie "stopMobileRedirect=true"
 *
 *  Maintainer: [[User:Brion VIBBER]], [[User:hcatlin]]
 */
var runMobileCheck = function() {
    if (stopMobileRedirectCookieExists()) {
        //addOnloadHook(showMobileLinkHeader);
    } else {
        document.location = mobileSiteLink();
    }
}


var stopMobileRedirectCookieExists = function() {
    return (document.cookie.indexOf("stopMobileRedirect=true") >= 0);
}

var showMobileLinkHeader = function() {
    var div = document.createElement('div');
    div.setAttribute("id", "mobileDeviceNotice");
    div.style.fontSize = '30pt';
    div.style.lineHeight = '40pt';
    div.style.textAlign = 'center';
    div.style.marginTop = '20px';
    div.style.marginBottom = '20px';
    div.style.padding = '20px';
    div.style.border = '2px solid gray';
    div.appendChild(document.createTextNode("View this page on "));
    var link = document.createElement('a');
    link.href = mobileSiteLink();
    link.appendChild(document.createTextNode("Wikipedia's mobile site"));
    div.appendChild(link);
    var content = document.getElementById('content');
    content.insertBefore(div,content.firstChild);
}

var mobileSiteLink = function() {
    if (wgCanonicalNamespace == 'Special' && wgCanonicalSpecialPageName == 'Search') {
        var pageLink = '?search=' + encodeURIComponent(document.getElementById('searchText').value);
    } else if (wgPageName == 'Main_Page') {
        var pageLink = '::Home'; // Special case
    } else {
        var pageLink = encodeURIComponent(wgPageName).replace('%2F','/').replace('%3A',':');
    }
    return 'http://' + wgUserLanguage + '.m.wikipedia.org/wiki/' + pageLink
}

// Code to run a certain number of users into the mobile site
//if (true && Math.random() > 0.0) {
    runMobileCheck();
//} else {
    //addOnloadHook(showMobileLinkHeader);
//}

//</source>