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

Add ability to filter images #34

Closed
wants to merge 2 commits into from
Closed
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
120 changes: 96 additions & 24 deletions tasks/tpl/canvas.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -255,37 +255,64 @@
background-color: #0F3340;
box-shadow: inset 0 1px 2px #000;
}

.filter {
font-size: 1.2em;
color: white;
padding: 30px 0 0 30px;
}

.filter p {
margin: 8px 0;
}

.filter input {
border: 1px solid white;
padding: 3px;
margin-left: 5px;
}

.hidden {
display: none !important;
}
</style>
</head>
<body>
<h1><i></i>Photobox</h1>
<main class="">
<div class="filter">
<p>Show only modified: <input type="checkbox" name="modified" class="checkbox"></p>
<p>Treshold: <input type="number" name="treshold" value="0" class="treshold"></p>
</div>

<% _.each( _.keys( templateData ), function( url ) { %>
<% var name = url.replace( /(http:\/\/|https:\/\/)/, '' ).replace( /\//g, '-' ); %>
<div class="name"><a href="<%= url %>" data-name="<%= name %>" target="_blank"><%= name %></a></div>

<% _.each( templateData[ url ], function( size ) {%>
<div class="row">
<div class="size"><%= size %></div>
<div class="colContainer">
<div class="col">
<h2>Old screens</h2>
<img src="" class="last" data-src="img/last/<%= name %>-<%= size %>.png?<%= now %>" data-size="<%= size %>">
<p><%= timestamps.last %></p>
</div><div class="col">
<h2>Difference</h2>
<h3 class="processing">
<div id="semi_border"></div>
we are checking for different pixels..</h3>
<canvas>canvas is not supported</canvas>
</div><div class="col">
<h2>New Screens</h2>
<img src="" class="current" data-src="img/current/<%= name %>-<%= size %>.png?<%= now %>" data-size="<%= size %>">
<p><%= timestamps.current %></p>
<div class="wrap">
<% var name = url.replace( /(http:\/\/|https:\/\/)/, '' ).replace( /\//g, '-' ); %>
<div class="name"><a href="<%= url %>" data-name="<%= name %>" target="_blank"><%= name %></a></div>

<% _.each( templateData[ url ], function( size ) {%>
<div class="row">
<div class="size"><%= size %></div>
<div class="colContainer">
<div class="col">
<h2>Old screens</h2>
<img src="" class="last" data-src="img/last/<%= name %>-<%= size %>.png?<%= now %>" data-size="<%= size %>">
<p><%= timestamps.last %></p>
</div><div class="col">
<h2>Difference</h2>
<h3 class="processing">
<div id="semi_border"></div>
we are checking for different pixels..</h3>
<canvas>canvas is not supported</canvas>
</div><div class="col">
<h2>New Screens</h2>
<img src="" class="current" data-src="img/current/<%= name %>-<%= size %>.png?<%= now %>" data-size="<%= size %>">
<p><%= timestamps.current %></p>
</div>
</div>
</div>
</div>
<% } );%>
<% } );%>
</div>
<% } );%>
</main>

Expand All @@ -306,6 +333,50 @@
}
} );

/**
* Get the closest parent element by class name (similiar to jquery parent())
* @param {dom} element
* @param {string} class selector
* @return {dom|false} closest matched selector, or false for no match
*/
function getClosestClass ( elem, selector ) {
var firstChar = selector.charAt(0);
// Get closest match
for ( ; elem && elem !== document; elem = elem.parentNode ) {
if ( elem.classList.contains( selector.substr(1) ) ) {
return elem;
}
}
return false;
}

/**
* Plug in filter event so we can show just screenshot that have some different pixels
* @return {void}
*/
function filter () {
var checkbox = document.querySelector('.checkbox');
document.querySelector('.checkbox').onclick = function(){
if ( checkbox.checked ) {
var rows = document.querySelectorAll('[data-pixels]');
var treshold = Number(document.querySelector('.treshold').value);

[].forEach.call(rows, function (row) {
if ( Number(row.getAttribute('data-pixels')) < treshold ) {
row.classList.add('hidden');
}
});
} else {
[].forEach.call(document.querySelectorAll('[data-pixels]'), function (row) {
row.classList.remove('hidden');
});

}
};
}

filter();


/**
* prepareDiff inits the canvas for the DIFF and
Expand Down Expand Up @@ -351,8 +422,9 @@
worker.postMessage( data );
worker.addEventListener( 'message', function( e ) {
ctx.putImageData( e.data.imageData, 0, 0 );
processing.style.display = 'none'
processing.style.display = 'none';
console.warn( 'Found ', e.data.amount, 'different pixels' );
(getClosestClass(imgA, '.wrap')).setAttribute('data-pixels', e.data.amount);
}, false);

}
Expand Down