Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

datepair.js

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datepair.js - npm Package Compare versions

Comparing version 0.4.15 to 0.4.16

2

bower.json
{
"name": "datepair.js",
"version": "0.4.15",
"version": "0.4.16",
"main": ["dist/datepair.js", "dist/jquery.datepair.js"],

@@ -5,0 +5,0 @@ "ignore": [

/*!
* datepair.js v0.4.15 - A javascript plugin for intelligently selecting date and time ranges inspired by Google Calendar.
* Copyright (c) 2016 Jon Thornton - http://jonthornton.github.com/Datepair.js
* datepair.js v0.4.16 - A javascript plugin for intelligently selecting date and time ranges inspired by Google Calendar.
* Copyright (c) 2018 Jon Thornton - http://jonthornton.github.com/Datepair.js
* License: MIT

@@ -13,6 +13,6 @@ */

var jq = window.Zepto || window.jQuery;
function simpleExtend(obj1, obj2) {
var out = obj2 || {};
for (var i in obj1) {

@@ -23,6 +23,6 @@ if (!(i in out)) {

}
return out;
}
// IE's custom event support is totally borked.

@@ -39,3 +39,3 @@ // Use jQuery if possible

}
// el.classList not supported by < IE10

@@ -50,3 +50,3 @@ // use jQuery if available

}
function Datepair(container, options) {

@@ -63,3 +63,3 @@ this.dateDelta = null;

anchor: 'start',
// defaults for jquery-timepicker; override when using other input widgets

@@ -75,3 +75,3 @@ parseTime: function(input){

},
// defaults for bootstrap datepicker; override when using other input widgets

@@ -85,6 +85,6 @@ parseDate: function(input){

};
this.container = container;
this.settings = simpleExtend(this._defaults, options);
this.startDateInput = this.container.querySelector('.'+this.settings.startClass+'.'+this.settings.dateClass);

@@ -94,13 +94,13 @@ this.endDateInput = this.container.querySelector('.'+this.settings.endClass+'.'+this.settings.dateClass);

this.endTimeInput = this.container.querySelector('.'+this.settings.endClass+'.'+this.settings.timeClass);
// initialize date and time deltas
this.refresh();
// init starts here
this._bindChangeHandler();
}
Datepair.prototype = {
constructor: Datepair,
option: function(key, value)

@@ -110,13 +110,13 @@ {

this.settings = simpleExtend(this.settings, key);
} else if (typeof key == 'string' && typeof value != 'undefined') {
this.settings[key] = value;
} else if (typeof key == 'string') {
return this.settings[key];
}
this._updateEndMintime();
},
getTimeDiff: function()

@@ -130,6 +130,6 @@ {

}
return delta;
},
refresh: function()

@@ -153,3 +153,3 @@ {

},
remove: function()

