-
Notifications
You must be signed in to change notification settings - Fork 1
/
bm-friday.html
90 lines (69 loc) · 2.2 KB
/
bm-friday.html
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<link rel="import" href="../polymer/polymer.html">
<!--
Use `<bm-friday>` to get informed whether or not today is a Friday.
## Example
```html
<bm-friday is-friday="{{ isFriday }}">
<div class="heading">IS IT FRIDAY ?</div>
<h1 hidden$="[[ isFriday ]]">NO :(</h1>
<h1 hidden$="[[ !isFriday ]]">YES!</h1>
</bm-friday>
```
This component checks if it's Friday _every minute_, and fires `bm-friday-is-friday` event when
today is Friday, and `bm-friday-other-day` on any other days.
@event bm-friday-is-friday
@event bm-friday-other-day
@element bm-friday
@demo demo/index.html
-->
<dom-module id="bm-friday">
<template>
<style>
:host {
display: block;
position: relative;
}
</style>
<content>IS IT FRIDAY?</content>
</template>
<script>
(function() {
'use strict';
Polymer({
is: 'bm-friday',
properties: {
/**
* True if today is Friday, false otherwise.
* @type {Boolean}
*/
isFriday: {
type: Boolean,
notify: true
},
_interval: {
type: Number,
value: 60 * 1000
},
_dayOfFriday: {
type: Number,
value: 5
}
},
attached: function () {
setInterval(function () {
this._checkIsFriday(new Date());
}.bind(this), this._interval);
this._checkIsFriday(new Date());
},
_checkIsFriday: function (date) {
this.isFriday = date.getDay() === this._dayOfFriday;
if (this.isFriday) {
this.fire('bm-friday-is-friday');
} else {
this.fire('bm-friday-other-day');
}
}
});
})();
</script>
</dom-module>