diff options
author | Junio C Hamano <gitster@pobox.com> | 2011-05-26 10:31:57 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2011-05-26 10:31:57 -0700 |
commit | a6f3f178bd7ce48f7fe4262a1e5efb3ae6a98a4d (patch) | |
tree | fa4658c6142b1561cc2459874968de5087ae8185 /gitweb/static/js/javascript-detection.js | |
parent | 229e72dd6a34a2fbe5998fbddde44cb00174a602 (diff) | |
parent | 2e987f92408f5ddd20246d7d9553b57d90767d54 (diff) | |
download | git-a6f3f178bd7ce48f7fe4262a1e5efb3ae6a98a4d.tar.gz |
Merge branch 'jn/gitweb-js'
* jn/gitweb-js:
gitweb: Make JavaScript ability to adjust timezones configurable
gitweb.js: Add UI for selecting common timezone to display dates
gitweb: JavaScript ability to adjust time based on timezone
gitweb: Unify the way long timestamp is displayed
gitweb: Refactor generating of long dates into format_timestamp_html
gitweb.js: Provide getElementsByClassName method (if it not exists)
gitweb.js: Introduce code to handle cookies from JavaScript
gitweb.js: Extract and improve datetime handling
gitweb.js: Provide default values for padding in padLeftStr and padLeft
gitweb.js: Update and improve comments in JavaScript files
gitweb: Split JavaScript for maintability, combining on build
Diffstat (limited to 'gitweb/static/js/javascript-detection.js')
-rw-r--r-- | gitweb/static/js/javascript-detection.js | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/gitweb/static/js/javascript-detection.js b/gitweb/static/js/javascript-detection.js new file mode 100644 index 0000000000..93dd2bdd91 --- /dev/null +++ b/gitweb/static/js/javascript-detection.js @@ -0,0 +1,43 @@ +// 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 + */ +var jsExceptionsRe = /[;?]js=[01]$/; + +/** + * 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]; + if (!jsExceptionsRe.test(link)) { // =~ /[;?]js=[01]$/; + link.href += + (link.href.indexOf('?') === -1 ? '?' : ';') + 'js=1'; + } + } +} + +/* end of javascript-detection.js */ |