User:Mwarren us/common.js
// Add an onClick function to the Mobile View link to unset the stopMobileRedirect cookie
// (Aug 15: Should not be needed any longer; TheDJ put it in the global Mediawiki:common.js file:
// https://en.wikipedia.org/w/index.php?title=MediaWiki%3ACommon.js&diff=507511838&oldid=499562302 )
// alas; the devil is in the details - setting the cookie to false is better than setting it to null.
/**** Bug 38009 - https://bugzilla.wikimedia.org/show_bug.cgi?id=38009 ****/
/* This works too allows me to check the default "Mobile View" link too.
/* Adding the handler to a link created by .after() */
$('a[href$="toggle_view_mobile"]').after(' <a id="jq-link" class="noprint" '
+'href="http://en.m.wikipedia.org/w/index.php?title=Main_Page&mobileaction=toggle_view_mobile">'
+'Mobile view (w/ doc.cookie)</a>');
$('a#jq-link').click(function(){
document.cookie = 'stopMobileRedirect=false; expires=Thu, 01-Jan-1970 00:00:00 GMT; '
+ 'path=/; domain=.wikipedia.org';
});
/** Fails: Use full set of parameters, but as separate arguments (Arthur's suggestion in Bugzilla) */
$('a#jq-link').after(' <a id="jq-link2" class="noprint" '
+'href="http://en.m.wikipedia.org/w/index.php?title=Main_Page&mobileaction=toggle_view_mobile">'
+'Mobile view (w/ $cookie.())</a>');
$('a#jq-link2').click(function(){
$.cookie( 'stopMobileRedirect', false, 'Thu, 01-Jan-1970 00:00:00 GMT','/' );
});
/** Try: this call to $.(cookie) works from firebug; maybe it will work in Safari */
$('a#jq-link2').after(' <a id="jq-link3" class="noprint" '
+'href="http://en.m.wikipedia.org/w/index.php?title=Main_Page&mobileaction=toggle_view_mobile">'
+'Mobile view (w/ $cookie.options)</a>');
$('a#jq-link3').click(function(){
$.cookie( 'stopMobileRedirect', 'false', {path: '/', domain: '.wikipedia.org'});
});
/******* More examples of things that work and do not work. Reverse chronological ********/
/***************** Experiments using document.cookie (see below for $.cookie() ) *********/
/** This works - hardcode the handler into the "newlink" html string */
/*
// Straight html for a working link and click handler
var newlink = ' <a id="jq-query" class="noprint" '
+'href="http://en.m.wikipedia.org/w/index.php?title=Main_Page&mobileaction=toggle_view_mobile" '
+'onClick="javascript:document.cookie='
+"'stopMobileRedirect=false; domain=.wikipedia.org; path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT;'"
+'">'
+'Mobile view (w/ static fix)</a>';
// Create a link using the above html
$('a[href$="toggle_view_mobile"]').after(newlink);
*/
/** This works - leave the default "Mobile View" link and */
/* create a new link using .after() and add with a new handler. */
/*
$('a[href$="toggle_view_mobile"]').after(' <a id="jq-link" class="noprint" '
+'href="http://en.m.wikipedia.org/w/index.php?title=Main_Page&mobileaction=toggle_view_mobile">'
+'Mobile view (w/ cookie fix)</a>');
$('a#jq-link').click(function(){
document.cookie = 'stopMobileRedirect=false; domain=.wikipedia.org; '
+ 'path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT;';
});
*/
/** This works very well - remove non-working handler, replace with working version */
/*
// Remove MediaWiki:common.js' handler; it doesn't work yet.
$('a[href$="toggle_view_mobile"]').unbind('click');
// Add a handler that does work
$('a[href$="toggle_view_mobile"]').click(function(){
document.cookie = 'stopMobileRedirect=false; domain=.wikipedia.org;'
+ 'path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT;'
});
*/
/** This works too: removed window from anon function() passed to .click() */
/*
$('a[href$="toggle_view_mobile"]').click(function(){
document.cookie = 'stopMobileRedirect=false; domain=.wikipedia.org;'
+ 'path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT;'
});
*/
/** This works: set document.cookie using a string */
/*
$('a[href$="toggle_view_mobile"]').click(function(window){
document.cookie = 'stopMobileRedirect=false; domain=.wikipedia.org;'
+ 'path=/; expires=Thu, 01-Jan-1970 00:00:00 GMT;'
});
*/
/** failed with error "window.document.cookie not defined" from inside of jQuery.
window.document.cookie = document.cookie.replace(/stopMobileRedirect\s*=[^;]+;/ig,'stopMobileRedirect=false;');
*/
/** failed - browser still hangs onto true value
document.cookie = document.cookie.replace(/stopMobileRedirect\s*=[^;]+;/ig,'stopMobileRedirect=false;');
*/
/** failed - appending cookie text wound up with multiple cookies set :(
document.cookie+='stopMobileRedirect=false; expires=Thu, 01-Jan-1970 00:00:00 GMT; path=/; domain=.wikipedia.org';
*/
/********************* Experiments using $.cookie() **********************/
/** failed - use $.cookie() with full set of parameters */
/*
$('a[href$="toggle_view_mobile"]').click(function(){
$.cookie('stopMobileRedirect','false',
{expires: 'Thu, 01-Jan-1970 00:00:00 GMT', path: '/', domain: '.wikipedia.org'});
});
*/
/** failed - doesn't delete cookie
$.cookie('stopMobileRedirect','true',{expires: 'Thu, 01-Jan-1970 00:00:00 GMT'});
*/
/*********** View cookies inline to help debug in iOS *************/
/*
$("div#footer").append('<div><h3>document.cookie</h3>'
+ '<div style="-webkit-column-count:3;-moz-column-count:3;column-count:3;">'
+ '<dl id=cooklist>' + printCookies()
+ '</dl></div></div>');
*/
function printCookies(w){
var cStr = "";
var dt = "<dt>"; // formatting - could be <dt>
var dtdd = "</dt><dd>"; // formatting - could be </dt><dd>
var dd = "</dd>"; // formatting - could be </dd>
var ck = new Array();
ck = document.cookie.split('; ');
cStr += '<dt>' + document.cookie.length + ' bytes</dt>';
cStr += '<dd>Raw cookie:\n' + document.cookie + '</dd>';
cStr += '<dt>Edit cookie:</dt>'
// RegExp fix from http://lea.verou.me/2009/12/reading-cookies-the-regular-expression-way/
cStr += '<dd>' + document.cookie.replace(/stopMobileRedirect\s*=(.*?)(?:;|$)/ig,'stopMobileRedirect=false;') + '</dd>';
for(i = 0; i < ck.length; i++){
NmeVal = new Array();
NmeVal = ck[i].split('=');
if(NmeVal[0]){
cStr += dt + unescape(NmeVal[0]) + dtdd + unescape(NmeVal[1]) + dd;
}
}
return cStr;
}
// alert(printCookies(window));
// shows the cookie contents at the bottom of the page.
/* $("div#footer").append('<div><h3>document.cookie</h3>'
+'<div style="-webkit-column-count:3;-moz-column-count:3;column-count:3;">'
+ toggler + '<dl id=cooklist>' + printCookies()
+ '</dl></div></div>');
*/
importScript('User:Enterprisey/diff-context.js'); // Backlink: [[User:Enterprisey/diff-context.js]]
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.