am: Use cat instead of echo to avoid DOS line-endings (fixes t4150)
[git/mingw/4msysgit.git] / gitweb / static / js / javascript-detection.js
blobfa2596f77c645b87e79aceb242d6074d6b2764ea
1 // Copyright (C) 2007, Fredrik Kuivinen <frekui@gmail.com>
2 // 2007, Petr Baudis <pasky@suse.cz>
3 // 2008-2011, Jakub Narebski <jnareb@gmail.com>
5 /**
6 * @fileOverview Detect if JavaScript is enabled, and pass it to server-side
7 * @license GPLv2 or later
8 */
11 /* ============================================================ */
12 /* Manipulating links */
14 /**
15 * used to check if link has 'js' query parameter already (at end),
16 * and other reasons to not add 'js=1' param at the end of link
17 * @constant
19 var jsExceptionsRe = /[;?]js=[01](#.*)?$/;
21 /**
22 * Add '?js=1' or ';js=1' to the end of every link in the document
23 * that doesn't have 'js' query parameter set already.
25 * Links with 'js=1' lead to JavaScript version of given action, if it
26 * exists (currently there is only 'blame_incremental' for 'blame')
28 * To be used as `window.onload` handler
30 * @globals jsExceptionsRe
32 function fixLinks() {
33 var allLinks = document.getElementsByTagName("a") || document.links;
34 for (var i = 0, len = allLinks.length; i < len; i++) {
35 var link = allLinks[i];
36 if (!jsExceptionsRe.test(link)) {
37 link.href = link.href.replace(/(#|$)/,
38 (link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1$1');
43 /* end of javascript-detection.js */