vendor/assets/javascripts/pickadate/picker.date.js in pickadate-rails-1.3.0 vs vendor/assets/javascripts/pickadate/picker.date.js in pickadate-rails-1.3.1

- old
+ new

@@ -1,8 +1,8 @@ /*! - * Date picker for pickadate.js v3.3.0 + * Date picker for pickadate.js v3.3.1 * http://amsul.github.io/pickadate.js/date.htm */ /*jshint debug: true, @@ -183,11 +183,11 @@ if ( value == -Infinity || value == Infinity ) { isInfiniteValue = value } // If it’s an object, use the native date object. - else if ( Picker._.isObject( value ) && Picker._.isInteger( value.pick ) ) { + else if ( $.isPlainObject( value ) && Picker._.isInteger( value.pick ) ) { value = value.obj } // If it’s an array, convert it into a date and make sure // that it’s a valid date – otherwise default to today. @@ -233,11 +233,11 @@ /** * Navigate to next/prev month. */ DatePicker.prototype.navigate = function( type, value, options ) { - if ( Picker._.isObject( value ) ) { + if ( $.isPlainObject( value ) ) { var targetDateObject = new Date( value.year, value.month + ( options && options.nav ? options.nav : 0 ), 1 ), year = targetDateObject.getFullYear(), month = targetDateObject.getMonth(), date = value.date @@ -305,11 +305,11 @@ // Make sure we have an interval. interval = options && options.interval ? options.interval : 1, // Check if the calendar enabled dates are inverted. - isInverted = calendar.item.enable === -1, + isFlippedBase = calendar.item.enable === -1, // Check if we have any enabled dates after/before now. hasEnabledBeforeTarget, hasEnabledAfterTarget, // The min & max limits. @@ -318,11 +318,11 @@ // Check if we’ve reached the limit during shifting. reachedMin, reachedMax, // Check if the calendar is inverted and at least one weekday is enabled. - hasEnabledWeekdays = isInverted && calendar.item.disable.filter( function( value ) { + hasEnabledWeekdays = isFlippedBase && calendar.item.disable.filter( function( value ) { // If there’s a date, check where it is relative to the target. if ( $.isArray( value ) ) { var dateTime = calendar.create( value ).pick if ( dateTime < dateObject.pick ) hasEnabledBeforeTarget = true @@ -344,19 +344,19 @@ // • Navigating months. // • Not inverted and date enabled. // • Inverted and all dates disabled. // • ..and anything else. if ( !options.nav ) if ( - /* 1 */ ( !isInverted && calendar.disabled( dateObject ) ) || - /* 2 */ ( isInverted && calendar.disabled( dateObject ) && ( hasEnabledWeekdays || hasEnabledBeforeTarget || hasEnabledAfterTarget ) ) || + /* 1 */ ( !isFlippedBase && calendar.disabled( dateObject ) ) || + /* 2 */ ( isFlippedBase && calendar.disabled( dateObject ) && ( hasEnabledWeekdays || hasEnabledBeforeTarget || hasEnabledAfterTarget ) ) || /* 3 */ ( dateObject.pick <= minLimitObject.pick || dateObject.pick >= maxLimitObject.pick ) ) { // When inverted, flip the direction if there aren’t any enabled weekdays // and there are no enabled dates in the direction of the interval. - if ( isInverted && !hasEnabledWeekdays && ( ( !hasEnabledAfterTarget && interval > 0 ) || ( !hasEnabledBeforeTarget && interval < 0 ) ) ) { + if ( isFlippedBase && !hasEnabledWeekdays && ( ( !hasEnabledAfterTarget && interval > 0 ) || ( !hasEnabledBeforeTarget && interval < 0 ) ) ) { interval *= -1 } // Keep looping until we reach an enabled date. @@ -405,27 +405,31 @@ DatePicker.prototype.disabled = function( dateObject ) { var calendar = this, // Filter through the disabled dates to check if this is one. - isDisabledDate = !!calendar.item.disable.filter( function( dateToDisable ) { + isDisabledMatch = calendar.item.disable.filter( function( dateToDisable ) { // If the date is a number, match the weekday with 0index and `firstDay` check. if ( Picker._.isInteger( dateToDisable ) ) { return dateObject.day === ( calendar.settings.firstDay ? dateToDisable : dateToDisable - 1 ) % 7 } // If it’s an array or a native JS date, create and match the exact date. if ( $.isArray( dateToDisable ) || Picker._.isDate( dateToDisable ) ) { return dateObject.pick === calendar.create( dateToDisable ).pick } - }).length + }) + // If this date matches a disabled date, confirm it’s not inverted. + isDisabledMatch = isDisabledMatch.length && !isDisabledMatch.filter(function( dateToDisable ) { + return $.isArray( dateToDisable ) && dateToDisable[3] == 'inverted' + }).length // Check the calendar “enabled” flag and respectively flip the // disabled state. Then also check if it’s beyond the min/max limits. - return calendar.item.enable === -1 ? !isDisabledDate : isDisabledDate || + return calendar.item.enable === -1 ? !isDisabledMatch : isDisabledMatch || dateObject.pick < calendar.item.min.pick || dateObject.pick > calendar.item.max.pick } //DatePicker.prototype.disabled @@ -436,11 +440,11 @@ DatePicker.prototype.parse = function( type, value, options ) { var calendar = this, parsingObject = {} - if ( !value || Picker._.isInteger( value ) || $.isArray( value ) || Picker._.isDate( value ) || Picker._.isObject( value ) && Picker._.isInteger( value.pick ) ) { + if ( !value || Picker._.isInteger( value ) || $.isArray( value ) || Picker._.isDate( value ) || $.isPlainObject( value ) && Picker._.isInteger( value.pick ) ) { return value } // We need a `.format` to parse the value. if ( !( options && options.format ) ) { @@ -585,15 +589,15 @@ */ DatePicker.prototype.flipItem = function( type, value/*, options*/ ) { var calendar = this, collection = calendar.item.disable, - isInverted = calendar.item.enable === -1 + isFlippedBase = calendar.item.enable === -1 // Flip the enabled and disabled dates. if ( value == 'flip' ) { - calendar.item.enable = isInverted ? 1 : -1 + calendar.item.enable = isFlippedBase ? 1 : -1 } // Reset the collection and enable the base state. else if ( ( type == 'enable' && value === true ) || ( type == 'disable' && value === false ) ) { calendar.item.enable = 1 @@ -608,43 +612,101 @@ // Make sure a collection of things was passed to add/remove. else if ( $.isArray( value ) ) { // Check if we have to add/remove from collection. - if ( !isInverted && type == 'enable' || isInverted && type == 'disable' ) { - collection = calendar.removeDisabled( collection, value ) - } - else if ( !isInverted && type == 'disable' || isInverted && type == 'enable' ) { + if ( isFlippedBase && type == 'enable' || !isFlippedBase && type == 'disable' ) { collection = calendar.addDisabled( collection, value ) } + else if ( !isFlippedBase && type == 'enable' ) { + collection = calendar.addEnabled( collection, value ) + } + else if ( isFlippedBase && type == 'disable' ) { + collection = calendar.removeDisabled( collection, value ) + } } return collection } //DatePicker.prototype.flipItem /** + * Add an enabled (inverted) item to the disabled collection. + */ +DatePicker.prototype.addEnabled = function( collection, item ) { + + var calendar = this + + // Go through each item to enable. + item.map( function( timeUnit ) { + + // Check if the time unit is already within the collection. + if ( calendar.filterDisabled( collection, timeUnit, 1 ).length ) { + + // Remove the unit directly from the collection. + collection = calendar.removeDisabled( collection, [timeUnit] ) + + // If the unit is an array and it falls within a + // disabled weekday, invert it and then insert it. + if ( + $.isArray( timeUnit ) && + collection.filter( function( disabledDate ) { + return Picker._.isInteger( disabledDate ) && calendar.create( timeUnit ).day === disabledDate - 1 + }).length + ) { + timeUnit = timeUnit.slice(0) + timeUnit.push( 'inverted' ) + collection.push( timeUnit ) + } + } + }) + + // Return the final collection. + return collection +} //DatePicker.prototype.addEnabled + + +/** * Add an item to the disabled collection. */ DatePicker.prototype.addDisabled = function( collection, item ) { + var calendar = this + + // Go through each item to disable. item.map( function( timeUnit ) { + + // Add the time unit if it isn’t already within the collection. if ( !calendar.filterDisabled( collection, timeUnit ).length ) { collection.push( timeUnit ) } + + // If the time unit is an array and falls within the range, just remove it. + else if ( $.isArray( timeUnit ) && calendar.filterDisabled( collection, timeUnit, 1 ).length ) { + collection = calendar.removeDisabled( collection, [timeUnit] ) + } }) + + // Return the final collection. return collection } //DatePicker.prototype.addDisabled /** * Remove an item from the disabled collection. */ DatePicker.prototype.removeDisabled = function( collection, item ) { + var calendar = this + + // Go through each item to enable. item.map( function( timeUnit ) { + + // Filter each item out of the collection. collection = calendar.filterDisabled( collection, timeUnit, 1 ) }) + + // Return the final colleciton. return collection } //DatePicker.prototype.removeDisabled /**