diff --git a/component.json b/component.json index 3b4cb43..6193e65 100644 --- a/component.json +++ b/component.json @@ -8,7 +8,8 @@ "component/calendar": "*", "component/popover": "*", "component/aurora": "*", - "component/event": "*" + "component/event": "*", + "samsonjs/strftime": "v0.6.1" }, "development": {}, "license": "MIT", diff --git a/example.html b/example.html index b6a69b7..8e81d31 100644 --- a/example.html +++ b/example.html @@ -12,12 +12,18 @@ + Y/m/d: +
+ d.m.Y: + \ No newline at end of file diff --git a/index.js b/index.js index c72ac95..ac942cb 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ var Calendar = require('calendar') , Popover = require('popover') , event = require('event') + , strftime = require('strftime') /** * Expose `Datepicker`. @@ -20,9 +21,12 @@ module.exports = Datepicker; * @api public */ -function Datepicker(el) { - if (!(this instanceof Datepicker)) return new Datepicker(el); +function Datepicker(el, format) { + if (!(this instanceof Datepicker)) return new Datepicker(el, format); this.el = el; + if (!format) + format = '%Y/%m/%d'; + this.format = format; this.cal = new Calendar; this.cal.el.addClass('datepicker-calendar'); event.bind(el, 'click', this.onclick.bind(this)); @@ -45,11 +49,7 @@ Datepicker.prototype.onclick = function(e){ */ Datepicker.prototype.onchange = function(date){ - this.el.value = date.getFullYear() - + '/' - + date.getMonth() - + '/' - + date.getDate(); + this.el.value = strftime(this.format, date); this.popover.remove(); this.popover = null;