Вход Регистрация
Файл: src/public/plugins/pickadate/picker.date.js
Строк: 1593
<?php
/*!
 * Date picker for pickadate.js v3.5.6
 * http://amsul.github.io/pickadate.js/date.htm
 */

(function ( factory ) {

    
// AMD.
    
if ( typeof define == 'function' && define.amd )
        
define( ['picker''jquery'], factory )

    
// Node.js/browserify.
    
else if ( typeof exports == 'object' )
        
module.exports factory( require('./picker.js'), require('jquery') )

    
// Browser globals.
    
else factoryPickerjQuery )

}(function( 
Picker, $ ) {


/**
 * Globals and constants
 */
var DAYS_IN_WEEK 7,
    
WEEKS_IN_CALENDAR 6,
    
Picker._



/**
 * The date picker constructor
 */
function DatePickerpickersettings ) {

    var 
calendar this,
        
element picker.$node],
        
elementValue element.value,
        
elementDataValue picker.$node.data'value' ),
        
valueString elementDataValue || elementValue,
        
formatString elementDataValue settings.formatSubmit settings.format,
        
isRTL = function() {

            return 
element.currentStyle ?

                
// For IE.
                
element.currentStyle.direction == 'rtl' :

                
// For normal browsers.
                
getComputedStylepicker.$root[0] ).direction == 'rtl'
        
}

    
calendar.settings settings
    calendar
.$node picker.$node

    
// The queue of methods that will be used to build item objects.
    
calendar.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'
    
}

    
// The component's item object.
    
calendar.item = {}

    
calendar.item.clear null
    calendar
.item.disable = ( settings.disable || [] ).slice)
    
calendar.item.enable = -(function( collectionDisabled ) {
        return 
collectionDisabled] === true collectionDisabled.shift() : -1
    
})( calendar.item.disable )

    
calendar.
        
set'min'settings.min ).
        
set'max'settings.max ).
        
set'now' )

    
// When there’s a value, set the `select`, which in turn
    // also sets the `highlight` and `view`.
    
if ( valueString ) {
        
calendar.set'select'valueString, {
            
formatformatString,
            
defaultValuetrue
        
})
    }

    
// If there’s no value, default to highlighting “today”.
    
else {
        
calendar.
            
set'select'null ).
            
set'highlight'calendar.item.now )
    }


    
// The keycode to movement mapping.
    
calendar.key = {
        
407// Down
        
38: -7// Up
        
39: function() { return isRTL() ? -}, // Right
        
37: function() { return isRTL() ? : -}, // Left
        
go: function( timeChange ) {
            var 
highlightedObject calendar.item.highlight,
                
targetDate = new DatehighlightedObject.yearhighlightedObject.monthhighlightedObject.date timeChange )
            
calendar.set(
                
'highlight',
                
targetDate,
                { 
intervaltimeChange }
            )
            
this.render()
        }
    }


    
// Bind some picker events.
    
picker.
        
on'render', function() {
            
picker.$root.find'.' settings.klass.selectMonth ).on'change', function() {
                var 
value this.value
                
if ( value ) {
                    
picker.set'highlight', [ picker.get'view' ).yearvaluepicker.get'highlight' ).date ] )
                    
picker.$root.find'.' settings.klass.selectMonth ).trigger'focus' )
                }
            })
            
picker.$root.find'.' settings.klass.selectYear ).on'change', function() {
                var 
value this.value
                
if ( value ) {
                    
picker.set'highlight', [ valuepicker.get'view' ).monthpicker.get'highlight' ).date ] )
                    
picker.$root.find'.' settings.klass.selectYear ).trigger'focus' )
                }
            })
        }, 
).
        
on'open', function() {
            var 
includeToday ''
            
if ( calendar.disabledcalendar.get('now') ) ) {
                
includeToday ':not(.' settings.klass.buttonToday ')'
            
}
            
picker.$root.find'button' includeToday ', select' ).attr'disabled'false )
        }, 
).
        
on'close', function() {
            
picker.$root.find'button, select' ).attr'disabled'true )
        }, 
)

//DatePicker


/**
 * Set a datepicker item object.
 */
DatePicker.prototype.set = function( typevalueoptions ) {

    var 
calendar this,
        
calendarItem calendar.item

    
// If the value is `null` just set it immediately.
    
if ( value === null ) {
        if ( 
type == 'clear' type 'select'
        
calendarItemtype ] = value
        
return calendar
    
}

    
// Otherwise go through the queue of methods, and invoke the functions.
    // Update this as the time unit, and set the final value as this item.
    // * In the case of `enable`, keep the queue but set `disable` instead.
    //   And in the case of `flip`, keep the queue but set `enable` instead.
    
calendarItem[ ( type == 'enable' 'disable' type == 'flip' 'enable' type ) ] = calendar.queuetype ].split' ' ).map( function( method ) {
        
value calendarmethod ]( typevalueoptions )
        return 
value
    
}).pop()

    
// Check if we need to cascade through more updates.
    
