diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2011-04-10 08:42:31 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2011-04-10 08:42:31 -0400 |
commit | 52e07c90b77b1d07ed95a6195ec5d895f0988224 (patch) | |
tree | 325346a20aedac88b3297919f5c1c89f79de7aed /coverage/htmlfiles | |
parent | d4dd809d27ad7f31431a4ef61309b6951ad41d9b (diff) | |
parent | 822b7c82f58bbd6f2b38cc98c7881cc405d0c69e (diff) | |
download | python-coveragepy-52e07c90b77b1d07ed95a6195ec5d895f0988224.tar.gz |
Merge Brett's __main__.py file for the tree.
Diffstat (limited to 'coverage/htmlfiles')
-rw-r--r-- | coverage/htmlfiles/coverage_html.js | 105 | ||||
-rw-r--r-- | coverage/htmlfiles/index.html | 2 | ||||
-rw-r--r-- | coverage/htmlfiles/jquery.isonscreen.js | 53 | ||||
-rw-r--r-- | coverage/htmlfiles/pyfile.html | 1 |
4 files changed, 160 insertions, 1 deletions
diff --git a/coverage/htmlfiles/coverage_html.js b/coverage/htmlfiles/coverage_html.js index 7b6db42..10482fa 100644 --- a/coverage/htmlfiles/coverage_html.js +++ b/coverage/htmlfiles/coverage_html.js @@ -90,8 +90,17 @@ coverage.pyfile_ready = function($) { var frag = location.hash; if (frag.length > 2 && frag[1] === 'n') { $(frag).addClass('highlight'); + coverage.sel_begin = parseInt(frag.substr(2)); + coverage.sel_end = coverage.sel_begin + 1; } + $(document) + .bind('keydown', 'j', coverage.to_next_chunk) + .bind('keydown', 'k', coverage.to_prev_chunk) + .bind('keydown', '0', coverage.to_top) + .bind('keydown', '1', coverage.to_first_chunk) + ; + coverage.assign_shortkeys(); }; @@ -108,3 +117,99 @@ coverage.toggle_lines = function(btn, cls) { } }; +// The first line selected, and the next line not selected. +coverage.sel_begin = 0; +coverage.sel_end = 1; + +coverage.to_top = function() { + coverage.sel_begin = 0; + coverage.sel_end = 1; + $("html").animate({scrollTop: 0}, 200); +}; + +coverage.to_first_chunk = function() { + coverage.sel_begin = 0; + coverage.sel_end = 1; + coverage.to_next_chunk(); +}; + +coverage.to_next_chunk = function() { + var c = coverage; + + // Find the start of the next colored chunk. + var probe = c.sel_end; + while (true) { + var probe_line = $("#t" + probe); + if (probe_line.length === 0) { + return; + } + var color = probe_line.css("background-color"); + if (color !== "transparent") { + break; + } + probe += 1; + } + + // There's a next chunk, `probe` points to it. + c.sel_begin = probe; + + // Find the end of this chunk. + var next_color = color; + while (next_color === color) { + probe += 1; + next_color = $("#t" + probe).css("background-color"); + } + c.sel_end = probe; + coverage.show_selected_chunk(); +}; + +coverage.to_prev_chunk = function() { + var c = coverage; + + // Find the end of the prev colored chunk. + var probe = c.sel_begin-1; + var color = $("#t" + probe).css("background-color"); + while (probe > 0 && color === "transparent") { + probe -= 1; + var probe_line = $("#t" + probe); + if (probe_line.length === 0) { + return; + } + color = probe_line.css("background-color"); + } + + // There's a prev chunk, `probe` points to its last line. + c.sel_end = probe+1; + + // Find the beginning of this chunk. + var prev_color = color; + while (prev_color === color) { + probe -= 1; + prev_color = $("#t" + probe).css("background-color"); + } + c.sel_begin = probe+1; + coverage.show_selected_chunk(); +}; + +coverage.show_selected_chunk = function() { + var c = coverage; + + // Highlight the lines in the chunk + $(".linenos p").removeClass("highlight"); + var probe = c.sel_begin; + while (probe > 0 && probe < c.sel_end) { + $("#n" + probe).addClass("highlight"); + probe += 1; + } + + // Scroll the page if the chunk isn't fully visible. + var top = $("#t" + c.sel_begin); + var next = $("#t" + c.sel_end); + + if (!top.isOnScreen() || !next.isOnScreen()) { + // Need to move the page. + var top_pos = parseInt(top.offset().top); + $("html").animate({scrollTop: top_pos-30}, 300); + } +}; + diff --git a/coverage/htmlfiles/index.html b/coverage/htmlfiles/index.html index f03c325..fb37d40 100644 --- a/coverage/htmlfiles/index.html +++ b/coverage/htmlfiles/index.html @@ -55,7 +55,7 @@ <tbody> {% for file in files %} <tr class='file'> - <td class='name left'><a href='{{file.html_filename}}'>{{file.cu.name}}</a></td> + <td class='name left'><a href='{{file.html_filename}}'>{{file.name}}</a></td> <td>{{file.nums.n_statements}}</td> <td>{{file.nums.n_missing}}</td> <td>{{file.nums.n_excluded}}</td> diff --git a/coverage/htmlfiles/jquery.isonscreen.js b/coverage/htmlfiles/jquery.isonscreen.js new file mode 100644 index 0000000..b147aff --- /dev/null +++ b/coverage/htmlfiles/jquery.isonscreen.js @@ -0,0 +1,53 @@ +/* Copyright (c) 2010
+ * @author Laurence Wheway
+ * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
+ * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
+ *
+ * @version 1.2.0
+ */
+(function($) {
+ jQuery.extend({
+ isOnScreen: function(box, container) {
+ //ensure numbers come in as intgers (not strings) and remove 'px' is it's there
+ for(var i in box){box[i] = parseFloat(box[i])};
+ for(var i in container){container[i] = parseFloat(container[i])};
+
+ if(!container){
+ container = {
+ left: $(window).scrollLeft(),
+ top: $(window).scrollTop(),
+ width: $(window).width(),
+ height: $(window).height()
+ }
+ }
+
+ if( box.left+box.width-container.left > 0 &&
+ box.left < container.width+container.left &&
+ box.top+box.height-container.top > 0 &&
+ box.top < container.height+container.top
+ ) return true;
+ return false;
+ }
+ })
+
+
+ jQuery.fn.isOnScreen = function (container) {
+ for(var i in container){container[i] = parseFloat(container[i])};
+
+ if(!container){
+ container = {
+ left: $(window).scrollLeft(),
+ top: $(window).scrollTop(),
+ width: $(window).width(),
+ height: $(window).height()
+ }
+ }
+
+ if( $(this).offset().left+$(this).width()-container.left > 0 &&
+ $(this).offset().left < container.width+container.left &&
+ $(this).offset().top+$(this).height()-container.top > 0 &&
+ $(this).offset().top < container.height+container.top
+ ) return true;
+ return false;
+ }
+})(jQuery);
diff --git a/coverage/htmlfiles/pyfile.html b/coverage/htmlfiles/pyfile.html index d9d0e4c..6f99e6a 100644 --- a/coverage/htmlfiles/pyfile.html +++ b/coverage/htmlfiles/pyfile.html @@ -9,6 +9,7 @@ <link rel='stylesheet' href='style.css' type='text/css'> <script type='text/javascript' src='jquery-1.4.3.min.js'></script> <script type='text/javascript' src='jquery.hotkeys.js'></script> + <script type='text/javascript' src='jquery.isonscreen.js'></script> <script type='text/javascript' src='coverage_html.js'></script> <script type='text/javascript' charset='utf-8'> jQuery(document).ready(coverage.pyfile_ready); |