Skip to content

Commit

Permalink
Merge pull request #574 from Martii/timeoutOnView
Browse files Browse the repository at this point in the history
Start timer on view for reminders

Auto-merge
  • Loading branch information
Martii committed Feb 8, 2015
2 parents 6a97a7c + 4cfdcdd commit 673278e
Showing 1 changed file with 38 additions and 5 deletions.
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>

0 comments on commit 673278e

Please sign in to comment.