if ( type == 'select' ) {
        
calendar.set'highlight'calendarItem.selectoptions )
    }
    else if ( 
type == 'highlight' ) {
        
calendar.set'view'calendarItem.highlightoptions )
    }
    else if ( 
type.match( /^(flip|min|max|disable|enable)$/ ) ) {
        if ( 
calendarItem.select && calendar.disabledcalendarItem.select ) ) {
            
calendar.set'select'calendarItem.selectoptions )
        }
        if ( 
calendarItem.highlight && calendar.disabledcalendarItem.highlight ) ) {
            
calendar.set'highlight'calendarItem.highlightoptions )
        }
    }

    return 
calendar
//DatePicker.prototype.set


/**
 * Get a datepicker item object.
 */
DatePicker.prototype.get = function( type ) {
    return 
this.itemtype ]
//DatePicker.prototype.get


/**
 * Create a picker date object.
 */
DatePicker.prototype.create = function( typevalueoptions ) {

    var 
isInfiniteValue,
        
calendar this

    
// If there’s no value, use the type as the value.
    
value value === undefined type value


    
// If it’s infinity, update the value.
    
if ( value == -Infinity || value == Infinity ) {
        
isInfiniteValue value
    
}

    
// If it’s an object, use the native date object.
    
else if ( $.isPlainObjectvalue ) && _.isIntegervalue.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.
    
else if ( $.isArrayvalue ) ) {
        
value = new Datevalue], value], value] )
        
value _.isDatevalue ) ? value calendar.create().obj
    
}

    
// If it’s a number or date object, make a normalized date.
    
else if ( _.isIntegervalue ) || _.isDatevalue ) ) {
        
value calendar.normalize( new Datevalue ), options )
    }

    
// If it’s a literal true or any other case, set it to now.
    
else /*if ( value === true )*/ {
        
value calendar.nowtypevalueoptions )
    }

    
// Return the compiled object.
    
return {
        
yearisInfiniteValue || value.getFullYear(),
        
monthisInfiniteValue || value.getMonth(),
        
dateisInfiniteValue || value.getDate(),
        
dayisInfiniteValue || value.getDay(),
        
objisInfiniteValue || value,
        
pickisInfiniteValue || value.getTime()
    }
//DatePicker.prototype.create


/**
 * Create a range limit object using an array, date object,
 * literal “true”, or integer relative to another time.
 */
DatePicker.prototype.createRange = function( fromto ) {

    var 
calendar this,
        
createDate = function( date ) {
            if ( 
date === true || $.isArraydate ) || _.isDatedate ) ) {
                return 
calendar.createdate )
            }
            return 
date
        
}

    
// Create objects if possible.
    
if ( !_.isIntegerfrom ) ) {
        
from createDatefrom )
    }
    if ( !
_.isIntegerto ) ) {
        
to createDateto )
    }

    
// Create relative dates.
    
if ( _.isIntegerfrom ) && $.isPlainObjectto ) ) {
        
from = [ to.yearto.monthto.date from ];
    }
    else if ( 
_.isIntegerto ) && $.isPlainObjectfrom ) ) {
        
to = [ from.yearfrom.monthfrom.date to ];
    }

    return {
        
fromcreateDatefrom ),
        
tocreateDateto )
    }
//DatePicker.prototype.createRange


/**
 * Check if a date unit falls within a date range object.
 */
DatePicker.prototype.withinRange = function( rangedateUnit ) {
    
range this.createRange(range.fromrange.to)
    return 
dateUnit.pick >= range.from.pick && dateUnit.pick <= range.to.pick
}


/**
 * Check if two date range objects overlap.
 */
DatePicker.prototype.overlapRanges = function( onetwo ) {

    var 
calendar this

    
// Convert the ranges into comparable dates.
    
one calendar.createRangeone.fromone.to )
    
two calendar.createRangetwo.fromtwo.to )

    return 
calendar.withinRangeonetwo.from ) || calendar.withinRangeonetwo.to ) ||
        
calendar.withinRangetwoone.from ) || calendar.withinRangetwoone.to )
}


/**
 * Get the date today.
 */
DatePicker.prototype.now = function( typevalueoptions ) {
    
value = new Date()
    if ( 
options && options.rel ) {
        
value.setDatevalue.getDate() + options.rel )
    }
    return 
this.normalizevalueoptions )
}


/**
 * Navigate to next/prev month.
 */
DatePicker.prototype.navigate = function( typevalueoptions ) {

    var 
targetDateObject,
        
targetYear,
        
targetMonth,
        
targetDate,
        
isTargetArray = $.isArrayvalue ),
        
isTargetObject = $.isPlainObjectvalue ),
        
viewsetObject this.item.view/*,
        safety = 100*/


    
if ( isTargetArray || isTargetObject ) {

        if ( 
isTargetObject ) {
            
targetYear value.year
            targetMonth 
value.month
            targetDate 
value.date
        
}
        else {
            
targetYear = +value[0]
            
targetMonth = +value[1]
            
targetDate = +value[2]
        }

        
// If we’re navigating months but the view is in a different
        // month, navigate to the view’s year and month.
        
if ( options && options.nav && viewsetObject && viewsetObject.month !== targetMonth ) {
            
targetYear viewsetObject.year
            targetMonth 
viewsetObject.month
        
}

        
// Figure out the expected target year and month.
        
targetDateObject = new DatetargetYeartargetMonth + ( options && options.nav options.nav ), )
        
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 DatetargetYeartargetMonthtargetDate ).getMonth() !== targetMonth ) {
            
targetDate -= 1
            
/*safety -= 1
            if ( !safety ) {
                throw 'Fell into an infinite loop while navigating to ' + new Date( targetYear, targetMonth, targetDate ) + '.'
            }*/
        
}

        
value = [ targetYeartargetMonthtargetDate ]
    }

    return 
