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

Start timer on view for reminders #574

Merged
merged 1 commit into from
Feb 8, 2015
Merged
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
43 changes: 38 additions & 5 deletions views/includes/scripts/hideReminders.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
<script type="text/javascript">
(function () {
function isElementInViewport(aEl) {
if (aEl instanceof jQuery) {
aEl = aEl[0];
}

setTimeout(function () {
$('.reminders .alert .close').each(function () {
this.click();
});
}, 7000);
var rect = aEl.getBoundingClientRect();

return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
);
}

var hasShownReminders = false;
function callback(aEl) {
if (!hasShownReminders) {
hasShownReminders = true;

setTimeout(function () {
$('.reminders .alert .close').each(function () {
this.click();
});
}, 7000);
}
}

function fireIfElementVisible(aEl, aCallback) {
return function () {
if (isElementInViewport(aEl)) {
aCallback(aEl);
}
}
}

var handler = fireIfElementVisible($('.reminders'), callback);

$(window).on('DOMContentLoaded load resize scroll', handler);

})();
</script>