update to bootstrap-datepicker 1.0.2
This commit is contained in:
parent
ccdd4c5746
commit
09aab3cfdd
@ -4,6 +4,7 @@ X-editable changelog
|
|||||||
|
|
||||||
Version 1.4.4 wip
|
Version 1.4.4 wip
|
||||||
----------------------------
|
----------------------------
|
||||||
|
[enh] update to bootstrap-datepicker 1.0.2 (vitalets)
|
||||||
[enh] update to combodate 1.0.3 with yearDescending and roundTime options (vitalets)
|
[enh] update to combodate 1.0.3 with yearDescending and roundTime options (vitalets)
|
||||||
[enh] add 'use strict' directive (vitalets)
|
[enh] add 'use strict' directive (vitalets)
|
||||||
[enh #202] allow pk=0 (mdeweerd)
|
[enh #202] allow pk=0 (mdeweerd)
|
||||||
|
@ -54,24 +54,30 @@ Applied as jQuery method.
|
|||||||
var $target = $(e.target), i,
|
var $target = $(e.target), i,
|
||||||
exclude_classes = ['.editable-container',
|
exclude_classes = ['.editable-container',
|
||||||
'.ui-datepicker-header',
|
'.ui-datepicker-header',
|
||||||
|
'.datepicker', //in inline mode datepicker is rendered into body
|
||||||
'.modal-backdrop',
|
'.modal-backdrop',
|
||||||
'.bootstrap-wysihtml5-insert-image-modal',
|
'.bootstrap-wysihtml5-insert-image-modal',
|
||||||
'.bootstrap-wysihtml5-insert-link-modal'
|
'.bootstrap-wysihtml5-insert-link-modal'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
//check if element is detached. It occurs when clicking in bootstrap datepicker
|
||||||
|
if (!$.contains(document.documentElement, e.target)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//for some reason FF 20 generates extra event (click) in select2 widget with e.target = document
|
||||||
|
//we need to filter it via construction below. See https://github.com/vitalets/x-editable/issues/199
|
||||||
|
//Possibly related to http://stackoverflow.com/questions/10119793/why-does-firefox-react-differently-from-webkit-and-ie-to-click-event-on-selec
|
||||||
|
if($target.is(document)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
//if click inside one of exclude classes --> no nothing
|
//if click inside one of exclude classes --> no nothing
|
||||||
for(i=0; i<exclude_classes.length; i++) {
|
for(i=0; i<exclude_classes.length; i++) {
|
||||||
if($target.is(exclude_classes[i]) || $target.parents(exclude_classes[i]).length) {
|
if($target.is(exclude_classes[i]) || $target.parents(exclude_classes[i]).length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//for some reason FF 20 generates extra event (click) in select2 widget with e.target = document
|
|
||||||
//we need to filter it via construction below. See https://github.com/vitalets/x-editable/issues/199
|
|
||||||
//Possibly related to http://stackoverflow.com/questions/10119793/why-does-firefox-react-differently-from-webkit-and-ie-to-click-event-on-selec
|
|
||||||
if($target.is(document)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//close all open containers (except one - target)
|
//close all open containers (except one - target)
|
||||||
Popup.prototype.closeOthers(e.target);
|
Popup.prototype.closeOthers(e.target);
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
*/
|
*/
|
||||||
.datepicker {
|
.datepicker {
|
||||||
padding: 4px;
|
padding: 4px;
|
||||||
margin-top: 1px;
|
|
||||||
-webkit-border-radius: 4px;
|
-webkit-border-radius: 4px;
|
||||||
-moz-border-radius: 4px;
|
-moz-border-radius: 4px;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
@ -112,6 +111,7 @@
|
|||||||
border-color: #fdf59a #fdf59a #fbed50;
|
border-color: #fdf59a #fdf59a #fbed50;
|
||||||
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
|
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
|
||||||
filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
|
filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
|
||||||
|
color: #000 !important;
|
||||||
}
|
}
|
||||||
.datepicker table tr td.today:hover,
|
.datepicker table tr td.today:hover,
|
||||||
.datepicker table tr td.today:hover:hover,
|
.datepicker table tr td.today:hover:hover,
|
||||||
|
@ -41,13 +41,11 @@
|
|||||||
this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||dates[this.language].format||'mm/dd/yyyy');
|
this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||dates[this.language].format||'mm/dd/yyyy');
|
||||||
this.isInline = false;
|
this.isInline = false;
|
||||||
this.isInput = this.element.is('input');
|
this.isInput = this.element.is('input');
|
||||||
this.component = this.element.is('.date') ? this.element.find('.add-on') : false;
|
this.component = this.element.is('.date') ? this.element.find('.add-on, .btn') : false;
|
||||||
this.hasInput = this.component && this.element.find('input').length;
|
this.hasInput = this.component && this.element.find('input').length;
|
||||||
if(this.component && this.component.length === 0)
|
if(this.component && this.component.length === 0)
|
||||||
this.component = false;
|
this.component = false;
|
||||||
|
|
||||||
this._attachEvents();
|
|
||||||
|
|
||||||
this.forceParse = true;
|
this.forceParse = true;
|
||||||
if ('forceParse' in options) {
|
if ('forceParse' in options) {
|
||||||
this.forceParse = options.forceParse;
|
this.forceParse = options.forceParse;
|
||||||
@ -55,16 +53,12 @@
|
|||||||
this.forceParse = this.element.data('date-force-parse');
|
this.forceParse = this.element.data('date-force-parse');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.picker = $(DPGlobal.template);
|
||||||
this.picker = $(DPGlobal.template)
|
this._buildEvents();
|
||||||
.appendTo(this.isInline ? this.element : 'body')
|
this._attachEvents();
|
||||||
.on({
|
|
||||||
click: $.proxy(this.click, this),
|
|
||||||
mousedown: $.proxy(this.mousedown, this)
|
|
||||||
});
|
|
||||||
|
|
||||||
if(this.isInline) {
|
if(this.isInline) {
|
||||||
this.picker.addClass('datepicker-inline');
|
this.picker.addClass('datepicker-inline').appendTo(this.element);
|
||||||
} else {
|
} else {
|
||||||
this.picker.addClass('datepicker-dropdown dropdown-menu');
|
this.picker.addClass('datepicker-dropdown dropdown-menu');
|
||||||
}
|
}
|
||||||
@ -73,12 +67,6 @@
|
|||||||
this.picker.find('.prev i, .next i')
|
this.picker.find('.prev i, .next i')
|
||||||
.toggleClass('icon-arrow-left icon-arrow-right');
|
.toggleClass('icon-arrow-left icon-arrow-right');
|
||||||
}
|
}
|
||||||
$(document).on('mousedown', function (e) {
|
|
||||||
// Clicked outside the datepicker, hide it
|
|
||||||
if ($(e.target).closest('.datepicker.datepicker-inline, .datepicker.datepicker-dropdown').length === 0) {
|
|
||||||
that.hide();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.autoclose = false;
|
this.autoclose = false;
|
||||||
if ('autoclose' in options) {
|
if ('autoclose' in options) {
|
||||||
@ -138,6 +126,8 @@
|
|||||||
return parseInt(val) + 1;
|
return parseInt(val) + 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this._allow_update = false;
|
||||||
|
|
||||||
this.weekStart = ((options.weekStart||this.element.data('date-weekstart')||dates[this.language].weekStart||0) % 7);
|
this.weekStart = ((options.weekStart||this.element.data('date-weekstart')||dates[this.language].weekStart||0) % 7);
|
||||||
this.weekEnd = ((this.weekStart + 6) % 7);
|
this.weekEnd = ((this.weekStart + 6) % 7);
|
||||||
this.startDate = -Infinity;
|
this.startDate = -Infinity;
|
||||||
@ -148,6 +138,9 @@
|
|||||||
this.setDaysOfWeekDisabled(options.daysOfWeekDisabled||this.element.data('date-days-of-week-disabled'));
|
this.setDaysOfWeekDisabled(options.daysOfWeekDisabled||this.element.data('date-days-of-week-disabled'));
|
||||||
this.fillDow();
|
this.fillDow();
|
||||||
this.fillMonths();
|
this.fillMonths();
|
||||||
|
|
||||||
|
this._allow_update = true;
|
||||||
|
|
||||||
this.update();
|
this.update();
|
||||||
this.showMode();
|
this.showMode();
|
||||||
|
|
||||||
@ -160,8 +153,22 @@
|
|||||||
constructor: Datepicker,
|
constructor: Datepicker,
|
||||||
|
|
||||||
_events: [],
|
_events: [],
|
||||||
_attachEvents: function(){
|
_secondaryEvents: [],
|
||||||
this._detachEvents();
|
_applyEvents: function(evs){
|
||||||
|
for (var i=0, el, ev; i<evs.length; i++){
|
||||||
|
el = evs[i][0];
|
||||||
|
ev = evs[i][1];
|
||||||
|
el.on(ev);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_unapplyEvents: function(evs){
|
||||||
|
for (var i=0, el, ev; i<evs.length; i++){
|
||||||
|
el = evs[i][0];
|
||||||
|
ev = evs[i][1];
|
||||||
|
el.off(ev);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_buildEvents: function(){
|
||||||
if (this.isInput) { // single input
|
if (this.isInput) { // single input
|
||||||
this._events = [
|
this._events = [
|
||||||
[this.element, {
|
[this.element, {
|
||||||
@ -184,9 +191,9 @@
|
|||||||
}]
|
}]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
else if (this.element.is('div')) { // inline datepicker
|
else if (this.element.is('div')) { // inline datepicker
|
||||||
this.isInline = true;
|
this.isInline = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this._events = [
|
this._events = [
|
||||||
[this.element, {
|
[this.element, {
|
||||||
@ -194,29 +201,47 @@
|
|||||||
}]
|
}]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
for (var i=0, el, ev; i<this._events.length; i++){
|
|
||||||
el = this._events[i][0];
|
this._secondaryEvents = [
|
||||||
ev = this._events[i][1];
|
[this.picker, {
|
||||||
el.on(ev);
|
click: $.proxy(this.click, this)
|
||||||
}
|
}],
|
||||||
|
[$(window), {
|
||||||
|
resize: $.proxy(this.place, this)
|
||||||
|
}],
|
||||||
|
[$(document), {
|
||||||
|
mousedown: $.proxy(function (e) {
|
||||||
|
// Clicked outside the datepicker, hide it
|
||||||
|
if ($(e.target).closest('.datepicker.datepicker-inline, .datepicker.datepicker-dropdown').length === 0) {
|
||||||
|
this.hide();
|
||||||
|
}
|
||||||
|
}, this)
|
||||||
|
}]
|
||||||
|
];
|
||||||
|
},
|
||||||
|
_attachEvents: function(){
|
||||||
|
this._detachEvents();
|
||||||
|
this._applyEvents(this._events);
|
||||||
},
|
},
|
||||||
_detachEvents: function(){
|
_detachEvents: function(){
|
||||||
for (var i=0, el, ev; i<this._events.length; i++){
|
this._unapplyEvents(this._events);
|
||||||
el = this._events[i][0];
|
},
|
||||||
ev = this._events[i][1];
|
_attachSecondaryEvents: function(){
|
||||||
el.off(ev);
|
this._detachSecondaryEvents();
|
||||||
}
|
this._applyEvents(this._secondaryEvents);
|
||||||
this._events = [];
|
},
|
||||||
|
_detachSecondaryEvents: function(){
|
||||||
|
this._unapplyEvents(this._secondaryEvents);
|
||||||
},
|
},
|
||||||
|
|
||||||
show: function(e) {
|
show: function(e) {
|
||||||
|
if (!this.isInline)
|
||||||
|
this.picker.appendTo('body');
|
||||||
this.picker.show();
|
this.picker.show();
|
||||||
this.height = this.component ? this.component.outerHeight() : this.element.outerHeight();
|
this.height = this.component ? this.component.outerHeight() : this.element.outerHeight();
|
||||||
this.update();
|
|
||||||
this.place();
|
this.place();
|
||||||
$(window).on('resize', $.proxy(this.place, this));
|
this._attachSecondaryEvents();
|
||||||
if (e ) {
|
if (e) {
|
||||||
e.stopPropagation();
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}
|
}
|
||||||
this.element.trigger({
|
this.element.trigger({
|
||||||
@ -228,13 +253,10 @@
|
|||||||
hide: function(e){
|
hide: function(e){
|
||||||
if(this.isInline) return;
|
if(this.isInline) return;
|
||||||
if (!this.picker.is(':visible')) return;
|
if (!this.picker.is(':visible')) return;
|
||||||
this.picker.hide();
|
this.picker.hide().detach();
|
||||||
$(window).off('resize', this.place);
|
this._detachSecondaryEvents();
|
||||||
this.viewMode = this.startViewMode;
|
this.viewMode = this.startViewMode;
|
||||||
this.showMode();
|
this.showMode();
|
||||||
if (!this.isInput) {
|
|
||||||
$(document).off('mousedown', this.hide);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.forceParse &&
|
this.forceParse &&
|
||||||
@ -251,9 +273,14 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
remove: function() {
|
remove: function() {
|
||||||
|
this.hide();
|
||||||
this._detachEvents();
|
this._detachEvents();
|
||||||
|
this._detachSecondaryEvents();
|
||||||
this.picker.remove();
|
this.picker.remove();
|
||||||
delete this.element.data().datepicker;
|
delete this.element.data().datepicker;
|
||||||
|
if (!this.isInput) {
|
||||||
|
delete this.element.data().date;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
getDate: function() {
|
getDate: function() {
|
||||||
@ -327,7 +354,7 @@
|
|||||||
var zIndex = parseInt(this.element.parents().filter(function() {
|
var zIndex = parseInt(this.element.parents().filter(function() {
|
||||||
return $(this).css('z-index') != 'auto';
|
return $(this).css('z-index') != 'auto';
|
||||||
}).first().css('z-index'))+10;
|
}).first().css('z-index'))+10;
|
||||||
var offset = this.component ? this.component.offset() : this.element.offset();
|
var offset = this.component ? this.component.parent().offset() : this.element.offset();
|
||||||
var height = this.component ? this.component.outerHeight(true) : this.element.outerHeight(true);
|
var height = this.component ? this.component.outerHeight(true) : this.element.outerHeight(true);
|
||||||
this.picker.css({
|
this.picker.css({
|
||||||
top: offset.top + height,
|
top: offset.top + height,
|
||||||
@ -336,7 +363,10 @@
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_allow_update: true,
|
||||||
update: function(){
|
update: function(){
|
||||||
|
if (!this._allow_update) return;
|
||||||
|
|
||||||
var date, fromArgs = false;
|
var date, fromArgs = false;
|
||||||
if(arguments && arguments.length && (typeof arguments[0] === 'string' || arguments[0] instanceof Date)) {
|
if(arguments && arguments.length && (typeof arguments[0] === 'string' || arguments[0] instanceof Date)) {
|
||||||
date = arguments[0];
|
date = arguments[0];
|
||||||
@ -491,6 +521,8 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
updateNavArrows: function() {
|
updateNavArrows: function() {
|
||||||
|
if (!this._allow_update) return;
|
||||||
|
|
||||||
var d = new Date(this.viewDate),
|
var d = new Date(this.viewDate),
|
||||||
year = d.getUTCFullYear(),
|
year = d.getUTCFullYear(),
|
||||||
month = d.getUTCMonth();
|
month = d.getUTCMonth();
|
||||||
@ -524,7 +556,6 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
click: function(e) {
|
click: function(e) {
|
||||||
e.stopPropagation();
|
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var target = $(e.target).closest('span, td, th');
|
var target = $(e.target).closest('span, td, th');
|
||||||
if (target.length == 1) {
|
if (target.length == 1) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user