Skip to content

Commit 4cfdcdd

Browse files
author
Martii
committed
Start timer on view for reminders
* Do this in case someone hotlinks lower in the page and ends up missing these when traversing Applies to #573 and #484 and more for #567 and start of #568
1 parent 6a97a7c commit 4cfdcdd

1 file changed

Lines changed: 38 additions & 5 deletions

File tree

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,44 @@
11
<script type="text/javascript">
22
(function () {
3+
function isElementInViewport(aEl) {
4+
if (aEl instanceof jQuery) {
5+
aEl = aEl[0];
6+
}
37

4-
setTimeout(function () {
5-
$('.reminders .alert .close').each(function () {
6-
this.click();
7-
});
8-
}, 7000);
8+
var rect = aEl.getBoundingClientRect();
9+
10+
return (
11+
rect.top >= 0 &&
12+
rect.left >= 0 &&
13+
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
14+
rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
15+
);
16+
}
17+
18+
var hasShownReminders = false;
19+
function callback(aEl) {
20+
if (!hasShownReminders) {
21+
hasShownReminders = true;
22+
23+
setTimeout(function () {
24+
$('.reminders .alert .close').each(function () {
25+
this.click();
26+
});
27+
}, 7000);
28+
}
29+
}
30+
31+
function fireIfElementVisible(aEl, aCallback) {
32+
return function () {
33+
if (isElementInViewport(aEl)) {
34+
aCallback(aEl);
35+
}
36+
}
37+
}
38+
39+
var handler = fireIfElementVisible($('.reminders'), callback);
40+
41+
$(window).on('DOMContentLoaded load resize scroll', handler);
942

1043
})();
1144
</script>

0 commit comments

Comments
 (0)