-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathnotification.js
38 lines (29 loc) · 983 Bytes
/
notification.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
PackeryDocs.notification = function( elem ) {
'use strict';
var docElem = document.documentElement;
var transitionProp = typeof docElem.style.transition == 'string' ?
'transition' : 'WebkitTransition';
var notifyTimeout;
PackeryDocs.notify = function( message ) {
elem.textContent = message + ' at ' + getTimestamp();
elem.style[ transitionProp ] = 'none';
elem.style.display = 'block';
elem.style.opacity = '1';
// hide the notification after a second
clearTimeout( notifyTimeout );
notifyTimeout = setTimeout( hideNotify, 1000 );
};
function getTimestamp() {
var now = new Date();
var min = leadZero( now.getMinutes() );
var seconds = leadZero( now.getSeconds() );
return [ now.getHours(), min, seconds ].join(':');
}
function leadZero( time ) {
return time < 10 ? '0' + time : time;
}
function hideNotify() {
elem.style[ transitionProp ] = 'opacity 1.0s';
elem.style.opacity = '0';
}
};