value
//DatePicker.prototype.navigate


/**
 * Normalize a date by setting the hours to midnight.
 */
DatePicker.prototype.normalize = function( value/*, options*/ ) {
    
value.setHours000)
    return 
value
}


/**
 * Measure the range of dates.
 */
DatePicker.prototype.measure = function( typevalue/*, options*/ ) {

    var 
calendar this

    
// If it’s anything false-y, remove the limits.
    
if ( !value ) {
        
value type == 'min' ? -Infinity Infinity
    
}

    
// If it’s a string, parse it.
    
else if ( typeof value == 'string' ) {
        
value calendar.parsetypevalue )
    }

    
// If it's an integer, get a date relative to today.
    
else if ( _.isIntegervalue ) ) {
        
value calendar.nowtypevalue, { relvalue } )
    }

    return 
value
///DatePicker.prototype.measure


/**
 * Create a viewset object based on navigation.
 */
DatePicker.prototype.viewset = function( typedateObject/*, options*/ ) {
    return 
this.create([ dateObject.yeardateObject.month])
}


/**
 * Validate a date as enabled and shift if needed.
 */
DatePicker.prototype.validate = function( typedateObjectoptions ) {

    var 
calendar this,

        
// Keep a reference to the original date.
        
originalDateObject dateObject,

        
// Make sure we have an interval.
        
interval options && options.interval options.interval 1,

        
// Check if the calendar enabled dates are inverted.
        
isFlippedBase calendar.item.enable === -1,

        
// Check if we have any enabled dates after/before now.
        
hasEnabledBeforeTargethasEnabledAfterTarget,

        
// The min & max limits.
        
minLimitObject calendar.item.min,
        
maxLimitObject calendar.item.max,

        
// Check if we’ve reached the limit during shifting.
        
reachedMinreachedMax,

        
// Check if the calendar is inverted and at least one weekday is enabled.
        
hasEnabledWeekdays isFlippedBase && calendar.item.disable.filter( function( value ) {

            
// If there’s a date, check where it is relative to the target.
            
if ( $.isArrayvalue ) ) {
                var 
dateTime calendar.createvalue ).pick
                
if ( dateTime dateObject.pick hasEnabledBeforeTarget true
                
else if ( dateTime dateObject.pick hasEnabledAfterTarget true
            
}

            
// Return only integers for enabled weekdays.
            
return _.isIntegervalue )
        }).
length/*,

        safety = 100*/



    // Cases to validate for:
    // [1] Not inverted and date disabled.
    // [2] Inverted and some dates enabled.
    // [3] Not inverted and out of range.
    //
    // Cases to **not** validate for:
    // • Navigating months.
    // • Not inverted and date enabled.
    // • Inverted and all dates disabled.
    // • ..and anything else.
    
if ( !options || (!options.nav && !options.defaultValue) ) if (
        
/* 1 */ ( !isFlippedBase && calendar.disableddateObject ) ) ||
        
/* 2 */ isFlippedBase && calendar.disableddateObject ) && ( hasEnabledWeekdays || hasEnabledBeforeTarget || hasEnabledAfterTarget ) ) ||
        
/* 3 */ ( !isFlippedBase && (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 ( isFlippedBase && !hasEnabledWeekdays && ( ( !hasEnabledAfterTarget && interval ) || ( !hasEnabledBeforeTarget && interval ) ) ) {
            
interval *= -1
        
}


        
// Keep looping until we reach an enabled date.
        
while ( /*safety &&*/ calendar.disableddateObject ) ) {

            
/*safety -= 1
            if ( !safety ) {
                throw 'Fell into an infinite loop while validating ' + dateObject.obj + '.'
            }*/


            // If we’ve looped into the next/prev month with a large interval, return to the original date and flatten the interval.
            
if ( Math.absinterval ) > && ( dateObject.month originalDateObject.month || dateObject.month originalDateObject.month ) ) {
                
dateObject originalDateObject
                interval 
interval : -1
            
}


            
// If we’ve reached the min/max limit, reverse the direction, flatten the interval and set it to the limit.
            
if ( dateObject.pick <= minLimitObject.pick ) {
                
reachedMin true
                interval 
1
                dateObject 
calendar.create([
                    
minLimitObject.year,
                    
minLimitObject.month,
                    
minLimitObject.date + (dateObject.pick === minLimitObject.pick : -1)
                ])
            }
            else if ( 
dateObject.pick >= maxLimitObject.pick ) {
                
reachedMax true
                interval 
= -1
                dateObject 
calendar.create([
                    
maxLimitObject.year,
                    
maxLimitObject.month,
                    
maxLimitObject.date + (dateObject.pick === maxLimitObject.pick 1)
                ])
            }


            
// If we’ve reached both limits, just break out of the loop.
            
if ( reachedMin && reachedMax ) {
                break
            }


            
// Finally, create the shifted date using the interval and keep looping.
            
dateObject calendar.create([ dateObject.yeardateObject.monthdateObject.date interval ])
        }

    } 
