Skip to content

Commit

Permalink
floatHeaders keep <TH>s on top. Update jQuery to latest 1.x version.
Browse files Browse the repository at this point in the history
This is a first attempt to keep table headers visible when scrolling.  A feature
requested by PenolopeFudd (https://github.com/PenelopeFudd).  See issue #14 on
github:  #14

THIS REVISION MIGHT NOT WORK AS EXPECTED IN SOME BROWSERS!

The author tested in a fairly recent version of Firefox, where everything works
like charm.  Some quirks where encountered in an ancient Opera (version 12 -
current version is 40.somthing).

We might want to add a commandline switch and/or buttons to turn this feature
on and off (see also 'BUGS' below).

CHANGES

  * Scripts in lib/Devel/NYTProf/js/

    - Include a more recent version of jQuery.  1.12.4 is the most up to date
      version in the 1.x series.  Stored as jqery-min.js again.
      Source: https://code.jquery.com/jquery-1.12.4.min.js

    - Include floatHeaders.js (in a minified version).  MIT License. Sources:
      + https://github.com/mkoryak/floatThead/tree/master/dist - Repo
      + http://mkoryak.github.io/floatThead - Homepage, demo, and download.
      "Release 1.4.4 released 5 days ago (October 3rd 2016)":
          https://api.github.com/repos/mkoryak/floatThead/tarball/1.4.4

  * nytprofhtml:

    - Add 'floadHeaders' to the class attribute of large tables.
    - Add a snippet to initialize the 'floadHeaders' (line 420 and 1501).

BUGS

  * When clicking on a link in the "Top 15 Subroutines" table, the method name
    in the target table is hidden by the floatHeaders.  The floatHeaders script
    does not take anchors into account.

  * Opera 12: floatHeaders are shrunk to a more narrow size by the script.
  • Loading branch information
Sebastian Rose, Hannover, Germany committed Oct 8, 2016
1 parent 3c53f5e commit b21dd1b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 43 deletions.
25 changes: 14 additions & 11 deletions bin/nytprofhtml
Expand Up @@ -336,7 +336,7 @@ sub subroutine_table {

my $sortby_desc = ($sortby eq 'excl_time') ? "exclusive time" : "inclusive time";
$sub_links .= qq{
<table id="subs_table" border="1" cellpadding="0" class="tablesorter">
<table id="subs_table" border="1" cellpadding="0" class="tablesorter floatHeaders">
<caption>${qualifier}Subroutines</caption>
<thead>
<tr>
Expand Down Expand Up @@ -409,15 +409,16 @@ sub subroutine_table {
$sub_links .= q{</table>};

# make table sortable if it contains all the subs
push @on_ready_js, q{
push @on_ready_js, q<
$("#subs_table").tablesorter({
sortList: [[3,1]],
headers: {
3: { sorter: 'fmt_time' },
4: { sorter: 'fmt_time' }
}
});
} if @subs_to_show == @subs;
$(".floatHeaders").each( function(){ $(this).floatThead(); } );
> if @subs_to_show == @subs;

return $sub_links;
}
Expand Down Expand Up @@ -461,7 +462,7 @@ $reporter->set_param(

return qq{
$sub_table
<table border="1" cellpadding="0">
<table border="1" cellpadding="0" class="floatHeaders">
<thead>
<tr><th>Line</th>
<th><span title="Number of statements executed">State<br />ments</span></th>
Expand Down Expand Up @@ -1375,7 +1376,7 @@ sub output_file_table {

# generate time-sorted sections for files
print $fh qq{
<table id="filestable" border="1" cellspacing="0" class="tablesorter">
<table id="filestable" border="1" cellspacing="0" class="tablesorter floatHeaders">
<caption>Source Code Files &mdash; ordered by exclusive time then name</caption>
};
print $fh qq{
Expand Down Expand Up @@ -1497,6 +1498,7 @@ sub output_file_table {
2: { sorter: false }
}
});
$(".floatHeaders").each( function(){ $(this).floatThead(); } );
};

return "";
Expand Down Expand Up @@ -1629,12 +1631,12 @@ This file was generated by Devel::NYTProf version $Devel::NYTProf::Core::VERSION
<title>$title</title>
EOD

$html .= qq{<link rel="stylesheet" type="text/css" href="style.css" />\n}
$html .= qq{ <link rel="stylesheet" type="text/css" href="style.css" />\n}
unless $opts->{skip_style};

if (my $css = $opts->{add_jit}) {
$html .= qq{<link rel="stylesheet" type="text/css" href="js/jit/$css.css" />\n};
$html .= qq{<script language="JavaScript" src="js/jit/jit.js"></script>\n};
$html .= qq{ <link rel="stylesheet" type="text/css" href="js/jit/$css.css" />\n};
$html .= qq{ <script language="JavaScript" src="js/jit/jit.js"></script>\n};
}

$html .= <<EOD unless $opts->{skip_jquery};
Expand Down Expand Up @@ -1667,9 +1669,10 @@ EOD
console.log('no match for fmt_time of '+orig+' (units:'+non_number+' charCodeAt0:'+non_number.charCodeAt(0)+')');
return orig;
},
type: 'numeric' // set type, either numeric or text
});
</script>
type: 'numeric' // set type, either numeric or text
});
</script>
<script type="text/javascript" src="js/jquery.floatThead.min.js"></script>
EOD
$html .= $opts->{head_epilogue} if $opts->{head_epilogue};

Expand Down

0 comments on commit b21dd1b

Please sign in to comment.