| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207 |
- /*!
- * pickadate.js v3.6.2, 2019/03/19
- * By Amsul, http://amsul.ca
- * Hosted on http://amsul.github.io/pickadate.js
- * Licensed under MIT
- */
-
- (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('jquery') )
-
- // Browser globals.
- else this.Picker = factory( jQuery )
-
- }(function( $ ) {
-
- var $window = $( window )
- var $document = $( document )
- var $html = $( document.documentElement )
- var supportsTransitions = document.documentElement.style.transition != null
-
-
- /**
- * The picker constructor that creates a blank picker.
- */
- function PickerConstructor( ELEMENT, NAME, COMPONENT, OPTIONS ) {
-
- // If there’s no element, return the picker constructor.
- if ( !ELEMENT ) return PickerConstructor
-
-
- var
- IS_DEFAULT_THEME = false,
-
-
- // The state of the picker.
- STATE = {
- id: ELEMENT.id || 'P' + Math.abs( ~~(Math.random() * new Date()) )
- },
-
-
- // Merge the defaults and options passed.
- SETTINGS = COMPONENT ? $.extend( true, {}, COMPONENT.defaults, OPTIONS ) : OPTIONS || {},
-
-
- // Merge the default classes with the settings classes.
- CLASSES = $.extend( {}, PickerConstructor.klasses(), SETTINGS.klass ),
-
-
- // The element node wrapper into a jQuery object.
- $ELEMENT = $( ELEMENT ),
-
-
- // Pseudo picker constructor.
- PickerInstance = function() {
- return this.start()
- },
-
-
- // The picker prototype.
- P = PickerInstance.prototype = {
-
- constructor: PickerInstance,
-
- $node: $ELEMENT,
-
-
- /**
- * Initialize everything
- */
- start: function() {
-
- // If it’s already started, do nothing.
- if ( STATE && STATE.start ) return P
-
-
- // Update the picker states.
- STATE.methods = {}
- STATE.start = true
- STATE.open = false
- STATE.type = ELEMENT.type
-
-
- // Confirm focus state, convert into text input to remove UA stylings,
- // and set as readonly to prevent keyboard popup.
- ELEMENT.autofocus = ELEMENT == getActiveElement()
- ELEMENT.readOnly = !SETTINGS.editable
- ELEMENT.id = ELEMENT.id || STATE.id
- if ( ELEMENT.type != 'text' ) {
- ELEMENT.type = 'text'
- }
-
-
- // Create a new picker component with the settings.
- P.component = new COMPONENT(P, SETTINGS)
-
-
- // Create the picker root and then prepare it.
- P.$root = $( '<div class="' + CLASSES.picker + '" id="' + ELEMENT.id + '_root" />' )
- prepareElementRoot()
-
-
- // Create the picker holder and then prepare it.
- P.$holder = $( createWrappedComponent() ).appendTo( P.$root )
- prepareElementHolder()
-
-
- // If there’s a format for the hidden input element, create the element.
- if ( SETTINGS.formatSubmit ) {
- prepareElementHidden()
- }
-
-
- // Prepare the input element.
- prepareElement()
-
-
- // Insert the hidden input as specified in the settings.
- if ( SETTINGS.containerHidden ) $( SETTINGS.containerHidden ).append( P._hidden )
- else $ELEMENT.after( P._hidden )
-
-
- // Insert the root as specified in the settings.
- if ( SETTINGS.container ) $( SETTINGS.container ).append( P.$root )
- else $ELEMENT.after( P.$root )
-
-
- // Bind the default component and settings events.
- P.on({
- start: P.component.onStart,
- render: P.component.onRender,
- stop: P.component.onStop,
- open: P.component.onOpen,
- close: P.component.onClose,
- set: P.component.onSet
- }).on({
- start: SETTINGS.onStart,
- render: SETTINGS.onRender,
- stop: SETTINGS.onStop,
- open: SETTINGS.onOpen,
- close: SETTINGS.onClose,
- set: SETTINGS.onSet
- })
-
-
- // Once we’re all set, check the theme in use.
- IS_DEFAULT_THEME = isUsingDefaultTheme( P.$holder[0] )
-
-
- // If the element has autofocus, open the picker.
- if ( ELEMENT.autofocus ) {
- P.open()
- }
-
-
- // Trigger queued the “start” and “render” events.
- return P.trigger( 'start' ).trigger( 'render' )
- }, //start
-
-
- /**
- * Render a new picker
- */
- render: function( entireComponent ) {
-
- // Insert a new component holder in the root or box.
- if ( entireComponent ) {
- P.$holder = $( createWrappedComponent() )
- prepareElementHolder()
- P.$root.html( P.$holder )
- }
- else P.$root.find( '.' + CLASSES.box ).html( P.component.nodes( STATE.open ) )
-
- // Trigger the queued “render” events.
- return P.trigger( 'render' )
- }, //render
-
-
- /**
- * Destroy everything
- */
- stop: function() {
-
- // If it’s already stopped, do nothing.
- if ( !STATE.start ) return P
-
- // Then close the picker.
- P.close()
-
- // Remove the hidden field.
- if ( P._hidden ) {
- P._hidden.parentNode.removeChild( P._hidden )
- }
-
- // Remove the root.
- P.$root.remove()
-
- // Remove the input class, remove the stored data, and unbind
- // the events (after a tick for IE - see `P.close`).
- $ELEMENT.removeClass( CLASSES.input ).removeData( NAME )
- setTimeout( function() {
- $ELEMENT.off( '.' + STATE.id )
- }, 0)
-
- // Restore the element state
- ELEMENT.type = STATE.type
- ELEMENT.readOnly = false
-
- // Trigger the queued “stop” events.
- P.trigger( 'stop' )
-
- // Reset the picker states.
- STATE.methods = {}
- STATE.start = false
-
- return P
- }, //stop
-
-
- /**
- * Open up the picker
- */
- open: function( dontGiveFocus ) {
-
- // If it’s already open, do nothing.
- if ( STATE.open ) return P
-
- // Add the “active” class.
- $ELEMENT.addClass( CLASSES.active )
- aria( ELEMENT, 'expanded', true )
-
- // * A Firefox bug, when `html` has `overflow:hidden`, results in
- // killing transitions :(. So add the “opened” state on the next tick.
- // Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=625289
- setTimeout( function() {
-
- // Add the “opened” class to the picker root.
- P.$root.addClass( CLASSES.opened )
- aria( P.$root[0], 'hidden', false )
-
- }, 0 )
-
- // If we have to give focus, bind the element and doc events.
- if ( dontGiveFocus !== false ) {
-
- // Set it as open.
- STATE.open = true
-
- // Prevent the page from scrolling.
- if ( IS_DEFAULT_THEME ) {
- $('body').
- css( 'overflow', 'hidden' ).
- css( 'padding-right', '+=' + getScrollbarWidth() )
- }
-
- // Pass focus to the root element’s jQuery object.
- focusPickerOnceOpened()
-
- // Bind the document events.
- $document.on( 'click.' + STATE.id + ' focusin.' + STATE.id, function( event ) {
-
- var target = getRealEventTarget( event, ELEMENT )
-
- // If the target of the event is not the element, close the picker picker.
- // * Don’t worry about clicks or focusins on the root because those don’t bubble up.
- // Also, for Firefox, a click on an `option` element bubbles up directly
- // to the doc. So make sure the target wasn't the doc.
- // * In Firefox stopPropagation() doesn’t prevent right-click events from bubbling,
- // which causes the picker to unexpectedly close when right-clicking it. So make
- // sure the event wasn’t a right-click.
- // * In Chrome 62 and up, password autofill causes a simulated focusin event which
- // closes the picker.
- if ( ! event.isSimulated && target != ELEMENT && target != document && event.which != 3 ) {
-
- // If the target was the holder that covers the screen,
- // keep the element focused to maintain tabindex.
- P.close( target === P.$holder[0] )
- }
-
- }).on( 'keydown.' + STATE.id, function( event ) {
-
- var
- // Get the keycode.
- keycode = event.keyCode,
-
- // Translate that to a selection change.
- keycodeToMove = P.component.key[ keycode ],
-
- // Grab the target.
- target = getRealEventTarget( event, ELEMENT )
-
-
- // On escape, close the picker and give focus.
- if ( keycode == 27 ) {
- P.close( true )
- }
-
-
- // Check if there is a key movement or “enter” keypress on the element.
- else if ( target == P.$holder[0] && ( keycodeToMove || keycode == 13 ) ) {
-
- // Prevent the default action to stop page movement.
- event.preventDefault()
-
- // Trigger the key movement action.
- if ( keycodeToMove ) {
- PickerConstructor._.trigger( P.component.key.go, P, [ PickerConstructor._.trigger( keycodeToMove ) ] )
- }
-
- // On “enter”, if the highlighted item isn’t disabled, set the value and close.
- else if ( !P.$root.find( '.' + CLASSES.highlighted ).hasClass( CLASSES.disabled ) ) {
- P.set( 'select', P.component.item.highlight )
- if ( SETTINGS.closeOnSelect ) {
- P.close( true )
- }
- }
- }
-
-
- // If the target is within the root and “enter” is pressed,
- // prevent the default action and trigger a click on the target instead.
- else if ( $.contains( P.$root[0], target ) && keycode == 13 ) {
- event.preventDefault()
- target.click()
- }
- })
- }
-
- // Trigger the queued “open” events.
- return P.trigger( 'open' )
- }, //open
-
-
- /**
- * Close the picker
- */
- close: function( giveFocus ) {
-
- // If we need to give focus, do it before changing states.
- if ( giveFocus ) {
- if ( SETTINGS.editable ) {
- ELEMENT.focus()
- }
- else {
- // ....ah yes! It would’ve been incomplete without a crazy workaround for IE :|
- // The focus is triggered *after* the close has completed - causing it
- // to open again. So unbind and rebind the event at the next tick.
- P.$holder.off( 'focus.toOpen' ).focus()
- setTimeout( function() {
- P.$holder.on( 'focus.toOpen', handleFocusToOpenEvent )
- }, 0 )
- }
- }
-
- // Remove the “active” class.
- $ELEMENT.removeClass( CLASSES.active )
- aria( ELEMENT, 'expanded', false )
-
- // * A Firefox bug, when `html` has `overflow:hidden`, results in
- // killing transitions :(. So remove the “opened” state on the next tick.
- // Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=625289
- setTimeout( function() {
-
- // Remove the “opened” and “focused” class from the picker root.
- P.$root.removeClass( CLASSES.opened + ' ' + CLASSES.focused )
- aria( P.$root[0], 'hidden', true )
-
- }, 0 )
-
- // If it’s already closed, do nothing more.
- if ( !STATE.open ) return P
-
- // Set it as closed.
- STATE.open = false
-
- // Allow the page to scroll.
- if ( IS_DEFAULT_THEME ) {
- $('body').
- css( 'overflow', '' ).
- css( 'padding-right', '-=' + getScrollbarWidth() )
- }
-
- // Unbind the document events.
- $document.off( '.' + STATE.id )
-
- // Trigger the queued “close” events.
- return P.trigger( 'close' )
- }, //close
-
-
- /**
- * Clear the values
- */
- clear: function( options ) {
- return P.set( 'clear', null, options )
- }, //clear
-
-
- /**
- * Set something
- */
- set: function( thing, value, options ) {
-
- var thingItem, thingValue,
- thingIsObject = $.isPlainObject( thing ),
- thingObject = thingIsObject ? thing : {}
-
- // Make sure we have usable options.
- options = thingIsObject && $.isPlainObject( value ) ? value : options || {}
-
- if ( thing ) {
-
- // If the thing isn’t an object, make it one.
- if ( !thingIsObject ) {
- thingObject[ thing ] = value
- }
-
- // Go through the things of items to set.
- for ( thingItem in thingObject ) {
-
- // Grab the value of the thing.
- thingValue = thingObject[ thingItem ]
-
- // First, if the item exists and there’s a value, set it.
- if ( thingItem in P.component.item ) {
- if ( thingValue === undefined ) thingValue = null
- P.component.set( thingItem, thingValue, options )
- }
-
- // Then, check to update the element value and broadcast a change.
- if ( ( thingItem == 'select' || thingItem == 'clear' ) && SETTINGS.updateInput ) {
- $ELEMENT.
- val( thingItem == 'clear' ? '' : P.get( thingItem, SETTINGS.format ) ).
- trigger( 'change' )
- }
- }
-
- // Render a new picker.
- P.render()
- }
-
- // When the method isn’t muted, trigger queued “set” events and pass the `thingObject`.
- return options.muted ? P : P.trigger( 'set', thingObject )
- }, //set
-
-
- /**
- * Get something
- */
- get: function( thing, format ) {
-
- // Make sure there’s something to get.
- thing = thing || 'value'
-
- // If a picker state exists, return that.
- if ( STATE[ thing ] != null ) {
- return STATE[ thing ]
- }
-
- // Return the submission value, if that.
- if ( thing == 'valueSubmit' ) {
- if ( P._hidden ) {
- return P._hidden.value
- }
- thing = 'value'
- }
-
- // Return the value, if that.
- if ( thing == 'value' ) {
- return ELEMENT.value
- }
-
- // Check if a component item exists, return that.
- if ( thing in P.component.item ) {
- if ( typeof format == 'string' ) {
- var thingValue = P.component.get( thing )
- return thingValue ?
- PickerConstructor._.trigger(
- P.component.formats.toString,
- P.component,
- [ format, thingValue ]
- ) : ''
- }
- return P.component.get( thing )
- }
- }, //get
-
-
-
- /**
- * Bind events on the things.
- */
- on: function( thing, method, internal ) {
-
- var thingName, thingMethod,
- thingIsObject = $.isPlainObject( thing ),
- thingObject = thingIsObject ? thing : {}
-
- if ( thing ) {
-
- // If the thing isn’t an object, make it one.
- if ( !thingIsObject ) {
- thingObject[ thing ] = method
- }
-
- // Go through the things to bind to.
- for ( thingName in thingObject ) {
-
- // Grab the method of the thing.
- thingMethod = thingObject[ thingName ]
-
- // If it was an internal binding, prefix it.
- if ( internal ) {
- thingName = '_' + thingName
- }
-
- // Make sure the thing methods collection exists.
- STATE.methods[ thingName ] = STATE.methods[ thingName ] || []
-
- // Add the method to the relative method collection.
- STATE.methods[ thingName ].push( thingMethod )
- }
- }
-
- return P
- }, //on
-
-
-
- /**
- * Unbind events on the things.
- */
- off: function() {
- var i, thingName,
- names = arguments;
- for ( i = 0, namesCount = names.length; i < namesCount; i += 1 ) {
- thingName = names[i]
- if ( thingName in STATE.methods ) {
- delete STATE.methods[thingName]
- }
- }
- return P
- },
-
-
- /**
- * Fire off method events.
- */
- trigger: function( name, data ) {
- var _trigger = function( name ) {
- var methodList = STATE.methods[ name ]
- if ( methodList ) {
- methodList.map( function( method ) {
- PickerConstructor._.trigger( method, P, [ data ] )
- })
- }
- }
- _trigger( '_' + name )
- _trigger( name )
- return P
- } //trigger
- } //PickerInstance.prototype
-
-
- /**
- * Wrap the picker holder components together.
- */
- function createWrappedComponent() {
-
- // Create a picker wrapper holder
- return PickerConstructor._.node( 'div',
-
- // Create a picker wrapper node
- PickerConstructor._.node( 'div',
-
- // Create a picker frame
- PickerConstructor._.node( 'div',
-
- // Create a picker box node
- PickerConstructor._.node( 'div',
-
- // Create the components nodes.
- P.component.nodes( STATE.open ),
-
- // The picker box class
- CLASSES.box
- ),
-
- // Picker wrap class
- CLASSES.wrap
- ),
-
- // Picker frame class
- CLASSES.frame
- ),
-
- // Picker holder class
- CLASSES.holder,
-
- 'tabindex="-1"'
- ) //endreturn
- } //createWrappedComponent
-
- /**
- * Prepare the input element with all bindings.
- */
- function prepareElement() {
-
- $ELEMENT.
-
- // Store the picker data by component name.
- data(NAME, P).
-
- // Add the “input” class name.
- addClass(CLASSES.input).
-
- // If there’s a `data-value`, update the value of the element.
- val( $ELEMENT.data('value') ?
- P.get('select', SETTINGS.format) :
- ELEMENT.value
- ).
-
- // On focus/click, open the picker.
- on( 'focus.' + STATE.id + ' click.' + STATE.id,
- debounce(function(event) {
- event.preventDefault()
- P.open()
- }, 100))
-
- // Only bind keydown events if the element isn’t editable.
- if ( !SETTINGS.editable ) {
-
- $ELEMENT.
-
- // Handle keyboard event based on the picker being opened or not.
- on( 'keydown.' + STATE.id, handleKeydownEvent )
- }
-
-
- // Update the aria attributes.
- aria(ELEMENT, {
- haspopup: true,
- expanded: false,
- readonly: false,
- owns: ELEMENT.id + '_root'
- })
- }
-
-
- /**
- * Prepare the root picker element with all bindings.
- */
- function prepareElementRoot() {
- aria( P.$root[0], 'hidden', true )
- }
-
-
- /**
- * Prepare the holder picker element with all bindings.
- */
- function prepareElementHolder() {
-
- P.$holder.
-
- on({
-
- // For iOS8.
- keydown: handleKeydownEvent,
-
- 'focus.toOpen': handleFocusToOpenEvent,
-
- blur: function() {
- // Remove the “target” class.
- $ELEMENT.removeClass( CLASSES.target )
- },
-
- // When something within the holder is focused, stop from bubbling
- // to the doc and remove the “focused” state from the root.
- focusin: function( event ) {
- P.$root.removeClass( CLASSES.focused )
- event.stopPropagation()
- },
-
- // When something within the holder is clicked, stop it
- // from bubbling to the doc.
- 'mousedown click': function( event ) {
-
- var target = getRealEventTarget( event, ELEMENT )
-
- // Make sure the target isn’t the root holder so it can bubble up.
- if ( target != P.$holder[0] ) {
-
- event.stopPropagation()
-
- // * For mousedown events, cancel the default action in order to
- // prevent cases where focus is shifted onto external elements
- // when using things like jQuery mobile or MagnificPopup (ref: #249 & #120).
- // Also, for Firefox, don’t prevent action on the `option` element.
- if ( event.type == 'mousedown' && !$( target ).is( 'input, select, textarea, button, option' )) {
-
- event.preventDefault()
-
- // Re-focus onto the holder so that users can click away
- // from elements focused within the picker.
- P.$holder.eq(0).focus()
- }
- }
- }
-
- }).
-
- // If there’s a click on an actionable element, carry out the actions.
- on( 'click', '[data-pick], [data-nav], [data-clear], [data-close]', function() {
-
- var $target = $( this ),
- targetData = $target.data(),
- targetDisabled = $target.hasClass( CLASSES.navDisabled ) || $target.hasClass( CLASSES.disabled ),
-
- // * For IE, non-focusable elements can be active elements as well
- // (http://stackoverflow.com/a/2684561).
- activeElement = getActiveElement()
- activeElement = activeElement && ( (activeElement.type || activeElement.href ) ? activeElement : null);
-
- // If it’s disabled or nothing inside is actively focused, re-focus the element.
- if ( targetDisabled || activeElement && !$.contains( P.$root[0], activeElement ) ) {
- P.$holder.eq(0).focus()
- }
-
- // If something is superficially changed, update the `highlight` based on the `nav`.
- if ( !targetDisabled && targetData.nav ) {
- P.set( 'highlight', P.component.item.highlight, { nav: targetData.nav } )
- }
-
- // If something is picked, set `select` then close with focus.
- else if ( !targetDisabled && 'pick' in targetData ) {
- P.set( 'select', targetData.pick )
- if ( SETTINGS.closeOnSelect ) {
- P.close( true )
- }
- }
-
- // If a “clear” button is pressed, empty the values and close with focus.
- else if ( targetData.clear ) {
- P.clear()
- if ( SETTINGS.closeOnClear ) {
- P.close( true )
- }
- }
-
- else if ( targetData.close ) {
- P.close( true )
- }
-
- }) //P.$holder
-
- }
-
-
- /**
- * Prepare the hidden input element along with all bindings.
- */
- function prepareElementHidden() {
-
- var name
-
- if ( SETTINGS.hiddenName === true ) {
- name = ELEMENT.name
- ELEMENT.name = ''
- }
- else {
- name = [
- typeof SETTINGS.hiddenPrefix == 'string' ? SETTINGS.hiddenPrefix : '',
- typeof SETTINGS.hiddenSuffix == 'string' ? SETTINGS.hiddenSuffix : '_submit'
- ]
- name = name[0] + ELEMENT.name + name[1]
- }
-
- P._hidden = $(
- '<input ' +
- 'type=hidden ' +
-
- // Create the name using the original input’s with a prefix and suffix.
- 'name="' + name + '"' +
-
- // If the element has a value, set the hidden value as well.
- (
- $ELEMENT.data('value') || ELEMENT.value ?
- ' value="' + P.get('select', SETTINGS.formatSubmit) + '"' :
- ''
- ) +
- '>'
- )[0]
-
- $ELEMENT.
-
- // If the value changes, update the hidden input with the correct format.
- on('change.' + STATE.id, function() {
- P._hidden.value = ELEMENT.value ?
- P.get('select', SETTINGS.formatSubmit) :
- ''
- })
- }
-
-
- // Wait for transitions to end before focusing the holder. Otherwise, while
- // using the `container` option, the view jumps to the container.
- function focusPickerOnceOpened() {
-
- if (IS_DEFAULT_THEME && supportsTransitions) {
- P.$holder.find('.' + CLASSES.frame).one('transitionend', function() {
- P.$holder.eq(0).focus()
- })
- }
- else {
- setTimeout(function() {
- P.$holder.eq(0).focus()
- }, 0)
- }
- }
-
-
- function handleFocusToOpenEvent(event) {
-
- // Stop the event from propagating to the doc.
- event.stopPropagation()
-
- // Add the “target” class.
- $ELEMENT.addClass( CLASSES.target )
-
- // Add the “focused” class to the root.
- P.$root.addClass( CLASSES.focused )
-
- // And then finally open the picker.
- P.open()
- }
-
-
- // For iOS8.
- function handleKeydownEvent( event ) {
-
- var keycode = event.keyCode,
-
- // Check if one of the delete keys was pressed.
- isKeycodeDelete = /^(8|46)$/.test(keycode)
-
- // For some reason IE clears the input value on “escape”.
- if ( keycode == 27 ) {
- P.close( true )
- return false
- }
-
- // Check if `space` or `delete` was pressed or the picker is closed with a key movement.
- if ( keycode == 32 || isKeycodeDelete || !STATE.open && P.component.key[keycode] ) {
-
- // Prevent it from moving the page and bubbling to doc.
- event.preventDefault()
- event.stopPropagation()
-
- // If `delete` was pressed, clear the values and close the picker.
- // Otherwise open the picker.
- if ( isKeycodeDelete ) { P.clear().close() }
- else { P.open() }
- }
- }
-
-
- // Return a new picker instance.
- return new PickerInstance()
- } //PickerConstructor
-
-
-
- /**
- * The default classes and prefix to use for the HTML classes.
- */
- PickerConstructor.klasses = function( prefix ) {
- prefix = prefix || 'picker'
- return {
-
- picker: prefix,
- opened: prefix + '--opened',
- focused: prefix + '--focused',
-
- input: prefix + '__input',
- active: prefix + '__input--active',
- target: prefix + '__input--target',
-
- holder: prefix + '__holder',
-
- frame: prefix + '__frame',
- wrap: prefix + '__wrap',
-
- box: prefix + '__box'
- }
- } //PickerConstructor.klasses
-
-
-
- /**
- * Check if the default theme is being used.
- */
- function isUsingDefaultTheme( element ) {
-
- var theme,
- prop = 'position'
-
- // For IE.
- if ( element.currentStyle ) {
- theme = element.currentStyle[prop]
- }
-
- // For normal browsers.
- else if ( window.getComputedStyle ) {
- theme = getComputedStyle( element )[prop]
- }
-
- return theme == 'fixed'
- }
-
-
-
- /**
- * Get the width of the browser’s scrollbar.
- * Taken from: https://github.com/VodkaBears/Remodal/blob/master/src/jquery.remodal.js
- */
- function getScrollbarWidth() {
-
- if ( $html.height() <= $window.height() ) {
- return 0
- }
-
- var $outer = $( '<div style="visibility:hidden;width:100px" />' ).
- appendTo( 'body' )
-
- // Get the width without scrollbars.
- var widthWithoutScroll = $outer[0].offsetWidth
-
- // Force adding scrollbars.
- $outer.css( 'overflow', 'scroll' )
-
- // Add the inner div.
- var $inner = $( '<div style="width:100%" />' ).appendTo( $outer )
-
- // Get the width with scrollbars.
- var widthWithScroll = $inner[0].offsetWidth
-
- // Remove the divs.
- $outer.remove()
-
- // Return the difference between the widths.
- return widthWithoutScroll - widthWithScroll
- }
-
-
-
- /**
- * Get the target element from the event.
- * If ELEMENT is supplied and present in the event path (ELEMENT is ancestor of the target),
- * returns ELEMENT instead
- */
- function getRealEventTarget( event, ELEMENT ) {
-
- var path = []
-
- if ( event.path ) {
- path = event.path
- }
-
- if ( event.originalEvent && event.originalEvent.path ) {
- path = event.originalEvent.path
- }
-
- if ( path && path.length > 0 ) {
- if ( ELEMENT && path.indexOf( ELEMENT ) >= 0 ) {
- return ELEMENT
- } else {
- return path[0]
- }
- }
-
- return event.target
- }
-
- // taken from https://davidwalsh.name/javascript-debounce-function
- function debounce(func, wait, immediate) {
- var timeout;
- return function() {
- var context = this, args = arguments;
- var later = function() {
- timeout = null;
- if (!immediate) func.apply(context, args);
- };
- var callNow = immediate && !timeout;
- clearTimeout(timeout);
- timeout = setTimeout(later, wait);
- if (callNow) func.apply(context, args);
- };
- }
-
- /**
- * PickerConstructor helper methods.
- */
- PickerConstructor._ = {
-
- /**
- * Create a group of nodes. Expects:
- * `
- {
- min: {Integer},
- max: {Integer},
- i: {Integer},
- node: {String},
- item: {Function}
- }
- * `
- */
- group: function( groupObject ) {
-
- var
- // Scope for the looped object
- loopObjectScope,
-
- // Create the nodes list
- nodesList = '',
-
- // The counter starts from the `min`
- counter = PickerConstructor._.trigger( groupObject.min, groupObject )
-
-
- // Loop from the `min` to `max`, incrementing by `i`
- for ( ; counter <= PickerConstructor._.trigger( groupObject.max, groupObject, [ counter ] ); counter += groupObject.i ) {
-
- // Trigger the `item` function within scope of the object
- loopObjectScope = PickerConstructor._.trigger( groupObject.item, groupObject, [ counter ] )
-
- // Splice the subgroup and create nodes out of the sub nodes
- nodesList += PickerConstructor._.node(
- groupObject.node,
- loopObjectScope[ 0 ], // the node
- loopObjectScope[ 1 ], // the classes
- loopObjectScope[ 2 ] // the attributes
- )
- }
-
- // Return the list of nodes
- return nodesList
- }, //group
-
-
- /**
- * Create a dom node string
- */
- node: function( wrapper, item, klass, attribute ) {
-
- // If the item is false-y, just return an empty string
- if ( !item ) return ''
-
- // If the item is an array, do a join
- item = $.isArray( item ) ? item.join( '' ) : item
-
- // Check for the class
- klass = klass ? ' class="' + klass + '"' : ''
-
- // Check for any attributes
- attribute = attribute ? ' ' + attribute : ''
-
- // Return the wrapped item
- return '<' + wrapper + klass + attribute + '>' + item + '</' + wrapper + '>'
- }, //node
-
-
- /**
- * Lead numbers below 10 with a zero.
- */
- lead: function( number ) {
- return ( number < 10 ? '0': '' ) + number
- },
-
-
- /**
- * Trigger a function otherwise return the value.
- */
- trigger: function( callback, scope, args ) {
- return typeof callback == 'function' ? callback.apply( scope, args || [] ) : callback
- },
-
-
- /**
- * If the second character is a digit, length is 2 otherwise 1.
- */
- digits: function( string ) {
- return ( /\d/ ).test( string[ 1 ] ) ? 2 : 1
- },
-
-
- /**
- * Tell if something is a date object.
- */
- isDate: function( value ) {
- return {}.toString.call( value ).indexOf( 'Date' ) > -1 && this.isInteger( value.getDate() )
- },
-
-
- /**
- * Tell if something is an integer.
- */
- isInteger: function( value ) {
- return {}.toString.call( value ).indexOf( 'Number' ) > -1 && value % 1 === 0
- },
-
-
- /**
- * Create ARIA attribute strings.
- */
- ariaAttr: ariaAttr
- } //PickerConstructor._
-
-
-
- /**
- * Extend the picker with a component and defaults.
- */
- PickerConstructor.extend = function( name, Component ) {
-
- // Extend jQuery.
- $.fn[ name ] = function( options, action ) {
-
- // Grab the component data.
- var componentData = this.data( name )
-
- // If the picker is requested, return the data object.
- if ( options == 'picker' ) {
- return componentData
- }
-
- // If the component data exists and `options` is a string, carry out the action.
- if ( componentData && typeof options == 'string' ) {
- return PickerConstructor._.trigger( componentData[ options ], componentData, [ action ] )
- }
-
- // Otherwise go through each matched element and if the component
- // doesn’t exist, create a new picker using `this` element
- // and merging the defaults and options with a deep copy.
- return this.each( function() {
- var $this = $( this )
- if ( !$this.data( name ) ) {
- new PickerConstructor( this, name, Component, options )
- }
- })
- }
-
- // Set the defaults.
- $.fn[ name ].defaults = Component.defaults
- } //PickerConstructor.extend
-
-
-
- function aria(element, attribute, value) {
- if ( $.isPlainObject(attribute) ) {
- for ( var key in attribute ) {
- ariaSet(element, key, attribute[key])
- }
- }
- else {
- ariaSet(element, attribute, value)
- }
- }
- function ariaSet(element, attribute, value) {
- element.setAttribute(
- (attribute == 'role' ? '' : 'aria-') + attribute,
- value
- )
- }
- function ariaAttr(attribute, data) {
- if ( !$.isPlainObject(attribute) ) {
- attribute = { attribute: data }
- }
- data = ''
- for ( var key in attribute ) {
- var attr = (key == 'role' ? '' : 'aria-') + key,
- attrVal = attribute[key]
- data += attrVal == null ? '' : attr + '="' + attribute[key] + '"'
- }
- return data
- }
-
- // IE8 bug throws an error for activeElements within iframes.
- function getActiveElement() {
- try {
- return document.activeElement
- } catch ( err ) { }
- }
-
-
-
- // Expose the picker constructor.
- return PickerConstructor
-
-
- }));
|