//endif


    // Return the date object settled on.
    
return dateObject
//DatePicker.prototype.validate


/**
 * Check if a date is disabled.
 */
DatePicker.prototype.disabled = function( dateToVerify ) {

    var
        
calendar this,

        
// Filter through the disabled dates to check if this is one.
        
isDisabledMatch calendar.item.disable.filter( function( dateToDisable ) {

            
// If the date is a number, match the weekday with 0index and `firstDay` check.
            
if ( _.isIntegerdateToDisable ) ) {
                return 
dateToVerify.day === ( calendar.settings.firstDay dateToDisable dateToDisable ) % 7
            
}

            
// If it’s an array or a native JS date, create and match the exact date.
            
if ( $.isArraydateToDisable ) || _.isDatedateToDisable ) ) {
                return 
dateToVerify.pick === calendar.createdateToDisable ).pick
            
}

            
// If it’s an object, match a date within the “from” and “to” range.
            
if ( $.isPlainObjectdateToDisable ) ) {
                return 
calendar.withinRangedateToDisabledateToVerify )
            }
        })

    
// If this date matches a disabled date, confirm it’s not inverted.
    
isDisabledMatch isDisabledMatch.length && !isDisabledMatch.filter(function( dateToDisable ) {
        return $.
isArraydateToDisable ) && dateToDisable[3] == 'inverted' ||
            $.
isPlainObjectdateToDisable ) && dateToDisable.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 === -? !isDisabledMatch isDisabledMatch ||
        
dateToVerify.pick calendar.item.min.pick ||
        
dateToVerify.pick calendar.item.max.pick

//DatePicker.prototype.disabled


/**
 * Parse a string into a usable type.
 */
DatePicker.prototype.parse = function( typevalueoptions ) {

    var 
calendar this,
        
parsingObject = {}

    
// If it’s already parsed, we’re good.
    
if ( !value || typeof value != 'string' ) {
        return 
value
    
}

    
// We need a `.format` to parse the value with.
    
if ( !( options && options.format ) ) {
        
options options || {}
        
options.format calendar.settings.format
    
}

    
// Convert the format into an array and then map through it.
    
calendar.formats.toArrayoptions.format ).map( function( label ) {

        var
            
// Grab the formatting label.
            
formattingLabel calendar.formatslabel ],

            
// The format length is from the formatting label function or the
            // label length without the escaping exclamation (!) mark.
            
formatLength formattingLabel _.triggerformattingLabelcalendar, [ valueparsingObject ] ) : label.replace( /^!/, '' ).length

        
// If there's a format label, split the value up to the format length.
        // Then add it to the parsing object with appropriate label.
        
if ( formattingLabel ) {
            
parsingObjectlabel ] = value.substr0formatLength )
        }

        
// Update the value as the substring from format length to end.
        
value value.substrformatLength )
    })

    
// Compensate for month 0index.
    
return [
        
parsingObject.yyyy || parsingObject.yy,
        +( 
parsingObject.mm || parsingObject.) - 1,
        
parsingObject.dd || parsingObject.d
    
]
//DatePicker.prototype.parse


/**
 * Various formats to display the object in.
 */
DatePicker.prototype.formats = (function() {

    
// Return the length of the first word in a collection.
    
function getWordLengthFromCollectionstringcollectiondateObject ) {

        
// Grab the first word from the string.
        // Regex pattern from http://stackoverflow.com/q/150033
        
var word string.match( /[^x00-x7F]+|w+/ )[ ]

        
// If there's no month index, add it to the date object
        
if ( !dateObject.mm && !dateObject.) {
            
dateObject.collection.indexOfword ) + 1
        
}

        
// Return the length of the word.
        
return word.length
    
}

    
// Get the length of the first word in a string.
    
function getFirstWordLength( string ) {
        return 
string.match( /w+/ )[ ].length
    
}

    return {

        
d: function( stringdateObject ) {

            
// If there's string, then get the digits length.
            // Otherwise return the selected date.
            
return string _.digits( string ) : dateObject.date
        
},
        
dd: function( stringdateObject ) {

            
// If there's a string, then the length is always 2.
            // Otherwise return the selected date with a leading zero.
            
return string _.leaddateObject.date )
        },
        
ddd: function( stringdateObject ) {

            
// If there's a string, then get the length of the first word.
            // Otherwise return the short selected weekday.
            
return string getFirstWordLength( string ) : this.settings.weekdaysShortdateObject.day ]
        },
        
dddd: function( stringdateObject ) {

            
// If there's a string, then get the length of the first word.
            // Otherwise return the full selected weekday.
            
return string getFirstWordLength( string ) : this.settings.weekdaysFulldateObject.day ]
        },
        