@@ -159,3 +159,3 @@ {

},
_bindChangeHandler: function(){

@@ -171,3 +171,3 @@ // addEventListener doesn't work with synthetic "change" events

},
_unbindChangeHandler: function(){

@@ -180,3 +180,3 @@ if (jq) {

},
// This function will be called when passing 'this' to addEventListener

@@ -187,3 +187,3 @@ handleEvent: function(e){

this._unbindChangeHandler();
if (hasClass(e.target, this.settings.dateClass)) {

@@ -196,3 +196,3 @@ if (e.target.value != '') {

}
} else if (hasClass(e.target, this.settings.timeClass)) {

@@ -205,3 +205,3 @@ if (e.target.value != '') {

}
this._validateRanges();

@@ -211,3 +211,3 @@ this._updateEndMintime();

},
_dateChanged: function(target){

@@ -217,6 +217,6 @@ if (!this.startDateInput || !this.endDateInput) {

}
var startDate = this.settings.parseDate(this.startDateInput);
var endDate = this.settings.parseDate(this.endDateInput);
if (!startDate || !endDate) {

@@ -227,3 +227,3 @@ if (this.settings.defaultDateDelta !== null) {

this.settings.updateDate(this.endDateInput, newEnd);
} else if (endDate) {

@@ -233,3 +233,3 @@ var newStart = new Date(endDate.getTime() - this.settings.defaultDateDelta * _ONE_DAY);

}
this.dateDelta = this.settings.defaultDateDelta * _ONE_DAY;

@@ -239,6 +239,6 @@ } else {

}
return;
}
if (this.settings.anchor == 'start' && hasClass(target, this.settings.startClass)) {

@@ -261,3 +261,3 @@ var newDate = new Date(startDate.getTime() + this.dateDelta);

},
_timeChanged: function(target){

@@ -267,39 +267,33 @@ if (!this.startTimeInput || !this.endTimeInput) {

}
var startTime = this.settings.parseTime(this.startTimeInput);
var endTime = this.settings.parseTime(this.endTimeInput);
if (!startTime || !endTime) {
if (this.settings.defaultTimeDelta !== null) {
this.timeDelta = this.settings.defaultTimeDelta;
if (startTime) {
var newEnd = new Date(startTime.getTime() + this.settings.defaultTimeDelta);
this.settings.updateTime(this.endTimeInput, newEnd);
endTime = this._setTimeAndReturn(this.endTimeInput, new Date(startTime.getTime() + this.settings.defaultTimeDelta));
this._doMidnightRollover(startTime, endTime);
} else if (endTime) {
var newStart = new Date(endTime.getTime() - this.settings.defaultTimeDelta);
this.settings.updateTime(this.startTimeInput, newStart);
startTime = this._setTimeAndReturn(this.startTimeInput, new Date(endTime.getTime() - this.settings.defaultTimeDelta));
this._doMidnightRollover(startTime, endTime);
}
this.timeDelta = this.settings.defaultTimeDelta;
} else {
this.timeDelta = null;
}
return;
}
if (this.settings.anchor == 'start' && hasClass(target, this.settings.startClass)) {
var newTime = new Date(startTime.getTime() + this.timeDelta);
this.settings.updateTime(this.endTimeInput, newTime);
endTime = this.settings.parseTime(this.endTimeInput);
endTime = this._setTimeAndReturn(this.endTimeInput, new Date(startTime.getTime() + this.timeDelta));
this._doMidnightRollover(startTime, endTime);
} else if (this.settings.anchor == 'end' && hasClass(target, this.settings.endClass)) {
var newTime = new Date(endTime.getTime() - this.timeDelta);
this.settings.updateTime(this.startTimeInput, newTime);
startTime = this.settings.parseTime(this.startTimeInput);
startTime = this._setTimeAndReturn(this.startTimeInput, new Date(endTime.getTime() - this.timeDelta));
this._doMidnightRollover(startTime, endTime);
} else {
this._doMidnightRollover(startTime, endTime);
var startDate, endDate;

@@ -310,3 +304,3 @@ if (this.startDateInput && this.endDateInput) {

}
if ((+startDate == +endDate) && (endTime < startTime)) {

@@ -322,6 +316,11 @@ var thisInput = hasClass(target, this.settings.endClass) ? this.endTimeInput : this.startTimeInput;

}
},
_setTimeAndReturn: function(input, newTime) {
this.settings.updateTime(input, newTime);
return this.settings.parseTime(input);
},
_doMidnightRollover: function(startTime, endTime) {

@@ -331,3 +330,3 @@ if (!this.startDateInput || !this.endDateInput) {

}
var endDate = this.settings.parseDate(this.endDateInput);

@@ -337,3 +336,3 @@ var startDate = this.settings.parseDate(this.startDateInput);

var offset = (endTime < startTime) ? _ONE_DAY : -1 * _ONE_DAY;
if (this.dateDelta !== null

@@ -344,3 +343,3 @@ && this.dateDelta + this.timeDelta <= _ONE_DAY

&& ((newDelta >= 0 && this.timeDelta < 0) || (newDelta < 0 && this.timeDelta >= 0))) {
if (this.settings.anchor == 'start') {

@@ -356,6 +355,6 @@ this.settings.updateDate(this.endDateInput, new Date(endDate.getTime() + offset));

},
_updateEndMintime: function(){
if (typeof this.settings.setMinTime != 'function') return;
var baseTime = null;

@@ -365,6 +364,6 @@ if (this.settings.anchor == 'start' && (!this.dateDelta || this.dateDelta < _ONE_DAY || (this.timeDelta && this.dateDelta + this.timeDelta < _ONE_DAY))) {

}
this.settings.setMinTime(this.endTimeInput, baseTime);
},
_validateRanges: function(){

@@ -375,3 +374,3 @@ if (this.startTimeInput && this.endTimeInput && this.timeDelta === null) {

}
if (this.startDateInput && this.endDateInput && this.dateDelta === null) {

@@ -381,3 +380,3 @@ triggerSimpleCustomEvent(this.container, 'rangeIncomplete');

}
// due to the fact that times can wrap around, any time-only pair will be considered valid

@@ -394,2 +393,2 @@ if (!this.startDateInput || !this.endDateInput || this.dateDelta + this.timeDelta >= 0) {

}(window, document));
}(window, document));
/*!
* datepair.js v0.4.15 - A javascript plugin for intelligently selecting date and time ranges inspired by Google Calendar.
* Copyright (c) 2016 Jon Thornton - http://jonthornton.github.com/Datepair.js
* datepair.js v0.4.16 - A javascript plugin for intelligently selecting date and time ranges inspired by Google Calendar.
* Copyright (c) 2018 Jon Thornton - http://jonthornton.github.com/Datepair.js
* License: MIT
*/
!function(a,b){"use strict";function c(a,b){var c=b||{};for(var d in a)d in c||(c[d]=a[d]);return c}function d(a,c){if(h)h(a).trigger(c);else{var d=b.createEvent("CustomEvent");d.initCustomEvent(c,!0,!0,{}),a.dispatchEvent(d)}}function e(a,b){return h?h(a).hasClass(b):a.classList.contains(b)}function f(a,b){this.dateDelta=null,this.timeDelta=null,this._defaults={startClass:"start",endClass:"end",timeClass:"time",dateClass:"date",defaultDateDelta:0,defaultTimeDelta:36e5,anchor:"start",parseTime:function(a){return h(a).timepicker("getTime")},updateTime:function(a,b){h(a).timepicker("setTime",b)},setMinTime:function(a,b){h(a).timepicker("option","minTime",b)},parseDate:function(a){return a.value&&h(a).datepicker("getDate")},updateDate:function(a,b){h(a).datepicker("update",b)}},this.container=a,this.settings=c(this._defaults,b),this.startDateInput=this.container.querySelector("."+this.settings.startClass+"."+this.settings.dateClass),this.endDateInput=this.container.querySelector("."+this.settings.endClass+"."+this.settings.dateClass),this.startTimeInput=this.container.querySelector("."+this.settings.startClass+"."+this.settings.timeClass),this.endTimeInput=this.container.querySelector("."+this.settings.endClass+"."+this.settings.timeClass),this.refresh(),this._bindChangeHandler()}var g=864e5,h=a.Zepto||a.jQuery;f.prototype={constructor:f,option:function(a,b){if("object"==typeof a)this.settings=c(this.settings,a);else if("string"==typeof a&&"undefined"!=typeof b)this.settings[a]=b;else if("string"==typeof a)return this.settings[a];this._updateEndMintime()},getTimeDiff:function(){var a=this.dateDelta+this.timeDelta;return!(a<0)||this.startDateInput&&this.endDateInput||(a+=g),a},refresh:function(){if(this.startDateInput&&this.startDateInput.value&&this.endDateInput&&this.endDateInput.value){var a=this.settings.parseDate(this.startDateInput),b=this.settings.parseDate(this.endDateInput);a&&b&&(this.dateDelta=b.getTime()-a.getTime())}if(this.startTimeInput&&this.startTimeInput.value&&this.endTimeInput&&this.endTimeInput.value){var c=this.settings.parseTime(this.startTimeInput),d=this.settings.parseTime(this.endTimeInput);c&&d&&(this.timeDelta=d.getTime()-c.getTime(),this._updateEndMintime())}},remove:function(){this._unbindChangeHandler()},_bindChangeHandler:function(){h?h(this.container).on("change.datepair",h.proxy(this.handleEvent,this)):this.container.addEventListener("change",this,!1)},_unbindChangeHandler:function(){h?h(this.container).off("change.datepair"):this.container.removeEventListener("change",this,!1)},handleEvent:function(a){this._unbindChangeHandler(),e(a.target,this.settings.dateClass)?""!=a.target.value?(this._dateChanged(a.target),this._timeChanged(a.target)):this.dateDelta=null:e(a.target,this.settings.timeClass)&&(""!=a.target.value?this._timeChanged(a.target):this.timeDelta=null),this._validateRanges(),this._updateEndMintime(),this._bindChangeHandler()},_dateChanged:function(a){if(this.startDateInput&&this.endDateInput){var b=this.settings.parseDate(this.startDateInput),c=this.settings.parseDate(this.endDateInput);if(b&&c)if("start"==this.settings.anchor&&e(a,this.settings.startClass)){var d=new Date(b.getTime()+this.dateDelta);this.settings.updateDate(this.endDateInput,d)}else if("end"==this.settings.anchor&&e(a,this.settings.endClass)){var d=new Date(c.getTime()-this.dateDelta);this.settings.updateDate(this.startDateInput,d)}else if(c<b){var f=e(a,this.settings.startClass)?this.endDateInput:this.startDateInput,h=this.settings.parseDate(a);this.dateDelta=0,this.settings.updateDate(f,h)}else this.dateDelta=c.getTime()-b.getTime();else if(null!==this.settings.defaultDateDelta){if(b){var i=new Date(b.getTime()+this.settings.defaultDateDelta*g);this.settings.updateDate(this.endDateInput,i)}else if(c){var j=new Date(c.getTime()-this.settings.defaultDateDelta*g);this.settings.updateDate(this.startDateInput,j)}this.dateDelta=this.settings.defaultDateDelta*g}else this.dateDelta=null}},_timeChanged:function(a){if(this.startTimeInput&&this.endTimeInput){var b=this.settings.parseTime(this.startTimeInput),c=this.settings.parseTime(this.endTimeInput);if(b&&c)if("start"==this.settings.anchor&&e(a,this.settings.startClass)){var d=new Date(b.getTime()+this.timeDelta);this.settings.updateTime(this.endTimeInput,d),c=this.settings.parseTime(this.endTimeInput),this._doMidnightRollover(b,c)}else if("end"==this.settings.anchor&&e(a,this.settings.endClass)){var d=new Date(c.getTime()-this.timeDelta);this.settings.updateTime(this.startTimeInput,d),b=this.settings.parseTime(this.startTimeInput),this._doMidnightRollover(b,c)}else{this._doMidnightRollover(b,c);var f,g;if(this.startDateInput&&this.endDateInput&&(f=this.settings.parseDate(this.startDateInput),g=this.settings.parseDate(this.endDateInput)),+f==+g&&c<b){var h=e(a,this.settings.endClass)?this.endTimeInput:this.startTimeInput,i=e(a,this.settings.startClass)?this.endTimeInput:this.startTimeInput,j=this.settings.parseTime(h);this.timeDelta=0,this.settings.updateTime(i,j)}else this.timeDelta=c.getTime()-b.getTime()}else if(null!==this.settings.defaultTimeDelta){if(b){var k=new Date(b.getTime()+this.settings.defaultTimeDelta);this.settings.updateTime(this.endTimeInput,k)}else if(c){var l=new Date(c.getTime()-this.settings.defaultTimeDelta);this.settings.updateTime(this.startTimeInput,l)}this.timeDelta=this.settings.defaultTimeDelta}else this.timeDelta=null}},_doMidnightRollover:function(a,b){if(this.startDateInput&&this.endDateInput){var c=this.settings.parseDate(this.endDateInput),d=this.settings.parseDate(this.startDateInput),e=b.getTime()-a.getTime(),f=b<a?g:-1*g;null!==this.dateDelta&&this.dateDelta+this.timeDelta<=g&&this.dateDelta+e!=0&&(f>0||0!=this.dateDelta)&&(e>=0&&this.timeDelta<0||e<0&&this.timeDelta>=0)&&("start"==this.settings.anchor?(this.settings.updateDate(this.endDateInput,new Date(c.getTime()+f)),this._dateChanged(this.endDateInput)):"end"==this.settings.anchor&&(this.settings.updateDate(this.startDateInput,new Date(d.getTime()-f)),this._dateChanged(this.startDateInput))),this.timeDelta=e}},_updateEndMintime:function(){if("function"==typeof this.settings.setMinTime){var a=null;"start"==this.settings.anchor&&(!this.dateDelta||this.dateDelta<g||this.timeDelta&&this.dateDelta+this.timeDelta<g)&&(a=this.settings.parseTime(this.startTimeInput)),this.settings.setMinTime(this.endTimeInput,a)}},_validateRanges:function(){return this.startTimeInput&&this.endTimeInput&&null===this.timeDelta?void d(this.container,"rangeIncomplete"):this.startDateInput&&this.endDateInput&&null===this.dateDelta?void d(this.container,"rangeIncomplete"):void(!this.startDateInput||!this.endDateInput||this.dateDelta+this.timeDelta>=0?d(this.container,"rangeSelected"):d(this.container,"rangeError"))}},a.Datepair=f}(window,document);
!function(a,b){"use strict";function c(a,b){var c=b||{};for(var d in a)d in c||(c[d]=a[d]);return c}function d(a,c){if(h)h(a).trigger(c);else{var d=b.createEvent("CustomEvent");d.initCustomEvent(c,!0,!0,{}),a.dispatchEvent(d)}}function e(a,b){return h?h(a).hasClass(b):a.classList.contains(b)}function f(a,b){this.dateDelta=null,this.timeDelta=null,this._defaults={startClass:"start",endClass:"end",timeClass:"time",dateClass:"date",defaultDateDelta:0,defaultTimeDelta:36e5,anchor:"start",parseTime:function(a){return h(a).timepicker("getTime")},updateTime:function(a,b){h(a).timepicker("setTime",b)},setMinTime:function(a,b){h(a).timepicker("option","minTime",b)},parseDate:function(a){return a.value&&h(a).datepicker("getDate")},updateDate:function(a,b){h(a).datepicker("update",b)}},this.container=a,this.settings=c(this._defaults,b),this.startDateInput=this.container.querySelector("."+this.settings.startClass+"."+this.settings.dateClass),this.endDateInput=this.container.querySelector("."+this.settings.endClass+"."+this.settings.dateClass),this.startTimeInput=this.container.querySelector("."+this.settings.startClass+"."+this.settings.timeClass),this.endTimeInput=this.container.querySelector("."+this.settings.endClass+"."+this.settings.timeClass),this.refresh(),this._bindChangeHandler()}var g=864e5,h=a.Zepto||a.jQuery;f.prototype={constructor:f,option:function(a,b){if("object"==typeof a)this.settings=c(this.settings,a);else if("string"==typeof a&&"undefined"!=typeof b)this.settings[a]=b;else if("string"==typeof a)return this.settings[a];this._updateEndMintime()},getTimeDiff:function(){var a=this.dateDelta+this.timeDelta;return!(a<0)||this.startDateInput&&this.endDateInput||(a+=g),a},refresh:function(){if(this.startDateInput&&this.startDateInput.value&&this.endDateInput&&this.endDateInput.value){var a=this.settings.parseDate(this.startDateInput),b=this.settings.parseDate(this.endDateInput);a&&b&&(this.dateDelta=b.getTime()-a.getTime())}if(this.startTimeInput&&this.startTimeInput.value&&this.endTimeInput&&this.endTimeInput.value){var c=this.settings.parseTime(this.startTimeInput),d=this.settings.parseTime(this.endTimeInput);c&&d&&(this.timeDelta=d.getTime()-c.getTime(),this._updateEndMintime())}},remove:function(){this._unbindChangeHandler()},_bindChangeHandler:function(){h?h(this.container).on("change.datepair",h.proxy(this.handleEvent,this)):this.container.addEventListener("change",this,!1)},_unbindChangeHandler:function(){h?h(this.container).off("change.datepair"):this.container.removeEventListener("change",this,!1)},handleEvent:function(a){this._unbindChangeHandler(),e(a.target,this.settings.dateClass)?""!=a.target.value?(this._dateChanged(a.target),this._timeChanged(a.target)):this.dateDelta=null:e(a.target,this.settings.timeClass)&&(""!=a.target.value?this._timeChanged(a.target):this.timeDelta=null),this._validateRanges(),this._updateEndMintime(),this._bindChangeHandler()},_dateChanged:function(a){if(this.startDateInput&&this.endDateInput){var b=this.settings.parseDate(this.startDateInput),c=this.settings.parseDate(this.endDateInput);if(b&&c)if("start"==this.settings.anchor&&e(a,this.settings.startClass)){var d=new Date(b.getTime()+this.dateDelta);this.settings.updateDate(this.endDateInput,d)}else if("end"==this.settings.anchor&&e(a,this.settings.endClass)){var d=new Date(c.getTime()-this.dateDelta);this.settings.updateDate(this.startDateInput,d)}else if(c<b){var f=e(a,this.settings.startClass)?this.endDateInput:this.startDateInput,h=this.settings.parseDate(a);this.dateDelta=0,this.settings.updateDate(f,h)}else this.dateDelta=c.getTime()-b.getTime();else if(null!==this.settings.defaultDateDelta){if(b){var i=new Date(b.getTime()+this.settings.defaultDateDelta*g);this.settings.updateDate(this.endDateInput,i)}else if(c){var j=new Date(c.getTime()-this.settings.defaultDateDelta*g);this.settings.updateDate(this.startDateInput,j)}this.dateDelta=this.settings.defaultDateDelta*g}else this.dateDelta=null}},_timeChanged:function(a){if(this.startTimeInput&&this.endTimeInput){var b=this.settings.parseTime(this.startTimeInput),c=this.settings.parseTime(this.endTimeInput);if(!b||!c)return void(null!==this.settings.defaultTimeDelta?(this.timeDelta=this.settings.defaultTimeDelta,b?(c=this._setTimeAndReturn(this.endTimeInput,new Date(b.getTime()+this.settings.defaultTimeDelta)),this._doMidnightRollover(b,c)):c&&(b=this._setTimeAndReturn(this.startTimeInput,new Date(c.getTime()-this.settings.defaultTimeDelta)),this._doMidnightRollover(b,c))):this.timeDelta=null);if("start"==this.settings.anchor&&e(a,this.settings.startClass))c=this._setTimeAndReturn(this.endTimeInput,new Date(b.getTime()+this.timeDelta)),this._doMidnightRollover(b,c);else if("end"==this.settings.anchor&&e(a,this.settings.endClass))b=this._setTimeAndReturn(this.startTimeInput,new Date(c.getTime()-this.timeDelta)),this._doMidnightRollover(b,c);else{this._doMidnightRollover(b,c);var d,f;if(this.startDateInput&&this.endDateInput&&(d=this.settings.parseDate(this.startDateInput),f=this.settings.parseDate(this.endDateInput)),+d==+f&&c<b){var g=e(a,this.settings.endClass)?this.endTimeInput:this.startTimeInput,h=e(a,this.settings.startClass)?this.endTimeInput:this.startTimeInput,i=this.settings.parseTime(g);this.timeDelta=0,this.settings.updateTime(h,i)}else this.timeDelta=c.getTime()-b.getTime()}}},_setTimeAndReturn:function(a,b){return this.settings.updateTime(a,b),this.settings.parseTime(a)},_doMidnightRollover:function(a,b){if(this.startDateInput&&this.endDateInput){var c=this.settings.parseDate(this.endDateInput),d=this.settings.parseDate(this.startDateInput),e=b.getTime()-a.getTime(),f=b<a?g:-1*g;null!==this.dateDelta&&this.dateDelta+this.timeDelta<=g&&this.dateDelta+e!=0&&(f>0||0!=this.dateDelta)&&(e>=0&&this.timeDelta<0||e<0&&this.timeDelta>=0)&&("start"==this.settings.anchor?(this.settings.updateDate(this.endDateInput,new Date(c.getTime()+f)),this._dateChanged(this.endDateInput)):"end"==this.settings.anchor&&(this.settings.updateDate(this.startDateInput,new Date(d.getTime()-f)),this._dateChanged(this.startDateInput))),this.timeDelta=e}},_updateEndMintime:function(){if("function"==typeof this.settings.setMinTime){var a=null;"start"==this.settings.anchor&&(!this.dateDelta||this.dateDelta<g||this.timeDelta&&this.dateDelta+this.timeDelta<g)&&(a=this.settings.parseTime(this.startTimeInput)),this.settings.setMinTime(this.endTimeInput,a)}},_validateRanges:function(){return this.startTimeInput&&this.endTimeInput&&null===this.timeDelta?void d(this.container,"rangeIncomplete"):this.startDateInput&&this.endDateInput&&null===this.dateDelta?void d(this.container,"rangeIncomplete"):void(!this.startDateInput||!this.endDateInput||this.dateDelta+this.timeDelta>=0?d(this.container,"rangeSelected"):d(this.container,"rangeError"))}},a.Datepair=f}(window,document);
/*!
* datepair.js v0.4.15 - A javascript plugin for intelligently selecting date and time ranges inspired by Google Calendar.
* Copyright (c) 2016 Jon Thornton - http://jonthornton.github.com/Datepair.js
* datepair.js v0.4.16 - A javascript plugin for intelligently selecting date and time ranges inspired by Google Calendar.
* Copyright (c) 2018 Jon Thornton - http://jonthornton.github.com/Datepair.js
* License: MIT

@@ -51,2 +51,2 @@ */

}(window.Zepto || window.jQuery));
}(window.Zepto || window.jQuery));
/*!
* datepair.js v0.4.15 - A javascript plugin for intelligently selecting date and time ranges inspired by Google Calendar.
* Copyright (c) 2015 Jon Thornton - http://jonthornton.github.com/Datepair.js
* datepair.js v0.4.16 - A javascript plugin for intelligently selecting date and time ranges inspired by Google Calendar.
* Copyright (c) 2018 Jon Thornton - http://jonthornton.github.com/Datepair.js
* License: MIT
*/
!function(a,b){"use strict";function c(a,b){var c=b||{};for(var d in a)d in c||(c[d]=a[d]);return c}function d(a,c){if(h)h(a).trigger(c);else{var d=b.createEvent("CustomEvent");d.initCustomEvent(c,!0,!0,{}),a.dispatchEvent(d)}}function e(a,b){return h?h(a).hasClass(b):a.classList.contains(b)}function f(a,b){this.dateDelta=null,this.timeDelta=null,this._defaults={startClass:"start",endClass:"end",timeClass:"time",dateClass:"date",defaultDateDelta:0,defaultTimeDelta:36e5,anchor:"start",parseTime:function(a){return h(a).timepicker("getTime")},updateTime:function(a,b){h(a).timepicker("setTime",b)},setMinTime:function(a,b){h(a).timepicker("option","minTime",b)},parseDate:function(a){return a.value&&h(a).datepicker("getDate")},updateDate:function(a,b){h(a).datepicker("update",b)}},this.container=a,this.settings=c(this._defaults,b),this.startDateInput=this.container.querySelector("."+this.settings.startClass+"."+this.settings.dateClass),this.endDateInput=this.container.querySelector("."+this.settings.endClass+"."+this.settings.dateClass),this.startTimeInput=this.container.querySelector("."+this.settings.startClass+"."+this.settings.timeClass),this.endTimeInput=this.container.querySelector("."+this.settings.endClass+"."+this.settings.timeClass),this.refresh(),this._bindChangeHandler()}var g=864e5,h=a.Zepto||a.jQuery;f.prototype={constructor:f,option:function(a,b){if("object"==typeof a)this.settings=c(this.settings,a);else if("string"==typeof a&&"undefined"!=typeof b)this.settings[a]=b;else if("string"==typeof a)return this.settings[a];this._updateEndMintime()},getTimeDiff:function(){var a=this.dateDelta+this.timeDelta;return!(0>a)||this.startDateInput&&this.endDateInput||(a+=g),a},refresh:function(){if(this.startDateInput&&this.startDateInput.value&&this.endDateInput&&this.endDateInput.value){var a=this.settings.parseDate(this.startDateInput),b=this.settings.parseDate(this.endDateInput);a&&b&&(this.dateDelta=b.getTime()-a.getTime())}if(this.startTimeInput&&this.startTimeInput.value&&this.endTimeInput&&this.endTimeInput.value){var c=this.settings.parseTime(this.startTimeInput),d=this.settings.parseTime(this.endTimeInput);c&&d&&(this.timeDelta=d.getTime()-c.getTime(),this._updateEndMintime())}},remove:function(){this._unbindChangeHandler()},_bindChangeHandler:function(){h?h(this.container).on("change.datepair",h.proxy(this.handleEvent,this)):this.container.addEventListener("change",this,!1)},_unbindChangeHandler:function(){h?h(this.container).off("change.datepair"):this.container.removeEventListener("change",this,!1)},handleEvent:function(a){this._unbindChangeHandler(),e(a.target,this.settings.dateClass)?""!=a.target.value?(this._dateChanged(a.target),this._timeChanged(a.target)):this.dateDelta=null:e(a.target,this.settings.timeClass)&&(""!=a.target.value?this._timeChanged(a.target):this.timeDelta=null),this._validateRanges(),this._updateEndMintime(),this._bindChangeHandler()},_dateChanged:function(a){if(this.startDateInput&&this.endDateInput){var b=this.settings.parseDate(this.startDateInput),c=this.settings.parseDate(this.endDateInput);if(b&&c)if("start"==this.settings.anchor&&e(a,this.settings.startClass)){var d=new Date(b.getTime()+this.dateDelta);this.settings.updateDate(this.endDateInput,d)}else if("end"==this.settings.anchor&&e(a,this.settings.endClass)){var d=new Date(c.getTime()-this.dateDelta);this.settings.updateDate(this.startDateInput,d)}else if(b>c){var f=e(a,this.settings.startClass)?this.endDateInput:this.startDateInput,h=this.settings.parseDate(a);this.dateDelta=0,this.settings.updateDate(f,h)}else this.dateDelta=c.getTime()-b.getTime();else if(null!==this.settings.defaultDateDelta){if(b){var i=new Date(b.getTime()+this.settings.defaultDateDelta*g);this.settings.updateDate(this.endDateInput,i)}else if(c){var j=new Date(c.getTime()-this.settings.defaultDateDelta*g);this.settings.updateDate(this.startDateInput,j)}this.dateDelta=this.settings.defaultDateDelta*g}else this.dateDelta=null}},_timeChanged:function(a){if(this.startTimeInput&&this.endTimeInput){var b=this.settings.parseTime(this.startTimeInput),c=this.settings.parseTime(this.endTimeInput);if(b&&c)if("start"==this.settings.anchor&&e(a,this.settings.startClass)){var d=new Date(b.getTime()+this.timeDelta);this.settings.updateTime(this.endTimeInput,d),c=this.settings.parseTime(this.endTimeInput),this._doMidnightRollover(b,c)}else if("end"==this.settings.anchor&&e(a,this.settings.endClass)){var d=new Date(c.getTime()-this.timeDelta);this.settings.updateTime(this.startTimeInput,d),b=this.settings.parseTime(this.startTimeInput),this._doMidnightRollover(b,c)}else{this._doMidnightRollover(b,c);var f,g;if(this.startDateInput&&this.endDateInput&&(f=this.settings.parseDate(this.startDateInput),g=this.settings.parseDate(this.endDateInput)),+f==+g&&b>c){var h=e(a,this.settings.endClass)?this.endTimeInput:this.startTimeInput,i=e(a,this.settings.startClass)?this.endTimeInput:this.startTimeInput,j=this.settings.parseTime(h);this.timeDelta=0,this.settings.updateTime(i,j)}else this.timeDelta=c.getTime()-b.getTime()}else if(null!==this.settings.defaultTimeDelta){if(b){var k=new Date(b.getTime()+this.settings.defaultTimeDelta);this.settings.updateTime(this.endTimeInput,k)}else if(c){var l=new Date(c.getTime()-this.settings.defaultTimeDelta);this.settings.updateTime(this.startTimeInput,l)}this.timeDelta=this.settings.defaultTimeDelta}else this.timeDelta=null}},_doMidnightRollover:function(a,b){if(this.startDateInput&&this.endDateInput){var c=this.settings.parseDate(this.endDateInput),d=this.settings.parseDate(this.startDateInput),e=b.getTime()-a.getTime(),f=a>b?g:-1*g;null!==this.dateDelta&&this.dateDelta+this.timeDelta<=g&&this.dateDelta+e!=0&&(f>0||0!=this.dateDelta)&&(e>=0&&this.timeDelta<0||0>e&&this.timeDelta>=0)&&("start"==this.settings.anchor?(this.settings.updateDate(this.endDateInput,new Date(c.getTime()+f)),this._dateChanged(this.endDateInput)):"end"==this.settings.anchor&&(this.settings.updateDate(this.startDateInput,new Date(d.getTime()-f)),this._dateChanged(this.startDateInput))),this.timeDelta=e}},_updateEndMintime:function(){if("function"==typeof this.settings.setMinTime){var a=null;"start"==this.settings.anchor&&(!this.dateDelta||this.dateDelta<g||this.timeDelta&&this.dateDelta+this.timeDelta<g)&&(a=this.settings.parseTime(this.startTimeInput)),this.settings.setMinTime(this.endTimeInput,a)}},_validateRanges:function(){return this.startTimeInput&&this.endTimeInput&&null===this.timeDelta?void d(this.container,"rangeIncomplete"):this.startDateInput&&this.endDateInput&&null===this.dateDelta?void d(this.container,"rangeIncomplete"):void(!this.startDateInput||!this.endDateInput||this.dateDelta+this.timeDelta>=0?d(this.container,"rangeSelected"):d(this.container,"rangeError"))}},a.Datepair=f}(window,document),function(a){a&&(a.fn.datepair=function(b){var c;return this.each(function(){var d=a(this),e=d.data("datepair"),f="object"==typeof b&&b;e||(e=new Datepair(this,f),d.data("datepair",e)),"string"==typeof b&&(c=e[b]())}),c||this},a("[data-datepair]").each(function(){var b=a(this);b.datepair(b.data())}))}(window.Zepto||window.jQuery);
!function(a,b){"use strict";function c(a,b){var c=b||{};for(var d in a)d in c||(c[d]=a[d]);return c}function d(a,c){if(h)h(a).trigger(c);else{var d=b.createEvent("CustomEvent");d.initCustomEvent(c,!0,!0,{}),a.dispatchEvent(d)}}function e(a,b){return h?h(a).hasClass(b):a.classList.contains(b)}function f(a,b){this.dateDelta=null,this.timeDelta=null,this._defaults={startClass:"start",endClass:"end",timeClass:"time",dateClass:"date",defaultDateDelta:0,defaultTimeDelta:36e5,anchor:"start",parseTime:function(a){return h(a).timepicker("getTime")},updateTime:function(a,b){h(a).timepicker("setTime",b)},setMinTime:function(a,b){h(a).timepicker("option","minTime",b)},parseDate:function(a){return a.value&&h(a).datepicker("getDate")},updateDate:function(a,b){h(a).datepicker("update",b)}},this.container=a,this.settings=c(this._defaults,b),this.startDateInput=this.container.querySelector("."+this.settings.startClass+"."+this.settings.dateClass),this.endDateInput=this.container.querySelector("."+this.settings.endClass+"."+this.settings.dateClass),this.startTimeInput=this.container.querySelector("."+this.settings.startClass+"."+this.settings.timeClass),this.endTimeInput=this.container.querySelector("."+this.settings.endClass+"."+this.settings.timeClass),this.refresh(),this._bindChangeHandler()}var g=864e5,h=a.Zepto||a.jQuery;f.prototype={constructor:f,option:function(a,b){if("object"==typeof a)this.settings=c(this.settings,a);else if("string"==typeof a&&"undefined"!=typeof b)this.settings[a]=b;else if("string"==typeof a)return this.settings[a];this._updateEndMintime()},getTimeDiff:function(){var a=this.dateDelta+this.timeDelta;return!(a<0)||this.startDateInput&&this.endDateInput||(a+=g),a},refresh:function(){if(this.startDateInput&&this.startDateInput.value&&this.endDateInput&&this.endDateInput.value){var a=this.settings.parseDate(this.startDateInput),b=this.settings.parseDate(this.endDateInput);a&&b&&(this.dateDelta=b.getTime()-a.getTime())}if(this.startTimeInput&&this.startTimeInput.value&&this.endTimeInput&&this.endTimeInput.value){var c=this.settings.parseTime(this.startTimeInput),d=this.settings.parseTime(this.endTimeInput);c&&d&&(this.timeDelta=d.getTime()-c.getTime(),this._updateEndMintime())}},remove:function(){this._unbindChangeHandler()},_bindChangeHandler:function(){h?h(this.container).on("change.datepair",h.proxy(this.handleEvent,this)):this.container.addEventListener("change",this,!1)},_unbindChangeHandler:function(){h?h(this.container).off("change.datepair"):this.container.removeEventListener("change",this,!1)},handleEvent:function(a){this._unbindChangeHandler(),e(a.target,this.settings.dateClass)?""!=a.target.value?(this._dateChanged(a.target),this._timeChanged(a.target)):this.dateDelta=null:e(a.target,this.settings.timeClass)&&(""!=a.target.value?this._timeChanged(a.target):this.timeDelta=null),this._validateRanges(),this._updateEndMintime(),this._bindChangeHandler()},_dateChanged:function(a){if(this.startDateInput&&this.endDateInput){var b=this.settings.parseDate(this.startDateInput),c=this.settings.parseDate(this.endDateInput);if(b&&c)if("start"==this.settings.anchor&&e(a,this.settings.startClass)){var d=new Date(b.getTime()+this.dateDelta);this.settings.updateDate(this.endDateInput,d)}else if("end"==this.settings.anchor&&e(a,this.settings.endClass)){var d=new Date(c.getTime()-this.dateDelta);this.settings.updateDate(this.startDateInput,d)}else if(c<b){var f=e(a,this.settings.startClass)?this.endDateInput:this.startDateInput,h=this.settings.parseDate(a);this.dateDelta=0,this.settings.updateDate(f,h)}else this.dateDelta=c.getTime()-b.getTime();else if(null!==this.settings.defaultDateDelta){if(b){var i=new Date(b.getTime()+this.settings.defaultDateDelta*g);this.settings.updateDate(this.endDateInput,i)}else if(c){var j=new Date(c.getTime()-this.settings.defaultDateDelta*g);this.settings.updateDate(this.startDateInput,j)}this.dateDelta=this.settings.defaultDateDelta*g}else this.dateDelta=null}},_timeChanged:function(a){if(this.startTimeInput&&this.endTimeInput){var b=this.settings.parseTime(this.startTimeInput),c=this.settings.parseTime(this.endTimeInput);if(!b||!c)return void(null!==this.settings.defaultTimeDelta?(this.timeDelta=this.settings.defaultTimeDelta,b?(c=this._setTimeAndReturn(this.endTimeInput,new Date(b.getTime()+this.settings.defaultTimeDelta)),this._doMidnightRollover(b,c)):c&&(b=this._setTimeAndReturn(this.startTimeInput,new Date(c.getTime()-this.settings.defaultTimeDelta)),this._doMidnightRollover(b,c))):this.timeDelta=null);if("start"==this.settings.anchor&&e(a,this.settings.startClass))c=this._setTimeAndReturn(this.endTimeInput,new Date(b.getTime()+this.timeDelta)),this._doMidnightRollover(b,c);else if("end"==this.settings.anchor&&e(a,this.settings.endClass))b=this._setTimeAndReturn(this.startTimeInput,new Date(c.getTime()-this.timeDelta)),this._doMidnightRollover(b,c);else{this._doMidnightRollover(b,c);var d,f;if(this.startDateInput&&this.endDateInput&&(d=this.settings.parseDate(this.startDateInput),f=this.settings.parseDate(this.endDateInput)),+d==+f&&c<b){var g=e(a,this.settings.endClass)?this.endTimeInput:this.startTimeInput,h=e(a,this.settings.startClass)?this.endTimeInput:this.startTimeInput,i=this.settings.parseTime(g);this.timeDelta=0,this.settings.updateTime(h,i)}else this.timeDelta=c.getTime()-b.getTime()}}},_setTimeAndReturn:function(a,b){return this.settings.updateTime(a,b),this.settings.parseTime(a)},_doMidnightRollover:function(a,b){if(this.startDateInput&&this.endDateInput){var c=this.settings.parseDate(this.endDateInput),d=this.settings.parseDate(this.startDateInput),e=b.getTime()-a.getTime(),f=b<a?g:-1*g;null!==this.dateDelta&&this.dateDelta+this.timeDelta<=g&&this.dateDelta+e!=0&&(f>0||0!=this.dateDelta)&&(e>=0&&this.timeDelta<0||e<0&&this.timeDelta>=0)&&("start"==this.settings.anchor?(this.settings.updateDate(this.endDateInput,new Date(c.getTime()+f)),this._dateChanged(this.endDateInput)):"end"==this.settings.anchor&&(this.settings.updateDate(this.startDateInput,new Date(d.getTime()-f)),this._dateChanged(this.startDateInput))),this.timeDelta=e}},_updateEndMintime:function(){if("function"==typeof this.settings.setMinTime){var a=null;"start"==this.settings.anchor&&(!this.dateDelta||this.dateDelta<g||this.timeDelta&&this.dateDelta+this.timeDelta<g)&&(a=this.settings.parseTime(this.startTimeInput)),this.settings.setMinTime(this.endTimeInput,a)}},_validateRanges:function(){return this.startTimeInput&&this.endTimeInput&&null===this.timeDelta?void d(this.container,"rangeIncomplete"):this.startDateInput&&this.endDateInput&&null===this.dateDelta?void d(this.container,"rangeIncomplete"):void(!this.startDateInput||!this.endDateInput||this.dateDelta+this.timeDelta>=0?d(this.container,"rangeSelected"):d(this.container,"rangeError"))}},a.Datepair=f}(window,document),function(a){a&&(a.fn.datepair=function(b){var c;return this.each(function(){var d=a(this),e=d.data("datepair"),f="object"==typeof b&&b;e||(e=new Datepair(this,f),d.data("datepair",e)),"remove"===b&&(c=e.remove(),d.removeData("datepair",e)),"string"==typeof b&&(c=e[b]())}),c||this},a("[data-datepair]").each(function(){var b=a(this);b.datepair(b.data())}))}(window.Zepto||window.jQuery);

