Skip to content
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
30 changes: 21 additions & 9 deletions background-check.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
'use strict';

var resizeEvent = window.orientation !== undefined ? 'orientationchange' : 'resize';
var resizeFn;
var scrollFn;
var supported;
var canvas;
var context;
Expand Down Expand Up @@ -70,12 +72,14 @@
canvas.style.width = '100%';
canvas.style.height = '100%';

window.addEventListener(resizeEvent, throttle.bind(null, function () {
resizeFn = throttle.bind(null, function () {
resizeCanvas();
check();
}));
});
window.addEventListener(resizeEvent, resizeFn);

window.addEventListener('scroll', throttle.bind(null, check));
scrollFn = throttle.bind(null, check);
window.addEventListener('scroll', scrollFn);

resizeCanvas();
check();
Expand All @@ -88,9 +92,17 @@
* Destructor
*/
function destroy() {
supported = null;
canvas = null;
context = null;
removeClasses();
if (supported) {
window.removeEventListener(resizeEvent, resizeFn);
window.removeEventListener('scroll', scrollFn);
resizeFn = undefined;
scrollFn = undefined;
}

supported = undefined;
canvas = undefined;
context = undefined;
attrs = {};

if (throttleDelay) {
Expand Down Expand Up @@ -241,7 +253,7 @@
*/
function kill(start) {
var duration = new Date().getTime() - start;

log('Duration: ' + duration + 'ms');

if (duration > get('maxDuration')) {
Expand Down Expand Up @@ -540,7 +552,7 @@
for (var t = 0; t < targets.length; t++) {
target = targets[t];
target = get('changeParent') ? target.parentNode : target;

classList(target, get('classes').light, 'remove');
classList(target, get('classes').dark, 'remove');
classList(target, get('classes').complex, 'remove');
Expand All @@ -549,7 +561,7 @@


/*
* Calculate average pixel brightness of a region
* Calculate average pixel brightness of a region
* and add 'light' or 'dark' accordingly
*/
function calculatePixelBrightness(target) {
Expand Down
2 changes: 1 addition & 1 deletion background-check.min.js

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

Loading