m: function( stringdateObject ) {

            
// If there's a string, then get the length of the digits
            // Otherwise return the selected month with 0index compensation.
            
return string _.digits( string ) : dateObject.month 1
        
},
        
mm: function( stringdateObject ) {

            
// If there's a string, then the length is always 2.
            // Otherwise return the selected month with 0index and leading zero.
            
return string _.leaddateObject.month )
        },
        
mmm: function( stringdateObject ) {

            var 
collection this.settings.monthsShort

            
// If there's a string, get length of the relevant month from the short
            // months collection. Otherwise return the selected month from that collection.
            
return string getWordLengthFromCollectionstringcollectiondateObject ) : collectiondateObject.month ]
        },
        
mmmm: function( stringdateObject ) {

            var 
collection this.settings.monthsFull

            
// If there's a string, get length of the relevant month from the full
            // months collection. Otherwise return the selected month from that collection.
            
return string getWordLengthFromCollectionstringcollectiondateObject ) : collectiondateObject.month ]
        },
        
yy: function( stringdateObject ) {

            
// If there's a string, then the length is always 2.
            // Otherwise return the selected year by slicing out the first 2 digits.
            
return string : ( '' dateObject.year ).slice)
        },
        
yyyy: function( stringdateObject ) {

            
// If there's a string, then the length is always 4.
            // Otherwise return the selected year.
            
return string dateObject.year
        
},

        
// Create an array by splitting the formatting string passed.
        
toArray: function( formatString ) { return formatString.split( /(d{1,4}|m{1,4}|y{4}|yy|!.)/) },

        
// Format an object into a string using the formatting options.
        
toString: function ( formatStringitemObject ) {
            var 
calendar this
            
return calendar.formats.toArrayformatString ).map( function( label ) {
                return 
_.triggercalendar.formatslabel ], calendar, [ 0itemObject ] ) || label.replace( /^!/, '' )
            }).
join'' )
        }
    }
})() 
//DatePicker.prototype.formats




/**
 * Check if two date units are the exact.
 */
DatePicker.prototype.isDateExact = function( onetwo ) {

    var 
calendar this

    
// When we’re working with weekdays, do a direct comparison.
    
if (
        ( 
_.isIntegerone ) && _.isIntegertwo ) ) ||
        ( 
typeof one == 'boolean' && typeof two == 'boolean' )
     ) {
        return 
one === two
    
}

    
// When we’re working with date representations, compare the “pick” value.
    
if (
        ( 
_.isDateone ) || $.isArrayone ) ) &&
        ( 
_.isDatetwo ) || $.isArraytwo ) )
    ) {
        return 
calendar.createone ).pick === calendar.createtwo ).pick
    
}

    
// When we’re working with range objects, compare the “from” and “to”.
    
if ( $.isPlainObjectone ) && $.isPlainObjecttwo ) ) {
        return 
calendar.isDateExactone.fromtwo.from ) && calendar.isDateExactone.totwo.to )
    }

    return 
false
}


/**
 * Check if two date units overlap.
 */
DatePicker.prototype.isDateOverlap = function( onetwo ) {

    var 
calendar this,
        
firstDay calendar.settings.firstDay 0

    
// When we’re working with a weekday index, compare the days.
    
if ( _.isIntegerone ) && ( _.isDatetwo ) || $.isArraytwo ) ) ) {
        
one one firstDay
        
return one === calendar.createtwo ).day 1
    
}
    if ( 
_.isIntegertwo ) && ( _.isDateone ) || $.isArrayone ) ) ) {
        
two two firstDay
        
return two === calendar.createone ).day 1
    
}

    
// When we’re working with range objects, check if the ranges overlap.
    
if ( $.isPlainObjectone ) && $.isPlainObjecttwo ) ) {
        return 
calendar.overlapRangesonetwo )
    }

    return 
false
}


/**
 * Flip the “enabled” state.
 */
DatePicker.prototype.flipEnable = function(val) {
    var 
itemObject this.item
    itemObject
.enable val || (itemObject.enable == -: -1)
}


/**
 * Mark a collection of dates as “disabled”.
 */
DatePicker.prototype.deactivate = function( typedatesToDisable ) {

    var 
calendar this,
        
disabledItems calendar.item.disable.slice(0)


    
// If we’re flipping, that’s all we need to do.
    
if ( datesToDisable == 'flip' ) {
        
calendar.flipEnable()
    }

    else if ( 
datesToDisable === false ) {
        
calendar.flipEnable(1)
        
disabledItems = []
    }

    else if ( 
datesToDisable === true ) {
        
calendar.flipEnable(-1)
        
disabledItems = []
    }

    
// Otherwise go through the dates to disable.
    
else {

        
datesToDisable.map(function( unitToDisable ) {

            var 
matchFound

            
// When we have disabled items, check for matches.
            // If something is matched, immediately break out.
            
for ( var index 0index disabledItems.lengthindex += ) {
                if ( 
calendar.isDateExactunitToDisabledisabledItems[index] ) ) {
                    
matchFound true
                    
break
                }
            }

            
// If nothing was found, add the validated unit to the collection.
            
if ( !matchFound ) {
                if (
                    
_.isIntegerunitToDisable ) ||
                    
_.isDateunitToDisable ) ||
                    $.
isArrayunitToDisable ) ||
                    ( $.
isPlainObjectunitToDisable ) && unitToDisable.from && unitToDisable.to )
                ) {
                    
disabledItems.pushunitToDisable )
                }
            }
        })
    }

    
