]> Lady’s Gitweb - Gitweb/blobdiff - gitweb.js
gitweb: Create links leading to 'blame_incremental' using JavaScript
[Gitweb] / gitweb.js
index 5ffc6f80f8643b7ee9495d894f1ef0bf568f0fa5c562748bdd527df01d1193fd..d1b64b2aa2b83e1ef875c35bdef23796021fb3398c33e2c07680bd9389be8bb9 100644 (file)
--- a/gitweb.js
+++ b/gitweb.js
@@ -7,6 +7,39 @@
  * @license GPLv2 or later
  */
 
+/* ============================================================ */
+/* functions for generic gitweb actions and views */
+
+/**
+ * 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')
+ *
+ * @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';
+               }
+       }
+}
+
+
+/* ============================================================ */
+
 /*
  * This code uses DOM methods instead of (nonstandard) innerHTML
  * to modify page.
@@ -89,6 +122,7 @@ function createRequestObject() {
        return null;
 }
 
+
 /* ============================================================ */
 /* utility/helper functions (and variables) */
 
This page took 0.281397 seconds and 4 git commands to generate.