2011-04-28 21:04:01 +02:00
|
|
|
// Copyright (C) 2007, Fredrik Kuivinen <frekui@gmail.com>
|
|
|
|
// 2007, Petr Baudis <pasky@suse.cz>
|
|
|
|
// 2008-2011, Jakub Narebski <jnareb@gmail.com>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @fileOverview Detect if JavaScript is enabled, and pass it to server-side
|
|
|
|
* @license GPLv2 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* ============================================================ */
|
|
|
|
/* Manipulating links */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* used to check if link has 'js' query parameter already (at end),
|
|
|
|
* and other reasons to not add 'js=1' param at the end of link
|
|
|
|
* @constant
|
|
|
|
*/
|
2011-09-27 11:51:00 +02:00
|
|
|
var jsExceptionsRe = /[;?]js=[01](#.*)?$/;
|
2011-04-28 21:04:01 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add '?js=1' or ';js=1' to the end of every link in the document
|
|
|
|
* that doesn't have 'js' query parameter set already.
|
|
|
|
*
|
|
|
|
* Links with 'js=1' lead to JavaScript version of given action, if it
|
|
|
|
* exists (currently there is only 'blame_incremental' for 'blame')
|
|
|
|
*
|
|
|
|
* To be used as `window.onload` handler
|
|
|
|
*
|
|
|
|
* @globals jsExceptionsRe
|
|
|
|
*/
|
|
|
|
function fixLinks() {
|
|
|
|
var allLinks = document.getElementsByTagName("a") || document.links;
|
|
|
|
for (var i = 0, len = allLinks.length; i < len; i++) {
|
|
|
|
var link = allLinks[i];
|
2011-09-27 11:51:00 +02:00
|
|
|
if (!jsExceptionsRe.test(link)) {
|
|
|
|
link.href = link.href.replace(/(#|$)/,
|
|
|
|
(link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1$1');
|
2011-04-28 21:04:01 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* end of javascript-detection.js */
|