@@ -27,3 +27,3 @@ module.exports = function(grunt) {

banner: '<%= meta.banner %>',
report: 'gzip'
report: 'min'
},

@@ -30,0 +30,0 @@ dist: {

@@ -5,3 +5,3 @@ {

"homepage": "http://jonthornton.github.com/Datepair.js",
"version": "0.4.15",
"version": "0.4.16",
"main": "dist/datepair.js",

@@ -8,0 +8,0 @@ "author": {

@@ -23,5 +23,5 @@ # Datepair.js

Where ```#container``` contains time/date input elements with the appropriate class names. ```options``` is an optional javascript object with parameters explained below.
Where `#container` contains time/date `<input />` elements with the appropriate class names. `options` is an optional javascript object with parameters explained below.
You can also install via [Bower](http://bower.io/) with `bower install datepair.js`.
Note that Datepair is triggered by `change` events and won't work unless the container has some `<input />` elements.

@@ -134,3 +134,7 @@ ## Options

parseDate: function (el) {
var utc = new Date($(el).datepicker('getDate'));
var val = $(el).datepicker('getDate');
if (!val) {
return null;
}
var utc = new Date(val);
return utc && new Date(utc.getTime() + (utc.getTimezoneOffset() * 60000));

@@ -144,2 +148,7 @@ },

## Packaging
https://www.npmjs.com/package/datepair.js
`npm install --save datepair.js`
## Help

@@ -146,0 +155,0 @@

@@ -240,11 +240,11 @@ var _ONE_DAY = 86400000;

if (this.settings.defaultTimeDelta !== null) {
this.timeDelta = this.settings.defaultTimeDelta;
if (startTime) {
var newEnd = new Date(startTime.getTime() + this.settings.defaultTimeDelta);
this.settings.updateTime(this.endTimeInput, newEnd);
endTime = this._setTimeAndReturn(this.endTimeInput, new Date(startTime.getTime() + this.settings.defaultTimeDelta));
this._doMidnightRollover(startTime, endTime);
} else if (endTime) {
var newStart = new Date(endTime.getTime() - this.settings.defaultTimeDelta);
this.settings.updateTime(this.startTimeInput, newStart);
startTime = this._setTimeAndReturn(this.startTimeInput, new Date(endTime.getTime() - this.settings.defaultTimeDelta));
this._doMidnightRollover(startTime, endTime);
}
this.timeDelta = this.settings.defaultTimeDelta;
} else {

@@ -258,12 +258,6 @@ this.timeDelta = null;

if (this.settings.anchor == 'start' && hasClass(target, this.settings.startClass)) {
var newTime = new Date(startTime.getTime() + this.timeDelta);
this.settings.updateTime(this.endTimeInput, newTime);
endTime = this.settings.parseTime(this.endTimeInput);
endTime = this._setTimeAndReturn(this.endTimeInput, new Date(startTime.getTime() + this.timeDelta));
this._doMidnightRollover(startTime, endTime);
} else if (this.settings.anchor == 'end' && hasClass(target, this.settings.endClass)) {
var newTime = new Date(endTime.getTime() - this.timeDelta);
this.settings.updateTime(this.startTimeInput, newTime);
startTime = this.settings.parseTime(this.startTimeInput);
startTime = this._setTimeAndReturn(this.startTimeInput, new Date(endTime.getTime() - this.timeDelta));
this._doMidnightRollover(startTime, endTime);

@@ -293,2 +287,7 @@ } else {

_setTimeAndReturn: function(input, newTime) {
this.settings.updateTime(input, newTime);
return this.settings.parseTime(input);
},
_doMidnightRollover: function(startTime, endTime) {

@@ -295,0 +294,0 @@ if (!this.startDateInput || !this.endDateInput) {

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc