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

ISSUE-31 update on window resize and path change #36

Merged
merged 12 commits into from
Jun 14, 2017
39 changes: 39 additions & 0 deletions app/public.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
const SVG_URL_REGEX = /\.svg/i;
const SVG_DATA_URI_REGEX = /^data:.*\/svg/i;
const MIN_IMAGE_SIZE = 10;
const CHECKER_INTERVAL_MS = 500;
let refreshImagesInterval;

/**
* Appends an overlay with images details over the whole web page
Expand Down Expand Up @@ -70,13 +72,50 @@
}
}
});
setEventListeners();
}

/**
* Refresh overlay
*/
function refreshImagesInfo() {
hideImagesInfo();
showImagesInfo();
}

/**
* Set event listeners
*/
function setEventListeners() {
let width = window.innerWidth;
let height = window.innerHeight;
let path = window.location.pathname;
let update;

refreshImagesInterval = setInterval(() => {
update = false;
if (window.location.pathname !== path) {
update = true;
path = window.location.pathname;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tabanliviu DoD - This doesn't include changes in the hash (either for traditional hash or non-HTML5 SPAs).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

}
if (window.innerHeight !== height || window.innerWidth !== width) {
update = true;
width = window.innerWidth;
height = window.innerHeight;
}
if (update) {
refreshImagesInfo();
}
}, CHECKER_INTERVAL_MS);
}


/**
* Remove all overlays
*/
function hideImagesInfo() {
nodeListToArray(document.querySelectorAll('.ncc-image-checker-overlay')).map(o => o.remove());
clearInterval(refreshImagesInterval);
}

/**
Expand Down