// Return the updated collection.
    
return disabledItems
//DatePicker.prototype.deactivate


/**
 * Mark a collection of dates as “enabled”.
 */
DatePicker.prototype.activate = function( typedatesToEnable ) {

    var 
calendar this,
        
disabledItems calendar.item.disable,
        
disabledItemsCount disabledItems.length

    
// If we’re flipping, that’s all we need to do.
    
if ( datesToEnable == 'flip' ) {
        
calendar.flipEnable()
    }

    else if ( 
datesToEnable === true ) {
        
calendar.flipEnable(1)
        
disabledItems = []
    }

    else if ( 
datesToEnable === false ) {
        
calendar.flipEnable(-1)
        
disabledItems = []
    }

    
// Otherwise go through the disabled dates.
    
else {

        
datesToEnable.map(function( unitToEnable ) {

            var 
matchFound,
                
disabledUnit,
                
index,
                
isExactRange

            
// Go through the disabled items and try to find a match.
            
for ( index 0index disabledItemsCountindex += ) {

                
disabledUnit disabledItems[index]

                
// When an exact match is found, remove it from the collection.
                
if ( calendar.isDateExactdisabledUnitunitToEnable ) ) {
                    
matchFound disabledItems[index] = null
                    isExactRange 
true
                    
break
                }

                
// When an overlapped match is found, add the “inverted” state to it.
                
else if ( calendar.isDateOverlapdisabledUnitunitToEnable ) ) {
                    if ( $.
isPlainObjectunitToEnable ) ) {
                        
unitToEnable.inverted true
                        matchFound 
unitToEnable
                    
}
                    else if ( $.
isArrayunitToEnable ) ) {
                        
matchFound unitToEnable
                        
if ( !matchFound[3] ) matchFound.push'inverted' )
                    }
                    else if ( 
_.isDateunitToEnable ) ) {
                        
matchFound = [ unitToEnable.getFullYear(), unitToEnable.getMonth(), unitToEnable.getDate(), 'inverted' ]
                    }
                    break
                }
            }

            
// If a match was found, remove a previous duplicate entry.
            
if ( matchFound ) for ( index 0index disabledItemsCountindex += ) {
                if ( 
calendar.isDateExactdisabledItems[index], unitToEnable ) ) {
                    
disabledItems[index] = null
                    
break
                }
            }

            
// In the event that we’re dealing with an exact range of dates,
            // make sure there are no “inverted” dates because of it.
            
if ( isExactRange ) for ( index 0index disabledItemsCountindex += ) {
                if ( 
calendar.isDateOverlapdisabledItems[index], unitToEnable ) ) {
                    
disabledItems[index] = null
                    
break
                }
            }

            
// If something is still matched, add it into the collection.
            
if ( matchFound ) {
                
disabledItems.pushmatchFound )
            }
        })
    }

    
// Return the updated collection.
    
return disabledItems.filter(function( val ) { return val != null })
//DatePicker.prototype.activate


/**
 * Create a string for the nodes in the picker.
 */
DatePicker.prototype.nodes = function( isOpen ) {

    var
        
calendar this,
        
settings calendar.settings,
        
calendarItem calendar.item,
        
nowObject calendarItem.now,
        
selectedObject calendarItem.select,
        
highlightedObject calendarItem.highlight,
        
viewsetObject calendarItem.view,
        
disabledCollection calendarItem.disable,
        
minLimitObject calendarItem.min,
        
maxLimitObject calendarItem.max,


        
// Create the calendar table head using a copy of weekday labels collection.
        // * We do a copy so we don't mutate the original array.
        
tableHead = (function( collectionfullCollection ) {

            
// If the first day should be Monday, move Sunday to the end.
            
if ( settings.firstDay ) {
                
collection.pushcollection.shift() )
                
fullCollection.pushfullCollection.shift() )
            }

            
// Create and return the table head group.
            
return _.node(
                
'thead',
                
_.node(
                    
'tr',
                    
_.group({
                        
min0,
                        
maxDAYS_IN_WEEK 1,
                        
i1,
                        
node'th',
                        
item: function( counter ) {
                            return [
                                
collectioncounter ],
                                
settings.klass.weekdays,
                                
'scope=col title="' fullCollectioncounter ] + '"'
                            
]
                        }
                    })
                )
            ) 
//endreturn
        
})( ( settings.showWeekdaysFull settings.weekdaysFull settings.weekdaysShort ).slice), settings.weekdaysFull.slice) ), //tableHead


        // Create the nav for next/prev month.
        
createMonthNav = function( next ) {

            
// Otherwise, return the created month tag.
            
return _.node(
                
'div',
                
' ',
                
settings.klass'nav' + ( next 'Next' 'Prev' ) ] + (

                    
// If the focused month is outside the range, disabled the button.
                    
next && viewsetObject.year >= maxLimitObject.year && viewsetObject.month >= maxLimitObject.month ) ||
                    ( !
next && viewsetObject.year <= minLimitObject.year && viewsetObject.month <= minLimitObject.month ) ?
                    
' ' settings.klass.navDisabled ''
                
),
                
