Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Large img preview in self-contained mode #573

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/layout/css/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ div.image {
margin-left: $spacing;
overflow: hidden;
width: $extra-media-width;
cursor: zoom-in;

img {
width: $extra-media-width;
Expand Down Expand Up @@ -215,3 +216,28 @@ div.video {
border-top: $triangle-width solid #999;
}
}


/*---------------------------
* 4. Zoom in self-contained
*---------------------------*/

#large {
display: none;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 100;
position: fixed;
margin: auto;
overflow: scroll;
cursor: zoom-out;
background: rgba(0,0,0,0.5) no-repeat center;

img {
display: block;
margin-left: auto;
margin-right: auto;
}
}
3 changes: 3 additions & 0 deletions src/pytest_html/html_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ def _generate_report(self, session):

body.extend(results)

if self.self_contained:
body.append(html.div(html.img(), id="large", onclick="zoomOut()"))

doc = html.html(head, body)

unicode_doc = "<!DOCTYPE html>\n{}".format(doc.unicode(indent=2))
Expand Down
19 changes: 19 additions & 0 deletions src/pytest_html/resources/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,23 @@ function addCollapse() {
});
}

function zoomIn(event) {
const large = find('#large');
find('img', large).setAttribute('src', event.target.getAttribute('src'));
large.style.display = 'block';
large.scrollTop = 0;
}

function zoomOut() { // eslint-disable-line no-unused-vars
find('#large').style.display = 'none';
}

function addZoomIn() {
findAll('.image img').forEach(function(elem) {
elem.addEventListener('click', zoomIn);
});
}

function getQueryParameter(name) {
const match = RegExp('[?&]' + name + '=([^&]*)').exec(window.location.search);
return match && decodeURIComponent(match[1].replace(/\+/g, ' '));
Expand All @@ -121,6 +138,8 @@ function init () { // eslint-disable-line no-unused-vars

addCollapse();

addZoomIn();

showFilters();

sortColumn(find('.initial-sort'));
Expand Down
24 changes: 24 additions & 0 deletions src/pytest_html/resources/style.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.