-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.jqExpire.js
59 lines (45 loc) · 1.34 KB
/
jquery.jqExpire.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
*
* jqExpire 0.1.2-alpha
* https://github.com/aalaap/jqExpire
*
* by Aalaap Ghag
* http://aalaap.com
*
* A jQuery plugin to automatically hide page elements after an 'expiry' date
* and/or time. Great for pages which have upcoming/ongoing event notices or
* cut-off times for forms and such.
*
* jqExpire has been released under the Do What the Fuck You Want to Public
* License, so you really can do whatever the fuck you want with it.
*
*/
(function( $ ) {
$.fn.jqExpire = function( parameter ) {
var expiryDate;
var rightNow = new Date().getTime();
// if parameter is empty, look for data-expire attributes
if ( arguments.length == 0 ) {
$( "*[data-expire]" ).each( function() {
expiryDate = new Date( $( this ).data( 'expire' ) ).getTime();
if ( expiryDate < rightNow ) {
$( this ).hide();
}
});
}
// if parameter type is an array, then loop through it individually
else if (typeof parameter == 'array') {
console.log("This feature is yet to be implemented!")
}
// if parameter type appears to be a date/time stamp, check that
// against each matched element.
else if (typeof parameter == 'string') {
expiryDate = new Date( parameter ).getTime();
if (expiryDate < rightNow) {
this.each( function() {
$( this ).hide();
} );
}
}
};
}( jQuery ));