From 04136cf9e1e28c83917273415b3cde3b5e375b79 Mon Sep 17 00:00:00 2001 From: Darren Haken Date: Wed, 9 Jul 2014 17:39:55 +0100 Subject: [PATCH 1/3] Revert "Converted all date/time handling and tests to use UTC" This reverts commit f828b5384e20db7d56da477cfa20c6a979c0cd13. Conflicts: api.htm lib/compressed/picker.date.js lib/compressed/picker.js lib/compressed/picker.time.js lib/picker.date.js --- lib/picker.date.js | 37 +++--- lib/picker.js | 2 +- lib/picker.time.js | 6 +- tests/units/date.js | 270 ++++++++++++++++++++++---------------------- tests/units/time.js | 30 ++--- 5 files changed, 170 insertions(+), 175 deletions(-) diff --git a/lib/picker.date.js b/lib/picker.date.js index c4e787f1..aa300c78 100644 --- a/lib/picker.date.js +++ b/lib/picker.date.js @@ -94,10 +94,10 @@ function DatePicker( picker, settings ) { 37: function() { return isRTL() ? 1 : -1 }, // Left go: function( timeChange ) { var highlightedObject = calendar.item.highlight, - targetDate = new Date( Date.UTC(highlightedObject.year, highlightedObject.month, highlightedObject.date + timeChange) ) + targetDate = new Date( highlightedObject.year, highlightedObject.month, highlightedObject.date + timeChange ) calendar.set( 'highlight', - [ targetDate.getUTCFullYear(), targetDate.getUTCMonth(), targetDate.getUTCDate() ], + [ targetDate.getFullYear(), targetDate.getMonth(), targetDate.getDate() ], { interval: timeChange } ) this.render() @@ -214,20 +214,15 @@ DatePicker.prototype.create = function( type, value, options ) { // If it’s an array, convert it into a date and make sure // that it’s a valid date – otherwise default to today. else if ( $.isArray( value ) ) { - value = new Date(Date.UTC(value[ 0 ], value[ 1 ], value[ 2 ] )) + value = new Date( value[ 0 ], value[ 1 ], value[ 2 ] ) value = _.isDate( value ) ? value : calendar.create().obj } - // If it’s a number, make a normalized date. - else if ( _.isInteger( value ) ) { + // If it’s a number or date object, make a normalized date. + else if ( _.isInteger( value ) || _.isDate( value ) ) { value = calendar.normalize( new Date( value ), options ) } - // If it’s a date object, make a normalized date. - else if ( _.isDate( value ) ) { - value = calendar.normalize( value, options ) - } - // If it’s a literal true or any other case, set it to now. else /*if ( value === true )*/ { value = calendar.now( type, value, options ) @@ -235,10 +230,10 @@ DatePicker.prototype.create = function( type, value, options ) { // Return the compiled object. return { - year: isInfiniteValue || value.getUTCFullYear(), - month: isInfiniteValue || value.getUTCMonth(), - date: isInfiniteValue || value.getUTCDate(), - day: isInfiniteValue || value.getUTCDay(), + year: isInfiniteValue || value.getFullYear(), + month: isInfiniteValue || value.getMonth(), + date: isInfiniteValue || value.getDate(), + day: isInfiniteValue || value.getDay(), obj: isInfiniteValue || value, pick: isInfiniteValue || value.getTime() } @@ -313,7 +308,7 @@ DatePicker.prototype.overlapRanges = function( one, two ) { DatePicker.prototype.now = function( type, value, options ) { value = new Date() if ( options && options.rel ) { - value.setUTCDate( value.getUTCDate() + options.rel ) + value.setDate( value.getDate() + options.rel ) } return this.normalize( value, options ) } @@ -355,13 +350,13 @@ DatePicker.prototype.navigate = function( type, value, options ) { } // Figure out the expected target year and month. - targetDateObject = new Date( Date.UTC( targetYear, targetMonth + ( options && options.nav ? options.nav : 0 ), 1 ) ) - targetYear = targetDateObject.getUTCFullYear() - targetMonth = targetDateObject.getUTCMonth() + targetDateObject = new Date( targetYear, targetMonth + ( options && options.nav ? options.nav : 0 ), 1 ) + targetYear = targetDateObject.getFullYear() + targetMonth = targetDateObject.getMonth() // If the month we’re going to doesn’t have enough days, // keep decreasing the date until we reach the month’s last date. - while ( /*safety &&*/ new Date( Date.UTC( targetYear, targetMonth, targetDate ) ).getUTCMonth() !== targetMonth ) { + while ( /*safety &&*/ new Date( targetYear, targetMonth, targetDate ).getMonth() !== targetMonth ) { targetDate -= 1 /*safety -= 1 if ( !safety ) { @@ -380,7 +375,7 @@ DatePicker.prototype.navigate = function( type, value, options ) { * Normalize a date by setting the hours to midnight. */ DatePicker.prototype.normalize = function( value/*, options*/ ) { - value.setUTCHours( 0, 0, 0, 0 ) + value.setHours( 0, 0, 0, 0 ) return value } @@ -920,7 +915,7 @@ DatePicker.prototype.activate = function( type, datesToEnable ) { if ( !matchFound[3] ) matchFound.push( 'inverted' ) } else if ( _.isDate( unitToEnable ) ) { - matchFound = [ unitToEnable.getUTCFullYear(), unitToEnable.getUTCMonth(), unitToEnable.getUTCDate(), 'inverted' ] + matchFound = [ unitToEnable.getFullYear(), unitToEnable.getMonth(), unitToEnable.getDate(), 'inverted' ] } break } diff --git a/lib/picker.js b/lib/picker.js index 52c0ba79..ecc88810 100644 --- a/lib/picker.js +++ b/lib/picker.js @@ -965,7 +965,7 @@ PickerConstructor._ = { * Tell if something is a date object. */ isDate: function( value ) { - return {}.toString.call( value ).indexOf( 'Date' ) > -1 && this.isInteger( value.getUTCDate() ) + return {}.toString.call( value ).indexOf( 'Date' ) > -1 && this.isInteger( value.getDate() ) }, diff --git a/lib/picker.time.js b/lib/picker.time.js index 9cacb376..5994273a 100644 --- a/lib/picker.time.js +++ b/lib/picker.time.js @@ -197,7 +197,7 @@ TimePicker.prototype.create = function( type, value, options ) { // If it’s a date object, convert it into an array. if ( _.isDate( value ) ) { - value = [ value.getUTCHours(), value.getUTCMinutes() ] + value = [ value.getHours(), value.getMinutes() ] } // If it’s an object, use the “pick” value. @@ -316,7 +316,7 @@ TimePicker.prototype.now = function( type, value/*, options*/ ) { var interval = this.item.interval, date = new Date(), - nowMinutes = date.getUTCHours() * MINUTES_IN_HOUR + date.getUTCMinutes(), + nowMinutes = date.getHours() * MINUTES_IN_HOUR + date.getMinutes(), isValueInteger = _.isInteger( value ), isBelowInterval @@ -813,7 +813,7 @@ TimePicker.prototype.activate = function( type, timesToEnable ) { if ( !matchFound[2] ) matchFound.push( 'inverted' ) } else if ( _.isDate( unitToEnable ) ) { - matchFound = [ unitToEnable.getUTCFullYear(), unitToEnable.getUTCMonth(), unitToEnable.getUTCDate(), 'inverted' ] + matchFound = [ unitToEnable.getFullYear(), unitToEnable.getMonth(), unitToEnable.getDate(), 'inverted' ] } break } diff --git a/tests/units/date.js b/tests/units/date.js index 48c096b5..daec4f15 100644 --- a/tests/units/date.js +++ b/tests/units/date.js @@ -41,14 +41,14 @@ test( 'Properties', function() { var picker = this.picker, today = new Date() - today.setUTCHours(0,0,0,0) + today.setHours( 0, 0, 0, 0 ) strictEqual( picker.get( 'min' ).pick, -Infinity, 'Default “min” is -Infinity' ) strictEqual( picker.get( 'max' ).pick, Infinity, 'Default “max’ is +Infinity' ) - strictEqual( picker.get( 'now' ).pick, today.getTime(), 'Default “now” is ' + today ) + strictEqual( picker.get( 'now' ).pick, today.getTime(), 'Default “now” is ' + picker.get( 'now', 'yyyy/mm/dd' ) ) deepEqual( picker.get( 'select' ), null, 'Default “select” is `null`' ) deepEqual( picker.get( 'highlight' ), picker.get( 'now' ), 'Default “highlight” is “now”' ) - strictEqual( picker.get( 'view' ).pick, today.setUTCDate( 1 ), 'Default “view” is ' + picker.get( 'view', 'yyyy/mm/dd' ) ) + strictEqual( picker.get( 'view' ).pick, today.setDate( 1 ), 'Default “view” is ' + picker.get( 'view', 'yyyy/mm/dd' ) ) }) test( 'First weekday', function() { @@ -74,38 +74,38 @@ test( 'Formats', function() { }, formats = { d: function() { - return '' + today.getUTCDate() + return '' + today.getDate() }, dd: function() { - return leadZero( today.getUTCDate() ) + return leadZero( today.getDate() ) }, ddd: function() { - return $.fn.pickadate.defaults.weekdaysShort[ today.getUTCDay() ] + return $.fn.pickadate.defaults.weekdaysShort[ today.getDay() ] }, dddd: function() { - return $.fn.pickadate.defaults.weekdaysFull[ today.getUTCDay() ] + return $.fn.pickadate.defaults.weekdaysFull[ today.getDay() ] }, m: function() { - return '' + ( today.getUTCMonth() + 1 ) + return '' + ( today.getMonth() + 1 ) }, mm: function() { - return leadZero( ( today.getUTCMonth() + 1 ) ) + return leadZero( ( today.getMonth() + 1 ) ) }, mmm: function() { - return $.fn.pickadate.defaults.monthsShort[ today.getUTCMonth() ] + return $.fn.pickadate.defaults.monthsShort[ today.getMonth() ] }, mmmm: function() { - return $.fn.pickadate.defaults.monthsFull[ today.getUTCMonth() ] + return $.fn.pickadate.defaults.monthsFull[ today.getMonth() ] }, yy: function() { - return ( '' + today.getUTCFullYear() ).slice(2) + return ( '' + today.getFullYear() ).slice(2) }, yyyy: function() { - return '' + today.getUTCFullYear() + return '' + today.getFullYear() } } - today.setUTCHours(0,0,0,0) + today.setHours(0,0,0,0) ;([ 'd', 'dd', 'ddd', 'dddd', 'm', 'mm', 'mmm', 'mmmm', 'yy', 'yyyy' ]).forEach( function( format ) { var expect = formats[ format ]() @@ -145,7 +145,7 @@ test( 'Disable today with `min` as `true`', function() { var highlighted = picker.get('highlight') deepEqual( - [today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate() + 1], + [today.getFullYear(), today.getMonth(), today.getDate() + 1], [highlighted.year, highlighted.month, highlighted.date], 'Able to disable today' ) @@ -164,7 +164,7 @@ test( 'Disable today with `max` as `true`', function() { var highlighted = picker.get('highlight') deepEqual( - [today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate() - 1], + [today.getFullYear(), today.getMonth(), today.getDate() - 1], [highlighted.year, highlighted.month, highlighted.date], 'Able to disable today' ) @@ -202,9 +202,9 @@ test( '`select`', function() { var picker = this.picker, today = new Date(), - playdate = new Date( Date.UTC( today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate() + 40 ) ) + playdate = new Date( today.getFullYear(), today.getMonth(), today.getDate() + 40 ) - today.setUTCHours(0,0,0,0) + today.setHours(0,0,0,0) // Using numbers picker.set( 'select', playdate.getTime() ) @@ -217,8 +217,8 @@ test( '`select`', function() { deepEqual( picker.get( 'max' ).pick, Infinity, '`max` unaffected' ) // Using arrays - playdate.setUTCDate( playdate.getUTCDate() + 40 ) - picker.set( 'select', [playdate.getUTCFullYear(),playdate.getUTCMonth(),playdate.getUTCDate()] ) + playdate.setDate( playdate.getDate() + 40 ) + picker.set( 'select', [playdate.getFullYear(),playdate.getMonth(),playdate.getDate()] ) deepEqual( picker.get( 'select' ).obj, playdate, '`select` using an array: ' + playdate ) strictEqual( picker.get( 'value' ), picker.get( 'select', $.fn.pickadate.defaults.format ), '`value` matches' ) deepEqual( picker.get( 'highlight' ), picker.get( 'select' ), '`highlight` updated' ) @@ -228,7 +228,7 @@ test( '`select`', function() { deepEqual( picker.get( 'max' ).pick, Infinity, '`max` unaffected' ) // Using JavaScript date objects - playdate.setUTCDate( playdate.getUTCDate() + 40 ) + playdate.setDate( playdate.getDate() + 40 ) picker.set( 'select', playdate ) deepEqual( picker.get( 'select' ).obj, playdate, '`select` using a JS date object: ' + playdate ) strictEqual( picker.get( 'value' ), picker.get( 'select', $.fn.pickadate.defaults.format ), '`value` matches' ) @@ -243,9 +243,9 @@ test( '`highlight`', function() { var picker = this.picker, today = new Date(), - playdate = new Date( Date.UTC( today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate() + 40 ) ) + playdate = new Date( today.getFullYear(), today.getMonth(), today.getDate() + 40 ) - today.setUTCHours(0,0,0,0) + today.setHours(0,0,0,0) // Using numbers picker.set( 'highlight', playdate.getTime() ) @@ -258,8 +258,8 @@ test( '`highlight`', function() { deepEqual( picker.get( 'max' ).pick, Infinity, '`max` unaffected' ) // Using arrays - playdate.setUTCDate( playdate.getUTCDate() + 40 ) - picker.set( 'highlight', [playdate.getUTCFullYear(),playdate.getUTCMonth(),playdate.getUTCDate()] ) + playdate.setDate( playdate.getDate() + 40 ) + picker.set( 'highlight', [playdate.getFullYear(),playdate.getMonth(),playdate.getDate()] ) deepEqual( picker.get( 'highlight' ).obj, playdate, '`highlight` using an array: ' + playdate ) strictEqual( picker.get( 'view', 'yyyy/mm/dd' ), picker.get( 'highlight', 'yyyy/mm/01' ), '`view` updated: ' + picker.get( 'view', 'yyyy/mm/dd' ) ) deepEqual( picker.get( 'now' ).obj, today, '`now` unaffected' ) @@ -269,7 +269,7 @@ test( '`highlight`', function() { deepEqual( picker.get( 'max' ).pick, Infinity, '`max` unaffected' ) // Using JavaScript date objects - playdate.setUTCDate( playdate.getUTCDate() + 40 ) + playdate.setDate( playdate.getDate() + 40 ) picker.set( 'highlight', playdate ) deepEqual( picker.get( 'highlight' ).obj, playdate, '`highlight` using a JS date object: ' + playdate ) strictEqual( picker.get( 'view', 'yyyy/mm/dd' ), picker.get( 'highlight', 'yyyy/mm/01' ), '`view` updated: ' + picker.get( 'view', 'yyyy/mm/dd' ) ) @@ -284,13 +284,13 @@ test( '`view`', function() { var picker = this.picker, today = new Date(), - playdate = new Date( Date.UTC( today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate() + 40 ) ) + playdate = new Date( today.getFullYear(), today.getMonth(), today.getDate() + 40 ) - today.setUTCHours(0,0,0,0) + today.setHours(0,0,0,0) // Using numbers picker.set( 'view', playdate.getTime() ) - playdate.setUTCDate( 1 ) + playdate.setDate( 1 ) deepEqual( picker.get( 'view' ).obj, playdate, '`view` using a number: ' + playdate ) deepEqual( picker.get( 'highlight' ).obj, today, '`highlight` unaffected' ) deepEqual( picker.get( 'now' ).obj, today, '`now` unaffected' ) @@ -300,9 +300,9 @@ test( '`view`', function() { deepEqual( picker.get( 'max' ).pick, Infinity, '`max` unaffected' ) // Using arrays - playdate.setUTCDate( playdate.getUTCDate() + 40 ) - picker.set( 'view', [playdate.getUTCFullYear(),playdate.getUTCMonth(),playdate.getUTCDate()] ) - playdate.setUTCDate( 1 ) + playdate.setDate( playdate.getDate() + 40 ) + picker.set( 'view', [playdate.getFullYear(),playdate.getMonth(),playdate.getDate()] ) + playdate.setDate( 1 ) deepEqual( picker.get( 'view' ).obj, playdate, '`view` using a number: ' + playdate ) deepEqual( picker.get( 'highlight' ).obj, today, '`highlight` unaffected' ) deepEqual( picker.get( 'now' ).obj, today, '`now` unaffected' ) @@ -313,9 +313,9 @@ test( '`view`', function() { // Using JavaScript date objects - playdate.setUTCDate( playdate.getUTCDate() + 40 ) + playdate.setDate( playdate.getDate() + 40 ) picker.set( 'view', playdate ) - playdate.setUTCDate( 1 ) + playdate.setDate( 1 ) deepEqual( picker.get( 'view' ).obj, playdate, '`view` using a JS date object: ' + playdate ) deepEqual( picker.get( 'highlight' ).obj, today, '`highlight` unaffected' ) deepEqual( picker.get( 'now' ).obj, today, '`now` unaffected' ) @@ -329,9 +329,9 @@ test( '`min`', function() { var picker = this.picker, today = new Date(), - playdate = new Date( Date.UTC( today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate() - 40 ) ) + playdate = new Date( today.getFullYear(), today.getMonth(), today.getDate() - 40 ) - today.setUTCHours(0,0,0,0) + today.setHours(0,0,0,0) // Using negative numbers picker.set( 'min', -40 ) @@ -340,41 +340,41 @@ test( '`min`', function() { deepEqual( picker.get( 'select' ), null, '`select` unaffected' ) deepEqual( picker.get( 'highlight' ), picker.get( 'now' ), '`highlight` unaffected' ) - playdate.setUTCDate( 1 ) - playdate.setUTCMonth( today.getUTCMonth() ) - playdate.setUTCFullYear( today.getUTCFullYear() ) + playdate.setDate( 1 ) + playdate.setMonth( today.getMonth() ) + playdate.setFullYear( today.getFullYear() ) deepEqual( picker.get( 'view' ).obj, playdate, '`view` unaffected' ) strictEqual( picker.get( 'value' ), '', '`value` unaffected' ) deepEqual( picker.get( 'max' ).pick, Infinity, '`max` unaffected' ) // Using positive numbers picker.set( 'min', 40 ) - playdate.setUTCDate( today.getUTCDate() + 40 ) + playdate.setDate( today.getDate() + 40 ) deepEqual( picker.get( 'min' ).obj, playdate, '`min` using a positive number: ' + playdate ) deepEqual( picker.get( 'now' ).obj, today, '`now` unaffected' ) deepEqual( picker.get( 'select' ), null, '`select` unaffected' ) deepEqual( picker.get( 'highlight' ), picker.get( 'min' ), '`highlight` updated' ) - playdate.setUTCDate( 1 ) + playdate.setDate( 1 ) deepEqual( picker.get( 'view' ).obj, playdate, '`view` updated' ) strictEqual( picker.get( 'value' ), '', '`value` unaffected' ) deepEqual( picker.get( 'max' ).pick, Infinity, '`max` unaffected' ) // Using arrays - playdate.setUTCDate( playdate.getUTCDate() + 40 ) - picker.set( 'min', [playdate.getUTCFullYear(),playdate.getUTCMonth(),playdate.getUTCDate()] ) + playdate.setDate( playdate.getDate() + 40 ) + picker.set( 'min', [playdate.getFullYear(),playdate.getMonth(),playdate.getDate()] ) deepEqual( picker.get( 'min' ).obj, playdate, '`min` using an array: ' + playdate ) deepEqual( picker.get( 'now' ).obj, today, '`now` unaffected' ) deepEqual( picker.get( 'select' ), null, '`select` unaffected' ) deepEqual( picker.get( 'highlight' ), picker.get( 'min' ), '`highlight` updated' ) strictEqual( picker.get( 'value' ), '', '`value` unaffected' ) - playdate.setUTCDate( 1 ) + playdate.setDate( 1 ) deepEqual( picker.get( 'view' ).obj, playdate, '`view` updated' ) deepEqual( picker.get( 'max' ).pick, Infinity, '`max` unaffected' ) // Using JavaScript date objects - playdate.setUTCDate( playdate.getUTCDate() + 40 ) + playdate.setDate( playdate.getDate() + 40 ) picker.set( 'min', playdate ) deepEqual( picker.get( 'min' ).obj, playdate, '`min` using a JS date object: ' + playdate ) deepEqual( picker.get( 'now' ).obj, today, '`now` unaffected' ) @@ -382,7 +382,7 @@ test( '`min`', function() { deepEqual( picker.get( 'highlight' ), picker.get( 'min' ), '`highlight` updated' ) strictEqual( picker.get( 'value' ), '', '`value` unaffected' ) - playdate.setUTCDate( 1 ) + playdate.setDate( 1 ) deepEqual( picker.get( 'view' ).obj, playdate, '`view` updated' ) deepEqual( picker.get( 'max' ).pick, Infinity, '`max` unaffected' ) }) @@ -391,9 +391,9 @@ test( '`min` using booleans', function() { var picker = this.picker, today = new Date(), - playdate = new Date( Date.UTC( today.getUTCFullYear(), today.getUTCMonth(), 1 ) ) + playdate = new Date( today.getFullYear(), today.getMonth(), 1 ) - today.setUTCHours(0,0,0,0) + today.setHours(0,0,0,0) // Using `true` picker.set( 'min', true ) @@ -420,9 +420,9 @@ test( '`max`', function() { var picker = this.picker, today = new Date(), - playdate = new Date( Date.UTC( today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate() + 40 ) ) + playdate = new Date( today.getFullYear(), today.getMonth(), today.getDate() + 40 ) - today.setUTCHours(0,0,0,0) + today.setHours(0,0,0,0) // Using positive numbers picker.set( 'max', 40 ) @@ -431,41 +431,41 @@ test( '`max`', function() { deepEqual( picker.get( 'select' ), null, '`select` unaffected' ) deepEqual( picker.get( 'highlight' ), picker.get( 'now' ), '`highlight` unaffected' ) - playdate.setUTCFullYear( today.getUTCFullYear() ) - playdate.setUTCMonth( today.getUTCMonth() ) - playdate.setUTCDate( 1 ) + playdate.setYear( today.getFullYear() ) + playdate.setMonth( today.getMonth() ) + playdate.setDate( 1 ) deepEqual( picker.get( 'view' ).obj, playdate, '`view` unaffected' ) strictEqual( picker.get( 'value' ), '', '`value` unaffected' ) deepEqual( picker.get( 'min' ).pick, -Infinity, '`min` unaffected' ) // Using negative numbers picker.set( 'max', -40 ) - playdate.setUTCDate( today.getUTCDate() - 40 ) + playdate.setDate( today.getDate() - 40 ) deepEqual( picker.get( 'max' ).obj, playdate, '`max` using a negative number: ' + playdate ) deepEqual( picker.get( 'now' ).obj, today, '`now` unaffected' ) deepEqual( picker.get( 'select' ), null, '`select` unaffected' ) deepEqual( picker.get( 'highlight' ), picker.get( 'max' ), '`highlight` updated' ) - playdate.setUTCDate( 1 ) + playdate.setDate( 1 ) deepEqual( picker.get( 'view' ).obj, playdate, '`view` unaffected' ) strictEqual( picker.get( 'value' ), '', '`value` unaffected' ) deepEqual( picker.get( 'min' ).pick, -Infinity, '`min` unaffected' ) // Using arrays - playdate.setUTCDate( playdate.getUTCDate() - 40 ) - picker.set( 'max', [playdate.getUTCFullYear(),playdate.getUTCMonth(),playdate.getUTCDate()] ) + playdate.setDate( playdate.getDate() - 40 ) + picker.set( 'max', [playdate.getFullYear(),playdate.getMonth(),playdate.getDate()] ) deepEqual( picker.get( 'max' ).obj, playdate, '`max` using an array: ' + playdate ) deepEqual( picker.get( 'now' ).obj, today, '`now` unaffected' ) deepEqual( picker.get( 'select' ), null, '`select` unaffected' ) deepEqual( picker.get( 'highlight' ), picker.get( 'max' ), '`highlight` updated' ) strictEqual( picker.get( 'value' ), '', '`value` unaffected' ) - playdate.setUTCDate( 1 ) + playdate.setDate( 1 ) deepEqual( picker.get( 'view' ).obj, playdate, '`view` updated' ) deepEqual( picker.get( 'min' ).pick, -Infinity, '`min` unaffected' ) // Using JavaScript date objects - playdate.setUTCDate( playdate.getUTCDate() - 40 ) + playdate.setDate( playdate.getDate() - 40 ) picker.set( 'max', playdate ) deepEqual( picker.get( 'max' ).obj, playdate, '`max` using a JS date object: ' + playdate ) deepEqual( picker.get( 'now' ).obj, today, '`now` unaffected' ) @@ -473,7 +473,7 @@ test( '`max`', function() { deepEqual( picker.get( 'highlight' ), picker.get( 'max' ), '`highlight` updated' ) strictEqual( picker.get( 'value' ), '', '`value` unaffected' ) - playdate.setUTCDate( 1 ) + playdate.setDate( 1 ) deepEqual( picker.get( 'view' ).obj, playdate, '`view` updated' ) deepEqual( picker.get( 'min' ).pick, -Infinity, '`min` unaffected' ) }) @@ -482,9 +482,9 @@ test( '`max` using booleans', function() { var picker = this.picker, today = new Date(), - playdate = new Date( Date.UTC( today.getUTCFullYear(), today.getUTCMonth(), 1 ) ) + playdate = new Date( today.getFullYear(), today.getMonth(), 1 ) - today.setUTCHours(0,0,0,0) + today.setHours(0,0,0,0) // Using `true` picker.set( 'max', true ) @@ -514,11 +514,11 @@ test( '`disable` and `enable` using integers', function() { picker = this.picker, $root = picker.$root - today.setUTCHours(0,0,0,0) + today.setHours(0,0,0,0) picker.set( 'disable', disableCollection ) - if ( disableCollection.indexOf( today.getUTCDay() + 1 ) > -1 ) { + if ( disableCollection.indexOf( today.getDay() + 1 ) > -1 ) { notDeepEqual( picker.get( 'highlight' ), picker.get( 'now' ), 'Shifted disabled `highlight`: ' + picker.get( 'highlight' ).obj ) } @@ -583,8 +583,8 @@ test( '`disable` and `enable` using integers', function() { test( '`disable` and `enable` using arrays', function() { var today = new Date(), - nowYear = today.getUTCFullYear(), - nowMonth = today.getUTCMonth(), + nowYear = today.getFullYear(), + nowMonth = today.getMonth(), disableCollection = [ [nowYear,nowMonth,1],[nowYear,nowMonth,25],[nowYear,nowMonth,17] ], picker = this.picker, viewday = picker.get( 'view' ).day, @@ -651,9 +651,9 @@ test( '`disable` and `enable` using arrays', function() { test( '`disable` and `enable` using JS dates', function() { var now = new Date(), - nowYear = now.getUTCFullYear(), - nowMonth = now.getUTCMonth(), - disableCollection = [ new Date(Date.UTC(nowYear,nowMonth,1)), new Date(Date.UTC(nowYear,nowMonth,17)), new Date(Date.UTC(nowYear,nowMonth,25)) ], + nowYear = now.getFullYear(), + nowMonth = now.getMonth(), + disableCollection = [ new Date(nowYear,nowMonth,1), new Date(nowYear,nowMonth,17), new Date(nowYear,nowMonth,25) ], picker = this.picker, viewday = picker.get( 'view' ).day, $root = picker.$root @@ -673,8 +673,8 @@ test( '`disable` and `enable` using JS dates', function() { }) - picker.set( 'enable', [ new Date(Date.UTC(nowYear,nowMonth,17)) ] ) - deepEqual( picker.get( 'disable' ), [ new Date(Date.UTC(nowYear,nowMonth,1)), new Date(Date.UTC(nowYear,nowMonth,25)) ], 'Disabled date removed from collection' ) + picker.set( 'enable', [ new Date(nowYear,nowMonth,17) ] ) + deepEqual( picker.get( 'disable' ), [ new Date(nowYear,nowMonth,1), new Date(nowYear,nowMonth,25) ], 'Disabled date removed from collection' ) $root.find( 'td [data-pick]' ).each( function( indexCell, tableCell ) { var index = indexCell - viewday + 1 @@ -688,7 +688,7 @@ test( '`disable` and `enable` using JS dates', function() { picker.set( 'enable', 'flip' ) - deepEqual( picker.get( 'disable' ), [ new Date(Date.UTC(nowYear,nowMonth,1)), new Date(Date.UTC(nowYear,nowMonth,25)) ], 'Disabled collection `enable` flipped' ) + deepEqual( picker.get( 'disable' ), [ new Date(nowYear,nowMonth,1), new Date(nowYear,nowMonth,25) ], 'Disabled collection `enable` flipped' ) $root.find( 'td [data-pick]' ).each( function( indexCell, tableCell ) { var index = indexCell - viewday + 1 @@ -702,7 +702,7 @@ test( '`disable` and `enable` using JS dates', function() { picker.set( 'disable', 'flip' ) - deepEqual( picker.get( 'disable' ), [ new Date(Date.UTC(nowYear,nowMonth,1)), new Date(Date.UTC(nowYear,nowMonth,25)) ], 'Disabled collection `disable` flipped' ) + deepEqual( picker.get( 'disable' ), [ new Date(nowYear,nowMonth,1), new Date(nowYear,nowMonth,25) ], 'Disabled collection `disable` flipped' ) $root.find( 'td [data-pick]' ).each( function( indexCell, tableCell ) { var index = indexCell - viewday + 1 @@ -718,8 +718,8 @@ test( '`disable` and `enable` using JS dates', function() { test( '`disable` and `enable` using booleans', function() { var now = new Date(), - nowYear = now.getUTCFullYear(), - nowMonth = now.getUTCMonth(), + nowYear = now.getFullYear(), + nowMonth = now.getMonth(), disableCollection = [ [nowYear,nowMonth,1],[nowYear,nowMonth,17],[nowYear,nowMonth,25] ], picker = this.picker, $root = picker.$root @@ -792,7 +792,7 @@ test( '`disable` and `enable` using ranges', function() { strictEqual( $root.find( '.' + $.fn.pickadate.defaults.klass.disabled ).length, 0, 'No dates disabled' ) - disableCollection = [ { from: new Date(Date.UTC(2014,2,7)), to: new Date(Date.UTC(2014,2,17)) } ] + disableCollection = [ { from: new Date(2014,2,7), to: new Date(2014,2,17) } ] picker.set( 'disable', disableCollection ) deepEqual( picker.get( 'disable' ), disableCollection, 'Disabled range updated' ) @@ -816,11 +816,11 @@ test( '`disable` and `enable` using relative ranges', function() { var picker = this.picker, $root = picker.$root, today = picker.get( 'now' ).obj, - yearToday = today.getUTCFullYear(), - monthToday = today.getUTCMonth(), - dateToday = today.getUTCDate(), + yearToday = today.getFullYear(), + monthToday = today.getMonth(), + dateToday = today.getDate(), backDay = [ yearToday, monthToday, dateToday - 10 ], - forwardDay = new Date( Date.UTC(yearToday, monthToday, dateToday + 10 ) ), + forwardDay = new Date( yearToday, monthToday, dateToday + 10 ), disableCollection, index, $dates, disabledDate, previousMonth disableCollection = [ { from: true, to: forwardDay } ] @@ -830,9 +830,9 @@ test( '`disable` and `enable` using relative ranges', function() { $dates = $root.find('.' + $.fn.pickadate.defaults.klass.disabled) for ( index = 0, datesCount = $dates.length; index < datesCount; index += 1 ) { disabledDate = +$dates[index].innerHTML - disabledDate = new Date(Date.UTC(yearToday, monthToday, disabledDate)) + disabledDate = new Date(yearToday, monthToday, disabledDate) ok( disabledDate >= today && - disabledDate <= new Date(Date.UTC(yearToday, monthToday, dateToday + 10)), + disabledDate <= new Date(yearToday, monthToday, dateToday + 10), 'Date is disabled: ' + disabledDate ); } @@ -849,9 +849,9 @@ test( '`disable` and `enable` using relative ranges', function() { for ( index = 0, datesCount = $dates.length; index < datesCount; index += 1 ) { disabledDate = +$dates[index].innerHTML previousMonth = disabledDate > dateToday ? 1 : 0 - disabledDate = new Date(Date.UTC(yearToday, monthToday - previousMonth, disabledDate)) + disabledDate = new Date(yearToday, monthToday - previousMonth, disabledDate) ok( disabledDate <= today && - disabledDate >= new Date(Date.UTC(yearToday, monthToday, dateToday - 10)), + disabledDate >= new Date(yearToday, monthToday, dateToday - 10), 'Date is disabled: ' + disabledDate ); } @@ -867,9 +867,9 @@ test( '`disable` and `enable` using relative ranges', function() { $dates = $root.find('.' + $.fn.pickadate.defaults.klass.disabled) for ( index = 0, datesCount = $dates.length; index < datesCount; index += 1 ) { disabledDate = +$dates[index].innerHTML - disabledDate = new Date(Date.UTC(yearToday, monthToday, disabledDate)) + disabledDate = new Date(yearToday, monthToday, disabledDate) ok( disabledDate >= today && - disabledDate <= new Date(Date.UTC(yearToday, monthToday, dateToday + 10)), + disabledDate <= new Date(yearToday, monthToday, dateToday + 10), 'Date is disabled: ' + disabledDate ); } @@ -886,9 +886,9 @@ test( '`disable` and `enable` using relative ranges', function() { for ( index = 0, datesCount = $dates.length; index < datesCount; index += 1 ) { disabledDate = +$dates[index].innerHTML previousMonth = disabledDate > dateToday ? 1 : 0 - disabledDate = new Date(Date.UTC(yearToday, monthToday - previousMonth, disabledDate)) + disabledDate = new Date(yearToday, monthToday - previousMonth, disabledDate) ok( disabledDate <= today && - disabledDate >= new Date(Date.UTC(yearToday, monthToday, dateToday - 10)), + disabledDate >= new Date(yearToday, monthToday, dateToday - 10), 'Date is disabled: ' + disabledDate ); } @@ -971,15 +971,15 @@ test( '`disable` and `enable` using overlapping ranges', function() { test( '`disable` and `enable` repeatedly', function() { - var now = new Date(Date.UTC(2014,3,6)), - nowYear = now.getUTCFullYear(), - nowMonth = now.getUTCMonth(), - nowDate = now.getUTCDate(), + var now = new Date(2014,3,6), + nowYear = now.getFullYear(), + nowMonth = now.getMonth(), + nowDate = now.getDate(), picker = this.picker, disabledCollection = [ [nowYear,nowMonth,1], [nowYear,nowMonth,17], - new Date(Date.UTC(nowYear,nowMonth,25)), + new Date(nowYear,nowMonth,25), 1, { from: [nowYear,nowMonth,4], to: [nowYear,nowMonth,10] }, { from: [nowYear,nowMonth,8], to: [nowYear,nowMonth,12] } @@ -1040,12 +1040,12 @@ test( '`select`', function() { var picker = this.picker, today = new Date() - today.setUTCHours(0,0,0,0) + today.setHours(0,0,0,0) - picker.set( 'select', new Date( Date.UTC( today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate() - 60 ) ) ) + picker.set( 'select', new Date( today.getFullYear(), today.getMonth(), today.getDate() - 60 ) ) deepEqual( picker.get( 'select' ), picker.get( 'min' ), 'Able to not `select` beyond lower limit' ) - picker.set( 'select', new Date( Date.UTC( today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate() + 60 ) ) ) + picker.set( 'select', new Date( today.getFullYear(), today.getMonth(), today.getDate() + 60 ) ) deepEqual( picker.get( 'select' ), picker.get( 'max' ), 'Able to not `select` beyond upper limit' ) }) @@ -1054,12 +1054,12 @@ test( '`highlight`', function() { var picker = this.picker, today = new Date() - today.setUTCHours(0,0,0,0) + today.setHours(0,0,0,0) - picker.set( 'highlight', new Date( Date.UTC( today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate() - 60 ) ) ) + picker.set( 'highlight', new Date( today.getFullYear(), today.getMonth(), today.getDate() - 60 ) ) deepEqual( picker.get( 'highlight' ), picker.get( 'min' ), 'Able to not `highlight` beyond lower limit' ) - picker.set( 'highlight', new Date( Date.UTC( today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate() + 60 ) ) ) + picker.set( 'highlight', new Date( today.getFullYear(), today.getMonth(), today.getDate() + 60 ) ) deepEqual( picker.get( 'highlight' ), picker.get( 'max' ), 'Able to not `highlight` beyond upper limit' ) }) @@ -1071,13 +1071,13 @@ test( '`view`', function() { min = picker.get( 'min' ), max = picker.get( 'max' ) - today.setUTCHours(0,0,0,0) + today.setHours(0,0,0,0) - picker.set( 'view', new Date( Date.UTC( today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate() - 60 ) ) ) + picker.set( 'view', new Date( today.getFullYear(), today.getMonth(), today.getDate() - 60 ) ) viewset = picker.get( 'view' ) deepEqual( [viewset.year,viewset.month,viewset.date], [min.year,min.month,1], 'Able to not `view` beyond lower limit' ) - picker.set( 'view', new Date( Date.UTC( today.getUTCFullYear(), today.getUTCMonth(), today.getUTCDate() + 60 ) ) ) + picker.set( 'view', new Date( today.getFullYear(), today.getMonth(), today.getDate() + 60 ) ) viewset = picker.get( 'view' ) deepEqual( [viewset.year,viewset.month,viewset.date], [max.year,max.month,1], 'Able to not `view` beyond upper limit' ) }) @@ -1103,11 +1103,11 @@ test( 'Select', function() { $root = picker.$root, viewsetObject = picker.get( 'view' ), monthStartDay = viewsetObject.day, - monthEndDate = new Date( Date.UTC( viewsetObject.year, viewsetObject.month + 1, 0 ) ).getUTCDate() + monthEndDate = new Date( viewsetObject.year, viewsetObject.month + 1, 0 ).getDate() for ( var i = monthStartDay; i < monthStartDay + monthEndDate; i += 1 ) { $root.find( '.' + $.fn.pickadate.defaults.klass.day ).eq( i ).click() - strictEqual( picker.get( 'select' ).pick, new Date( Date.UTC( viewsetObject.year, viewsetObject.month, viewsetObject.date + i - monthStartDay ) ).getTime(), 'Selected ' + picker.get( 'select', 'yyyy/mm/dd' ) ) + strictEqual( picker.get( 'select' ).pick, new Date( viewsetObject.year, viewsetObject.month, viewsetObject.date + i - monthStartDay ).getTime(), 'Selected ' + picker.get( 'select', 'yyyy/mm/dd' ) ) strictEqual( picker.get( 'value' ), picker.get( 'select', $.fn.pickadate.defaults.format ), 'Input value updated to ' + picker.get( 'value' ) ) } }) @@ -1119,29 +1119,29 @@ test( 'Highlight', function() { today = new Date(), playdate = new Date() - today.setUTCHours(0,0,0,0) - playdate.setUTCHours(0,0,0,0) + today.setHours(0,0,0,0) + playdate.setHours(0,0,0,0) $root.find( '.' + $.fn.pickadate.defaults.klass.navPrev ).click() - playdate.setUTCMonth( playdate.getUTCMonth() - 1 ) + playdate.setMonth( playdate.getMonth() - 1 ) deepEqual( picker.get( 'highlight' ).obj, playdate, 'Previous month: ' + playdate ) deepEqual( picker.get( 'select' ), null, 'Select unaffected' ) - playdate.setUTCDate( 1 ) + playdate.setDate( 1 ) deepEqual( picker.get( 'view' ).obj, playdate, 'View updated' ) $root.find( '.' + $.fn.pickadate.defaults.klass.navNext ).click() $root.find( '.' + $.fn.pickadate.defaults.klass.navNext ).click() - playdate.setUTCMonth( today.getUTCMonth() + 1 ) + playdate.setMonth( today.getMonth() + 1 ) - playdate = new Date(Date.UTC(today.getUTCFullYear(), today.getUTCMonth() + 1, today.getUTCDate())) - while ( playdate.getUTCMonth() > today.getUTCMonth() + 1 ) { - playdate = new Date(Date.UTC(playdate.getUTCFullYear(), playdate.getUTCMonth(), playdate.getUTCDate() - 1)) + playdate = new Date(today.getFullYear(), today.getMonth() + 1, today.getDate()) + while ( playdate.getMonth() > today.getMonth() + 1 ) { + playdate = new Date(playdate.getFullYear(), playdate.getMonth(), playdate.getDate() - 1) } deepEqual( picker.get( 'highlight' ).obj, playdate, 'Next month: ' + playdate ) deepEqual( picker.get( 'select' ), null, 'Select unaffected' ) - playdate.setUTCDate( 1 ) + playdate.setDate( 1 ) deepEqual( picker.get( 'view' ).obj, playdate, 'View updated' ) }) @@ -1189,7 +1189,7 @@ test( 'Select', function() { $input = picker.$node, playdate = new Date() - playdate.setUTCHours(0,0,0,0) + playdate.setHours(0,0,0,0) for ( var i = 0; i < 10; i += 1 ) { @@ -1197,7 +1197,7 @@ test( 'Select', function() { picker.open() // Update the playdate. - playdate.setUTCDate( playdate.getUTCDate() + 10 ) + playdate.setDate( playdate.getDate() + 10 ) // Set the highlight. picker.set( 'highlight', playdate ) @@ -1223,8 +1223,8 @@ test( 'Highlight', function() { for ( var i = 0; i < 10; i += 1 ) { $input.trigger({ type: 'keydown', keyCode: 40 }) - playdate.setUTCDate( playdate.getUTCDate() + 7 ) - strictEqual( picker.get( 'highlight' ).date, playdate.getUTCDate(), 'Keyed "down" to: ' + picker.get( 'highlight', 'yyyy/mm/dd' ) ) + playdate.setDate( playdate.getDate() + 7 ) + strictEqual( picker.get( 'highlight' ).date, playdate.getDate(), 'Keyed "down" to: ' + picker.get( 'highlight', 'yyyy/mm/dd' ) ) strictEqual( picker.get( 'view' ).month, picker.get( 'highlight' ).month, 'Updated "view" to: ' + picker.get( 'view', 'yyyy/mm/dd' ) ) } @@ -1232,8 +1232,8 @@ test( 'Highlight', function() { for ( var j = 0; j < 10; j += 1 ) { $input.trigger({ type: 'keydown', keyCode: 38 }) - playdate.setUTCDate( playdate.getUTCDate() - 7 ) - strictEqual( picker.get( 'highlight' ).date, playdate.getUTCDate(), 'Keyed "up" to: ' + picker.get( 'highlight', 'yyyy/mm/dd' ) ) + playdate.setDate( playdate.getDate() - 7 ) + strictEqual( picker.get( 'highlight' ).date, playdate.getDate(), 'Keyed "up" to: ' + picker.get( 'highlight', 'yyyy/mm/dd' ) ) strictEqual( picker.get( 'view' ).month, picker.get( 'highlight' ).month, 'Updated "view" to: ' + picker.get( 'view', 'yyyy/mm/dd' ) ) } @@ -1241,8 +1241,8 @@ test( 'Highlight', function() { for ( var k = 0; k < 10; k += 1 ) { $input.trigger({ type: 'keydown', keyCode: 37 }) - playdate.setUTCDate( playdate.getUTCDate() - 1 ) - ok( picker.get( 'highlight' ).date === playdate.getUTCDate() && picker.get( 'highlight' ).day === playdate.getUTCDay(), 'Keyed "left" to: ' + picker.get( 'highlight', 'yyyy/mm/dd' ) ) + playdate.setDate( playdate.getDate() - 1 ) + ok( picker.get( 'highlight' ).date === playdate.getDate() && picker.get( 'highlight' ).day === playdate.getDay(), 'Keyed "left" to: ' + picker.get( 'highlight', 'yyyy/mm/dd' ) ) strictEqual( picker.get( 'view' ).month, picker.get( 'highlight' ).month, 'Updated "view" to: ' + picker.get( 'view', 'yyyy/mm/dd' ) ) } @@ -1250,8 +1250,8 @@ test( 'Highlight', function() { for ( var l = 0; l < 10; l += 1 ) { $input.trigger({ type: 'keydown', keyCode: 39 }) - playdate.setUTCDate( playdate.getUTCDate() + 1 ) - ok( picker.get( 'highlight' ).date === playdate.getUTCDate() && picker.get( 'highlight' ).day === playdate.getUTCDay(), 'Keyed "right" to: ' + picker.get( 'highlight', 'yyyy/mm/dd' ) ) + playdate.setDate( playdate.getDate() + 1 ) + ok( picker.get( 'highlight' ).date === playdate.getDate() && picker.get( 'highlight' ).day === playdate.getDay(), 'Keyed "right" to: ' + picker.get( 'highlight', 'yyyy/mm/dd' ) ) strictEqual( picker.get( 'view' ).month, picker.get( 'highlight' ).month, 'Updated "view" to: ' + picker.get( 'view', 'yyyy/mm/dd' ) ) } }) @@ -1274,9 +1274,9 @@ module( 'Date picker with a visible value', { test( '`value` to select, highlight, and view', function() { var picker = this.picker ok( !picker._hidden, 'No hidden input' ) - deepEqual( picker.get( 'select' ).obj, new Date(Date.UTC(1988,7,14)), 'Selects date' ) - deepEqual( picker.get( 'highlight' ).obj, new Date(Date.UTC(1988,7,14)), 'Highlights date' ) - deepEqual( picker.get( 'view' ).obj, new Date(Date.UTC(1988,7,1)), 'Viewsets date' ) + deepEqual( picker.get( 'select' ).obj, new Date(1988,7,14), 'Selects date' ) + deepEqual( picker.get( 'highlight' ).obj, new Date(1988,7,14), 'Highlights date' ) + deepEqual( picker.get( 'view' ).obj, new Date(1988,7,1), 'Viewsets date' ) }) @@ -1297,9 +1297,9 @@ module( 'Date picker with a simple format', { test( '`value` to select, highlight, and view', function() { var picker = this.picker ok( !picker._hidden, 'No hidden input' ) - deepEqual( picker.get( 'select' ).obj, new Date(Date.UTC(1988,7,14)), 'Selects date' ) - deepEqual( picker.get( 'highlight' ).obj, new Date(Date.UTC(1988,7,14)), 'Highlights date' ) - deepEqual( picker.get( 'view' ).obj, new Date(Date.UTC(1988,7,1)), 'Viewsets date' ) + deepEqual( picker.get( 'select' ).obj, new Date(1988,7,14), 'Selects date' ) + deepEqual( picker.get( 'highlight' ).obj, new Date(1988,7,14), 'Highlights date' ) + deepEqual( picker.get( 'view' ).obj, new Date(1988,7,1), 'Viewsets date' ) }) @@ -1321,9 +1321,9 @@ test( '`value` to select, highlight, and view', function() { ok( picker._hidden, 'Has hidden input' ) strictEqual( picker._hidden.value, '1988/08/14', 'Hidden input value' ) - deepEqual( picker.get( 'select' ).obj, new Date(Date.UTC(1988,7,14)), 'Selects date' ) - deepEqual( picker.get( 'highlight' ).obj, new Date(Date.UTC(1988,7,14)), 'Highlights date' ) - deepEqual( picker.get( 'view' ).obj, new Date(Date.UTC(1988,7,1)), 'Viewsets date' ) + deepEqual( picker.get( 'select' ).obj, new Date(1988,7,14), 'Selects date' ) + deepEqual( picker.get( 'highlight' ).obj, new Date(1988,7,14), 'Highlights date' ) + deepEqual( picker.get( 'view' ).obj, new Date(1988,7,1), 'Viewsets date' ) }) test( '`data-value` to select, highlight, and view', function() { @@ -1336,9 +1336,9 @@ test( '`data-value` to select, highlight, and view', function() { ok( picker._hidden, 'Has hidden input' ) strictEqual( picker._hidden.value, '1988/08/14', 'Hidden input value' ) - deepEqual( picker.get( 'select' ).obj, new Date(Date.UTC(1988,7,14)), 'Selects date' ) - deepEqual( picker.get( 'highlight' ).obj, new Date(Date.UTC(1988,7,14)), 'Highlights date' ) - deepEqual( picker.get( 'view' ).obj, new Date(Date.UTC(1988,7,1)), 'Viewsets date' ) + deepEqual( picker.get( 'select' ).obj, new Date(1988,7,14), 'Selects date' ) + deepEqual( picker.get( 'highlight' ).obj, new Date(1988,7,14), 'Highlights date' ) + deepEqual( picker.get( 'view' ).obj, new Date(1988,7,1), 'Viewsets date' ) }) diff --git a/tests/units/time.js b/tests/units/time.js index 72f0e0dd..f642a67c 100644 --- a/tests/units/time.js +++ b/tests/units/time.js @@ -41,7 +41,7 @@ test( 'Properties', function() { var picker = this.picker, today = new Date(), interval = picker.get( 'interval' ), - nowMinutes = today.getUTCHours() * 60 + today.getUTCMinutes() + nowMinutes = today.getHours() * 60 + today.getMinutes() strictEqual( interval, 30, 'Default interval is 30' ) @@ -60,7 +60,7 @@ test( 'Formats', function() { var picker = this.picker, interval = $.fn.pickatime.defaults.interval, today = new Date(), - minutes = today.getUTCHours() * 60 + today.getUTCMinutes(), + minutes = today.getHours() * 60 + today.getMinutes(), leadZero = function( number ) { return ( number < 10 ? '0' : '' ) + number }, @@ -177,7 +177,7 @@ test( '`select`', function() { // Using JavaScript date objects var dateObject = new Date() - dateObject.setUTCHours(4,20) + dateObject.setHours(4,20) picker.set( 'select', dateObject ) strictEqual( picker.get('select').pick, 270, '`select` using a JS date object: ' + picker.get( 'select', 'HH:i' ) ) strictEqual( picker.get( 'highlight' ).pick, 270, '`highlight` updated' ) @@ -208,7 +208,7 @@ test( '`highlight`', function() { // Using JavaScript date objects var dateObject = new Date() - dateObject.setUTCHours(4,20) + dateObject.setHours(4,20) picker.set( 'highlight', dateObject ) strictEqual( picker.get('highlight').pick, 270, '`highlight` using a JS date object: ' + picker.get( 'highlight', 'HH:i' ) ) deepEqual( picker.get( 'view' ), picker.get( 'highlight' ), '`view` updated' ) @@ -239,7 +239,7 @@ test( '`view`', function() { // Using JavaScript date objects var dateObject = new Date() - dateObject.setUTCHours(4,20) + dateObject.setHours(4,20) picker.set( 'view', dateObject ) strictEqual( picker.get('view').pick, 270, '`view` using a JS date object: ' + picker.get( 'view', 'HH:i' ) ) strictEqual( picker.get( 'highlight' ).pick, picker.get( 'now' ).pick, '`highlight` unaffected' ) @@ -339,7 +339,7 @@ test( '`min` using JS dates', function() { // Using JavaScript date objects var dateObject = new Date() - dateObject.setUTCHours(4,30) + dateObject.setHours(4,30) picker.set( 'min', dateObject ) strictEqual( picker.get( 'min' ).pick, 270, '`min` using a JS date: ' + picker.get( 'min', 'HH:i' ) ) deepEqual( picker.get( 'select' ), null, '`select` unaffected' ) @@ -435,7 +435,7 @@ test( '`max` using JS dates', function() { // Using JavaScript date objects var dateObject = new Date() - dateObject.setUTCHours(16,20) + dateObject.setHours(16,20) picker.set( 'max', dateObject ) strictEqual( picker.get( 'max' ).pick, 960, '`max` using a JS date: ' + picker.get( 'max', 'HH:i' ) ) deepEqual( picker.get( 'select' ), null, '`select` unaffected' ) @@ -582,7 +582,7 @@ test( '`disable` and `enable` using arrays', function() { test( '`disable` and `enable` using JS times', function() { - var disableCollection = [ new Date(Date.UTC(2014,2,2,1)), new Date(Date.UTC(2014,2,2,17,30)), new Date(Date.UTC(2014,2,2,3)) ], + var disableCollection = [ new Date(2014,2,2,1), new Date(2014,2,2,17,30), new Date(2014,2,2,3) ], picker = this.picker, $root = picker.$root @@ -600,8 +600,8 @@ test( '`disable` and `enable` using JS times', function() { }) - picker.set( 'enable', [ new Date(Date.UTC(2014,2,2,17,30)) ] ) - deepEqual( picker.get( 'disable' ), [ new Date(Date.UTC(2014,2,2,1)), new Date(Date.UTC(2014,2,2,3)) ], 'Disabled time removed' ) + picker.set( 'enable', [ new Date(2014,2,2,17,30) ] ) + deepEqual( picker.get( 'disable' ), [ new Date(2014,2,2,1), new Date(2014,2,2,3) ], 'Disabled time removed' ) $root.find( '.' + $.fn.pickatime.defaults.klass.listItem ).each( function( index, item ) { if ( index === 2 || index === 6 ) { @@ -614,7 +614,7 @@ test( '`disable` and `enable` using JS times', function() { picker.set( 'enable', 'flip' ) - deepEqual( picker.get( 'disable' ), [ new Date(Date.UTC(2014,2,2,1)), new Date(Date.UTC(2014,2,2,3)) ], 'Disabled collection `enable` flipped' ) + deepEqual( picker.get( 'disable' ), [ new Date(2014,2,2,1), new Date(2014,2,2,3) ], 'Disabled collection `enable` flipped' ) $root.find( '[data-pick]' ).each( function( index, item ) { if ( index !== 2 && index !== 6 ) { @@ -627,7 +627,7 @@ test( '`disable` and `enable` using JS times', function() { picker.set( 'disable', 'flip' ) - deepEqual( picker.get( 'disable' ), [ new Date(Date.UTC(2014,2,2,1)), new Date(Date.UTC(2014,2,2,3)) ], 'Disabled collection `disable` flipped' ) + deepEqual( picker.get( 'disable' ), [ new Date(2014,2,2,1), new Date(2014,2,2,3) ], 'Disabled collection `disable` flipped' ) $root.find( '[data-pick]' ).each( function( index, item ) { if ( index === 2 || index === 6 ) { @@ -709,7 +709,7 @@ test( '`disable` and `enable` using ranges', function() { strictEqual( $root.find( '.' + $.fn.pickatime.defaults.klass.disabled ).length, 0, 'No times disabled' ) - disableCollection = [ { from: new Date(Date.UTC(2014,2,7,5,30)), to: new Date(Date.UTC(2014,2,7,19)) } ] + disableCollection = [ { from: new Date(2014,2,7,5,30), to: new Date(2014,2,7,19) } ] picker.set( 'disable', disableCollection ) deepEqual( picker.get( 'disable' ), disableCollection, 'Disabled range updated' ) @@ -881,12 +881,12 @@ test( '`disable` and `enable` using overlapping ranges', function() { test( '`disable` and `enable` repeatedly', function() { - var now = new Date(Date.UTC(2014,3,20,4,30)), + var now = new Date(2014,3,20,4,30), picker = this.picker, disabledCollection = [ [14,0], [16,30], - new Date(Date.UTC(2014,3,20,22)), + new Date(2014,3,20,22), 1, { from: [3,0], to: [7,30] }, { from: [6,0], to: [11,30] } From 5aee7e8b5e7ab307e850f1b8b6a2bfb8167e3d43 Mon Sep 17 00:00:00 2001 From: Darren Haken Date: Thu, 10 Jul 2014 09:54:59 +0100 Subject: [PATCH 2/3] Added test that uses local time to ensure that the date value is correct for the users timezone. For example 'Wed Jul 23 2014 00:00:00 GMT+0100 (BST)' should be interpretted as 23 July, 2014'. Added .idea to gitignore for JetBrains IDEs. --- .gitignore | 2 ++ tests/units/date.js | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/.gitignore b/.gitignore index 24a1ece6..c5871a2b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ node_modules/* *.log + +.idea \ No newline at end of file diff --git a/tests/units/date.js b/tests/units/date.js index daec4f15..24bb3978 100644 --- a/tests/units/date.js +++ b/tests/units/date.js @@ -198,6 +198,20 @@ test( '`clear`', function() { strictEqual( picker.get('select'), null, 'Clears out selection' ) }) +test('Does not set today to previous day', function() { + + var picker = this.picker, + currentDate = new Date('Wed Jul 23 2014 00:00:00 GMT+0100 (BST)'); + + console.log(currentDate); + + picker.open(); + picker.set('select', currentDate); + + strictEqual(picker.get('value'), '23 July, 2014', 'Picker should be set to expected date'); +}); + + test( '`select`', function() { var picker = this.picker, From 89e46ba13152e53ba42844720f0683bb6edbc943 Mon Sep 17 00:00:00 2001 From: Darren Haken Date: Thu, 10 Jul 2014 10:40:26 +0100 Subject: [PATCH 3/3] Added close button to picker. Resolved jshint errors which already existed in the code base through unused variables/functions in demo.js --- README.md | 8 +++--- api.htm | 30 +++++++++++----------- demo/scripts/demo.js | 20 --------------- lib/compressed/picker.date.js | 2 +- lib/compressed/picker.js | 2 +- lib/compressed/picker.time.js | 2 +- lib/compressed/themes/classic.date.css | 2 +- lib/compressed/themes/default.date.css | 2 +- lib/picker.date.js | 6 ++++- lib/picker.js | 3 +++ lib/themes-source/base.date.less | 23 +++++++++++++---- lib/themes/classic.date.css | 22 ++++++++++++---- lib/themes/default.date.css | 22 ++++++++++++---- tests/units/date.js | 35 ++++++++++++++++++++++++-- 14 files changed, 117 insertions(+), 62 deletions(-) diff --git a/README.md b/README.md index 1d2860d9..1309bfde 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,9 @@ There are currently two pickers: **date** and **time**. File | Contents | Size (min & gzip) ----------------------- | ------------------------ | ---------------------- -`picker.js` | __Base *__ | 1.75kb +`picker.js` | __Base *__ | 1.76kb `picker.date.js` | Date picker | 2.65kb -`picker.time.js` | Time picker | 1.86kb +`picker.time.js` | Time picker | 1.85kb __*__ The base script is **required** for any of the pickers to function. @@ -52,10 +52,10 @@ All themes are [generated using LESS](#less-styling) and compiled from the `lib/ File | Contents | Size (min & gzip) ----------------------- | ---------------------------- | ---------------------- `default.css` | __Base default *__ | 0.49kb -`default.date.css` | Default date picker | 0.72kb +`default.date.css` | Default date picker | 0.74kb `default.time.css` | Default time picker | 0.35kb `classic.css` | __Base classic *__ | 0.39kb -`classic.date.css` | Classic date picker | 0.72kb +`classic.date.css` | Classic date picker | 0.74kb `classic.time.css` | Classic time picker | 0.35kb `rtl.css` | __RTL language stylings **__ | 0.10kb diff --git a/api.htm b/api.htm index 39ec44ad..685126a9 100644 --- a/api.htm +++ b/api.htm @@ -308,16 +308,16 @@

* Item Ob month: 3, // The date of the month. - date: 20, + date: 19, // The day of the week with zero-as-index. - day: 6, + day: 5, // The underlying JavaScript Date object. - obj: { 'Sat, 20 Apr 2013 04:00:00 GMT' }, + obj: { 'Fri, 19 Apr 2013 23:00:00 GMT' }, // The “pick” value used for comparisons. - pick: 1366430400000 + pick: 1366412400000 }

Here’s a time picker item object for 4:20 PM:

@@ -556,13 +556,13 @@

Set Select a date item object§

// Using arrays formatted as [YEAR,MONTH,DATE].
-picker.set('select', [2013,3,20])
+picker.set('select', [2013,3,19])
 
 // Using JavaScript Date objects.
-picker.set('select', new Date(2013, 3, 30))
+picker.set('select', new Date(2013, 3, 28))
 
 // Using positive integers as UNIX timestamps.
-picker.set('select', 1366898887654)
+picker.set('select', 1366880887654)
 
 // Using a string along with the parsing format (defaults to `format` option).
 picker.set('select', '2014-04-20', { format: 'yyyy-mm-dd' })
@@ -575,7 +575,7 @@

Select a time Set Highlight a date item object§

// Using arrays formatted as [YEAR,MONTH,DATE].
-picker.set('highlight', [2013,3,20])
+picker.set('highlight', [2013,3,19])
 
 // Using JavaScript Date objects.
-picker.set('highlight', new Date(2013, 3, 30))
+picker.set('highlight', new Date(2013, 3, 28))
 
 // Using positive integers as UNIX timestamps.
-picker.set('highlight', 1366898887654)
+picker.set('highlight', 1366880887654)
 
 // Using a string along with the parsing format (defaults to `format` option).
 picker.set('highlight', '2014-04-20', { format: 'yyyy-mm-dd' })
@@ -619,7 +619,7 @@

Highlight a time picker.set('highlight', [15,30]) // Using JavaScript Date objects. -picker.set('highlight', new Date(2013, 3, 20, 10, 30)) +picker.set('highlight', new Date(2013, 3, 19, 10, 30)) // Using positive integers as minutes. picker.set('highlight', 1080) @@ -665,7 +665,7 @@

Viewset a time < picker.set('view', [15,30]) // Using JavaScript Date objects. -picker.set('view', new Date(2013, 3, 20, 10, 30)) +picker.set('view', new Date(2013, 3, 19, 10, 30)) // Using positive integers as minutes. picker.set('view', 1080) @@ -712,7 +712,7 @@

Limit the min ti picker.set('min', [15,30]) // Using JavaScript Date objects. -picker.set('min', new Date(2013, 3, 20, 10, 30)) +picker.set('min', new Date(2013, 3, 19, 10, 30)) // Using integers as intervals relative from now. picker.set('min', -4) @@ -762,7 +762,7 @@

Limit the max ti picker.set('max', [15,30]) // Using JavaScript Date objects. -picker.set('max', new Date(2013, 3, 20, 10, 30)) +picker.set('max', new Date(2013, 3, 19, 10, 30)) // Using integers as intervals relative from now. picker.set('max', 4) diff --git a/demo/scripts/demo.js b/demo/scripts/demo.js index 93e39f36..7d24a9c7 100644 --- a/demo/scripts/demo.js +++ b/demo/scripts/demo.js @@ -1144,26 +1144,6 @@ $( '#button__api-set--enable-time-all' ).on( 'click', function( event ) { event.stopPropagation() }) -//enable/disable: range -var $input_set__enable_disable_in_range_date = $( '#demo__api-set--enable-disable-in-range-date' ).pickadate({ - disable: [ - 1, [2013, 10, 17, 'inverted'], - { from: [2014, 2, 2], to: [2014, 2, 28] }, - [2014, 2, 10, 'inverted'], - { from: [2014, 2, 14], to: [2014, 2, 23], inverted: true } - ] - }), - picker_set__enable_disable_in_range_date = $input_set__enable_disable_in_range_date.pickadate( 'picker' ) -var $input_set__enable_disable_in_range_time = $( '#demo__api-set--enable-disable-in-range-time' ).pickatime({ - disable: [ - 1, [1, 30, 'inverted'], - { from: [3,0], to: [18,0] }, - [4, 30, 'inverted'], - { from: [7,30], to: [11,30], inverted: true } - ] - }), - picker_set__enable_disable_in_range_time = $input_set__enable_disable_in_range_time.pickatime( 'picker' ) - //interval: time var $input_set__interval_time = $( '#demo__api-set--interval' ).pickatime(), picker_set__interval_time = $input_set__interval_time.pickatime( 'picker' ) diff --git a/lib/compressed/picker.date.js b/lib/compressed/picker.date.js index 373a9497..09b50f09 100644 --- a/lib/compressed/picker.date.js +++ b/lib/compressed/picker.date.js @@ -2,4 +2,4 @@ * Date picker for pickadate.js v3.5.0 * http://amsul.github.io/pickadate.js/date.htm */ -!function(a){"function"==typeof define&&define.amd?define(["picker","jquery"],a):"object"==typeof exports?module.exports=a(require("./picker.js"),require("jquery")):a(Picker,jQuery)}(function(a,b){function c(a,b){var c=this,d=a.$node[0].value,e=a.$node.data("value"),f=e||d,g=e?b.formatSubmit:b.format,h=function(){return"rtl"===getComputedStyle(a.$root[0]).direction};c.settings=b,c.$node=a.$node,c.queue={min:"measure create",max:"measure create",now:"now create",select:"parse create validate",highlight:"parse navigate create validate",view:"parse create validate viewset",disable:"deactivate",enable:"activate"},c.item={},c.item.clear=null,c.item.disable=(b.disable||[]).slice(0),c.item.enable=-function(a){return a[0]===!0?a.shift():-1}(c.item.disable),c.set("min",b.min).set("max",b.max).set("now"),f?c.set("select",f,{format:g}):c.set("select",null).set("highlight",c.item.now),c.key={40:7,38:-7,39:function(){return h()?-1:1},37:function(){return h()?1:-1},go:function(a){var b=c.item.highlight,d=new Date(Date.UTC(b.year,b.month,b.date+a));c.set("highlight",[d.getUTCFullYear(),d.getUTCMonth(),d.getUTCDate()],{interval:a}),this.render()}},a.on("render",function(){a.$root.find("."+b.klass.selectMonth).on("change",function(){var c=this.value;c&&(a.set("highlight",[a.get("view").year,c,a.get("highlight").date]),a.$root.find("."+b.klass.selectMonth).trigger("focus"))}),a.$root.find("."+b.klass.selectYear).on("change",function(){var c=this.value;c&&(a.set("highlight",[c,a.get("view").month,a.get("highlight").date]),a.$root.find("."+b.klass.selectYear).trigger("focus"))})}).on("open",function(){var d="";c.disabled(c.get("now"))&&(d=":not(."+b.klass.buttonToday+")"),a.$root.find("button"+d+", select").attr("disabled",!1)}).on("close",function(){a.$root.find("button, select").attr("disabled",!0)})}var d=7,e=6,f=a._;c.prototype.set=function(a,b,c){var d=this,e=d.item;return null===b?("clear"==a&&(a="select"),e[a]=b,d):(e["enable"==a?"disable":"flip"==a?"enable":a]=d.queue[a].split(" ").map(function(e){return b=d[e](a,b,c)}).pop(),"select"==a?d.set("highlight",e.select,c):"highlight"==a?d.set("view",e.highlight,c):a.match(/^(flip|min|max|disable|enable)$/)&&(e.select&&d.disabled(e.select)&&d.set("select",e.select,c),e.highlight&&d.disabled(e.highlight)&&d.set("highlight",e.highlight,c)),d)},c.prototype.get=function(a){return this.item[a]},c.prototype.create=function(a,c,d){var e,g=this;return c=void 0===c?a:c,c==-1/0||1/0==c?e=c:b.isPlainObject(c)&&f.isInteger(c.pick)?c=c.obj:b.isArray(c)?(c=new Date(Date.UTC(c[0],c[1],c[2])),c=f.isDate(c)?c:g.create().obj):c=f.isInteger(c)?g.normalize(new Date(c),d):f.isDate(c)?g.normalize(c,d):g.now(a,c,d),{year:e||c.getUTCFullYear(),month:e||c.getUTCMonth(),date:e||c.getUTCDate(),day:e||c.getUTCDay(),obj:e||c,pick:e||c.getTime()}},c.prototype.createRange=function(a,c){var d=this,e=function(a){return a===!0||b.isArray(a)||f.isDate(a)?d.create(a):a};return f.isInteger(a)||(a=e(a)),f.isInteger(c)||(c=e(c)),f.isInteger(a)&&b.isPlainObject(c)?a=[c.year,c.month,c.date+a]:f.isInteger(c)&&b.isPlainObject(a)&&(c=[a.year,a.month,a.date+c]),{from:e(a),to:e(c)}},c.prototype.withinRange=function(a,b){return a=this.createRange(a.from,a.to),b.pick>=a.from.pick&&b.pick<=a.to.pick},c.prototype.overlapRanges=function(a,b){var c=this;return a=c.createRange(a.from,a.to),b=c.createRange(b.from,b.to),c.withinRange(a,b.from)||c.withinRange(a,b.to)||c.withinRange(b,a.from)||c.withinRange(b,a.to)},c.prototype.now=function(a,b,c){return b=new Date,c&&c.rel&&b.setUTCDate(b.getUTCDate()+c.rel),this.normalize(b,c)},c.prototype.navigate=function(a,c,d){var e,f,g,h,i=b.isArray(c),j=b.isPlainObject(c),k=this.item.view;if(i||j){for(j?(f=c.year,g=c.month,h=c.date):(f=+c[0],g=+c[1],h=+c[2]),d&&d.nav&&k&&k.month!==g&&(f=k.year,g=k.month),e=new Date(Date.UTC(f,g+(d&&d.nav?d.nav:0),1)),f=e.getUTCFullYear(),g=e.getUTCMonth();new Date(Date.UTC(f,g,h)).getUTCMonth()!==g;)h-=1;c=[f,g,h]}return c},c.prototype.normalize=function(a){return a.setUTCHours(0,0,0,0),a},c.prototype.measure=function(a,b){var c=this;return b?f.isInteger(b)&&(b=c.now(a,b,{rel:b})):b="min"==a?-1/0:1/0,b},c.prototype.viewset=function(a,b){return this.create([b.year,b.month,1])},c.prototype.validate=function(a,c,d){var e,g,h,i,j=this,k=c,l=d&&d.interval?d.interval:1,m=-1===j.item.enable,n=j.item.min,o=j.item.max,p=m&&j.item.disable.filter(function(a){if(b.isArray(a)){var d=j.create(a).pick;dc.pick&&(g=!0)}return f.isInteger(a)}).length;if((!d||!d.nav)&&(!m&&j.disabled(c)||m&&j.disabled(c)&&(p||e||g)||!m&&(c.pick<=n.pick||c.pick>=o.pick)))for(m&&!p&&(!g&&l>0||!e&&0>l)&&(l*=-1);j.disabled(c)&&(Math.abs(l)>1&&(c.monthk.month)&&(c=k,l=l>0?1:-1),c.pick<=n.pick?(h=!0,l=1,c=j.create([n.year,n.month,n.date+(c.pick===n.pick?0:-1)])):c.pick>=o.pick&&(i=!0,l=-1,c=j.create([o.year,o.month,o.date+(c.pick===o.pick?0:1)])),!h||!i);)c=j.create([c.year,c.month,c.date+l]);return c},c.prototype.disabled=function(a){var c=this,d=c.item.disable.filter(function(d){return f.isInteger(d)?a.day===(c.settings.firstDay?d:d-1)%7:b.isArray(d)||f.isDate(d)?a.pick===c.create(d).pick:b.isPlainObject(d)?c.withinRange(d,a):void 0});return d=d.length&&!d.filter(function(a){return b.isArray(a)&&"inverted"==a[3]||b.isPlainObject(a)&&a.inverted}).length,-1===c.item.enable?!d:d||a.pickc.item.max.pick},c.prototype.parse=function(a,b,c){var d=this,e={};return b&&"string"==typeof b?(c&&c.format||(c=c||{},c.format=d.settings.format),d.formats.toArray(c.format).map(function(a){var c=d.formats[a],g=c?f.trigger(c,d,[b,e]):a.replace(/^!/,"").length;c&&(e[a]=b.substr(0,g)),b=b.substr(g)}),[e.yyyy||e.yy,+(e.mm||e.m)-1,e.dd||e.d]):b},c.prototype.formats=function(){function a(a,b,c){var d=a.match(/\w+/)[0];return c.mm||c.m||(c.m=b.indexOf(d)+1),d.length}function b(a){return a.match(/\w+/)[0].length}return{d:function(a,b){return a?f.digits(a):b.date},dd:function(a,b){return a?2:f.lead(b.date)},ddd:function(a,c){return a?b(a):this.settings.weekdaysShort[c.day]},dddd:function(a,c){return a?b(a):this.settings.weekdaysFull[c.day]},m:function(a,b){return a?f.digits(a):b.month+1},mm:function(a,b){return a?2:f.lead(b.month+1)},mmm:function(b,c){var d=this.settings.monthsShort;return b?a(b,d,c):d[c.month]},mmmm:function(b,c){var d=this.settings.monthsFull;return b?a(b,d,c):d[c.month]},yy:function(a,b){return a?2:(""+b.year).slice(2)},yyyy:function(a,b){return a?4:b.year},toArray:function(a){return a.split(/(d{1,4}|m{1,4}|y{4}|yy|!.)/g)},toString:function(a,b){var c=this;return c.formats.toArray(a).map(function(a){return f.trigger(c.formats[a],c,[0,b])||a.replace(/^!/,"")}).join("")}}}(),c.prototype.isDateExact=function(a,c){var d=this;return f.isInteger(a)&&f.isInteger(c)||"boolean"==typeof a&&"boolean"==typeof c?a===c:(f.isDate(a)||b.isArray(a))&&(f.isDate(c)||b.isArray(c))?d.create(a).pick===d.create(c).pick:b.isPlainObject(a)&&b.isPlainObject(c)?d.isDateExact(a.from,c.from)&&d.isDateExact(a.to,c.to):!1},c.prototype.isDateOverlap=function(a,c){var d=this,e=d.settings.firstDay?1:0;return f.isInteger(a)&&(f.isDate(c)||b.isArray(c))?(a=a%7+e,a===d.create(c).day+1):f.isInteger(c)&&(f.isDate(a)||b.isArray(a))?(c=c%7+e,c===d.create(a).day+1):b.isPlainObject(a)&&b.isPlainObject(c)?d.overlapRanges(a,c):!1},c.prototype.flipEnable=function(a){var b=this.item;b.enable=a||(-1==b.enable?1:-1)},c.prototype.deactivate=function(a,c){var d=this,e=d.item.disable.slice(0);return"flip"==c?d.flipEnable():c===!1?(d.flipEnable(1),e=[]):c===!0?(d.flipEnable(-1),e=[]):c.map(function(a){for(var c,g=0;gi;i+=1){if(h=e[i],d.isDateExact(h,a)){c=e[i]=null,j=!0;break}if(d.isDateOverlap(h,a)){b.isPlainObject(a)?(a.inverted=!0,c=a):b.isArray(a)?(c=a,c[3]||c.push("inverted")):f.isDate(a)&&(c=[a.getUTCFullYear(),a.getUTCMonth(),a.getUTCDate(),"inverted"]);break}}if(c)for(i=0;g>i;i+=1)if(d.isDateExact(e[i],a)){e[i]=null;break}if(j)for(i=0;g>i;i+=1)if(d.isDateOverlap(e[i],a)){e[i]=null;break}c&&e.push(c)}),e.filter(function(a){return null!=a})},c.prototype.nodes=function(a){var b=this,c=b.settings,g=b.item,h=g.now,i=g.select,j=g.highlight,k=g.view,l=g.disable,m=g.min,n=g.max,o=function(a,b){return c.firstDay&&(a.push(a.shift()),b.push(b.shift())),f.node("thead",f.node("tr",f.group({min:0,max:d-1,i:1,node:"th",item:function(d){return[a[d],c.klass.weekdays,'scope=col title="'+b[d]+'"']}})))}((c.showWeekdaysFull?c.weekdaysFull:c.weekdaysShort).slice(0),c.weekdaysFull.slice(0)),p=function(a){return f.node("div"," ",c.klass["nav"+(a?"Next":"Prev")]+(a&&k.year>=n.year&&k.month>=n.month||!a&&k.year<=m.year&&k.month<=m.month?" "+c.klass.navDisabled:""),"data-nav="+(a||-1)+" "+f.ariaAttr({role:"button",controls:b.$node[0].id+"_table"})+' title="'+(a?c.labelMonthNext:c.labelMonthPrev)+'"')},q=function(){var d=c.showMonthsShort?c.monthsShort:c.monthsFull;return c.selectMonths?f.node("select",f.group({min:0,max:11,i:1,node:"option",item:function(a){return[d[a],0,"value="+a+(k.month==a?" selected":"")+(k.year==m.year&&an.month?" disabled":"")]}}),c.klass.selectMonth,(a?"":"disabled")+" "+f.ariaAttr({controls:b.$node[0].id+"_table"})+' title="'+c.labelMonthSelect+'"'):f.node("div",d[k.month],c.klass.month)},r=function(){var d=k.year,e=c.selectYears===!0?5:~~(c.selectYears/2);if(e){var g=m.year,h=n.year,i=d-e,j=d+e;if(g>i&&(j+=g-i,i=g),j>h){var l=i-g,o=j-h;i-=l>o?o:l,j=h}return f.node("select",f.group({min:i,max:j,i:1,node:"option",item:function(a){return[a,0,"value="+a+(d==a?" selected":"")]}}),c.klass.selectYear,(a?"":"disabled")+" "+f.ariaAttr({controls:b.$node[0].id+"_table"})+' title="'+c.labelYearSelect+'"')}return f.node("div",d,c.klass.year)};return f.node("div",(c.selectYears?r()+q():q()+r())+p()+p(1),c.klass.header)+f.node("table",o+f.node("tbody",f.group({min:0,max:e-1,i:1,node:"tr",item:function(a){var e=c.firstDay&&0===b.create([k.year,k.month,1]).day?-7:0;return[f.group({min:d*a-k.day+e+1,max:function(){return this.min+d-1},i:1,node:"td",item:function(a){a=b.create([k.year,k.month,a+(c.firstDay?1:0)]);var d=i&&i.pick==a.pick,e=j&&j.pick==a.pick,g=l&&b.disabled(a)||a.pickn.pick;return[f.node("div",a.date,function(b){return b.push(k.month==a.month?c.klass.infocus:c.klass.outfocus),h.pick==a.pick&&b.push(c.klass.now),d&&b.push(c.klass.selected),e&&b.push(c.klass.highlighted),g&&b.push(c.klass.disabled),b.join(" ")}([c.klass.day]),"data-pick="+a.pick+" "+f.ariaAttr({role:"gridcell",selected:d&&b.$node.val()===f.trigger(b.formats.toString,b,[c.format,a])?!0:null,activedescendant:e?!0:null,disabled:g?!0:null})),"",f.ariaAttr({role:"presentation"})]}})]}})),c.klass.table,'id="'+b.$node[0].id+'_table" '+f.ariaAttr({role:"grid",controls:b.$node[0].id,readonly:!0}))+f.node("div",f.node("button",c.today,c.klass.buttonToday,"type=button data-pick="+h.pick+(a&&!b.disabled(h)?"":" disabled")+" "+f.ariaAttr({controls:b.$node[0].id}))+f.node("button",c.clear,c.klass.buttonClear,"type=button data-clear=1"+(a?"":" disabled")+" "+f.ariaAttr({controls:b.$node[0].id})),c.klass.footer)},c.defaults=function(a){return{labelMonthNext:"Next month",labelMonthPrev:"Previous month",labelMonthSelect:"Select a month",labelYearSelect:"Select a year",monthsFull:["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"],weekdaysFull:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],weekdaysShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],today:"Today",clear:"Clear",format:"d mmmm, yyyy",klass:{table:a+"table",header:a+"header",navPrev:a+"nav--prev",navNext:a+"nav--next",navDisabled:a+"nav--disabled",month:a+"month",year:a+"year",selectMonth:a+"select--month",selectYear:a+"select--year",weekdays:a+"weekday",day:a+"day",disabled:a+"day--disabled",selected:a+"day--selected",highlighted:a+"day--highlighted",now:a+"day--today",infocus:a+"day--infocus",outfocus:a+"day--outfocus",footer:a+"footer",buttonClear:a+"button--clear",buttonToday:a+"button--today"}}}(a.klasses().picker+"__"),a.extend("pickadate",c)}); \ No newline at end of file +!function(a){"function"==typeof define&&define.amd?define(["picker","jquery"],a):"object"==typeof exports?module.exports=a(require("./picker.js"),require("jquery")):a(Picker,jQuery)}(function(a,b){function c(a,b){var c=this,d=a.$node[0].value,e=a.$node.data("value"),f=e||d,g=e?b.formatSubmit:b.format,h=function(){return"rtl"===getComputedStyle(a.$root[0]).direction};c.settings=b,c.$node=a.$node,c.queue={min:"measure create",max:"measure create",now:"now create",select:"parse create validate",highlight:"parse navigate create validate",view:"parse create validate viewset",disable:"deactivate",enable:"activate"},c.item={},c.item.clear=null,c.item.disable=(b.disable||[]).slice(0),c.item.enable=-function(a){return a[0]===!0?a.shift():-1}(c.item.disable),c.set("min",b.min).set("max",b.max).set("now"),f?c.set("select",f,{format:g}):c.set("select",null).set("highlight",c.item.now),c.key={40:7,38:-7,39:function(){return h()?-1:1},37:function(){return h()?1:-1},go:function(a){var b=c.item.highlight,d=new Date(b.year,b.month,b.date+a);c.set("highlight",[d.getFullYear(),d.getMonth(),d.getDate()],{interval:a}),this.render()}},a.on("render",function(){a.$root.find("."+b.klass.selectMonth).on("change",function(){var c=this.value;c&&(a.set("highlight",[a.get("view").year,c,a.get("highlight").date]),a.$root.find("."+b.klass.selectMonth).trigger("focus"))}),a.$root.find("."+b.klass.selectYear).on("change",function(){var c=this.value;c&&(a.set("highlight",[c,a.get("view").month,a.get("highlight").date]),a.$root.find("."+b.klass.selectYear).trigger("focus"))})}).on("open",function(){var d="";c.disabled(c.get("now"))&&(d=":not(."+b.klass.buttonToday+")"),a.$root.find("button"+d+", select").attr("disabled",!1)}).on("close",function(){a.$root.find("button, select").attr("disabled",!0)})}var d=7,e=6,f=a._;c.prototype.set=function(a,b,c){var d=this,e=d.item;return null===b?("clear"==a&&(a="select"),e[a]=b,d):(e["enable"==a?"disable":"flip"==a?"enable":a]=d.queue[a].split(" ").map(function(e){return b=d[e](a,b,c)}).pop(),"select"==a?d.set("highlight",e.select,c):"highlight"==a?d.set("view",e.highlight,c):a.match(/^(flip|min|max|disable|enable)$/)&&(e.select&&d.disabled(e.select)&&d.set("select",e.select,c),e.highlight&&d.disabled(e.highlight)&&d.set("highlight",e.highlight,c)),d)},c.prototype.get=function(a){return this.item[a]},c.prototype.create=function(a,c,d){var e,g=this;return c=void 0===c?a:c,c==-1/0||1/0==c?e=c:b.isPlainObject(c)&&f.isInteger(c.pick)?c=c.obj:b.isArray(c)?(c=new Date(c[0],c[1],c[2]),c=f.isDate(c)?c:g.create().obj):c=f.isInteger(c)||f.isDate(c)?g.normalize(new Date(c),d):g.now(a,c,d),{year:e||c.getFullYear(),month:e||c.getMonth(),date:e||c.getDate(),day:e||c.getDay(),obj:e||c,pick:e||c.getTime()}},c.prototype.createRange=function(a,c){var d=this,e=function(a){return a===!0||b.isArray(a)||f.isDate(a)?d.create(a):a};return f.isInteger(a)||(a=e(a)),f.isInteger(c)||(c=e(c)),f.isInteger(a)&&b.isPlainObject(c)?a=[c.year,c.month,c.date+a]:f.isInteger(c)&&b.isPlainObject(a)&&(c=[a.year,a.month,a.date+c]),{from:e(a),to:e(c)}},c.prototype.withinRange=function(a,b){return a=this.createRange(a.from,a.to),b.pick>=a.from.pick&&b.pick<=a.to.pick},c.prototype.overlapRanges=function(a,b){var c=this;return a=c.createRange(a.from,a.to),b=c.createRange(b.from,b.to),c.withinRange(a,b.from)||c.withinRange(a,b.to)||c.withinRange(b,a.from)||c.withinRange(b,a.to)},c.prototype.now=function(a,b,c){return b=new Date,c&&c.rel&&b.setDate(b.getDate()+c.rel),this.normalize(b,c)},c.prototype.navigate=function(a,c,d){var e,f,g,h,i=b.isArray(c),j=b.isPlainObject(c),k=this.item.view;if(i||j){for(j?(f=c.year,g=c.month,h=c.date):(f=+c[0],g=+c[1],h=+c[2]),d&&d.nav&&k&&k.month!==g&&(f=k.year,g=k.month),e=new Date(f,g+(d&&d.nav?d.nav:0),1),f=e.getFullYear(),g=e.getMonth();new Date(f,g,h).getMonth()!==g;)h-=1;c=[f,g,h]}return c},c.prototype.normalize=function(a){return a.setHours(0,0,0,0),a},c.prototype.measure=function(a,b){var c=this;return b?f.isInteger(b)&&(b=c.now(a,b,{rel:b})):b="min"==a?-1/0:1/0,b},c.prototype.viewset=function(a,b){return this.create([b.year,b.month,1])},c.prototype.validate=function(a,c,d){var e,g,h,i,j=this,k=c,l=d&&d.interval?d.interval:1,m=-1===j.item.enable,n=j.item.min,o=j.item.max,p=m&&j.item.disable.filter(function(a){if(b.isArray(a)){var d=j.create(a).pick;dc.pick&&(g=!0)}return f.isInteger(a)}).length;if((!d||!d.nav)&&(!m&&j.disabled(c)||m&&j.disabled(c)&&(p||e||g)||!m&&(c.pick<=n.pick||c.pick>=o.pick)))for(m&&!p&&(!g&&l>0||!e&&0>l)&&(l*=-1);j.disabled(c)&&(Math.abs(l)>1&&(c.monthk.month)&&(c=k,l=l>0?1:-1),c.pick<=n.pick?(h=!0,l=1,c=j.create([n.year,n.month,n.date+(c.pick===n.pick?0:-1)])):c.pick>=o.pick&&(i=!0,l=-1,c=j.create([o.year,o.month,o.date+(c.pick===o.pick?0:1)])),!h||!i);)c=j.create([c.year,c.month,c.date+l]);return c},c.prototype.disabled=function(a){var c=this,d=c.item.disable.filter(function(d){return f.isInteger(d)?a.day===(c.settings.firstDay?d:d-1)%7:b.isArray(d)||f.isDate(d)?a.pick===c.create(d).pick:b.isPlainObject(d)?c.withinRange(d,a):void 0});return d=d.length&&!d.filter(function(a){return b.isArray(a)&&"inverted"==a[3]||b.isPlainObject(a)&&a.inverted}).length,-1===c.item.enable?!d:d||a.pickc.item.max.pick},c.prototype.parse=function(a,b,c){var d=this,e={};return b&&"string"==typeof b?(c&&c.format||(c=c||{},c.format=d.settings.format),d.formats.toArray(c.format).map(function(a){var c=d.formats[a],g=c?f.trigger(c,d,[b,e]):a.replace(/^!/,"").length;c&&(e[a]=b.substr(0,g)),b=b.substr(g)}),[e.yyyy||e.yy,+(e.mm||e.m)-1,e.dd||e.d]):b},c.prototype.formats=function(){function a(a,b,c){var d=a.match(/\w+/)[0];return c.mm||c.m||(c.m=b.indexOf(d)+1),d.length}function b(a){return a.match(/\w+/)[0].length}return{d:function(a,b){return a?f.digits(a):b.date},dd:function(a,b){return a?2:f.lead(b.date)},ddd:function(a,c){return a?b(a):this.settings.weekdaysShort[c.day]},dddd:function(a,c){return a?b(a):this.settings.weekdaysFull[c.day]},m:function(a,b){return a?f.digits(a):b.month+1},mm:function(a,b){return a?2:f.lead(b.month+1)},mmm:function(b,c){var d=this.settings.monthsShort;return b?a(b,d,c):d[c.month]},mmmm:function(b,c){var d=this.settings.monthsFull;return b?a(b,d,c):d[c.month]},yy:function(a,b){return a?2:(""+b.year).slice(2)},yyyy:function(a,b){return a?4:b.year},toArray:function(a){return a.split(/(d{1,4}|m{1,4}|y{4}|yy|!.)/g)},toString:function(a,b){var c=this;return c.formats.toArray(a).map(function(a){return f.trigger(c.formats[a],c,[0,b])||a.replace(/^!/,"")}).join("")}}}(),c.prototype.isDateExact=function(a,c){var d=this;return f.isInteger(a)&&f.isInteger(c)||"boolean"==typeof a&&"boolean"==typeof c?a===c:(f.isDate(a)||b.isArray(a))&&(f.isDate(c)||b.isArray(c))?d.create(a).pick===d.create(c).pick:b.isPlainObject(a)&&b.isPlainObject(c)?d.isDateExact(a.from,c.from)&&d.isDateExact(a.to,c.to):!1},c.prototype.isDateOverlap=function(a,c){var d=this,e=d.settings.firstDay?1:0;return f.isInteger(a)&&(f.isDate(c)||b.isArray(c))?(a=a%7+e,a===d.create(c).day+1):f.isInteger(c)&&(f.isDate(a)||b.isArray(a))?(c=c%7+e,c===d.create(a).day+1):b.isPlainObject(a)&&b.isPlainObject(c)?d.overlapRanges(a,c):!1},c.prototype.flipEnable=function(a){var b=this.item;b.enable=a||(-1==b.enable?1:-1)},c.prototype.deactivate=function(a,c){var d=this,e=d.item.disable.slice(0);return"flip"==c?d.flipEnable():c===!1?(d.flipEnable(1),e=[]):c===!0?(d.flipEnable(-1),e=[]):c.map(function(a){for(var c,g=0;gi;i+=1){if(h=e[i],d.isDateExact(h,a)){c=e[i]=null,j=!0;break}if(d.isDateOverlap(h,a)){b.isPlainObject(a)?(a.inverted=!0,c=a):b.isArray(a)?(c=a,c[3]||c.push("inverted")):f.isDate(a)&&(c=[a.getFullYear(),a.getMonth(),a.getDate(),"inverted"]);break}}if(c)for(i=0;g>i;i+=1)if(d.isDateExact(e[i],a)){e[i]=null;break}if(j)for(i=0;g>i;i+=1)if(d.isDateOverlap(e[i],a)){e[i]=null;break}c&&e.push(c)}),e.filter(function(a){return null!=a})},c.prototype.nodes=function(a){var b=this,c=b.settings,g=b.item,h=g.now,i=g.select,j=g.highlight,k=g.view,l=g.disable,m=g.min,n=g.max,o=function(a,b){return c.firstDay&&(a.push(a.shift()),b.push(b.shift())),f.node("thead",f.node("tr",f.group({min:0,max:d-1,i:1,node:"th",item:function(d){return[a[d],c.klass.weekdays,'scope=col title="'+b[d]+'"']}})))}((c.showWeekdaysFull?c.weekdaysFull:c.weekdaysShort).slice(0),c.weekdaysFull.slice(0)),p=function(a){return f.node("div"," ",c.klass["nav"+(a?"Next":"Prev")]+(a&&k.year>=n.year&&k.month>=n.month||!a&&k.year<=m.year&&k.month<=m.month?" "+c.klass.navDisabled:""),"data-nav="+(a||-1)+" "+f.ariaAttr({role:"button",controls:b.$node[0].id+"_table"})+' title="'+(a?c.labelMonthNext:c.labelMonthPrev)+'"')},q=function(){var d=c.showMonthsShort?c.monthsShort:c.monthsFull;return c.selectMonths?f.node("select",f.group({min:0,max:11,i:1,node:"option",item:function(a){return[d[a],0,"value="+a+(k.month==a?" selected":"")+(k.year==m.year&&an.month?" disabled":"")]}}),c.klass.selectMonth,(a?"":"disabled")+" "+f.ariaAttr({controls:b.$node[0].id+"_table"})+' title="'+c.labelMonthSelect+'"'):f.node("div",d[k.month],c.klass.month)},r=function(){var d=k.year,e=c.selectYears===!0?5:~~(c.selectYears/2);if(e){var g=m.year,h=n.year,i=d-e,j=d+e;if(g>i&&(j+=g-i,i=g),j>h){var l=i-g,o=j-h;i-=l>o?o:l,j=h}return f.node("select",f.group({min:i,max:j,i:1,node:"option",item:function(a){return[a,0,"value="+a+(d==a?" selected":"")]}}),c.klass.selectYear,(a?"":"disabled")+" "+f.ariaAttr({controls:b.$node[0].id+"_table"})+' title="'+c.labelYearSelect+'"')}return f.node("div",d,c.klass.year)};return f.node("div",(c.selectYears?r()+q():q()+r())+p()+p(1),c.klass.header)+f.node("table",o+f.node("tbody",f.group({min:0,max:e-1,i:1,node:"tr",item:function(a){var e=c.firstDay&&0===b.create([k.year,k.month,1]).day?-7:0;return[f.group({min:d*a-k.day+e+1,max:function(){return this.min+d-1},i:1,node:"td",item:function(a){a=b.create([k.year,k.month,a+(c.firstDay?1:0)]);var d=i&&i.pick==a.pick,e=j&&j.pick==a.pick,g=l&&b.disabled(a)||a.pickn.pick;return[f.node("div",a.date,function(b){return b.push(k.month==a.month?c.klass.infocus:c.klass.outfocus),h.pick==a.pick&&b.push(c.klass.now),d&&b.push(c.klass.selected),e&&b.push(c.klass.highlighted),g&&b.push(c.klass.disabled),b.join(" ")}([c.klass.day]),"data-pick="+a.pick+" "+f.ariaAttr({role:"gridcell",selected:d&&b.$node.val()===f.trigger(b.formats.toString,b,[c.format,a])?!0:null,activedescendant:e?!0:null,disabled:g?!0:null})),"",f.ariaAttr({role:"presentation"})]}})]}})),c.klass.table,'id="'+b.$node[0].id+'_table" '+f.ariaAttr({role:"grid",controls:b.$node[0].id,readonly:!0}))+f.node("div",f.node("button",c.today,c.klass.buttonToday,"type=button data-pick="+h.pick+(a&&!b.disabled(h)?"":" disabled")+" "+f.ariaAttr({controls:b.$node[0].id}))+f.node("button",c.clear,c.klass.buttonClear,"type=button data-clear=1"+(a?"":" disabled")+" "+f.ariaAttr({controls:b.$node[0].id}))+f.node("button",c.close,c.klass.buttonClose,"type=button data-close=true "+f.ariaAttr({controls:b.$node[0].id})),c.klass.footer)},c.defaults=function(a){return{labelMonthNext:"Next month",labelMonthPrev:"Previous month",labelMonthSelect:"Select a month",labelYearSelect:"Select a year",monthsFull:["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"],weekdaysFull:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],weekdaysShort:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],today:"Today",clear:"Clear",close:"Close",format:"d mmmm, yyyy",klass:{table:a+"table",header:a+"header",navPrev:a+"nav--prev",navNext:a+"nav--next",navDisabled:a+"nav--disabled",month:a+"month",year:a+"year",selectMonth:a+"select--month",selectYear:a+"select--year",weekdays:a+"weekday",day:a+"day",disabled:a+"day--disabled",selected:a+"day--selected",highlighted:a+"day--highlighted",now:a+"day--today",infocus:a+"day--infocus",outfocus:a+"day--outfocus",footer:a+"footer",buttonClear:a+"button--clear",buttonToday:a+"button--today",buttonClose:a+"button--close"}}}(a.klasses().picker+"__"),a.extend("pickadate",c)}); \ No newline at end of file diff --git a/lib/compressed/picker.js b/lib/compressed/picker.js index 096a6d51..b57f0820 100644 --- a/lib/compressed/picker.js +++ b/lib/compressed/picker.js @@ -4,4 +4,4 @@ * Hosted on http://amsul.github.io/pickadate.js * Licensed under MIT */ -!function(a){"function"==typeof define&&define.amd?define("picker",["jquery"],a):"object"==typeof exports?module.exports=a(require("jquery")):this.Picker=a(jQuery)}(function(a){function b(f,g,h,k){function l(){return b._.node("div",b._.node("div",b._.node("div",b._.node("div",w.component.nodes(r.open),t.box),t.wrap),t.frame),t.holder)}function m(){u.data(g,w).addClass(t.input).val(u.data("value")?w.get("select",s.format):f.value).on("focus."+r.id+" click."+r.id,p),s.editable||u.on("keydown."+r.id,function(a){var b=a.keyCode,c=/^(8|46)$/.test(b);return 27==b?(w.close(),!1):void((32==b||c||!r.open&&w.component.key[b])&&(a.preventDefault(),a.stopPropagation(),c?w.clear().close():w.open()))}),e(f,{haspopup:!0,expanded:!1,readonly:!1,owns:f.id+"_root"+(w._hidden?" "+w._hidden.id:"")})}function n(){w.$root.on({focusin:function(a){w.$root.removeClass(t.focused),a.stopPropagation()},"mousedown click":function(b){var c=b.target;c!=w.$root.children()[0]&&(b.stopPropagation(),"mousedown"!=b.type||a(c).is(":input")||"OPTION"==c.nodeName||(b.preventDefault(),f.focus()))}}).on("click","[data-pick], [data-nav], [data-clear]",function(){var c=a(this),d=c.data(),e=c.hasClass(t.navDisabled)||c.hasClass(t.disabled),g=document.activeElement;g=g&&(g.type||g.href)&&g,(e||g&&!a.contains(w.$root[0],g))&&f.focus(),d.nav&&!e?w.set("highlight",w.component.item.highlight,{nav:d.nav}):b._.isInteger(d.pick)&&!e?w.set("select",d.pick).close(!0):d.clear&&w.clear().close(!0)}),e(w.$root[0],"hidden",!0)}function o(){var b;s.hiddenName===!0?(b=f.name,f.name=""):(b=["string"==typeof s.hiddenPrefix?s.hiddenPrefix:"","string"==typeof s.hiddenSuffix?s.hiddenSuffix:"_submit"],b=b[0]+f.name+b[1]),w._hidden=a('")[0],u.on("change."+r.id,function(){w._hidden.value=f.value?w.get("select",s.formatSubmit):""}).after(w._hidden)}function p(a){a.stopPropagation(),"focus"==a.type&&w.$root.addClass(t.focused),w.open()}if(!f)return b;var q=!1,r={id:f.id||"P"+Math.abs(~~(Math.random()*new Date))},s=h?a.extend(!0,{},h.defaults,k):k||{},t=a.extend({},b.klasses(),s.klass),u=a(f),v=function(){return this.start()},w=v.prototype={constructor:v,$node:u,start:function(){return r&&r.start?w:(r.methods={},r.start=!0,r.open=!1,r.type=f.type,f.autofocus=f==document.activeElement,f.type="text",f.readOnly=!s.editable,f.id=f.id||r.id,w.component=new h(w,s),w.$root=a(b._.node("div",l(),t.picker,'id="'+f.id+'_root"')),n(),s.formatSubmit&&o(),m(),s.container?a(s.container).append(w.$root):u.after(w.$root),w.on({start:w.component.onStart,render:w.component.onRender,stop:w.component.onStop,open:w.component.onOpen,close:w.component.onClose,set:w.component.onSet}).on({start:s.onStart,render:s.onRender,stop:s.onStop,open:s.onOpen,close:s.onClose,set:s.onSet}),q=c(w.$root.children()[0]),f.autofocus&&w.open(),w.trigger("start").trigger("render"))},render:function(a){return a?w.$root.html(l()):w.$root.find("."+t.box).html(w.component.nodes(r.open)),w.trigger("render")},stop:function(){return r.start?(w.close(),w._hidden&&w._hidden.parentNode.removeChild(w._hidden),w.$root.remove(),u.removeClass(t.input).removeData(g),setTimeout(function(){u.off("."+r.id)},0),f.type=r.type,f.readOnly=!1,w.trigger("stop"),r.methods={},r.start=!1,w):w},open:function(c){return r.open?w:(u.addClass(t.active),e(f,"expanded",!0),setTimeout(function(){w.$root.addClass(t.opened),e(w.$root[0],"hidden",!1)},0),c!==!1&&(r.open=!0,q&&j.css("overflow","hidden").css("padding-right","+="+d()),u.trigger("focus"),i.on("click."+r.id+" focusin."+r.id,function(a){var b=a.target;b!=f&&b!=document&&3!=a.which&&w.close(b===w.$root.children()[0])}).on("keydown."+r.id,function(c){var d=c.keyCode,e=w.component.key[d],g=c.target;27==d?w.close(!0):g!=f||!e&&13!=d?a.contains(w.$root[0],g)&&13==d&&(c.preventDefault(),g.click()):(c.preventDefault(),e?b._.trigger(w.component.key.go,w,[b._.trigger(e)]):w.$root.find("."+t.highlighted).hasClass(t.disabled)||w.set("select",w.component.item.highlight).close())})),w.trigger("open"))},close:function(a){return a&&(u.off("focus."+r.id).trigger("focus"),setTimeout(function(){u.on("focus."+r.id,p)},0)),u.removeClass(t.active),e(f,"expanded",!1),setTimeout(function(){w.$root.removeClass(t.opened+" "+t.focused),e(w.$root[0],"hidden",!0)},0),r.open?(r.open=!1,q&&j.css("overflow","").css("padding-right","-="+d()),i.off("."+r.id),w.trigger("close")):w},clear:function(a){return w.set("clear",null,a)},set:function(b,c,d){var e,f,g=a.isPlainObject(b),h=g?b:{};if(d=g&&a.isPlainObject(c)?c:d||{},b){g||(h[b]=c);for(e in h)f=h[e],e in w.component.item&&(void 0===f&&(f=null),w.component.set(e,f,d)),("select"==e||"clear"==e)&&u.val("clear"==e?"":w.get(e,s.format)).trigger("change");w.render()}return d.muted?w:w.trigger("set",h)},get:function(a,c){if(a=a||"value",null!=r[a])return r[a];if("value"==a)return f.value;if(a in w.component.item){if("string"==typeof c){var d=w.component.get(a);return d?b._.trigger(w.component.formats.toString,w.component,[c,d]):""}return w.component.get(a)}},on:function(b,c){var d,e,f=a.isPlainObject(b),g=f?b:{};if(b){f||(g[b]=c);for(d in g)e=g[d],r.methods[d]=r.methods[d]||[],r.methods[d].push(e)}return w},off:function(){var a,b,c=arguments;for(a=0,namesCount=c.length;namesCount>a;a+=1)b=c[a],b in r.methods&&delete r.methods[b];return w},trigger:function(a,c){var d=r.methods[a];return d&&d.map(function(a){b._.trigger(a,w,[c])}),w}};return new v}function c(a){var b,c="position";return a.currentStyle?b=a.currentStyle[c]:window.getComputedStyle&&(b=getComputedStyle(a)[c]),"fixed"==b}function d(){if(j.height()<=h.height())return 0;var b=a('
').appendTo("body"),c=b[0].offsetWidth;b.css("overflow","scroll");var d=a('
').appendTo(b),e=d[0].offsetWidth;return b.remove(),c-e}function e(b,c,d){if(a.isPlainObject(c))for(var e in c)f(b,e,c[e]);else f(b,c,d)}function f(a,b,c){a.setAttribute(("role"==b?"":"aria-")+b,c)}function g(b,c){a.isPlainObject(b)||(b={attribute:c}),c="";for(var d in b){var e=("role"==d?"":"aria-")+d,f=b[d];c+=null==f?"":e+'="'+b[d]+'"'}return c}var h=a(window),i=a(document),j=a(document.documentElement);return b.klasses=function(a){return a=a||"picker",{picker:a,opened:a+"--opened",focused:a+"--focused",input:a+"__input",active:a+"__input--active",holder:a+"__holder",frame:a+"__frame",wrap:a+"__wrap",box:a+"__box"}},b._={group:function(a){for(var c,d="",e=b._.trigger(a.min,a);e<=b._.trigger(a.max,a,[e]);e+=a.i)c=b._.trigger(a.item,a,[e]),d+=b._.node(a.node,c[0],c[1],c[2]);return d},node:function(b,c,d,e){return c?(c=a.isArray(c)?c.join(""):c,d=d?' class="'+d+'"':"",e=e?" "+e:"","<"+b+d+e+">"+c+""):""},lead:function(a){return(10>a?"0":"")+a},trigger:function(a,b,c){return"function"==typeof a?a.apply(b,c||[]):a},digits:function(a){return/\d/.test(a[1])?2:1},isDate:function(a){return{}.toString.call(a).indexOf("Date")>-1&&this.isInteger(a.getUTCDate())},isInteger:function(a){return{}.toString.call(a).indexOf("Number")>-1&&a%1===0},ariaAttr:g},b.extend=function(c,d){a.fn[c]=function(e,f){var g=this.data(c);return"picker"==e?g:g&&"string"==typeof e?b._.trigger(g[e],g,[f]):this.each(function(){var f=a(this);f.data(c)||new b(this,c,d,e)})},a.fn[c].defaults=d.defaults},b}); \ No newline at end of file +!function(a){"function"==typeof define&&define.amd?define("picker",["jquery"],a):"object"==typeof exports?module.exports=a(require("jquery")):this.Picker=a(jQuery)}(function(a){function b(f,g,h,k){function l(){return b._.node("div",b._.node("div",b._.node("div",b._.node("div",w.component.nodes(r.open),t.box),t.wrap),t.frame),t.holder)}function m(){u.data(g,w).addClass(t.input).val(u.data("value")?w.get("select",s.format):f.value).on("focus."+r.id+" click."+r.id,p),s.editable||u.on("keydown."+r.id,function(a){var b=a.keyCode,c=/^(8|46)$/.test(b);return 27==b?(w.close(),!1):void((32==b||c||!r.open&&w.component.key[b])&&(a.preventDefault(),a.stopPropagation(),c?w.clear().close():w.open()))}),e(f,{haspopup:!0,expanded:!1,readonly:!1,owns:f.id+"_root"+(w._hidden?" "+w._hidden.id:"")})}function n(){w.$root.on({focusin:function(a){w.$root.removeClass(t.focused),a.stopPropagation()},"mousedown click":function(b){var c=b.target;c!=w.$root.children()[0]&&(b.stopPropagation(),"mousedown"!=b.type||a(c).is(":input")||"OPTION"==c.nodeName||(b.preventDefault(),f.focus()))}}).on("click","[data-pick], [data-nav], [data-clear]",function(){var c=a(this),d=c.data(),e=c.hasClass(t.navDisabled)||c.hasClass(t.disabled),g=document.activeElement;g=g&&(g.type||g.href)&&g,(e||g&&!a.contains(w.$root[0],g))&&f.focus(),d.nav&&!e?w.set("highlight",w.component.item.highlight,{nav:d.nav}):b._.isInteger(d.pick)&&!e?w.set("select",d.pick).close(!0):d.clear&&w.clear().close(!0)}).on("click","[data-close]",function(){w.close(!0)}),e(w.$root[0],"hidden",!0)}function o(){var b;s.hiddenName===!0?(b=f.name,f.name=""):(b=["string"==typeof s.hiddenPrefix?s.hiddenPrefix:"","string"==typeof s.hiddenSuffix?s.hiddenSuffix:"_submit"],b=b[0]+f.name+b[1]),w._hidden=a('")[0],u.on("change."+r.id,function(){w._hidden.value=f.value?w.get("select",s.formatSubmit):""}).after(w._hidden)}function p(a){a.stopPropagation(),"focus"==a.type&&w.$root.addClass(t.focused),w.open()}if(!f)return b;var q=!1,r={id:f.id||"P"+Math.abs(~~(Math.random()*new Date))},s=h?a.extend(!0,{},h.defaults,k):k||{},t=a.extend({},b.klasses(),s.klass),u=a(f),v=function(){return this.start()},w=v.prototype={constructor:v,$node:u,start:function(){return r&&r.start?w:(r.methods={},r.start=!0,r.open=!1,r.type=f.type,f.autofocus=f==document.activeElement,f.type="text",f.readOnly=!s.editable,f.id=f.id||r.id,w.component=new h(w,s),w.$root=a(b._.node("div",l(),t.picker,'id="'+f.id+'_root"')),n(),s.formatSubmit&&o(),m(),s.container?a(s.container).append(w.$root):u.after(w.$root),w.on({start:w.component.onStart,render:w.component.onRender,stop:w.component.onStop,open:w.component.onOpen,close:w.component.onClose,set:w.component.onSet}).on({start:s.onStart,render:s.onRender,stop:s.onStop,open:s.onOpen,close:s.onClose,set:s.onSet}),q=c(w.$root.children()[0]),f.autofocus&&w.open(),w.trigger("start").trigger("render"))},render:function(a){return a?w.$root.html(l()):w.$root.find("."+t.box).html(w.component.nodes(r.open)),w.trigger("render")},stop:function(){return r.start?(w.close(),w._hidden&&w._hidden.parentNode.removeChild(w._hidden),w.$root.remove(),u.removeClass(t.input).removeData(g),setTimeout(function(){u.off("."+r.id)},0),f.type=r.type,f.readOnly=!1,w.trigger("stop"),r.methods={},r.start=!1,w):w},open:function(c){return r.open?w:(u.addClass(t.active),e(f,"expanded",!0),setTimeout(function(){w.$root.addClass(t.opened),e(w.$root[0],"hidden",!1)},0),c!==!1&&(r.open=!0,q&&j.css("overflow","hidden").css("padding-right","+="+d()),u.trigger("focus"),i.on("click."+r.id+" focusin."+r.id,function(a){var b=a.target;b!=f&&b!=document&&3!=a.which&&w.close(b===w.$root.children()[0])}).on("keydown."+r.id,function(c){var d=c.keyCode,e=w.component.key[d],g=c.target;27==d?w.close(!0):g!=f||!e&&13!=d?a.contains(w.$root[0],g)&&13==d&&(c.preventDefault(),g.click()):(c.preventDefault(),e?b._.trigger(w.component.key.go,w,[b._.trigger(e)]):w.$root.find("."+t.highlighted).hasClass(t.disabled)||w.set("select",w.component.item.highlight).close())})),w.trigger("open"))},close:function(a){return a&&(u.off("focus."+r.id).trigger("focus"),setTimeout(function(){u.on("focus."+r.id,p)},0)),u.removeClass(t.active),e(f,"expanded",!1),setTimeout(function(){w.$root.removeClass(t.opened+" "+t.focused),e(w.$root[0],"hidden",!0)},0),r.open?(r.open=!1,q&&j.css("overflow","").css("padding-right","-="+d()),i.off("."+r.id),w.trigger("close")):w},clear:function(a){return w.set("clear",null,a)},set:function(b,c,d){var e,f,g=a.isPlainObject(b),h=g?b:{};if(d=g&&a.isPlainObject(c)?c:d||{},b){g||(h[b]=c);for(e in h)f=h[e],e in w.component.item&&(void 0===f&&(f=null),w.component.set(e,f,d)),("select"==e||"clear"==e)&&u.val("clear"==e?"":w.get(e,s.format)).trigger("change");w.render()}return d.muted?w:w.trigger("set",h)},get:function(a,c){if(a=a||"value",null!=r[a])return r[a];if("value"==a)return f.value;if(a in w.component.item){if("string"==typeof c){var d=w.component.get(a);return d?b._.trigger(w.component.formats.toString,w.component,[c,d]):""}return w.component.get(a)}},on:function(b,c){var d,e,f=a.isPlainObject(b),g=f?b:{};if(b){f||(g[b]=c);for(d in g)e=g[d],r.methods[d]=r.methods[d]||[],r.methods[d].push(e)}return w},off:function(){var a,b,c=arguments;for(a=0,namesCount=c.length;namesCount>a;a+=1)b=c[a],b in r.methods&&delete r.methods[b];return w},trigger:function(a,c){var d=r.methods[a];return d&&d.map(function(a){b._.trigger(a,w,[c])}),w}};return new v}function c(a){var b,c="position";return a.currentStyle?b=a.currentStyle[c]:window.getComputedStyle&&(b=getComputedStyle(a)[c]),"fixed"==b}function d(){if(j.height()<=h.height())return 0;var b=a('
').appendTo("body"),c=b[0].offsetWidth;b.css("overflow","scroll");var d=a('
').appendTo(b),e=d[0].offsetWidth;return b.remove(),c-e}function e(b,c,d){if(a.isPlainObject(c))for(var e in c)f(b,e,c[e]);else f(b,c,d)}function f(a,b,c){a.setAttribute(("role"==b?"":"aria-")+b,c)}function g(b,c){a.isPlainObject(b)||(b={attribute:c}),c="";for(var d in b){var e=("role"==d?"":"aria-")+d,f=b[d];c+=null==f?"":e+'="'+b[d]+'"'}return c}var h=a(window),i=a(document),j=a(document.documentElement);return b.klasses=function(a){return a=a||"picker",{picker:a,opened:a+"--opened",focused:a+"--focused",input:a+"__input",active:a+"__input--active",holder:a+"__holder",frame:a+"__frame",wrap:a+"__wrap",box:a+"__box"}},b._={group:function(a){for(var c,d="",e=b._.trigger(a.min,a);e<=b._.trigger(a.max,a,[e]);e+=a.i)c=b._.trigger(a.item,a,[e]),d+=b._.node(a.node,c[0],c[1],c[2]);return d},node:function(b,c,d,e){return c?(c=a.isArray(c)?c.join(""):c,d=d?' class="'+d+'"':"",e=e?" "+e:"","<"+b+d+e+">"+c+""):""},lead:function(a){return(10>a?"0":"")+a},trigger:function(a,b,c){return"function"==typeof a?a.apply(b,c||[]):a},digits:function(a){return/\d/.test(a[1])?2:1},isDate:function(a){return{}.toString.call(a).indexOf("Date")>-1&&this.isInteger(a.getDate())},isInteger:function(a){return{}.toString.call(a).indexOf("Number")>-1&&a%1===0},ariaAttr:g},b.extend=function(c,d){a.fn[c]=function(e,f){var g=this.data(c);return"picker"==e?g:g&&"string"==typeof e?b._.trigger(g[e],g,[f]):this.each(function(){var f=a(this);f.data(c)||new b(this,c,d,e)})},a.fn[c].defaults=d.defaults},b}); \ No newline at end of file diff --git a/lib/compressed/picker.time.js b/lib/compressed/picker.time.js index 4b052d06..a6d2b56c 100644 --- a/lib/compressed/picker.time.js +++ b/lib/compressed/picker.time.js @@ -2,4 +2,4 @@ * Time picker for pickadate.js v3.5.0 * http://amsul.github.io/pickadate.js/time.htm */ -!function(a){"function"==typeof define&&define.amd?define(["picker","jquery"],a):"object"==typeof exports?module.exports=a(require("./picker.js"),require("jquery")):a(Picker,jQuery)}(function(a,b){function c(a,b){var c=this,d=a.$node[0].value,e=a.$node.data("value"),f=e||d,g=e?b.formatSubmit:b.format;c.settings=b,c.$node=a.$node,c.queue={interval:"i",min:"measure create",max:"measure create",now:"now create",select:"parse create validate",highlight:"parse create validate",view:"parse create validate",disable:"deactivate",enable:"activate"},c.item={},c.item.clear=null,c.item.interval=b.interval||30,c.item.disable=(b.disable||[]).slice(0),c.item.enable=-function(a){return a[0]===!0?a.shift():-1}(c.item.disable),c.set("min",b.min).set("max",b.max).set("now"),f?c.set("select",f,{format:g,fromValue:!!d}):c.set("select",null).set("highlight",c.item.now),c.key={40:1,38:-1,39:1,37:-1,go:function(a){c.set("highlight",c.item.highlight.pick+a*c.item.interval,{interval:a*c.item.interval}),this.render()}},a.on("render",function(){var c=a.$root.children(),d=c.find("."+b.klass.viewset);d.length&&(c[0].scrollTop=~~d.position().top-2*d[0].clientHeight)}).on("open",function(){a.$root.find("button").attr("disabled",!1)}).on("close",function(){a.$root.find("button").attr("disabled",!0)})}var d=24,e=60,f=12,g=d*e,h=a._;c.prototype.set=function(a,b,c){var d=this,e=d.item;return null===b?("clear"==a&&(a="select"),e[a]=b,d):(e["enable"==a?"disable":"flip"==a?"enable":a]=d.queue[a].split(" ").map(function(e){return b=d[e](a,b,c)}).pop(),"select"==a?d.set("highlight",e.select,c):"highlight"==a?d.set("view",e.highlight,c):"interval"==a?d.set("min",e.min,c).set("max",e.max,c):a.match(/^(flip|min|max|disable|enable)$/)&&("min"==a&&d.set("max",e.max,c),e.select&&d.disabled(e.select)&&d.set("select",e.select,c),e.highlight&&d.disabled(e.highlight)&&d.set("highlight",e.highlight,c)),d)},c.prototype.get=function(a){return this.item[a]},c.prototype.create=function(a,c,f){var i=this;return c=void 0===c?a:c,h.isDate(c)&&(c=[c.getUTCHours(),c.getUTCMinutes()]),b.isPlainObject(c)&&h.isInteger(c.pick)?c=c.pick:b.isArray(c)?c=+c[0]*e+ +c[1]:h.isInteger(c)||(c=i.now(a,c,f)),"max"==a&&c=a.from.pick&&b.pick<=a.to.pick},c.prototype.overlapRanges=function(a,b){var c=this;return a=c.createRange(a.from,a.to),b=c.createRange(b.from,b.to),c.withinRange(a,b.from)||c.withinRange(a,b.to)||c.withinRange(b,a.from)||c.withinRange(b,a.to)},c.prototype.now=function(a,b){var c,d=this.item.interval,f=new Date,g=f.getUTCHours()*e+f.getUTCMinutes(),i=h.isInteger(b);return g-=g%d,c=0>b&&-d>=d*b+g,g+="min"==a&&c?0:d,i&&(g+=d*(c&&"max"!=a?b+1:b)),g},c.prototype.normalize=function(a,b){var c=this.item.interval,d=this.item.min&&this.item.min.pick||0;return b-="min"==a?0:(b-d)%c},c.prototype.measure=function(a,c,f){var g=this;return c?c===!0||h.isInteger(c)?c=g.now(a,c,f):b.isPlainObject(c)&&h.isInteger(c.pick)&&(c=g.normalize(a,c.pick,f)):c="min"==a?[0,0]:[d-1,e-1],c},c.prototype.validate=function(a,b,c){var d=this,e=c&&c.interval?c.interval:d.item.interval;return d.disabled(b)&&(b=d.shift(b,e)),b=d.scope(b),d.disabled(b)&&(b=d.shift(b,-1*e)),b},c.prototype.disabled=function(a){var c=this,d=c.item.disable.filter(function(d){return h.isInteger(d)?a.hour==d:b.isArray(d)||h.isDate(d)?a.pick==c.create(d).pick:b.isPlainObject(d)?c.withinRange(d,a):void 0});return d=d.length&&!d.filter(function(a){return b.isArray(a)&&"inverted"==a[2]||b.isPlainObject(a)&&a.inverted}).length,-1===c.item.enable?!d:d||a.pickc.item.max.pick},c.prototype.shift=function(a,b){var c=this,d=c.item.min.pick,e=c.item.max.pick;for(b=b||c.item.interval;c.disabled(a)&&(a=c.create(a.pick+=b),!(a.pick<=d||a.pick>=e)););return a},c.prototype.scope=function(a){var b=this.item.min.pick,c=this.item.max.pick;return this.create(a.pick>c?c:a.pickb.time%g?"a.m.":"p.m."},A:function(a,b){return a?2:g/2>b.time%g?"AM":"PM"},toArray:function(a){return a.split(/(h{1,2}|H{1,2}|i|a|A|!.)/g)},toString:function(a,b){var c=this;return c.formats.toArray(a).map(function(a){return h.trigger(c.formats[a],c,[0,b])||a.replace(/^!/,"")}).join("")}},c.prototype.isTimeExact=function(a,c){var d=this;return h.isInteger(a)&&h.isInteger(c)||"boolean"==typeof a&&"boolean"==typeof c?a===c:(h.isDate(a)||b.isArray(a))&&(h.isDate(c)||b.isArray(c))?d.create(a).pick===d.create(c).pick:b.isPlainObject(a)&&b.isPlainObject(c)?d.isTimeExact(a.from,c.from)&&d.isTimeExact(a.to,c.to):!1},c.prototype.isTimeOverlap=function(a,c){var d=this;return h.isInteger(a)&&(h.isDate(c)||b.isArray(c))?a===d.create(c).hour:h.isInteger(c)&&(h.isDate(a)||b.isArray(a))?c===d.create(a).hour:b.isPlainObject(a)&&b.isPlainObject(c)?d.overlapRanges(a,c):!1},c.prototype.flipEnable=function(a){var b=this.item;b.enable=a||(-1==b.enable?1:-1)},c.prototype.deactivate=function(a,c){var d=this,e=d.item.disable.slice(0);return"flip"==c?d.flipEnable():c===!1?(d.flipEnable(1),e=[]):c===!0?(d.flipEnable(-1),e=[]):c.map(function(a){for(var c,f=0;fi;i+=1){if(g=e[i],d.isTimeExact(g,a)){c=e[i]=null,j=!0;break}if(d.isTimeOverlap(g,a)){b.isPlainObject(a)?(a.inverted=!0,c=a):b.isArray(a)?(c=a,c[2]||c.push("inverted")):h.isDate(a)&&(c=[a.getUTCFullYear(),a.getUTCMonth(),a.getUTCDate(),"inverted"]);break}}if(c)for(i=0;f>i;i+=1)if(d.isTimeExact(e[i],a)){e[i]=null;break}if(j)for(i=0;f>i;i+=1)if(d.isTimeOverlap(e[i],a)){e[i]=null;break}c&&e.push(c)}),e.filter(function(a){return null!=a})},c.prototype.i=function(a,b){return h.isInteger(b)&&b>0?b:this.item.interval},c.prototype.nodes=function(a){var b=this,c=b.settings,d=b.item.select,e=b.item.highlight,f=b.item.view,g=b.item.disable;return h.node("ul",h.group({min:b.item.min.pick,max:b.item.max.pick,i:b.item.interval,node:"li",item:function(a){a=b.create(a);var i=a.pick,j=d&&d.pick==i,k=e&&e.pick==i,l=g&&b.disabled(a);return[h.trigger(b.formats.toString,b,[h.trigger(c.formatLabel,b,[a])||c.format,a]),function(a){return j&&a.push(c.klass.selected),k&&a.push(c.klass.highlighted),f&&f.pick==i&&a.push(c.klass.viewset),l&&a.push(c.klass.disabled),a.join(" ")}([c.klass.listItem]),"data-pick="+a.pick+" "+h.ariaAttr({role:"option",selected:j&&b.$node.val()===h.trigger(b.formats.toString,b,[c.format,a])?!0:null,activedescendant:k?!0:null,disabled:l?!0:null})]}})+h.node("li",h.node("button",c.clear,c.klass.buttonClear,"type=button data-clear=1"+(a?"":" disabled")+" "+h.ariaAttr({controls:b.$node[0].id})),"",h.ariaAttr({role:"presentation"})),c.klass.list,h.ariaAttr({role:"listbox",controls:b.$node[0].id}))},c.defaults=function(a){return{clear:"Clear",format:"h:i A",interval:30,klass:{picker:a+" "+a+"--time",holder:a+"__holder",list:a+"__list",listItem:a+"__list-item",disabled:a+"__list-item--disabled",selected:a+"__list-item--selected",highlighted:a+"__list-item--highlighted",viewset:a+"__list-item--viewset",now:a+"__list-item--now",buttonClear:a+"__button--clear"}}}(a.klasses().picker),a.extend("pickatime",c)}); \ No newline at end of file +!function(a){"function"==typeof define&&define.amd?define(["picker","jquery"],a):"object"==typeof exports?module.exports=a(require("./picker.js"),require("jquery")):a(Picker,jQuery)}(function(a,b){function c(a,b){var c=this,d=a.$node[0].value,e=a.$node.data("value"),f=e||d,g=e?b.formatSubmit:b.format;c.settings=b,c.$node=a.$node,c.queue={interval:"i",min:"measure create",max:"measure create",now:"now create",select:"parse create validate",highlight:"parse create validate",view:"parse create validate",disable:"deactivate",enable:"activate"},c.item={},c.item.clear=null,c.item.interval=b.interval||30,c.item.disable=(b.disable||[]).slice(0),c.item.enable=-function(a){return a[0]===!0?a.shift():-1}(c.item.disable),c.set("min",b.min).set("max",b.max).set("now"),f?c.set("select",f,{format:g,fromValue:!!d}):c.set("select",null).set("highlight",c.item.now),c.key={40:1,38:-1,39:1,37:-1,go:function(a){c.set("highlight",c.item.highlight.pick+a*c.item.interval,{interval:a*c.item.interval}),this.render()}},a.on("render",function(){var c=a.$root.children(),d=c.find("."+b.klass.viewset);d.length&&(c[0].scrollTop=~~d.position().top-2*d[0].clientHeight)}).on("open",function(){a.$root.find("button").attr("disabled",!1)}).on("close",function(){a.$root.find("button").attr("disabled",!0)})}var d=24,e=60,f=12,g=d*e,h=a._;c.prototype.set=function(a,b,c){var d=this,e=d.item;return null===b?("clear"==a&&(a="select"),e[a]=b,d):(e["enable"==a?"disable":"flip"==a?"enable":a]=d.queue[a].split(" ").map(function(e){return b=d[e](a,b,c)}).pop(),"select"==a?d.set("highlight",e.select,c):"highlight"==a?d.set("view",e.highlight,c):"interval"==a?d.set("min",e.min,c).set("max",e.max,c):a.match(/^(flip|min|max|disable|enable)$/)&&("min"==a&&d.set("max",e.max,c),e.select&&d.disabled(e.select)&&d.set("select",e.select,c),e.highlight&&d.disabled(e.highlight)&&d.set("highlight",e.highlight,c)),d)},c.prototype.get=function(a){return this.item[a]},c.prototype.create=function(a,c,f){var i=this;return c=void 0===c?a:c,h.isDate(c)&&(c=[c.getHours(),c.getMinutes()]),b.isPlainObject(c)&&h.isInteger(c.pick)?c=c.pick:b.isArray(c)?c=+c[0]*e+ +c[1]:h.isInteger(c)||(c=i.now(a,c,f)),"max"==a&&c=a.from.pick&&b.pick<=a.to.pick},c.prototype.overlapRanges=function(a,b){var c=this;return a=c.createRange(a.from,a.to),b=c.createRange(b.from,b.to),c.withinRange(a,b.from)||c.withinRange(a,b.to)||c.withinRange(b,a.from)||c.withinRange(b,a.to)},c.prototype.now=function(a,b){var c,d=this.item.interval,f=new Date,g=f.getHours()*e+f.getMinutes(),i=h.isInteger(b);return g-=g%d,c=0>b&&-d>=d*b+g,g+="min"==a&&c?0:d,i&&(g+=d*(c&&"max"!=a?b+1:b)),g},c.prototype.normalize=function(a,b){var c=this.item.interval,d=this.item.min&&this.item.min.pick||0;return b-="min"==a?0:(b-d)%c},c.prototype.measure=function(a,c,f){var g=this;return c?c===!0||h.isInteger(c)?c=g.now(a,c,f):b.isPlainObject(c)&&h.isInteger(c.pick)&&(c=g.normalize(a,c.pick,f)):c="min"==a?[0,0]:[d-1,e-1],c},c.prototype.validate=function(a,b,c){var d=this,e=c&&c.interval?c.interval:d.item.interval;return d.disabled(b)&&(b=d.shift(b,e)),b=d.scope(b),d.disabled(b)&&(b=d.shift(b,-1*e)),b},c.prototype.disabled=function(a){var c=this,d=c.item.disable.filter(function(d){return h.isInteger(d)?a.hour==d:b.isArray(d)||h.isDate(d)?a.pick==c.create(d).pick:b.isPlainObject(d)?c.withinRange(d,a):void 0});return d=d.length&&!d.filter(function(a){return b.isArray(a)&&"inverted"==a[2]||b.isPlainObject(a)&&a.inverted}).length,-1===c.item.enable?!d:d||a.pickc.item.max.pick},c.prototype.shift=function(a,b){var c=this,d=c.item.min.pick,e=c.item.max.pick;for(b=b||c.item.interval;c.disabled(a)&&(a=c.create(a.pick+=b),!(a.pick<=d||a.pick>=e)););return a},c.prototype.scope=function(a){var b=this.item.min.pick,c=this.item.max.pick;return this.create(a.pick>c?c:a.pickb.time%g?"a.m.":"p.m."},A:function(a,b){return a?2:g/2>b.time%g?"AM":"PM"},toArray:function(a){return a.split(/(h{1,2}|H{1,2}|i|a|A|!.)/g)},toString:function(a,b){var c=this;return c.formats.toArray(a).map(function(a){return h.trigger(c.formats[a],c,[0,b])||a.replace(/^!/,"")}).join("")}},c.prototype.isTimeExact=function(a,c){var d=this;return h.isInteger(a)&&h.isInteger(c)||"boolean"==typeof a&&"boolean"==typeof c?a===c:(h.isDate(a)||b.isArray(a))&&(h.isDate(c)||b.isArray(c))?d.create(a).pick===d.create(c).pick:b.isPlainObject(a)&&b.isPlainObject(c)?d.isTimeExact(a.from,c.from)&&d.isTimeExact(a.to,c.to):!1},c.prototype.isTimeOverlap=function(a,c){var d=this;return h.isInteger(a)&&(h.isDate(c)||b.isArray(c))?a===d.create(c).hour:h.isInteger(c)&&(h.isDate(a)||b.isArray(a))?c===d.create(a).hour:b.isPlainObject(a)&&b.isPlainObject(c)?d.overlapRanges(a,c):!1},c.prototype.flipEnable=function(a){var b=this.item;b.enable=a||(-1==b.enable?1:-1)},c.prototype.deactivate=function(a,c){var d=this,e=d.item.disable.slice(0);return"flip"==c?d.flipEnable():c===!1?(d.flipEnable(1),e=[]):c===!0?(d.flipEnable(-1),e=[]):c.map(function(a){for(var c,f=0;fi;i+=1){if(g=e[i],d.isTimeExact(g,a)){c=e[i]=null,j=!0;break}if(d.isTimeOverlap(g,a)){b.isPlainObject(a)?(a.inverted=!0,c=a):b.isArray(a)?(c=a,c[2]||c.push("inverted")):h.isDate(a)&&(c=[a.getFullYear(),a.getMonth(),a.getDate(),"inverted"]);break}}if(c)for(i=0;f>i;i+=1)if(d.isTimeExact(e[i],a)){e[i]=null;break}if(j)for(i=0;f>i;i+=1)if(d.isTimeOverlap(e[i],a)){e[i]=null;break}c&&e.push(c)}),e.filter(function(a){return null!=a})},c.prototype.i=function(a,b){return h.isInteger(b)&&b>0?b:this.item.interval},c.prototype.nodes=function(a){var b=this,c=b.settings,d=b.item.select,e=b.item.highlight,f=b.item.view,g=b.item.disable;return h.node("ul",h.group({min:b.item.min.pick,max:b.item.max.pick,i:b.item.interval,node:"li",item:function(a){a=b.create(a);var i=a.pick,j=d&&d.pick==i,k=e&&e.pick==i,l=g&&b.disabled(a);return[h.trigger(b.formats.toString,b,[h.trigger(c.formatLabel,b,[a])||c.format,a]),function(a){return j&&a.push(c.klass.selected),k&&a.push(c.klass.highlighted),f&&f.pick==i&&a.push(c.klass.viewset),l&&a.push(c.klass.disabled),a.join(" ")}([c.klass.listItem]),"data-pick="+a.pick+" "+h.ariaAttr({role:"option",selected:j&&b.$node.val()===h.trigger(b.formats.toString,b,[c.format,a])?!0:null,activedescendant:k?!0:null,disabled:l?!0:null})]}})+h.node("li",h.node("button",c.clear,c.klass.buttonClear,"type=button data-clear=1"+(a?"":" disabled")+" "+h.ariaAttr({controls:b.$node[0].id})),"",h.ariaAttr({role:"presentation"})),c.klass.list,h.ariaAttr({role:"listbox",controls:b.$node[0].id}))},c.defaults=function(a){return{clear:"Clear",format:"h:i A",interval:30,klass:{picker:a+" "+a+"--time",holder:a+"__holder",list:a+"__list",listItem:a+"__list-item",disabled:a+"__list-item--disabled",selected:a+"__list-item--selected",highlighted:a+"__list-item--highlighted",viewset:a+"__list-item--viewset",now:a+"__list-item--now",buttonClear:a+"__button--clear"}}}(a.klasses().picker),a.extend("pickatime",c)}); \ No newline at end of file diff --git a/lib/compressed/themes/classic.date.css b/lib/compressed/themes/classic.date.css index 8f4f9bb5..435f0c96 100644 --- a/lib/compressed/themes/classic.date.css +++ b/lib/compressed/themes/classic.date.css @@ -1 +1 @@ -.picker__box{padding:0 1em}.picker__header{text-align:center;position:relative;margin-top:.75em}.picker__month,.picker__year{font-weight:500;display:inline-block;margin-left:.25em;margin-right:.25em}.picker__year{color:#999;font-size:.8em;font-style:italic}.picker__select--month,.picker__select--year{border:1px solid #b7b7b7;height:2em;padding:.5em;margin-left:.25em;margin-right:.25em}@media (min-width:24.5em){.picker__select--month,.picker__select--year{margin-top:-.5em}}.picker__select--month{width:35%}.picker__select--year{width:22.5%}.picker__select--month:focus,.picker__select--year:focus{border-color:#0089ec}.picker__nav--next,.picker__nav--prev{position:absolute;padding:.5em 1.25em;width:1em;height:1em;box-sizing:content-box;top:-.25em}@media (min-width:24.5em){.picker__nav--next,.picker__nav--prev{top:-.33em}}.picker__nav--prev{left:-1em;padding-right:1.25em}@media (min-width:24.5em){.picker__nav--prev{padding-right:1.5em}}.picker__nav--next{right:-1em;padding-left:1.25em}@media (min-width:24.5em){.picker__nav--next{padding-left:1.5em}}.picker__nav--next:before,.picker__nav--prev:before{content:" ";border-top:.5em solid transparent;border-bottom:.5em solid transparent;border-right:.75em solid #000;width:0;height:0;display:block;margin:0 auto}.picker__nav--next:before{border-right:0;border-left:.75em solid #000}.picker__nav--next:hover,.picker__nav--prev:hover{cursor:pointer;color:#000;background:#b1dcfb}.picker__nav--disabled,.picker__nav--disabled:before,.picker__nav--disabled:before:hover,.picker__nav--disabled:hover{cursor:default;background:0 0;border-right-color:#f5f5f5;border-left-color:#f5f5f5}.picker__table{text-align:center;border-collapse:collapse;border-spacing:0;table-layout:fixed;font-size:inherit;width:100%;margin-top:.75em;margin-bottom:.5em}@media (min-height:33.875em){.picker__table{margin-bottom:.75em}}.picker__table td{margin:0;padding:0}.picker__weekday{width:14.285714286%;font-size:.75em;padding-bottom:.25em;color:#999;font-weight:500}@media (min-height:33.875em){.picker__weekday{padding-bottom:.5em}}.picker__day{padding:.3125em 0;font-weight:200;border:1px solid transparent}.picker__day--today{position:relative}.picker__day--today:before{content:" ";position:absolute;top:2px;right:2px;width:0;height:0;border-top:.5em solid #0059bc;border-left:.5em solid transparent}.picker__day--disabled:before{border-top-color:#aaa}.picker__day--outfocus{color:#ddd}.picker__day--infocus:hover,.picker__day--outfocus:hover{cursor:pointer;color:#000;background:#b1dcfb}.picker__day--highlighted{border-color:#0089ec}.picker--focused .picker__day--highlighted,.picker__day--highlighted:hover{cursor:pointer;color:#000;background:#b1dcfb}.picker--focused .picker__day--selected,.picker__day--selected,.picker__day--selected:hover{background:#0089ec;color:#fff}.picker--focused .picker__day--disabled,.picker__day--disabled,.picker__day--disabled:hover{background:#f5f5f5;border-color:#f5f5f5;color:#ddd;cursor:default}.picker__day--highlighted.picker__day--disabled,.picker__day--highlighted.picker__day--disabled:hover{background:#bbb}.picker__footer{text-align:center}.picker__button--clear,.picker__button--today{border:1px solid #fff;background:#fff;font-size:.8em;padding:.66em 0;font-weight:700;width:50%;display:inline-block;vertical-align:bottom}.picker__button--clear:hover,.picker__button--today:hover{cursor:pointer;color:#000;background:#b1dcfb;border-bottom-color:#b1dcfb}.picker__button--clear:focus,.picker__button--today:focus{background:#b1dcfb;border-color:#0089ec;outline:0}.picker__button--clear:before,.picker__button--today:before{position:relative;display:inline-block;height:0}.picker__button--today:before{content:" ";margin-right:.45em;top:-.05em;width:0;border-top:.66em solid #0059bc;border-left:.66em solid transparent}.picker__button--clear:before{content:"\D7";margin-right:.35em;top:-.1em;color:#e20;vertical-align:top;font-size:1.1em}.picker__button--today[disabled],.picker__button--today[disabled]:hover{background:#f5f5f5;border-color:#f5f5f5;color:#ddd;cursor:default}.picker__button--today[disabled]:before{border-top-color:#aaa} \ No newline at end of file +.picker__box{padding:0 1em}.picker__header{text-align:center;position:relative;margin-top:.75em}.picker__month,.picker__year{font-weight:500;display:inline-block;margin-left:.25em;margin-right:.25em}.picker__year{color:#999;font-size:.8em;font-style:italic}.picker__select--month,.picker__select--year{border:1px solid #b7b7b7;height:2em;padding:.5em;margin-left:.25em;margin-right:.25em}@media (min-width:24.5em){.picker__select--month,.picker__select--year{margin-top:-.5em}}.picker__select--month{width:35%}.picker__select--year{width:22.5%}.picker__select--month:focus,.picker__select--year:focus{border-color:#0089ec}.picker__nav--next,.picker__nav--prev{position:absolute;padding:.5em 1.25em;width:1em;height:1em;box-sizing:content-box;top:-.25em}@media (min-width:24.5em){.picker__nav--next,.picker__nav--prev{top:-.33em}}.picker__nav--prev{left:-1em;padding-right:1.25em}@media (min-width:24.5em){.picker__nav--prev{padding-right:1.5em}}.picker__nav--next{right:-1em;padding-left:1.25em}@media (min-width:24.5em){.picker__nav--next{padding-left:1.5em}}.picker__nav--next:before,.picker__nav--prev:before{content:" ";border-top:.5em solid transparent;border-bottom:.5em solid transparent;border-right:.75em solid #000;width:0;height:0;display:block;margin:0 auto}.picker__nav--next:before{border-right:0;border-left:.75em solid #000}.picker__nav--next:hover,.picker__nav--prev:hover{cursor:pointer;color:#000;background:#b1dcfb}.picker__nav--disabled,.picker__nav--disabled:before,.picker__nav--disabled:before:hover,.picker__nav--disabled:hover{cursor:default;background:0 0;border-right-color:#f5f5f5;border-left-color:#f5f5f5}.picker__table{text-align:center;border-collapse:collapse;border-spacing:0;table-layout:fixed;font-size:inherit;width:100%;margin-top:.75em;margin-bottom:.5em}@media (min-height:33.875em){.picker__table{margin-bottom:.75em}}.picker__table td{margin:0;padding:0}.picker__weekday{width:14.285714286%;font-size:.75em;padding-bottom:.25em;color:#999;font-weight:500}@media (min-height:33.875em){.picker__weekday{padding-bottom:.5em}}.picker__day{padding:.3125em 0;font-weight:200;border:1px solid transparent}.picker__day--today{position:relative}.picker__day--today:before{content:" ";position:absolute;top:2px;right:2px;width:0;height:0;border-top:.5em solid #0059bc;border-left:.5em solid transparent}.picker__day--disabled:before{border-top-color:#aaa}.picker__day--outfocus{color:#ddd}.picker__day--infocus:hover,.picker__day--outfocus:hover{cursor:pointer;color:#000;background:#b1dcfb}.picker__day--highlighted{border-color:#0089ec}.picker--focused .picker__day--highlighted,.picker__day--highlighted:hover{cursor:pointer;color:#000;background:#b1dcfb}.picker--focused .picker__day--selected,.picker__day--selected,.picker__day--selected:hover{background:#0089ec;color:#fff}.picker--focused .picker__day--disabled,.picker__day--disabled,.picker__day--disabled:hover{background:#f5f5f5;border-color:#f5f5f5;color:#ddd;cursor:default}.picker__day--highlighted.picker__day--disabled,.picker__day--highlighted.picker__day--disabled:hover{background:#bbb}.picker__footer{text-align:center}.picker__button--clear,.picker__button--close,.picker__button--today{border:1px solid #fff;background:#fff;font-size:.8em;padding:.66em 0;font-weight:700;width:33%;display:inline-block;vertical-align:bottom}.picker__button--clear:hover,.picker__button--close:hover,.picker__button--today:hover{cursor:pointer;color:#000;background:#b1dcfb;border-bottom-color:#b1dcfb}.picker__button--clear:focus,.picker__button--close:focus,.picker__button--today:focus{background:#b1dcfb;border-color:#0089ec;outline:0}.picker__button--clear:before,.picker__button--close:before,.picker__button--today:before{position:relative;display:inline-block;height:0}.picker__button--today:before{content:" ";margin-right:.45em;top:-.05em;width:0;border-top:.66em solid #0059bc;border-left:.66em solid transparent}.picker__button--clear:before{content:"\D7";margin-right:.35em;top:-.1em;color:#e20;vertical-align:top;font-size:1.1em}.picker__button--close:before{content:"\D7";margin-right:.35em;top:-.1em;color:#000;vertical-align:top;font-size:1.1em}.picker__button--today[disabled],.picker__button--today[disabled]:hover{background:#f5f5f5;border-color:#f5f5f5;color:#ddd;cursor:default}.picker__button--today[disabled]:before{border-top-color:#aaa} \ No newline at end of file diff --git a/lib/compressed/themes/default.date.css b/lib/compressed/themes/default.date.css index 8f4f9bb5..435f0c96 100644 --- a/lib/compressed/themes/default.date.css +++ b/lib/compressed/themes/default.date.css @@ -1 +1 @@ -.picker__box{padding:0 1em}.picker__header{text-align:center;position:relative;margin-top:.75em}.picker__month,.picker__year{font-weight:500;display:inline-block;margin-left:.25em;margin-right:.25em}.picker__year{color:#999;font-size:.8em;font-style:italic}.picker__select--month,.picker__select--year{border:1px solid #b7b7b7;height:2em;padding:.5em;margin-left:.25em;margin-right:.25em}@media (min-width:24.5em){.picker__select--month,.picker__select--year{margin-top:-.5em}}.picker__select--month{width:35%}.picker__select--year{width:22.5%}.picker__select--month:focus,.picker__select--year:focus{border-color:#0089ec}.picker__nav--next,.picker__nav--prev{position:absolute;padding:.5em 1.25em;width:1em;height:1em;box-sizing:content-box;top:-.25em}@media (min-width:24.5em){.picker__nav--next,.picker__nav--prev{top:-.33em}}.picker__nav--prev{left:-1em;padding-right:1.25em}@media (min-width:24.5em){.picker__nav--prev{padding-right:1.5em}}.picker__nav--next{right:-1em;padding-left:1.25em}@media (min-width:24.5em){.picker__nav--next{padding-left:1.5em}}.picker__nav--next:before,.picker__nav--prev:before{content:" ";border-top:.5em solid transparent;border-bottom:.5em solid transparent;border-right:.75em solid #000;width:0;height:0;display:block;margin:0 auto}.picker__nav--next:before{border-right:0;border-left:.75em solid #000}.picker__nav--next:hover,.picker__nav--prev:hover{cursor:pointer;color:#000;background:#b1dcfb}.picker__nav--disabled,.picker__nav--disabled:before,.picker__nav--disabled:before:hover,.picker__nav--disabled:hover{cursor:default;background:0 0;border-right-color:#f5f5f5;border-left-color:#f5f5f5}.picker__table{text-align:center;border-collapse:collapse;border-spacing:0;table-layout:fixed;font-size:inherit;width:100%;margin-top:.75em;margin-bottom:.5em}@media (min-height:33.875em){.picker__table{margin-bottom:.75em}}.picker__table td{margin:0;padding:0}.picker__weekday{width:14.285714286%;font-size:.75em;padding-bottom:.25em;color:#999;font-weight:500}@media (min-height:33.875em){.picker__weekday{padding-bottom:.5em}}.picker__day{padding:.3125em 0;font-weight:200;border:1px solid transparent}.picker__day--today{position:relative}.picker__day--today:before{content:" ";position:absolute;top:2px;right:2px;width:0;height:0;border-top:.5em solid #0059bc;border-left:.5em solid transparent}.picker__day--disabled:before{border-top-color:#aaa}.picker__day--outfocus{color:#ddd}.picker__day--infocus:hover,.picker__day--outfocus:hover{cursor:pointer;color:#000;background:#b1dcfb}.picker__day--highlighted{border-color:#0089ec}.picker--focused .picker__day--highlighted,.picker__day--highlighted:hover{cursor:pointer;color:#000;background:#b1dcfb}.picker--focused .picker__day--selected,.picker__day--selected,.picker__day--selected:hover{background:#0089ec;color:#fff}.picker--focused .picker__day--disabled,.picker__day--disabled,.picker__day--disabled:hover{background:#f5f5f5;border-color:#f5f5f5;color:#ddd;cursor:default}.picker__day--highlighted.picker__day--disabled,.picker__day--highlighted.picker__day--disabled:hover{background:#bbb}.picker__footer{text-align:center}.picker__button--clear,.picker__button--today{border:1px solid #fff;background:#fff;font-size:.8em;padding:.66em 0;font-weight:700;width:50%;display:inline-block;vertical-align:bottom}.picker__button--clear:hover,.picker__button--today:hover{cursor:pointer;color:#000;background:#b1dcfb;border-bottom-color:#b1dcfb}.picker__button--clear:focus,.picker__button--today:focus{background:#b1dcfb;border-color:#0089ec;outline:0}.picker__button--clear:before,.picker__button--today:before{position:relative;display:inline-block;height:0}.picker__button--today:before{content:" ";margin-right:.45em;top:-.05em;width:0;border-top:.66em solid #0059bc;border-left:.66em solid transparent}.picker__button--clear:before{content:"\D7";margin-right:.35em;top:-.1em;color:#e20;vertical-align:top;font-size:1.1em}.picker__button--today[disabled],.picker__button--today[disabled]:hover{background:#f5f5f5;border-color:#f5f5f5;color:#ddd;cursor:default}.picker__button--today[disabled]:before{border-top-color:#aaa} \ No newline at end of file +.picker__box{padding:0 1em}.picker__header{text-align:center;position:relative;margin-top:.75em}.picker__month,.picker__year{font-weight:500;display:inline-block;margin-left:.25em;margin-right:.25em}.picker__year{color:#999;font-size:.8em;font-style:italic}.picker__select--month,.picker__select--year{border:1px solid #b7b7b7;height:2em;padding:.5em;margin-left:.25em;margin-right:.25em}@media (min-width:24.5em){.picker__select--month,.picker__select--year{margin-top:-.5em}}.picker__select--month{width:35%}.picker__select--year{width:22.5%}.picker__select--month:focus,.picker__select--year:focus{border-color:#0089ec}.picker__nav--next,.picker__nav--prev{position:absolute;padding:.5em 1.25em;width:1em;height:1em;box-sizing:content-box;top:-.25em}@media (min-width:24.5em){.picker__nav--next,.picker__nav--prev{top:-.33em}}.picker__nav--prev{left:-1em;padding-right:1.25em}@media (min-width:24.5em){.picker__nav--prev{padding-right:1.5em}}.picker__nav--next{right:-1em;padding-left:1.25em}@media (min-width:24.5em){.picker__nav--next{padding-left:1.5em}}.picker__nav--next:before,.picker__nav--prev:before{content:" ";border-top:.5em solid transparent;border-bottom:.5em solid transparent;border-right:.75em solid #000;width:0;height:0;display:block;margin:0 auto}.picker__nav--next:before{border-right:0;border-left:.75em solid #000}.picker__nav--next:hover,.picker__nav--prev:hover{cursor:pointer;color:#000;background:#b1dcfb}.picker__nav--disabled,.picker__nav--disabled:before,.picker__nav--disabled:before:hover,.picker__nav--disabled:hover{cursor:default;background:0 0;border-right-color:#f5f5f5;border-left-color:#f5f5f5}.picker__table{text-align:center;border-collapse:collapse;border-spacing:0;table-layout:fixed;font-size:inherit;width:100%;margin-top:.75em;margin-bottom:.5em}@media (min-height:33.875em){.picker__table{margin-bottom:.75em}}.picker__table td{margin:0;padding:0}.picker__weekday{width:14.285714286%;font-size:.75em;padding-bottom:.25em;color:#999;font-weight:500}@media (min-height:33.875em){.picker__weekday{padding-bottom:.5em}}.picker__day{padding:.3125em 0;font-weight:200;border:1px solid transparent}.picker__day--today{position:relative}.picker__day--today:before{content:" ";position:absolute;top:2px;right:2px;width:0;height:0;border-top:.5em solid #0059bc;border-left:.5em solid transparent}.picker__day--disabled:before{border-top-color:#aaa}.picker__day--outfocus{color:#ddd}.picker__day--infocus:hover,.picker__day--outfocus:hover{cursor:pointer;color:#000;background:#b1dcfb}.picker__day--highlighted{border-color:#0089ec}.picker--focused .picker__day--highlighted,.picker__day--highlighted:hover{cursor:pointer;color:#000;background:#b1dcfb}.picker--focused .picker__day--selected,.picker__day--selected,.picker__day--selected:hover{background:#0089ec;color:#fff}.picker--focused .picker__day--disabled,.picker__day--disabled,.picker__day--disabled:hover{background:#f5f5f5;border-color:#f5f5f5;color:#ddd;cursor:default}.picker__day--highlighted.picker__day--disabled,.picker__day--highlighted.picker__day--disabled:hover{background:#bbb}.picker__footer{text-align:center}.picker__button--clear,.picker__button--close,.picker__button--today{border:1px solid #fff;background:#fff;font-size:.8em;padding:.66em 0;font-weight:700;width:33%;display:inline-block;vertical-align:bottom}.picker__button--clear:hover,.picker__button--close:hover,.picker__button--today:hover{cursor:pointer;color:#000;background:#b1dcfb;border-bottom-color:#b1dcfb}.picker__button--clear:focus,.picker__button--close:focus,.picker__button--today:focus{background:#b1dcfb;border-color:#0089ec;outline:0}.picker__button--clear:before,.picker__button--close:before,.picker__button--today:before{position:relative;display:inline-block;height:0}.picker__button--today:before{content:" ";margin-right:.45em;top:-.05em;width:0;border-top:.66em solid #0059bc;border-left:.66em solid transparent}.picker__button--clear:before{content:"\D7";margin-right:.35em;top:-.1em;color:#e20;vertical-align:top;font-size:1.1em}.picker__button--close:before{content:"\D7";margin-right:.35em;top:-.1em;color:#000;vertical-align:top;font-size:1.1em}.picker__button--today[disabled],.picker__button--today[disabled]:hover{background:#f5f5f5;border-color:#f5f5f5;color:#ddd;cursor:default}.picker__button--today[disabled]:before{border-top-color:#aaa} \ No newline at end of file diff --git a/lib/picker.date.js b/lib/picker.date.js index aa300c78..e187e26f 100644 --- a/lib/picker.date.js +++ b/lib/picker.date.js @@ -1243,6 +1243,8 @@ DatePicker.prototype.nodes = function( isOpen ) { _.node( 'button', settings.clear, settings.klass.buttonClear, 'type=button data-clear=1' + ( isOpen ? '' : ' disabled' ) + ' ' + + _.ariaAttr({ controls: calendar.$node[0].id }) ) + + _.node('button', settings.close, settings.klass.buttonClose, 'type=button data-close=true ' + _.ariaAttr({ controls: calendar.$node[0].id }) ), settings.klass.footer ) //endreturn @@ -1275,6 +1277,7 @@ DatePicker.defaults = (function( prefix ) { // Today and clear today: 'Today', clear: 'Clear', + close: 'Close', // The format to show on the `input` element format: 'd mmmm, yyyy', @@ -1309,7 +1312,8 @@ DatePicker.defaults = (function( prefix ) { footer: prefix + 'footer', buttonClear: prefix + 'button--clear', - buttonToday: prefix + 'button--today' + buttonToday: prefix + 'button--today', + buttonClose: prefix + 'button--close' } } })( Picker.klasses().picker + '__' ) diff --git a/lib/picker.js b/lib/picker.js index ecc88810..4006a278 100644 --- a/lib/picker.js +++ b/lib/picker.js @@ -703,6 +703,9 @@ function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) { else if ( targetData.clear ) { P.clear().close( true ) } + }) + .on('click', '[data-close]', function () { + P.close(true); }) //P.$root aria( P.$root[0], 'hidden', true ) diff --git a/lib/themes-source/base.date.less b/lib/themes-source/base.date.less index b8075830..a87aaf96 100644 --- a/lib/themes-source/base.date.less +++ b/lib/themes-source/base.date.less @@ -262,23 +262,26 @@ // Today and clear buttons. .picker__button--today, -.picker__button--clear { +.picker__button--clear, +.picker__button--close{ border: 1px solid @white; background: @white; font-size: .8em; padding: .66em 0; font-weight: bold; - width: 50%; + width: 33%; display: inline-block; vertical-align: bottom; } .picker__button--today:hover, -.picker__button--clear:hover { +.picker__button--clear:hover, +.picker__button--close:hover{ .picker-item-hovered; border-bottom-color: @blue-hover; } .picker__button--today:focus, -.picker__button--clear:focus { +.picker__button--clear:focus, +.picker__button--close:focus{ background: @blue-hover; border-color: @blue; outline: none; @@ -286,7 +289,8 @@ // Today and clear “indicators”. .picker__button--today:before, -.picker__button--clear:before { +.picker__button--clear:before, +.picker__button--close:before{ position: relative; display: inline-block; height: 0; @@ -308,6 +312,15 @@ font-size: 1.1em; } +.picker__button--close:before { + content: "\D7"; // × + margin-right: .35em; + top: -.1em; + color: @black; + vertical-align: top; + font-size: 1.1em; +} + // Today when “disabled”. .picker__button--today[disabled], .picker__button--today[disabled]:hover { diff --git a/lib/themes/classic.date.css b/lib/themes/classic.date.css index 9a44184b..021e4de1 100644 --- a/lib/themes/classic.date.css +++ b/lib/themes/classic.date.css @@ -228,31 +228,35 @@ text-align: center; } .picker__button--today, -.picker__button--clear { +.picker__button--clear, +.picker__button--close { border: 1px solid #ffffff; background: #ffffff; font-size: .8em; padding: .66em 0; font-weight: bold; - width: 50%; + width: 33%; display: inline-block; vertical-align: bottom; } .picker__button--today:hover, -.picker__button--clear:hover { +.picker__button--clear:hover, +.picker__button--close:hover { cursor: pointer; color: #000000; background: #b1dcfb; border-bottom-color: #b1dcfb; } .picker__button--today:focus, -.picker__button--clear:focus { +.picker__button--clear:focus, +.picker__button--close:focus { background: #b1dcfb; border-color: #0089ec; outline: none; } .picker__button--today:before, -.picker__button--clear:before { +.picker__button--clear:before, +.picker__button--close:before { position: relative; display: inline-block; height: 0; @@ -273,6 +277,14 @@ vertical-align: top; font-size: 1.1em; } +.picker__button--close:before { + content: "\D7"; + margin-right: .35em; + top: -0.1em; + color: #000000; + vertical-align: top; + font-size: 1.1em; +} .picker__button--today[disabled], .picker__button--today[disabled]:hover { background: #f5f5f5; diff --git a/lib/themes/default.date.css b/lib/themes/default.date.css index 99c08192..e52d67f7 100644 --- a/lib/themes/default.date.css +++ b/lib/themes/default.date.css @@ -228,31 +228,35 @@ text-align: center; } .picker__button--today, -.picker__button--clear { +.picker__button--clear, +.picker__button--close { border: 1px solid #ffffff; background: #ffffff; font-size: .8em; padding: .66em 0; font-weight: bold; - width: 50%; + width: 33%; display: inline-block; vertical-align: bottom; } .picker__button--today:hover, -.picker__button--clear:hover { +.picker__button--clear:hover, +.picker__button--close:hover { cursor: pointer; color: #000000; background: #b1dcfb; border-bottom-color: #b1dcfb; } .picker__button--today:focus, -.picker__button--clear:focus { +.picker__button--clear:focus, +.picker__button--close:focus { background: #b1dcfb; border-color: #0089ec; outline: none; } .picker__button--today:before, -.picker__button--clear:before { +.picker__button--clear:before, +.picker__button--close:before { position: relative; display: inline-block; height: 0; @@ -273,6 +277,14 @@ vertical-align: top; font-size: 1.1em; } +.picker__button--close:before { + content: "\D7"; + margin-right: .35em; + top: -0.1em; + color: #000000; + vertical-align: top; + font-size: 1.1em; +} .picker__button--today[disabled], .picker__button--today[disabled]:hover { background: #f5f5f5; diff --git a/tests/units/date.js b/tests/units/date.js index 24bb3978..988322d7 100644 --- a/tests/units/date.js +++ b/tests/units/date.js @@ -203,8 +203,6 @@ test('Does not set today to previous day', function() { var picker = this.picker, currentDate = new Date('Wed Jul 23 2014 00:00:00 GMT+0100 (BST)'); - console.log(currentDate); - picker.open(); picker.set('select', currentDate); @@ -1355,5 +1353,38 @@ test( '`data-value` to select, highlight, and view', function() { deepEqual( picker.get( 'view' ).obj, new Date(1988,7,1), 'Viewsets date' ) }) +module( 'Closing date picker with value already populated', { + setup: function() { + $DOM.append($INPUT.clone().val('14 August, 1988')); + var $input = $DOM.find('input').pickadate(); + this.picker = $input.pickadate('picker'); + }, + teardown: function() { + this.picker.stop(); + $DOM.empty(); + } +}); + +test('Close Button should keep the currently selected date', function() { + var picker = this.picker, + currentDate = new Date(); + + picker.open(); + picker.set('select', currentDate ); + picker.$root.find('.' + $.fn.pickadate.defaults.klass.buttonClose).click(); + + var actualDate = new Date(picker.get('value')).toLocaleDateString(); + strictEqual(actualDate, currentDate.toLocaleDateString(), 'Value should be still the current date'); +}); + +test('Close Button should close the modal', function() { + var picker = this.picker, + currentDate = new Date('08 May 2012'); + picker.open(); + picker.set('select', currentDate); + picker.$root.find('.' + $.fn.pickadate.defaults.klass.buttonClose).click(); + + strictEqual(picker.get('open'), false, 'Picker should be closed'); +});