gitweb / static / js / javascript-detection.json commit Merge branch 'dn/test-reject-utf-16' (d6f3ab5)
   1// Copyright (C) 2007, Fredrik Kuivinen <frekui@gmail.com>
   2//               2007, Petr Baudis <pasky@suse.cz>
   3//          2008-2011, Jakub Narebski <jnareb@gmail.com>
   4
   5/**
   6 * @fileOverview Detect if JavaScript is enabled, and pass it to server-side
   7 * @license GPLv2 or later
   8 */
   9
  10
  11/* ============================================================ */
  12/* Manipulating links */
  13
  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
  18 */
  19var jsExceptionsRe = /[;?]js=[01](#.*)?$/;
  20
  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.
  24 *
  25 * Links with 'js=1' lead to JavaScript version of given action, if it
  26 * exists (currently there is only 'blame_incremental' for 'blame')
  27 *
  28 * To be used as `window.onload` handler
  29 *
  30 * @globals jsExceptionsRe
  31 */
  32function 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');
  39                }
  40        }
  41}
  42
  43/* end of javascript-detection.js */