[Reproducible-commits] [diffoscope] 01/01: Some more JS sophistication to track how many pieces are left to load
Ximin Luo
infinity0 at debian.org
Wed Aug 24 19:56:49 UTC 2016
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch better-lazy-loading
in repository diffoscope.
commit 47b9c4603869f8565d52b08defb2a6abffcde5f4
Author: Ximin Luo <infinity0 at debian.org>
Date: Wed Aug 24 21:53:52 2016 +0200
Some more JS sophistication to track how many pieces are left to load
---
diffoscope/presenters/html.py | 46 +++++++++++++++++++++----------------------
1 file changed, 23 insertions(+), 23 deletions(-)
diff --git a/diffoscope/presenters/html.py b/diffoscope/presenters/html.py
index 40d7b7f..e4c7442 100644
--- a/diffoscope/presenters/html.py
+++ b/diffoscope/presenters/html.py
@@ -168,29 +168,29 @@ SCRIPTS = """
<script src="%(jquery_url)s"></script>
<script type="text/javascript">
$(function() {
- var cont_click = function() {
- var filename = $(this).attr('href');
- var div = $(this).parent();
- div.text('... loading ...');
- div.parent().load(filename + " tr", function() {
- // http://stackoverflow.com/a/8452751/946226
- $(this).children(':first').unwrap();
- $(".ondemand-cont a").on('click', cont_click);
- });
- return false;
+ var load_cont;
+ var create_loader = function(tag, findContainer) {
+ return function() {
+ var a = $(this);
+ var filename = a.attr('href');
+ var numleft = Number.parseInt(/\((\d+) pieces?\)/.exec(a.text())[1]) - 1
+ var parent = a.parent();
+ parent.text('... loading ...');
+ findContainer(parent).load(filename + " " + tag, function() {
+ // http://stackoverflow.com/a/8452751/946226
+ var elems = $(this).children(':first').unwrap();
+ // set this behaviour for the next link too
+ var a = findContainer(elems).find(".ondemand-cont a");
+ var noun = numleft > 1 ? "pieces" : "piece" // be sure the regex matches either
+ a.text(a.text() + " (" + numleft + " " + noun + ")");
+ a.on('click', load_cont);
+ });
+ return false;
+ };
};
- $(".ondemand a").on('click', function (){
- var filename = $(this).attr('href');
- var div = $(this).parent();
- div.text('... loading ...');
- div.load(filename + " table", function() {
- // http://stackoverflow.com/a/8452751/946226
- $(this).children(':first').unwrap();
- $(".ondemand-cont a").on('click', cont_click);
- });
- return false;
- });
- $(".ondemand-cont a").on('click', cont_click);
+ load_cont = create_loader("tr", function(x) { return x.parent(); });
+ $(".ondemand-cont a").on('click', load_cont);
+ $(".ondemand a").on('click', create_loader("table", function(x) { return x; }));
});
</script>
"""
@@ -585,7 +585,7 @@ def output_unified_diff(print_func, css_url, directory, unified_diff):
row_print_exit_else()
print_func("<div class='ondemand'>\n")
- print_func("... <a href='%s'>load diff (%s pieces) </a> ...\n" % (escape(filename), num_pages))
+ print_func("... <a href='%s'>load diff (%s pieces)</a> ...\n" % (escape(filename), num_pages))
print_func("</div>\n")
else:
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git
More information about the Reproducible-commits
mailing list