'data-nav=' + ( next || -) + ' ' +
                
_.ariaAttr({
                    
role'button',
                    
controlscalendar.$node[0].id '_table'
                
}) + ' ' +
                
'title="' + (next settings.labelMonthNext settings.labelMonthPrev ) + '"'
            
//endreturn
        
}, //createMonthNav


        // Create the month label.
        
createMonthLabel = function() {

            var 
monthsCollection settings.showMonthsShort settings.monthsShort settings.monthsFull

            
// If there are months to select, add a dropdown menu.
            
if ( settings.selectMonths ) {

                return 
_.node'select',
                    
_.group({
                        
min0,
                        
max11,
                        
i1,
                        
node'option',
                        
item: function( loopedMonth ) {

                            return [

                                
// The looped month and no classes.
                                
monthsCollectionloopedMonth ], 0,

                                
// Set the value and selected index.
                                
'value=' loopedMonth +
                                ( 
viewsetObject.month == loopedMonth ' selected' '' ) +
                                (
                                    (
                                        ( 
viewsetObject.year == minLimitObject.year && loopedMonth minLimitObject.month ) ||
                                        ( 
viewsetObject.year == maxLimitObject.year && loopedMonth maxLimitObject.month )
                                    ) ?
                                    
' disabled' ''
                                
)
                            ]
                        }
                    }),
                    
settings.klass.selectMonth,
                    ( 
isOpen '' 'disabled' ) + ' ' +
                    
_.ariaAttr({ controlscalendar.$node[0].id '_table' }) + ' ' +
                    
'title="' settings.labelMonthSelect '"'
                
)
            }

            
// If there's a need for a month selector
            
return _.node'div'monthsCollectionviewsetObject.month ], settings.klass.month )
        }, 
//createMonthLabel


        // Create the year label.
        
createYearLabel = function() {

            var 
focusedYear viewsetObject.year,

            
// If years selector is set to a literal "true", set it to 5. Otherwise
            // divide in half to get half before and half after focused year.
            
numberYears settings.selectYears === true : ~~( settings.selectYears )

            
// If there are years to select, add a dropdown menu.
            
if ( numberYears ) {

                var
                    
minYear minLimitObject.year,
                    
maxYear maxLimitObject.year,
                    
lowestYear focusedYear numberYears,
                    
highestYear focusedYear numberYears

                
// If the min year is greater than the lowest year, increase the highest year
                // by the difference and set the lowest year to the min year.
                
if ( minYear lowestYear ) {
                    
highestYear += minYear lowestYear
                    lowestYear 
minYear
                
}

                
// If the max year is less than the highest year, decrease the lowest year
                // by the lower of the two: available and needed years. Then set the
                // highest year to the max year.
                
if ( maxYear highestYear ) {

                    var 
availableYears lowestYear minYear,
                        
neededYears highestYear maxYear

                    lowestYear 
-= availableYears neededYears neededYears availableYears
                    highestYear 
maxYear
                
}

                return 
_.node'select',
                    
_.group({
                        
minlowestYear,
                        
maxhighestYear,
                        
i1,
                        
node'option',
                        
item: function( loopedYear ) {
                            return [

                                
// The looped year and no classes.
                                
loopedYear0,

                                
// Set the value and selected index.
                                
'value=' loopedYear + ( focusedYear == loopedYear ' selected' '' )
                            ]
                        }
                    }),
                    
settings.klass.selectYear,
                    ( 
isOpen '' 'disabled' ) + ' ' _.ariaAttr({ controlscalendar.$node[0].id '_table' }) + ' ' +
                    
'title="' settings.labelYearSelect '"'
                
)
            }

            
// Otherwise just return the year focused
            
return _.node'div'focusedYearsettings.klass.year )
        } 
//createYearLabel


    // Create and return the entire calendar.
    
return _.node(
        
'div',
        ( 
settings.selectYears createYearLabel() + createMonthLabel() : createMonthLabel() + createYearLabel() ) +
        
createMonthNav() + createMonthNav),
        
