forked from component/datepicker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (43 loc) · 1011 Bytes
/
index.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
/**
* Module dependencies.
*/
var Calendar = require('calendar')
, Popover = require('popover')
, event = require('event')
/**
* Expose `Datepicker`.
*/
module.exports = Datepicker;
/**
* Initialize a new date picker with the given input `el`.
*
* @param {Element} el
* @api public
*/
function Datepicker(el) {
if (!(this instanceof Datepicker)) return new Datepicker(el);
this.el = el;
this.cal = new Calendar;
this.cal.el.addClass('datepicker-calendar');
event.bind(el, 'click', this.onclick.bind(this));
}
/**
* Handle input clicks.
*/
Datepicker.prototype.onclick = function(e){
this.cal.on('change', this.onchange.bind(this));
this.popover = new Popover(this.cal.el);
this.popover.classname = 'datepicker-popover popover';
this.popover.show(this.el);
};
/**
* Handle date changes.
*/
Datepicker.prototype.onchange = function(date){
this.el.value = date.getFullYear()
+ '/'
+ date.getMonth()
+ '/'
+ date.getDate();
this.popover.hide();
};