assets/js/romo/datepicker.js in romo-0.15.3 vs assets/js/romo/datepicker.js in romo-0.15.4
- old
+ new
@@ -9,17 +9,18 @@
this.defaultFormat = 'yyyy-mm-dd'
this.monthNames = [
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
]
- this.defaultPrevClass = undefined;
- this.defaultNextClass = undefined;
- this.defaultIndicatorClass = undefined;
- this.itemSelector = 'TD.romo-datepicker-day:not(.disabled)';
- this.calTable = $();
- this.date = undefined;
- this.today = new Date;
+ this.defaultPrevClass = undefined;
+ this.defaultNextClass = undefined;
+ this.defaultIndicatorClass = undefined;
+ this.itemSelector = 'TD.romo-datepicker-day:not(.disabled)';
+ this.calTable = $();
+ this.date = undefined;
+ this.today = new Date;
+ this.prevValue = undefined;
this.doInit();
this.doBindElem();
this.doSetFormat();
this.doSetDate(this.elem.val());
@@ -65,16 +66,27 @@
this.indicatorElem.on('click', $.proxy(this.onIndicatorClick, this));
this.elem.css({'padding-right': '22px'});
this.elem.after(this.indicatorElem);
}
+ this.prevValue = this.elem.val();
+ this.elem.on('change', $.proxy(function(e) {
+ var newValue = this.elem.val();
+ this.elem.trigger('datepicker:change', [newValue, this.prevValue, this]);
+ this.prevValue = newValue;
+ }, this));
+
this.elem.on('datepicker:triggerEnable', $.proxy(function(e) {
this.doEnable();
}, this));
this.elem.on('datepicker:triggerDisable', $.proxy(function(e) {
this.doDisable();
}, this));
+ this.elem.on('datepicker:triggerSetFormat', $.proxy(function(e) {
+ this.doSetFormat();
+ }, this));
+ this.elem.on('datepicker:triggerSetDate', $.proxy(this.onTriggerSetDate, this));
}
RomoDatepicker.prototype.doSetFormat = function() {
var format = this.elem.data('romo-datepicker-format') || this.defaultFormat;
this.formatValues = this._parseFormatValues(format);
@@ -193,22 +205,22 @@
this.doRefreshUI(nDate);
this.elem.trigger('datepicker:nextRefresh', [nDate, this]);
}
RomoDatepicker.prototype.doSelectHighlightedItem = function() {
- var prevValue = this.elem.val();
- var newValue = this.calTable.find('TD.romo-datepicker-highlight').data('romo-datepicker-value');
+ var newValue = this.calTable.find('TD.romo-datepicker-highlight').data('romo-datepicker-value');
this.romoDropdown.doPopupClose();
this.doSetDate(newValue);
this.elem.focus();
- this.elem.trigger('datepicker:itemSelected', [newValue, prevValue, this]);
+ this.elem.trigger('datepicker:itemSelected', [newValue, this.prevValue, this]);
+ this._triggerSetDateChangeEvent();
+}
- if (newValue !== prevValue) {
- this.elem.trigger('change');
- this.elem.trigger('datepicker:change', [newValue, prevValue, this]);
- }
+RomoDatepicker.prototype.onTriggerSetDate = function(e, value) {
+ this.doSetDate(value);
+ this._triggerSetDateChangeEvent();
}
RomoDatepicker.prototype.onElemKeyDown = function(e) {
if (this.elem.hasClass('disabled') === false) {
if (this.romoDropdown.popupElem.hasClass('romo-dropdown-open')) {
@@ -288,9 +300,17 @@
this.popupMouseDown = true;
}
RomoDatepicker.prototype.onPopupMouseUp = function(e) {
this.popupMouseDown = false;
+}
+
+// private
+
+RomoDatepicker.prototype._triggerSetDateChangeEvent = function() {
+ if (this.elem.val() !== this.prevValue) {
+ this.elem.trigger('change');
+ }
}
RomoDatepicker.prototype._clearBlurTimeout = function() {
if (this.blurTimeoutId !== undefined) {
clearTimeout(this.blurTimeoutId);