Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
Merge pull request #222 from gemini-testing/feature/lazy-report
Browse files Browse the repository at this point in the history
html report: Load report image in lazy mode
  • Loading branch information
scf2k committed Aug 27, 2015
2 parents d11160c + bf3d91f commit 09d08e6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
13 changes: 13 additions & 0 deletions lib/reporters/html/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
filter = Array.prototype.filter;

function expandAll() {
loadLazyImages(document, '.section_collapsed img');
forEach.call(document.querySelectorAll('.section'), function(section) {
section.classList.remove('section_collapsed');
});
Expand All @@ -18,6 +19,7 @@
}

function expandErrors() {
loadLazyImages(document, '.section_status_fail > .section__body > .image-box img');
forEach.call(document.querySelectorAll('.section'), function(section) {
if (section.classList.contains('section_status_fail')) {
section.classList.remove('section_collapsed');
Expand Down Expand Up @@ -63,6 +65,14 @@
}
}

function loadLazyImages(elem, selector) {
forEach.call(elem.querySelectorAll(selector), function(img) {
if (img.dataset.src && img.src !== img.dataset.src) {
img.src = img.dataset.src;
}
});
}

document.addEventListener('DOMContentLoaded', function() {
document.getElementById('expandAll').addEventListener('click', expandAll);
document.getElementById('collapseAll').addEventListener('click', collapseAll);
Expand All @@ -71,8 +81,11 @@

forEach.call(document.querySelectorAll('.section'), function(section) {
section.querySelector('.section__title').addEventListener('click', function() {
loadLazyImages(section, ':scope > .section__body > .image-box img');
section.classList.toggle('section_collapsed');
});
});
});

expandErrors();
}());
2 changes: 1 addition & 1 deletion lib/reporters/html/suite.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="section__title">{{name}}</div>
<div class="section__body section__body_guided">
{{#each browsers}}
<div class="section {{collapse}} {{status}}">
<div class="section section_collapsed {{status}}">
{{#if skipped}}
<div class="section__title">[skipped] {{name}}</div>
{{/if}}
Expand Down
6 changes: 1 addition & 5 deletions lib/reporters/html/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ Handlebars.registerHelper('has-fails', function() {
});

Handlebars.registerHelper('image', function(kind) {
return new Handlebars.SafeString('<img src="' + encodeURI(this[kind + 'Path']) + '">');
});

Handlebars.registerHelper('collapse', function() {
return hasFails(this)? '' : 'section_collapsed';
return new Handlebars.SafeString('<img data-src="' + encodeURI(this[kind + 'Path']) + '">');
});

function loadTemplate(name) {
Expand Down

0 comments on commit 09d08e6

Please sign in to comment.