public/libraries.js
function prepareElementRoot() {

        P.$root.

            on({

                // For iOS8.
                keydown: handleKeydownEvent,

                // When something within the root 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 root holder is clicked, stop it
                // from bubbling to the doc.
                'mousedown click': function( event ) {

                    var target = event.target

                    // Make sure the target isn’t the root holder so it can bubble up.
                    if ( target != P.$root.children()[ 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 root so that users can click away
                            // from elements focused within the picker.
                            P.$root[0].focus()
                        }
                    }
                }
            }).

            // Add/remove the “target” class on focus and blur.
            on({
                focus: function() {
                    $ELEMENT.addClass( CLASSES.target )
                },
                blur: function() {
                    $ELEMENT.removeClass( CLASSES.target )
                }
            }).

            // Open the picker and adjust the root “focused” state
            on( 'focus.toOpen', handleFocusToOpenEvent ).

            // 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 )

                // If it’s disabled or nothing inside is actively focused, re-focus the element.
                if ( targetDisabled || activeElement && !$.contains( P.$root[0], activeElement ) ) {
                    P.$root[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 a “clear” button is pressed, empty the values and close with focus.
                else if ( targetData.clear ) {
                    P.clear().close( true )
                }

                else if ( targetData.close ) {
                    P.close( true )
                }

            }) //P.$root

        aria( P.$root[0], 'hidden', true )
    }
function prepareElementRoot() {

        P.$root.

            on({

                // For iOS8.
                keydown: handleKeydownEvent,

                // When something within the root 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 root holder is clicked, stop it
                // from bubbling to the doc.
                'mousedown click': function( event ) {

                    var target = event.target

                    // Make sure the target isn’t the root holder so it can bubble up.
                    if ( target != P.$root.children()[ 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 root so that users can click away
                            // from elements focused within the picker.
                            P.$root[0].focus()
                        }
                    }
                }
            }).

            // Add/remove the “target” class on focus and blur.
            on({
                focus: function() {
                    $ELEMENT.addClass( CLASSES.target )
                },
                blur: function() {
                    $ELEMENT.removeClass( CLASSES.target )
                }
            }).

            // Open the picker and adjust the root “focused” state
            on( 'focus.toOpen', handleFocusToOpenEvent ).

            // 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 )

                // If it’s disabled or nothing inside is actively focused, re-focus the element.
                if ( targetDisabled || activeElement && !$.contains( P.$root[0], activeElement ) ) {
                    P.$root[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 a “clear” button is pressed, empty the values and close with focus.
                else if ( targetData.clear ) {
                    P.clear().close( true )
                }

                else if ( targetData.close ) {
                    P.close( true )
                }

            }) //P.$root

        aria( P.$root[0], 'hidden', true )
    }
function prepareElementRoot ( ) { P . $root . on ( { // For iOS8. keydown : handleKeydownEvent , // When something within the root 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 root holder is clicked, stop it // from bubbling to the doc. 'mousedown click' : function ( event ) { var target = event . target // Make sure the target isn’t the root holder so it can bubble up. if ( target != P . $root . children ( ) [ 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 root so that users can click away // from elements focused within the picker. P . $root [ 0 ] . focus ( ) } } } } ) . // Add/remove the “target” class on focus and blur. on ( { focus : function ( ) { $ELEMENT . addClass ( CLASSES . target ) } , blur : function ( ) { $ELEMENT . removeClass ( CLASSES . target ) } } ) . // Open the picker and adjust the root “focused” state on ( 'focus.toOpen' , handleFocusToOpenEvent ) . // 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 ) // If it’s disabled or nothing inside is actively focused, re-focus the element. if ( targetDisabled || activeElement && ! $ . contains ( P . $root [ 0 ] , activeElement ) ) { P . $root [ 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 a “clear” button is pressed, empty the values and close with focus. else if ( targetData . clear ) { P . clear ( ) . close ( true ) } else if ( targetData . close ) { P . close ( true ) } } ) //P.$root aria ( P . $root [ 0 ] , 'hidden' , true ) }
Prepare the root picker element with all bindings.
Prepare the root picker element with all bindings .