Repository navigation
Expand file tree
/
Copy pathdouble_date.js
More file actions
56 lines (45 loc) · 1.62 KB
/
Copy pathdouble_date.js
File metadata and controls
56 lines (45 loc) · 1.62 KB
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
// Generated by CoffeeScript 1.4.0
(function() {
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
this.DoubleDate = (function() {
DoubleDate.prototype.$hiddenInput = null;
DoubleDate.prototype.settings = {
dateFormat: "mm/dd/yy",
altFormat: "yy-mm-dd"
};
function DoubleDate(options) {
this._onInputChange = __bind(this._onInputChange, this);
this._formatDate = __bind(this._formatDate, this);
var date;
this.$el = $(options.el);
this.options = $.extend({}, this.settings, options);
this.$hiddenInput = this.$el.clone();
this.$hiddenInput.attr("type", "hidden");
date = new Date("" + (this.$el.val()) + " 00:00:00");
if (date.getFullYear() < 1970) {
date.setFullYear(date.getFullYear() + 100);
}
if (this.$el.val()) {
this.$hiddenInput.val(this._formatDate(this.options.altFormat, date));
this.$el.val(this._formatDate(this.options.dateFormat, date));
}
this.$el.removeAttr("name").removeAttr("id");
this.$el.after(this.$hiddenInput);
this.$el.datepicker({
dateFormat: this.options.dateFormat,
altField: this.$hiddenInput,
altFormat: this.options.altFormat
});
this.$el.bind("keyup", this._onInputChange);
}
DoubleDate.prototype._formatDate = function(format, date) {
return $.datepicker.formatDate(format, date);
};
DoubleDate.prototype._onInputChange = function() {
if (!this.$el.val()) {
return this.$hiddenInput.val("");
}
};
return DoubleDate;
})();
}).call(this);