From 0475cfba82e5c285ad1100c8560edf6493ed53ee Mon Sep 17 00:00:00 2001 From: jaumeMR Date: Tue, 8 Sep 2015 16:59:56 +0200 Subject: [PATCH] Update to last version with new options --- lib/bootstrap-material-datepicker.js | 456 ++++++++++++++++++--------- 1 file changed, 303 insertions(+), 153 deletions(-) diff --git a/lib/bootstrap-material-datepicker.js b/lib/bootstrap-material-datepicker.js index b1625db..f643056 100644 --- a/lib/bootstrap-material-datepicker.js +++ b/lib/bootstrap-material-datepicker.js @@ -2,10 +2,11 @@ { var pluginName = "bootstrapMaterialDatePicker"; var pluginDataName = "plugin_" + pluginName; + + moment.locale('en'); function Plugin(element, options) { - this.currentDate = moment(); this.currentView = 0; this.minDate; @@ -16,7 +17,7 @@ this.element = element; this.$element = $(element); - this.params = { date : true, time : true, format : 'YYYY-MM-DD', minDate : null, maxDate : null, currentDate : null, lang : 'en', weekStart : 0 }; + this.params = { date : true, time : true, format : 'YYYY-MM-DD', minDate : null, maxDate : null, currentDate : null, lang : 'en', weekStart : 0, shortTime : false, 'cancelText' : 'Cancel', 'okText' : 'OK' }; this.params = $.fn.extend(this.params, options); this.name = "dtp_" + this.setName(); @@ -51,7 +52,7 @@ Plugin.prototype = { init: function() - { + { this.initDays(); this.initDates(); @@ -59,7 +60,11 @@ this.initButtons(); - this._attachEvent(this.$element, 'click', function(){ this._onClick(); }.bind(this)); + this._attachEvent($(window), 'resize', this._centerBox(this)); + this._attachEvent(this.$dtpElement.find('.dtp-content'), 'click', this._onElementClick.bind(this)); + this._attachEvent(this.$dtpElement, 'click', this._onBackgroundClick.bind(this)); + this._attachEvent(this.$dtpElement.find('.dtp-close > a'), 'click', this._onCloseClick.bind(this)); + this._attachEvent(this.$element, 'click', this._onClick.bind(this)); }, initDays: function() { @@ -75,32 +80,65 @@ }, initDates: function() { - if(typeof(this.params.currentDate) !== 'undefined' && this.params.currentDate !== null) + if(this.$element.val().length > 0) { - if(typeof(this.params.currentDate) === 'string') + if(typeof(this.params.format) !== 'undefined' && this.params.format !== null) { - if(typeof(this.params.format) !== 'undefined' && this.params.format !== null) - { - this.currentDate = moment(this.params.currentDate, this.params.format).locale(this.params.lang); - } - else + this.currentDate = moment(this.$element.val(), this.params.format).locale(this.params.lang); + } + else + { + this.currentDate = moment(this.$element.val()).locale(this.params.lang); + } + } + else + { + if(typeof(this.$element.attr('value')) !== 'undefined' && this.$element.attr('value') !== null && this.$element.attr('value') !== "") + { + if(typeof(this.$element.attr('value')) === 'string') { - this.currentDate = moment(this.params.currentDate).locale(this.params.lang); + if(typeof(this.params.format) !== 'undefined' && this.params.format !== null) + { + this.currentDate = moment(this.$element.attr('value'), this.params.format).locale(this.params.lang); + } + else + { + this.currentDate = moment(this.$element.attr('value')).locale(this.params.lang); + } } } else { - if(typeof(this.params.currentDate.isValid) === 'undefined' || typeof(this.params.currentDate.isValid) !== 'function') + if(typeof(this.params.currentDate) !== 'undefined' && this.params.currentDate !== null) { - var x = this.params.currentDate.getTime(); - this.currentDate = moment(x, "x").locale(this.params.lang); + if(typeof(this.params.currentDate) === 'string') + { + if(typeof(this.params.format) !== 'undefined' && this.params.format !== null) + { + this.currentDate = moment(this.params.currentDate, this.params.format).locale(this.params.lang); + } + else + { + this.currentDate = moment(this.params.currentDate).locale(this.params.lang); + } + } + else + { + if(typeof(this.params.currentDate.isValid) === 'undefined' || typeof(this.params.currentDate.isValid) !== 'function') + { + var x = this.params.currentDate.getTime(); + this.currentDate = moment(x, "x").locale(this.params.lang); + } + else + { + this.currentDate = this.params.currentDate; + } + } + this.$element.val(this.currentDate.format(this.params.format)); } else - { - this.currentDate = this.params.currentDate; - } + this.currentDate = moment(); } - this.$element.val(this.params.currentDate.format(this.params.format)); } if(typeof(this.params.minDate) !== 'undefined' && this.params.minDate !== null) @@ -168,59 +206,60 @@ }, initTemplate: function() { - this.template = '