Skip to content

Commit

Permalink
Merge 93d5b6d into b9fcc4e
Browse files Browse the repository at this point in the history
  • Loading branch information
gotwarlost committed Feb 7, 2015
2 parents b9fcc4e + 93d5b6d commit eef3381
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 110 deletions.
2 changes: 1 addition & 1 deletion .jshintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lib/vendor
lib/assets/vendor
test/cli/sample-project
test/cli/sample-project-link
test/browser/support/vendor
Expand Down
10 changes: 4 additions & 6 deletions lib/vendor/base.css → lib/assets/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,17 @@ div.coverage-summary a:visited { text-decoration: none; color: #333; }
div.coverage-summary a:hover { text-decoration: underline; }
div.coverage-summary tfoot td { border-top: 1px solid #666; }

div.coverage-summary .yui3-datatable-sort-indicator, div.coverage-summary .dummy-sort-indicator {
div.coverage-summary .sorter {
height: 10px;
width: 7px;
display: inline-block;
margin-left: 0.5em;
background: url(sort-arrow-sprite.png) no-repeat scroll 0 0 transparent;
}
div.coverage-summary .yui3-datatable-sort-indicator {
background: url("https://yui-s.yahooapis.com/3.6.0/build/datatable-sort/assets/skins/sam/sort-arrow-sprite.png") no-repeat scroll 0 0 transparent;
}
div.coverage-summary .yui3-datatable-sorted .yui3-datatable-sort-indicator {
div.coverage-summary .sorted .sorter {
background-position: 0 -20px;
}
div.coverage-summary .yui3-datatable-sorted-desc .yui3-datatable-sort-indicator {
div.coverage-summary .sorted-desc .sorter {
background-position: 0 -10px;
}

Expand Down
Binary file added lib/assets/sort-arrow-sprite.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
156 changes: 156 additions & 0 deletions lib/assets/sorter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
var addSorting = (function () {
"use strict";
var cols,
currentSort = {
index: 0,
desc: false
};

// returns the summary table element
function getTable() { return document.querySelector('.coverage-summary table'); }
// returns the thead element of the summary table
function getTableHeader() { return getTable().querySelector('thead tr'); }
// returns the tbody element of the summary table
function getTableBody() { return getTable().querySelector('tbody'); }
// returns the th element for nth column
function getNthColumn(n) { return getTableHeader().querySelectorAll('th')[n]; }

// loads all columns
function loadColumns() {
var colNodes = getTableHeader().querySelectorAll('th'),
colNode,
cols = [],
col,
i;

for (i = 0; i < colNodes.length; i += 1) {
colNode = colNodes[i];
col = {
key: colNode.getAttribute('data-col'),
sortable: !colNode.getAttribute('data-nosort'),
type: colNode.getAttribute('data-type') || 'string'
};
cols.push(col);
if (col.sortable) {
col.defaultDescSort = col.type === 'number';
colNode.innerHTML = colNode.innerHTML + '<span class="sorter"></span>';
}
}
return cols;
}
// attaches a data attribute to every tr element with an object
// of data values keyed by column name
function loadRowData(tableRow) {
var tableCols = tableRow.querySelectorAll('td'),
colNode,
col,
data = {},
i,
val;
for (i = 0; i < tableCols.length; i += 1) {
colNode = tableCols[i];
col = cols[i];
val = colNode.getAttribute('data-value');
if (col.type === 'number') {
val = Number(val);
}
data[col.key] = val;
}
return data;
}
// loads all row data
function loadData() {
var rows = getTableBody().querySelectorAll('tr'),
i;

for (i = 0; i < rows.length; i += 1) {
rows[i].data = loadRowData(rows[i]);
}
}
// sorts the table using the data for the ith column
function sortByIndex(index, desc) {
var key = cols[index].key,
sorter = function (a, b) {
a = a.data[key];
b = b.data[key];
return a < b ? -1 : a > b ? 1 : 0;
},
finalSorter = sorter,
tableBody = document.querySelector('.coverage-summary tbody'),
rowNodes = tableBody.querySelectorAll('tr'),
rows = [],
i;

if (desc) {
finalSorter = function (a, b) {
return -1 * sorter(a, b);
};
}

for (i = 0; i < rowNodes.length; i += 1) {
rows.push(rowNodes[i]);
tableBody.removeChild(rowNodes[i]);
}

rows.sort(finalSorter);

for (i = 0; i < rows.length; i += 1) {
tableBody.appendChild(rows[i]);
}
}
// removes sort indicators for current column being sorted
function removeSortIndicators() {
var col = getNthColumn(currentSort.index),
cls = col.className;

cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
col.className = cls;
}
// adds sort indicators for current column being sorted
function addSortIndicators() {
getNthColumn(currentSort.index).className += currentSort.desc ? ' sorted-desc' : ' sorted';
}
// adds event listeners for all sorter widgets
function enableUI() {
var i,
el,
ithSorter = function ithSorter(i) {
var col = cols[i];

return function () {
var desc = col.defaultDescSort;

if (currentSort.index === i) {
desc = !currentSort.desc;
}
sortByIndex(i, desc);
removeSortIndicators();
currentSort.index = i;
currentSort.desc = desc;
addSortIndicators();
};
};
for (i =0 ; i < cols.length; i += 1) {
if (cols[i].sortable) {
el = getNthColumn(i).querySelector('.sorter');
if (el.addEventListener) {
el.addEventListener('click', ithSorter(i));
} else {
el.attachEvent('onclick', ithSorter(i));
}
}
}
}
// adds sorting functionality to the UI
return function () {
if (!getTable()) {
return;
}
cols = loadColumns();
loadData(cols);
addSortIndicators();
enableUI();
};
})();

window.addEventListener('load', addSorting);
File renamed without changes.
File renamed without changes.
35 changes: 22 additions & 13 deletions lib/report/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,12 @@ Report.mix(HtmlReport, {
templateData.reportClass = getReportClass(node.metrics.statements, opts.watermarks.statements);
templateData.pathHtml = pathTemplate({ html: this.getPathHtml(node, linkMapper) });
templateData.base = {
js: linkMapper.asset(node, 'base.js'),
css: linkMapper.asset(node, 'base.css')
};
templateData.sorter = {
js: linkMapper.asset(node, 'sorter.js'),
image: linkMapper.asset(node, 'sort-arrow-sprite.png')
};
templateData.prettify = {
js: linkMapper.asset(node, 'prettify.js'),
css: linkMapper.asset(node, 'prettify.css')
Expand Down Expand Up @@ -521,23 +524,29 @@ Report.mix(HtmlReport, {
summarizer = new TreeSummarizer(),
writer = opts.writer || new FileWriter(sync),
that = this,
tree;
tree,
copyAssets = function (subdir) {
var srcDir = path.resolve(__dirname, '..', 'assets', subdir);
fs.readdirSync(srcDir).forEach(function (f) {
var resolvedSource = path.resolve(srcDir, f),
resolvedDestination = path.resolve(dir, f),
stat = fs.statSync(resolvedSource);

if (stat.isFile()) {
if (opts.verbose) {
console.log('Write asset: ' + resolvedDestination);
}
writer.copyFile(resolvedSource, resolvedDestination);
}
});
};

collector.files().forEach(function (key) {
summarizer.addFileCoverageSummary(key, utils.summarizeFileCoverage(collector.fileCoverageFor(key)));
});
tree = summarizer.getTreeSummary();
fs.readdirSync(path.resolve(__dirname, '..', 'vendor')).forEach(function (f) {
var resolvedSource = path.resolve(__dirname, '..', 'vendor', f),
resolvedDestination = path.resolve(dir, f),
stat = fs.statSync(resolvedSource);

if (stat.isFile()) {
if (opts.verbose) {
console.log('Write asset: ' + resolvedDestination);
}
writer.copyFile(resolvedSource, resolvedDestination);
}
[ '.', 'vendor'].forEach(function (subdir) {
copyAssets(subdir);
});
writer.on('done', function () { that.emit('done'); });
//console.log(JSON.stringify(tree.root, undefined, 4));
Expand Down
10 changes: 8 additions & 2 deletions lib/report/templates/foot.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
</div>
{{#if prettify}}
<script src="{{prettify.js}}"></script>
<script>
window.onload = function () {
if (typeof prettyPrint === 'function') {
prettyPrint();
}
};
</script>
{{/if}}
<script src="https://yui-s.yahooapis.com/3.6.0/build/yui/yui-min.js"></script>
<script src="{{base.js}}"></script>
<script src="{{sorter.js}}"></script>
</body>
</html>
5 changes: 5 additions & 0 deletions lib/report/templates/head.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
<link rel="stylesheet" href="{{prettify.css}}">
{{/if}}
<link rel="stylesheet" href="{{base.css}}">
<style type='text/css'>
div.coverage-summary .sorter {
background-image: url({{sorter.image}});
}
</style>
</head>
<body>
<div class="header {{reportClass}}">
Expand Down
88 changes: 0 additions & 88 deletions lib/vendor/base.js

This file was deleted.

0 comments on commit eef3381

Please sign in to comment.