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 = '
' +
- '
' +
- '
' +
- '
' +
- '
' +
- '' +
- '
' +
- '
' +
- '
' +
- '
MAR
' +
- '
' +
- '
' +
- '
13
' +
- '
' +
- '
' +
- '
2014
' +
- '
' +
- '
' +
+ this.template = '
' +
+ '
' +
+ '
' +
+ '' +
+ '
' +
+ '
' +
+ '
' +
- '
' +
- '
' +
- '
' +
- '
' +
- '
' +
- '
' +
- '
' +
+ '
MAR
' +
+ '
' +
+ '
' +
'
' +
- '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
'
' +
'
';
@@ -235,30 +274,12 @@
},
initButtons: function()
{
- this._attachEvent(this.$dtpElement.find('.dtp-btn-cancel'), 'click', function()
- {
- this._onCancelClick();
- }.bind(this));
- this._attachEvent(this.$dtpElement.find('.dtp-btn-ok'), 'click', function()
- {
- this._onOKClick();
- }.bind(this));
- this._attachEvent(this.$dtpElement.find('a.dtp-select-month-before'), 'click', function()
- {
- this._onMonthBeforeClick();
- }.bind(this));
- this._attachEvent(this.$dtpElement.find('a.dtp-select-month-after'), 'click', function()
- {
- this._onMonthAfterClick();
- }.bind(this));
- this._attachEvent(this.$dtpElement.find('a.dtp-select-year-before'), 'click', function()
- {
- this._onYearBeforeClick();
- }.bind(this));
- this._attachEvent(this.$dtpElement.find('a.dtp-select-year-after'), 'click', function()
- {
- this._onYearAfterClick();
- }.bind(this));
+ this._attachEvent(this.$dtpElement.find('.dtp-btn-cancel'), 'click', this._onCancelClick.bind(this));
+ this._attachEvent(this.$dtpElement.find('.dtp-btn-ok'), 'click', this._onOKClick.bind(this));
+ this._attachEvent(this.$dtpElement.find('a.dtp-select-month-before'), 'click', this._onMonthBeforeClick.bind(this));
+ this._attachEvent(this.$dtpElement.find('a.dtp-select-month-after'), 'click', this._onMonthAfterClick.bind(this));
+ this._attachEvent(this.$dtpElement.find('a.dtp-select-year-before'), 'click', this._onYearBeforeClick.bind(this));
+ this._attachEvent(this.$dtpElement.find('a.dtp-select-year-after'), 'click', this._onYearAfterClick.bind(this));
},
initMeridienButtons: function()
{
@@ -273,13 +294,6 @@
this.$dtpElement.find('.dtp-picker-datetime').addClass('hidden');
var _date = ((typeof(this.currentDate) !== 'undefined' && this.currentDate !== null) ? this.currentDate : null);
- if(this.$element.val().length > 0)
- {
- _date = moment(this.$element.val(), this.params.format).locale(this.params.lang);
- }
-
- this.showDate(_date);
-
var _calendar = this.generateCalendar(this.currentDate);
if(typeof(_calendar.week) !== 'undefined' && typeof(_calendar.days) !== 'undefined')
@@ -289,24 +303,37 @@
this.$dtpElement.find('a.dtp-select-day').off('click');
this.$dtpElement.find('.dtp-picker-calendar').html(_template);
- if(typeof($.material) !== 'undefined')
- {
- $.material.init();
- }
-
this.$dtpElement.find('a.dtp-select-day').on('click', this._onSelectDate.bind(this));
this.toggleButtons(_date);
}
+
+ this._centerBox();
+ this.showDate(_date);
},
initHours: function()
{
this.currentView = 1;
- this.showTime(this.currentDate);
+ if(!this.params.date)
+ {
+ var w = this.$dtpElement.find('.dtp-content').width();
+
+ var ml = this.$dtpElement.find('.dtp-picker-clock').css('marginLeft').replace('px', '');
+ var mr = this.$dtpElement.find('.dtp-picker-clock').css('marginRight').replace('px', '');
+
+ var pl = this.$dtpElement.find('.dtp-picker').css('paddingLeft').replace('px', '');
+ var pr = this.$dtpElement.find('.dtp-picker').css('paddingRight').replace('px', '');
+
+ this.$dtpElement.find('.dtp-picker-clock').innerWidth(w - (parseInt(ml) + parseInt(mr) + parseInt(pl) + parseInt(pr)));
+ }
+ this.showTime(this.currentDate);
this.initMeridienButtons();
+ this.$dtpElement.find('.dtp-picker-datetime').removeClass('hidden');
+ this.$dtpElement.find('.dtp-picker-calendar').addClass('hidden');
+
if(this.currentDate.hour() < 12)
{
this.$dtpElement.find('a.dtp-meridien-am').click();
@@ -316,11 +343,13 @@
this.$dtpElement.find('a.dtp-meridien-pm').click();
}
- this.$dtpElement.find('.dtp-picker-calendar').addClass('hidden');
- this.$dtpElement.find('.dtp-picker-datetime').removeClass('hidden');
+ var pL = this.$dtpElement.find('.dtp-picker-clock').parent().parent().css('paddingLeft').replace('px', '');
+ var pT = this.$dtpElement.find('.dtp-picker-clock').parent().parent().css('paddingTop').replace('px', '');
+ var mL = this.$dtpElement.find('.dtp-picker-clock').css('marginLeft').replace('px', '');
+ var mT = this.$dtpElement.find('.dtp-picker-clock').css('marginTop').replace('px', '');
- var r = this.$dtpElement.find('.dtp-picker-clock').innerWidth() / 2;
- var j = r - 25;
+ var r = (this.$dtpElement.find('.dtp-picker-clock').innerWidth() / 2);
+ var j = r / 1.2;
var hours = [];
@@ -332,11 +361,12 @@
var hour = $('