X-Git-Url: https://git.ladys.computer/Gitweb/blobdiff_plain/64ed658324c681ab03a354df8dac0d502969c19a9c92e06b19454a9648c8181d..367f1aa76008d203d3ef9f2ec5580a750d45c854823d513a9e45bcd5b6caa8f9:/gitweb.js diff --git a/gitweb.js b/gitweb.js index 5ffc6f8..1b0d1f9 100644 --- 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) */ @@ -532,8 +566,11 @@ function handleLine(commit, group) { if (group.numlines >= 2) { var fragment = document.createDocumentFragment(); var br = document.createElement("br"); - var text = document.createTextNode( - commit.author.match(/\b([A-Z])\B/g).join('')); + var match = commit.author.match(/\b([A-Z])\B/g); + if (match) { + var text = document.createTextNode( + match.join('')); + } if (br && text) { var elem = fragment || td_sha1; elem.appendChild(br);