MediaWiki:Gadget-mobile-sidebar.js

/* _____________________________________________________________________________

* | |

* | === WARNING: GLOBAL GADGET FILE === |

* | Changes to this page affect many users. |

* | Please discuss changes on the talk page or on WT:Gadget before editing. |

* |_____________________________________________________________________________|

*

* Copied from meta:User:Brion VIBBER/mobile-sidebar.js as of last update (2014-10-13, meta:Special:Permalink/10185490)

* See also https://github.com/brion/MediaWiki-MobileSidebar

*

* Mobile sidebar preview gadget

*

* Quick hack to show how pages look on mobile

* while browsing the desktop site.

*

* Brion Vibber

* 2014-10-10

* Cleaned up and enhanced by prtksxna

* Further cleaned up by Brion :D

*/

$(function () {

// Old iPhone size, the minimum we usually see

var width = 320, height = 480;

// @todo possibly make size selectable from some options...

// Note that pixel sizes are deceiving on mobile, as there's often a

// density factor. For instance 480x800 screens at 1.5x would cover

// only 320x533 or so. And let's not even get into the iPhone 6 Plus!

function showSidebar() {

localStorage['mw-mobile-sidebar-state'] = 'show';

var $content = $('#content');

var top = $content.position().top,

page = mw.config.get('wgPageName'),

src = '/wiki/' + encodeURIComponent(page) + '?useformat=mobile',

lang = mw.config.get('wgContentLanguage');

var $container = $('

').attr('id', 'mobile-sidebar');

var $mobileLink = $('')

.text( 'Mobile' )

.addClass ( 'mobile_link' )

.attr( 'href', src )

.attr( 'target', '_blank')

.appendTo( $container );

var $egg = $( '

' )

.addClass( 'egg' )

.append(

$( '' ).attr( 'src', 'https://upload.wikimedia.org/wikipedia/commons/thumb/8/81/Wikimedia-logo.svg/240px-Wikimedia-logo.svg.png' ),

$( '

' ).html( 'If lost please return to Brion Vibber' )

)

.appendTo( $container )

.hide();

// @todo detect scrollbars and compensate width

var $frame = $('