Switch to stable 1.4.0 bootstrap-datepicker

master
Daniel Berteaud 9 years ago
parent c7fc40b2f3
commit fe5b1766c2
  1. 206
      public/js/bootstrap-datepicker.js

@ -1,34 +1,10 @@
/* ========================================================= /*!
* bootstrap-datepicker.js * Datepicker for Bootstrap v1.4.0 (https://github.com/eternicode/bootstrap-datepicker)
* Repo: https://github.com/eternicode/bootstrap-datepicker/
* Demo: http://eternicode.github.io/bootstrap-datepicker/
* Docs: http://bootstrap-datepicker.readthedocs.org/
* Forked from http://www.eyecon.ro/bootstrap-datepicker
* =========================================================
* Started by Stefan Petre; improvements by Andrew Rowls + contributors
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Copyright 2012 Stefan Petre
* you may not use this file except in compliance with the License. * Improvements by Andrew Rowls
* You may obtain a copy of the License at * Licensed under the Apache License v2.0 (http://www.apache.org/licenses/LICENSE-2.0)
* */(function($, undefined){
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ========================================================= */
(function(factory){
if (typeof define === "function" && define.amd) {
define(["jquery"], factory);
} else if (typeof exports === 'object') {
factory(require('jquery'));
} else {
factory(jQuery);
}
}(function($, undefined){
function UTCDate(){ function UTCDate(){
return new Date(Date.UTC.apply(Date, arguments)); return new Date(Date.UTC.apply(Date, arguments));
@ -139,7 +115,6 @@
this.setStartDate(this._o.startDate); this.setStartDate(this._o.startDate);
this.setEndDate(this._o.endDate); this.setEndDate(this._o.endDate);
this.setDaysOfWeekDisabled(this.o.daysOfWeekDisabled); this.setDaysOfWeekDisabled(this.o.daysOfWeekDisabled);
this.setDaysOfWeekHighlighted(this.o.daysOfWeekHighlighted);
this.setDatesDisabled(this.o.datesDisabled); this.setDatesDisabled(this.o.datesDisabled);
this.fillDow(); this.fillDow();
@ -200,20 +175,6 @@
o.minViewMode = 0; o.minViewMode = 0;
} }
switch (o.maxViewMode) {
case 0:
case 'days':
o.maxViewMode = 0;
break;
case 1:
case 'months':
o.maxViewMode = 1;
break;
default:
o.maxViewMode = 2;
}
o.startView = Math.min(o.startView, o.maxViewMode);
o.startView = Math.max(o.startView, o.minViewMode); o.startView = Math.max(o.startView, o.minViewMode);
// true, false, or Number > 0 // true, false, or Number > 0
@ -258,13 +219,6 @@
return parseInt(d, 10); return parseInt(d, 10);
}); });
o.daysOfWeekHighlighted = o.daysOfWeekHighlighted||[];
if (!$.isArray(o.daysOfWeekHighlighted))
o.daysOfWeekHighlighted = o.daysOfWeekHighlighted.split(/[,\s]*/);
o.daysOfWeekHighlighted = $.map(o.daysOfWeekHighlighted, function(d){
return parseInt(d, 10);
});
o.datesDisabled = o.datesDisabled||[]; o.datesDisabled = o.datesDisabled||[];
if (!$.isArray(o.datesDisabled)) { if (!$.isArray(o.datesDisabled)) {
var datesDisabled = []; var datesDisabled = [];
@ -352,8 +306,7 @@
if ($.inArray(e.keyCode, [27, 37, 39, 38, 40, 32, 13, 9]) === -1) if ($.inArray(e.keyCode, [27, 37, 39, 38, 40, 32, 13, 9]) === -1)
this.update(); this.update();
}, this), }, this),
keydown: $.proxy(this.keydown, this), keydown: $.proxy(this.keydown, this)
paste: $.proxy(this.paste, this)
}; };
if (this.o.showOnFocus === true) { if (this.o.showOnFocus === true) {
@ -399,15 +352,6 @@
}] }]
); );
if (this.o.immediateUpdates) {
// Trigger input updates immediately on changed year/month
this._events.push([this.element, {
'changeYear changeMonth': $.proxy(function(e){
this.update(e.date);
}, this)
}]);
}
this._secondaryEvents = [ this._secondaryEvents = [
[this.picker, { [this.picker, {
click: $.proxy(this.click, this) click: $.proxy(this.click, this)
@ -416,17 +360,15 @@
resize: $.proxy(this.place, this) resize: $.proxy(this.place, this)
}], }],
[$(document), { [$(document), {
mousedown: $.proxy(function(e){ 'mousedown touchstart': $.proxy(function(e){
// Clicked outside the datepicker, hide it // Clicked outside the datepicker, hide it
if (!( if (!(
this.element.is(e.target) || this.element.is(e.target) ||
this.element.find(e.target).length || this.element.find(e.target).length ||
this.picker.is(e.target) || this.picker.is(e.target) ||
this.picker.find(e.target).length || this.picker.find(e.target).length
this.picker.hasClass('datepicker-inline')
)){ )){
$(this.picker).hide(); this.hide();
this._trigger('hide');
} }
}, this) }, this)
}] }]
@ -520,23 +462,6 @@
return this; return this;
}, },
paste: function(evt){
var dateString;
if (evt.originalEvent.clipboardData && evt.originalEvent.clipboardData.types
&& $.inArray('text/plain', evt.originalEvent.clipboardData.types) !== -1) {
dateString = evt.originalEvent.clipboardData.getData('text/plain');
}
else if (window.clipboardData) {
dateString = window.clipboardData.getData('Text');
}
else {
return;
}
this.setDate(dateString);
this.update();
evt.preventDefault();
},
_utc_to_local: function(utc){ _utc_to_local: function(utc){
return utc && new Date(utc.getTime() + (utc.getTimezoneOffset()*60000)); return utc && new Date(utc.getTime() + (utc.getTimezoneOffset()*60000));
}, },
@ -582,7 +507,7 @@
} }
if (element) { if (element) {
element.val(''); element.val('').change();
} }
this.update(); this.update();
@ -615,11 +540,11 @@
var formatted = this.getFormattedDate(); var formatted = this.getFormattedDate();
if (!this.isInput){ if (!this.isInput){
if (this.component){ if (this.component){
this.element.find('input').val(formatted); this.element.find('input').val(formatted).change();
} }
} }
else { else {
this.element.val(formatted); this.element.val(formatted).change();
} }
return this; return this;
}, },
@ -655,12 +580,6 @@
return this; return this;
}, },
setDaysOfWeekHighlighted: function(daysOfWeekHighlighted){
this._process_options({daysOfWeekHighlighted: daysOfWeekHighlighted});
this.update();
return this;
},
setDatesDisabled: function(datesDisabled){ setDatesDisabled: function(datesDisabled){
this._process_options({datesDisabled: datesDisabled}); this._process_options({datesDisabled: datesDisabled});
this.update(); this.update();
@ -673,11 +592,10 @@
var calendarWidth = this.picker.outerWidth(), var calendarWidth = this.picker.outerWidth(),
calendarHeight = this.picker.outerHeight(), calendarHeight = this.picker.outerHeight(),
visualPadding = 10, visualPadding = 10,
container = $(this.o.container), windowWidth = $(this.o.container).width(),
windowWidth = container.width(), windowHeight = $(this.o.container).height(),
windowHeight = container.height(), scrollTop = $(this.o.container).scrollTop(),
scrollTop = container.scrollTop(), appendOffset = $(this.o.container).offset();
appendOffset = container.offset();
var parentsZindex = []; var parentsZindex = [];
this.element.parents().each(function(){ this.element.parents().each(function(){
@ -732,9 +650,9 @@
} }
this.picker.addClass('datepicker-orient-' + yorient); this.picker.addClass('datepicker-orient-' + yorient);
if (yorient === 'top') if (yorient === 'top')
top -= calendarHeight + parseInt(this.picker.css('padding-top'));
else
top += height; top += height;
else
top -= calendarHeight + parseInt(this.picker.css('padding-top'));
if (this.o.rtl) { if (this.o.rtl) {
var right = windowWidth - (left + width); var right = windowWidth - (left + width);
@ -798,8 +716,6 @@
this.viewDate = new Date(this.o.startDate); this.viewDate = new Date(this.o.startDate);
else if (this.viewDate > this.o.endDate) else if (this.viewDate > this.o.endDate)
this.viewDate = new Date(this.o.endDate); this.viewDate = new Date(this.o.endDate);
else
this.viewDate = this.o.defaultViewDate;
if (fromArgs){ if (fromArgs){
// setting date by clicking // setting date by clicking
@ -814,7 +730,6 @@
this._trigger('clearDate'); this._trigger('clearDate');
this.fill(); this.fill();
this.element.change();
return this; return this;
}, },
@ -822,11 +737,12 @@
var dowCnt = this.o.weekStart, var dowCnt = this.o.weekStart,
html = '<tr>'; html = '<tr>';
if (this.o.calendarWeeks){ if (this.o.calendarWeeks){
this.picker.find('.datepicker-days .datepicker-switch') this.picker.find('.datepicker-days thead tr:first-child .datepicker-switch')
.attr('colspan', function(i, val){ .attr('colspan', function(i, val){
return parseInt(val) + 1; return parseInt(val) + 1;
}); });
html += '<th class="cw">&#160;</th>'; var cell = '<th class="cw">&#160;</th>';
html += cell;
} }
while (dowCnt < this.o.weekStart + 7){ while (dowCnt < this.o.weekStart + 7){
html += '<th class="dow">'+dates[this.o.language].daysMin[(dowCnt++)%7]+'</th>'; html += '<th class="dow">'+dates[this.o.language].daysMin[(dowCnt++)%7]+'</th>';
@ -880,10 +796,6 @@
$.inArray(date.getUTCDay(), this.o.daysOfWeekDisabled) !== -1){ $.inArray(date.getUTCDay(), this.o.daysOfWeekDisabled) !== -1){
cls.push('disabled'); cls.push('disabled');
} }
if (date.valueOf() < this.o.startDate || date.valueOf() > this.o.endDate ||
$.inArray(date.getUTCDay(), this.o.daysOfWeekHighlighted) !== -1){
cls.push('highlighted');
}
if (this.o.datesDisabled.length > 0 && if (this.o.datesDisabled.length > 0 &&
$.grep(this.o.datesDisabled, function(d){ $.grep(this.o.datesDisabled, function(d){
return isUTCEquals(date, d); }).length > 0) { return isUTCEquals(date, d); }).length > 0) {
@ -911,21 +823,17 @@
endMonth = this.o.endDate !== Infinity ? this.o.endDate.getUTCMonth() : Infinity, endMonth = this.o.endDate !== Infinity ? this.o.endDate.getUTCMonth() : Infinity,
todaytxt = dates[this.o.language].today || dates['en'].today || '', todaytxt = dates[this.o.language].today || dates['en'].today || '',
cleartxt = dates[this.o.language].clear || dates['en'].clear || '', cleartxt = dates[this.o.language].clear || dates['en'].clear || '',
titleFormat = dates[this.o.language].titleFormat || dates['en'].titleFormat,
tooltip; tooltip;
if (isNaN(year) || isNaN(month)) if (isNaN(year) || isNaN(month))
return; return;
this.picker.find('.datepicker-days thead .datepicker-switch') this.picker.find('.datepicker-days thead .datepicker-switch')
.text(DPGlobal.formatDate(new Date(year, month), titleFormat, this.o.language)); .text(dates[this.o.language].months[month]+' '+year);
this.picker.find('tfoot .today') this.picker.find('tfoot .today')
.text(todaytxt) .text(todaytxt)
.toggle(this.o.todayBtn !== false); .toggle(this.o.todayBtn !== false);
this.picker.find('tfoot .clear') this.picker.find('tfoot .clear')
.text(cleartxt) .text(cleartxt)
.toggle(this.o.clearBtn !== false); .toggle(this.o.clearBtn !== false);
this.picker.find('thead .datepicker-title')
.text(this.o.title)
.toggle(this.o.title !== '');
this.updateNavArrows(); this.updateNavArrows();
this.fillMonths(); this.fillMonths();
var prevMonth = UTCDate(year, month-1, 28), var prevMonth = UTCDate(year, month-1, 28),
@ -986,8 +894,8 @@
this.picker.find('.datepicker-days tbody').empty().append(html.join('')); this.picker.find('.datepicker-days tbody').empty().append(html.join(''));
var months = this.picker.find('.datepicker-months') var months = this.picker.find('.datepicker-months')
.find('.datepicker-switch') .find('th:eq(1)')
.text(this.o.maxViewMode < 2 ? 'Months' : year) .text(year)
.end() .end()
.find('span').removeClass('active'); .find('span').removeClass('active');
@ -1021,7 +929,7 @@
html = ''; html = '';
year = parseInt(year/10, 10) * 10; year = parseInt(year/10, 10) * 10;
var yearCont = this.picker.find('.datepicker-years') var yearCont = this.picker.find('.datepicker-years')
.find('.datepicker-switch') .find('th:eq(1)')
.text(year + '-' + (year + 9)) .text(year + '-' + (year + 9))
.end() .end()
.find('td'); .find('td');
@ -1032,8 +940,6 @@
classes; classes;
for (var i = -1; i < 11; i++){ for (var i = -1; i < 11; i++){
classes = ['year']; classes = ['year'];
tooltip = null;
if (i === -1) if (i === -1)
classes.push('old'); classes.push('old');
else if (i === 10) else if (i === 10)
@ -1042,24 +948,7 @@
classes.push('active'); classes.push('active');
if (year < startYear || year > endYear) if (year < startYear || year > endYear)
classes.push('disabled'); classes.push('disabled');
html += '<span class="' + classes.join(' ') + '">' + year + '</span>';
if (this.o.beforeShowYear !== $.noop) {
var yrBefore = this.o.beforeShowYear(new Date(year, 0, 1));
if (yrBefore === undefined)
yrBefore = {};
else if (typeof(yrBefore) === 'boolean')
yrBefore = {enabled: yrBefore};
else if (typeof(yrBefore) === 'string')
yrBefore = {classes: yrBefore};
if (yrBefore.enabled === false)
classes.push('disabled');
if (yrBefore.classes)
classes = classes.concat(yrBefore.classes.split(/\s+/));
if (yrBefore.tooltip)
tooltip = yrBefore.tooltip;
}
html += '<span class="' + classes.join(' ') + '"' + (tooltip ? ' title="'+tooltip+'"' : '') + '>' + year + '</span>';
year += 1; year += 1;
} }
yearCont.html(html); yearCont.html(html);
@ -1089,13 +978,13 @@
break; break;
case 1: case 1:
case 2: case 2:
if (this.o.startDate !== -Infinity && year <= this.o.startDate.getUTCFullYear() || this.o.maxViewMode < 2){ if (this.o.startDate !== -Infinity && year <= this.o.startDate.getUTCFullYear()){
this.picker.find('.prev').css({visibility: 'hidden'}); this.picker.find('.prev').css({visibility: 'hidden'});
} }
else { else {
this.picker.find('.prev').css({visibility: 'visible'}); this.picker.find('.prev').css({visibility: 'visible'});
} }
if (this.o.endDate !== Infinity && year >= this.o.endDate.getUTCFullYear() || this.o.maxViewMode < 2){ if (this.o.endDate !== Infinity && year >= this.o.endDate.getUTCFullYear()){
this.picker.find('.next').css({visibility: 'hidden'}); this.picker.find('.next').css({visibility: 'hidden'});
} }
else { else {
@ -1107,7 +996,6 @@
click: function(e){ click: function(e){
e.preventDefault(); e.preventDefault();
e.stopPropagation();
var target = $(e.target).closest('span, td, th'), var target = $(e.target).closest('span, td, th'),
year, month, day; year, month, day;
if (target.length === 1){ if (target.length === 1){
@ -1158,9 +1046,6 @@
this._trigger('changeMonth', this.viewDate); this._trigger('changeMonth', this.viewDate);
if (this.o.minViewMode === 1){ if (this.o.minViewMode === 1){
this._setDate(UTCDate(year, month, day)); this._setDate(UTCDate(year, month, day));
this.showMode();
} else {
this.showMode(-1);
} }
} }
else { else {
@ -1172,8 +1057,8 @@
if (this.o.minViewMode === 2){ if (this.o.minViewMode === 2){
this._setDate(UTCDate(year, month, day)); this._setDate(UTCDate(year, month, day));
} }
this.showMode(-1);
} }
this.showMode(-1);
this.fill(); this.fill();
} }
break; break;
@ -1320,7 +1205,7 @@
keydown: function(e){ keydown: function(e){
if (!this.picker.is(':visible')){ if (!this.picker.is(':visible')){
if (e.keyCode === 40 || e.keyCode === 27) // allow down to re-show picker if (e.keyCode === 27) // allow escape to hide and re-show picker
this.show(); this.show();
return; return;
} }
@ -1446,13 +1331,13 @@
showMode: function(dir){ showMode: function(dir){
if (dir){ if (dir){
this.viewMode = Math.max(this.o.minViewMode, Math.min(this.o.maxViewMode, this.viewMode + dir)); this.viewMode = Math.max(this.o.minViewMode, Math.min(2, this.viewMode + dir));
} }
this.picker this.picker
.children('div') .children('div')
.hide() .hide()
.filter('.datepicker-' + DPGlobal.modes[this.viewMode].clsName) .filter('.datepicker-' + DPGlobal.modes[this.viewMode].clsName)
.show(); .css('display', 'block');
this.updateNavArrows(); this.updateNavArrows();
} }
}; };
@ -1465,7 +1350,7 @@
delete options.inputs; delete options.inputs;
datepickerPlugin.call($(this.inputs), options) datepickerPlugin.call($(this.inputs), options)
.on('changeDate', $.proxy(this.dateUpdated, this)); .bind('changeDate', $.proxy(this.dateUpdated, this));
this.pickers = $.map(this.inputs, function(i){ this.pickers = $.map(this.inputs, function(i){
return $(i).data('datepicker'); return $(i).data('datepicker');
@ -1609,12 +1494,10 @@
autoclose: false, autoclose: false,
beforeShowDay: $.noop, beforeShowDay: $.noop,
beforeShowMonth: $.noop, beforeShowMonth: $.noop,
beforeShowYear: $.noop,
calendarWeeks: false, calendarWeeks: false,
clearBtn: false, clearBtn: false,
toggleActive: false, toggleActive: false,
daysOfWeekDisabled: [], daysOfWeekDisabled: [],
daysOfWeekHighlighted: [],
datesDisabled: [], datesDisabled: [],
endDate: Infinity, endDate: Infinity,
forceParse: true, forceParse: true,
@ -1622,7 +1505,6 @@
keyboardNavigation: true, keyboardNavigation: true,
language: 'en', language: 'en',
minViewMode: 0, minViewMode: 0,
maxViewMode: 2,
multidate: false, multidate: false,
multidateSeparator: ',', multidateSeparator: ',',
orientation: "auto", orientation: "auto",
@ -1634,9 +1516,7 @@
weekStart: 0, weekStart: 0,
disableTouchKeyboard: false, disableTouchKeyboard: false,
enableOnReadonly: true, enableOnReadonly: true,
container: 'body', container: 'body'
immediateUpdates: false,
title: ''
}; };
var locale_opts = $.fn.datepicker.locale_opts = [ var locale_opts = $.fn.datepicker.locale_opts = [
'format', 'format',
@ -1646,14 +1526,13 @@
$.fn.datepicker.Constructor = Datepicker; $.fn.datepicker.Constructor = Datepicker;
var dates = $.fn.datepicker.dates = { var dates = $.fn.datepicker.dates = {
en: { en: {
days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], daysShort: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"], daysMin: ["Su", "Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"],
months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"], monthsShort: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
today: "Today", today: "Today",
clear: "Clear", clear: "Clear"
titleFormat: "MM yyyy"
} }
}; };
@ -1827,9 +1706,6 @@
}, },
headTemplate: '<thead>'+ headTemplate: '<thead>'+
'<tr>'+ '<tr>'+
'<th colspan="7" class="datepicker-title"></th>'+
'</tr>'+
'<tr>'+
'<th class="prev">&#171;</th>'+ '<th class="prev">&#171;</th>'+
'<th colspan="5" class="datepicker-switch"></th>'+ '<th colspan="5" class="datepicker-switch"></th>'+
'<th class="next">&#187;</th>'+ '<th class="next">&#187;</th>'+
@ -1882,7 +1758,7 @@
/* DATEPICKER VERSION /* DATEPICKER VERSION
* =================== */ * =================== */
$.fn.datepicker.version = "1.4.1-dev"; $.fn.datepicker.version = "1.4.0";
/* DATEPICKER DATA-API /* DATEPICKER DATA-API
* ================== */ * ================== */
@ -1903,4 +1779,4 @@
datepickerPlugin.call($('[data-provide="datepicker-inline"]')); datepickerPlugin.call($('[data-provide="datepicker-inline"]'));
}); });
})); }(window.jQuery));

Loading…
Cancel
Save