settings.klass.header
    
) + _.node(
        
'table',
        
tableHead +
        
_.node(
            
'tbody',
            
_.group({
                
min0,
                
maxWEEKS_IN_CALENDAR 1,
                
i1,
                
node'tr',
                
item: function( rowCounter ) {

                    
// If Monday is the first day and the month starts on Sunday, shift the date back a week.
                    
var shiftDateBy settings.firstDay && calendar.create([ viewsetObject.yearviewsetObject.month]).day === ? -0

                    
return [
                        
_.group({
                            
minDAYS_IN_WEEK rowCounter viewsetObject.day shiftDateBy 1// Add 1 for weekday 0index
                            
max: function() {
                                return 
this.min DAYS_IN_WEEK 1
                            
},
                            
i1,
                            
node'td',
                            
item: function( targetDate ) {

                                
// Convert the time date from a relative date to a target date.
                                
targetDate calendar.create([ viewsetObject.yearviewsetObject.monthtargetDate + ( settings.firstDay ) ])

                                var 
isSelected selectedObject && selectedObject.pick == targetDate.pick,
                                    
isHighlighted highlightedObject && highlightedObject.pick == targetDate.pick,
                                    
isDisabled disabledCollection && calendar.disabledtargetDate ) || targetDate.pick minLimitObject.pick || targetDate.pick maxLimitObject.pick,
                                    
formattedDate _.triggercalendar.formats.toStringcalendar, [ settings.formattargetDate ] )

                                return [
                                    
_.node(
                                        
'div',
                                        
targetDate.date,
                                        (function( 
klasses ) {

                                            
// Add the `infocus` or `outfocus` classes based on month in view.
                                            
klasses.pushviewsetObject.month == targetDate.month settings.klass.infocus settings.klass.outfocus )

                                            
// Add the `today` class if needed.
                                            
if ( nowObject.pick == targetDate.pick ) {
                                                
klasses.pushsettings.klass.now )
                                            }

                                            
// Add the `selected` class if something's selected and the time matches.
                                            
if ( isSelected ) {
                                                
klasses.pushsettings.klass.selected )
                                            }

                                            
// Add the `highlighted` class if something's highlighted and the time matches.
                                            
if ( isHighlighted ) {
                                                
klasses.pushsettings.klass.highlighted )
                                            }

                                            
// Add the `disabled` class if something's disabled and the object matches.
                                            
if ( isDisabled ) {
                                                
klasses.pushsettings.klass.disabled )
                                            }

                                            return 
klasses.join' ' )
                                        })([ 
settings.klass.day ]),
                                        
'data-pick=' targetDate.pick ' ' _.ariaAttr({
                                            
role'gridcell',
                                            
labelformattedDate,
                                            
selectedisSelected && calendar.$node.val() === formattedDate true null,
                                            
activedescendantisHighlighted true null,
                                            
disabledisDisabled true null
                                        
})
                                    ),
                                    
'',
                                    
_.ariaAttr({ role'presentation' })
                                ] 
//endreturn
                            
}
                        })
                    ] 
//endreturn
                
}
            })
        ),
        
settings.klass.table,
        
'id="' calendar.$node[0].id '_table' '" ' _.ariaAttr({
            
role'grid',
            
controlscalendar.$node[0].id,
            
readonlytrue
        
})
    ) +

    
// * For Firefox forms to submit, make sure to set the buttons’ `type` attributes as “button”.
    
_.node(
        
'div',
        
_.node'button'settings.todaysettings.klass.buttonToday,
            
'type=button data-pick=' nowObject.pick +
            ( 
isOpen && !calendar.disabled(nowObject) ? '' ' disabled' ) + ' ' +
            
_.ariaAttr({ controlscalendar.$node[0].id }) ) +
        
_.node'button'settings.clearsettings.klass.buttonClear,
            
'type=button data-clear=1' +
            ( 
isOpen '' ' disabled' ) + ' ' +
            
_.ariaAttr({ controlscalendar.$node[0].id }) ) +
        
_.node('button'settings.closesettings.klass.buttonClose,
            
'type=button data-close=true ' +
            ( 
isOpen '' ' disabled' ) + ' ' +
            
_.ariaAttr({ controlscalendar.$node[0].id }) ),
        
settings.klass.footer
    
//endreturn
//DatePicker.prototype.nodes




/**
 * The date picker defaults.
 */
DatePicker.defaults = (function( prefix ) {

    return {

        
// The title label to use for the month nav buttons
        
labelMonthNext'Next month',
        
labelMonthPrev'Previous month',

        
// The title label to use for the dropdown selectors
        
labelMonthSelect'Select a month',
        
labelYearSelect'Select a year',

        
// Months and weekdays
        
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 and clear
        
today'Today',
        
clear'Clear',
        
close'Close',

        
// Picker close behavior
        
closeOnSelecttrue,
        
closeOnCleartrue,

        
// The format to show on the `input` element
        
format'd mmmm, yyyy',

        
// Classes
        
klass: {

            
tableprefix 'table',

            
headerprefix 'header',

            
navPrevprefix 'nav--prev',
            
navNextprefix 'nav--next',
            
navDisabledprefix 'nav--disabled',

            
monthprefix 'month',
            
yearprefix 'year',

            
selectMonthprefix 'select--month',
            
selectYearprefix 'select--year',

            
weekdaysprefix 'weekday',

            
dayprefix 'day',
            
disabledprefix 'day--disabled',
            
selectedprefix 'day--selected',
            
highlightedprefix 'day--highlighted',
            
nowprefix 'day--today',
            
infocusprefix 'day--infocus',
            
outfocusprefix 'day--outfocus',

            
footerprefix 'footer',

            
buttonClearprefix 'button--clear',
            
buttonTodayprefix 'button--today',
            
buttonCloseprefix 'button--close'
        
}
    }
})( 
Picker.klasses().picker '__' )





/**
 * Extend the picker to add the date picker.
 */
Picker.extend'pickadate'DatePicker )


}));
?>
Онлайн: 2
Реклама