diff options
-rw-r--r-- | gitweb/gitweb.js | 34 | ||||
-rwxr-xr-x | gitweb/gitweb.perl | 28 |
2 files changed, 53 insertions, 9 deletions
diff --git a/gitweb/gitweb.js b/gitweb/gitweb.js index 22570f5e53..91b766e336 100644 --- a/gitweb/gitweb.js +++ b/gitweb/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) */ diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 6cdd8c39b4..4a63646861 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -560,6 +560,8 @@ our @cgi_param_mapping = ( snapshot_format => "sf", extra_options => "opt", search_use_regexp => "sr", + # this must be last entry (for manipulation from JavaScript) + javascript => "js" ); our %cgi_param_mapping = @cgi_param_mapping; @@ -3242,6 +3244,18 @@ sub git_footer_html { insert_file($site_footer); } + print qq!<script type="text/javascript" src="$javascript"></script>\n!; + if ($action eq 'blame_incremental') { + print qq!<script type="text/javascript">\n!. + qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!. + qq! "!. href() .qq!");\n!. + qq!</script>\n!; + } else { + print qq!<script type="text/javascript">\n!. + qq!window.onload = fixLinks;\n!. + qq!</script>\n!; + } + print "</body>\n" . "</html>"; } @@ -4793,6 +4807,10 @@ sub git_tag { sub git_blame_common { my $format = shift || 'porcelain'; + if ($format eq 'porcelain' && $cgi->param('js')) { + $format = 'incremental'; + $action = 'blame_incremental'; # for page title etc + } # permissions gitweb_check_feature('blame') @@ -4872,7 +4890,7 @@ sub git_blame_common { if ($format eq 'incremental') { print "<noscript>\n<div class=\"error\"><center><b>\n". "This page requires JavaScript to run.\n Use ". - $cgi->a({-href => href(action=>'blame',-replay=>1)}, + $cgi->a({-href => href(action=>'blame',javascript=>0,-replay=>1)}, 'this page'). " instead.\n". "</b></center></div>\n</noscript>\n"; @@ -5003,14 +5021,6 @@ sub git_blame_common { close $fd or print "Reading blob failed\n"; - if ($format eq 'incremental') { - print qq!<script type="text/javascript" src="$javascript"></script>\n!. - qq!<script type="text/javascript">\n!. - qq!startBlame("!. href(action=>"blame_data", -replay=>1) .qq!",\n!. - qq! "!. href() .qq!");\n!. - qq!</script>\n!; - } - git_footer_html(); } |