Вход Регистрация
Файл: plugins/google_map_location/static/js/jquery.ui.menu.js
Строк: 695
<?php
/*!
 * jQuery UI Menu 1.10.3
 * http://jqueryui.com
 *
 * Copyright 2013 jQuery Foundation and other contributors
 * Released under the MIT license.
 * http://jquery.org/license
 *
 * http://api.jqueryui.com/menu/
 *
 * Depends:
 *    jquery.ui.core.js
 *    jquery.ui.widget.js
 *    jquery.ui.position.js
 */
(function( $, undefined ) {

$.
widget"ui.menu", {
    
version"1.10.3",
    
defaultElement"<ul>",
    
delay300,
    
options: {
        
icons: {
            
submenu"ui-icon-carat-1-e"
        
},
        
menus"ul",
        
position: {
            
my"left top",
            
at"right top"
        
},
        
role"menu",

        
// callbacks
        
blurnull,
        
focusnull,
        
selectnull
    
},

    
_create: function() {
        
this.activeMenu this.element;
        
// flag used to prevent firing of the click handler
        // as the event bubbles up through nested menus
        
this.mouseHandled false;
        
this.element
            
.uniqueId()
            .
addClass"ui-menu ui-widget ui-widget-content ui-corner-all" )
            .
toggleClass"ui-menu-icons", !!this.element.find".ui-icon" ).length )
            .
attr({
                
rolethis.options.role,
                
tabIndex0
            
})
            
// need to catch all clicks on disabled menu
            // not possible through _on
            
.bind"click" this.eventNamespace, $.proxy(function( event ) {
                if ( 
this.options.disabled ) {
                    
event.preventDefault();
                }
            }, 
this ));

        if ( 
this.options.disabled ) {
            
this.element
                
.addClass"ui-state-disabled" )
                .
attr"aria-disabled""true" );
        }

        
this._on({
            
// Prevent focus from sticking to links inside menu after clicking
            // them (focus should always stay on UL during navigation).
            
"mousedown .ui-menu-item > a": function( event ) {
                
event.preventDefault();
            },
            
"click .ui-state-disabled > a": function( event ) {
                
event.preventDefault();
            },
            
"click .ui-menu-item:has(a)": function( event ) {
                var 
target = $( event.target ).closest".ui-menu-item" );
                if ( !
this.mouseHandled && target.not".ui-state-disabled" ).length ) {
                    
this.mouseHandled true;

                    
this.selectevent );
                    
// Open submenu on click
                    
if ( target.has".ui-menu" ).length ) {
                        
this.expandevent );
                    } else if ( !
this.element.is":focus" ) ) {
                        
// Redirect focus to the menu
                        
this.element.trigger"focus", [ true ] );

                        
// If the active item is on the top level, let it stay active.
                        // Otherwise, blur the active item since it is no longer visible.
                        
if ( this.active && this.active.parents".ui-menu" ).length === ) {
                            
clearTimeoutthis.timer );
                        }
                    }
                }
            },
            
"mouseenter .ui-menu-item": function( event ) {
                var 
target = $( event.currentTarget );
                
// Remove ui-state-active class from siblings of the newly focused menu item
                // to avoid a jump caused by adjacent elements both having a class with a border
                
target.siblings().children".ui-state-active" ).removeClass"ui-state-active" );
                
this.focuseventtarget );
            },
            
mouseleave"collapseAll",
            
"mouseleave .ui-menu""collapseAll",
            
focus: function( eventkeepActiveItem ) {
                
// If there's already an active item, keep it active
                // If not, activate the first item
                
var item this.active || this.element.children".ui-menu-item" ).eq);

                if ( !
keepActiveItem ) {
                    
this.focuseventitem );
                }
            },
            
blur: function( event ) {
                
this._delay(function() {
                    if ( !$.
containsthis.element[0], this.document[0].activeElement ) ) {
                        
this.collapseAllevent );
                    }
                });
            },
            
keydown"_keydown"
        
});

        
this.refresh();

        
// Clicks outside of a menu collapse any open menus
        
this._onthis.document, {
            
click: function( event ) {
                if ( !$( 
event.target ).closest".ui-menu" ).length ) {
                    
this.collapseAllevent );
                }

                
// Reset the mouseHandled flag
                
this.mouseHandled false;
            }
        });
    },

    
_destroy: function() {
        
// Destroy (sub)menus
        
this.element
            
.removeAttr"aria-activedescendant" )
            .
find".ui-menu" ).addBack()
                .
removeClass"ui-menu ui-widget ui-widget-content ui-corner-all ui-menu-icons" )
                .
removeAttr"role" )
                .
removeAttr"tabIndex" )
                .
removeAttr"aria-labelledby" )
                .
removeAttr"aria-expanded" )
                .
removeAttr"aria-hidden" )
                .
removeAttr"aria-disabled" )
                .
removeUniqueId()
                .
show();

        
// Destroy menu items
        
this.element.find".ui-menu-item" )
            .
removeClass"ui-menu-item" )
            .
removeAttr"role" )
            .
removeAttr"aria-disabled" )
            .
children"a" )
                .
removeUniqueId()
                .
removeClass"ui-corner-all ui-state-hover" )
                .
removeAttr"tabIndex" )
                .
removeAttr"role" )
                .
removeAttr"aria-haspopup" )
                .
children().each( function() {
                    var 
elem = $( this );
                    if ( 
elem.data"ui-menu-submenu-carat" ) ) {
                        
elem.remove();
                    }
                });

        
// Destroy menu dividers
        
this.element.find".ui-menu-divider" ).removeClass"ui-menu-divider ui-widget-content" );
    },

    
_keydown: function( event ) {
        
/*jshint maxcomplexity:20*/
        
var matchprevcharacterskipregex,
            
preventDefault true;

        function 
escapevalue ) {
            return 
value.replace( /[-[]{}()*+?.,\^$|#s]/g, "\$&" );
        
}

        switch ( 
event.keyCode ) {
        case $.
ui.keyCode.PAGE_UP:
            
this.previousPageevent );
            break;
        case $.
ui.keyCode.PAGE_DOWN:
            
this.nextPageevent );
            break;
        case $.
ui.keyCode.HOME:
            
this._move"first""first"event );
            break;
        case $.
ui.keyCode.END:
            
this._move"last""last"event );
            break;
        case $.
ui.keyCode.UP:
            
this.previousevent );
            break;
        case $.
ui.keyCode.DOWN:
            
this.nextevent );
            break;
        case $.
ui.keyCode.LEFT:
            
this.collapseevent );
            break;
        case $.
ui.keyCode.RIGHT:
            if ( 
this.active && !this.active.is".ui-state-disabled" ) ) {
                
this.expandevent );
            }
            break;
        case $.
ui.keyCode.ENTER:
        case $.
ui.keyCode.SPACE:
            
this._activateevent );
            break;
        case $.
ui.keyCode.ESCAPE:
            
this.collapseevent );
            break;
        default:
            
preventDefault false;
            
prev this.previousFilter || "";
            
character String.fromCharCodeevent.keyCode );
            
skip false;

            
clearTimeoutthis.filterTimer );

            if ( 
character === prev ) {
                
skip true;
            } else {
                
character prev character;
            }

            
regex = new RegExp"^" escapecharacter ), "i" );
            
match this.activeMenu.children".ui-menu-item" ).filter(function() {
                return 
regex.test( $( this ).children"a" ).text() );
            });
            
match skip && match.indexthis.active.next() ) !== -?
                
this.active.nextAll".ui-menu-item" ) :
                
match;

            
// If no matches on the current filter, reset to the last character pressed
            // to move down the menu to the first item that starts with that character
            
if ( !match.length ) {
                
character String.fromCharCodeevent.keyCode );
                
regex = new RegExp"^" escapecharacter ), "i" );
                
match this.activeMenu.children".ui-menu-item" ).filter(function() {
                    return 
regex.test( $( this ).children"a" ).text() );
                });
            }

            if ( 
match.length ) {
                
this.focuseventmatch );
                if ( 
match.length ) {
                    
this.previousFilter character;
                    
this.filterTimer this._delay(function() {
                        
delete this.previousFilter;
                    }, 
1000 );
                } else {
                    
delete this.previousFilter;
                }
            } else {
                
delete this.previousFilter;
            }
        }

        if ( 
preventDefault ) {
            
event.preventDefault();
        }
    },

    
_activate: function( event ) {
        if ( !
this.active.is".ui-state-disabled" ) ) {
            if ( 
this.active.children"a[aria-haspopup='true']" ).length ) {
                
this.expandevent );
            } else {
                
this.selectevent );
            }
        }
    },

    
refresh: function() {
        var 
menus,
            
icon this.options.icons.submenu,
            
submenus this.element.findthis.options.menus );

        
// Initialize nested menus
        
submenus.filter":not(.ui-menu)" )
            .
addClass"ui-menu ui-widget ui-widget-content ui-corner-all" )
            .
hide()
            .
attr({
                
rolethis.options.role,
                
"aria-hidden""true",
                
"aria-expanded""false"
            
})
            .
each(function() {
                var 
menu = $( this ),
                    
item menu.prev"a" ),
                    
submenuCarat = $( "<span>" )
                        .
addClass"ui-menu-icon ui-icon " icon )
                        .
data"ui-menu-submenu-carat"true );

                
item
                    
.attr"aria-haspopup""true" )
                    .
prependsubmenuCarat );
                
menu.attr"aria-labelledby"item.attr"id" ) );
            });

        
menus submenus.addthis.element );

        
// Don't refresh list items that are already adapted
        
menus.children":not(.ui-menu-item):has(a)" )
            .
addClass"ui-menu-item" )
            .
attr"role""presentation" )
            .
children"a" )
                .
uniqueId()
                .
addClass"ui-corner-all" )
                .
attr({
                    
tabIndex: -1,
                    
rolethis._itemRole()
                });

        
// Initialize unlinked menu-items containing spaces and/or dashes only as dividers
        
menus.children":not(.ui-menu-item)" ).each(function() {
            var 
item = $( this );
            
// hyphen, em dash, en dash
            
if ( !/[^-u2014u2013s]/.testitem.text() ) ) {
                
item.addClass"ui-widget-content ui-menu-divider" );
            }
        });

        
// Add aria-disabled attribute to any disabled menu item
        
menus.children".ui-state-disabled" ).attr"aria-disabled""true" );

        
// If the active item has been removed, blur the menu
        
if ( this.active && !$.containsthis.element], this.active] ) ) {
            
this.blur();
        }
    },

    
_itemRole: function() {
        return {
            
menu"menuitem",
            
listbox"option"
        
}[ this.options.role ];
    },

    
_setOption: function( keyvalue ) {
        if ( 
key === "icons" ) {
            
this.element.find".ui-menu-icon" )
                .
removeClassthis.options.icons.submenu )
                .
addClassvalue.submenu );
        }
        
this._superkeyvalue );
    },

    
focus: function( eventitem ) {
        var 
nestedfocused;
        
this.blureventevent && event.type === "focus" );

        
this._scrollIntoViewitem );

        
this.active item.first();
        
focused this.active.children"a" ).addClass"ui-state-focus" );
        
// Only update aria-activedescendant if there's a role
        // otherwise we assume focus is managed elsewhere
        
if ( this.options.role ) {
            
this.element.attr"aria-activedescendant"focused.attr"id" ) );
        }

        
// Highlight active parent menu item, if any
        
this.active
            
.parent()
            .
closest".ui-menu-item" )
            .
children"a:first" )
            .
addClass"ui-state-active" );

        if ( 
event && event.type === "keydown" ) {
            
this._close();
        } else {
            
this.timer this._delay(function() {
                
this._close();
            }, 
this.delay );
        }

        
nested item.children".ui-menu" );
        if ( 
nested.length && ( /^mouse/.testevent.type ) ) ) {
            
this._startOpening(nested);
        }
        
this.activeMenu item.parent();

        
this._trigger"focus"event, { itemitem } );
    },

    
_scrollIntoView: function( item ) {
        var 
borderToppaddingTopoffsetscrollelementHeightitemHeight;
        if ( 
this._hasScroll() ) {
            
borderTop parseFloat( $.cssthis.activeMenu[0], "borderTopWidth" ) ) || 0;
            
paddingTop parseFloat( $.cssthis.activeMenu[0], "paddingTop" ) ) || 0;
            
offset item.offset().top this.activeMenu.offset().top borderTop paddingTop;
            
scroll this.activeMenu.scrollTop();
            
elementHeight this.activeMenu.height();
            
itemHeight item.height();

            if ( 
offset ) {
                
this.activeMenu.scrollTopscroll offset );
            } else if ( 
offset itemHeight elementHeight ) {
                
this.activeMenu.scrollTopscroll offset elementHeight itemHeight );
            }
        }
    },

    
blur: function( eventfromFocus ) {
        if ( !
fromFocus ) {
            
clearTimeoutthis.timer );
        }

        if ( !
this.active ) {
            return;
        }

        
this.active.children"a" ).removeClass"ui-state-focus" );
        
this.active null;

        
this._trigger"blur"event, { itemthis.active } );
    },

    
_startOpening: function( submenu ) {
        
clearTimeoutthis.timer );

        
// Don't open if already open fixes a Firefox bug that caused a .5 pixel
        // shift in the submenu position when mousing over the carat icon
        
if ( submenu.attr"aria-hidden" ) !== "true" ) {
            return;
        }

        
this.timer this._delay(function() {
            
this._close();
            
this._opensubmenu );
        }, 
this.delay );
    },

    
_open: function( submenu ) {
        var 
position = $.extend({
            
ofthis.active
        
}, this.options.position );

        
clearTimeoutthis.timer );
        
this.element.find".ui-menu" ).notsubmenu.parents".ui-menu" ) )
            .
hide()
            .
attr"aria-hidden""true" );

        
submenu
            
.show()
            .
removeAttr"aria-hidden" )
            .
attr"aria-expanded""true" )
            .
positionposition );
    },

    
collapseAll: function( eventall ) {
        
clearTimeoutthis.timer );
        
this.timer this._delay(function() {
            
// If we were passed an event, look for the submenu that contains the event
            
var currentMenu all this.element :
                $( 
event && event.target ).closestthis.element.find".ui-menu" ) );

            
// If we found no valid submenu ancestor, use the main menu to close all sub menus anyway
            
if ( !currentMenu.length ) {
                
currentMenu this.element;
            }

            
this._closecurrentMenu );

            
this.blurevent );
            
this.activeMenu currentMenu;
        }, 
this.delay );
    },

    
// With no arguments, closes the currently active menu - if nothing is active
    // it closes all menus.  If passed an argument, it will search for menus BELOW
    
_close: function( startMenu ) {
        if ( !
startMenu ) {
            
startMenu this.active this.active.parent() : this.element;
        }

        
startMenu
            
.find".ui-menu" )
                .
hide()
                .
attr"aria-hidden""true" )
                .
attr"aria-expanded""false" )
            .
end()
            .
find"a.ui-state-active" )
                .
removeClass"ui-state-active" );
    },

    
collapse: function( event ) {
        var 
newItem this.active &&
            
this.active.parent().closest".ui-menu-item"this.element );
        if ( 
newItem && newItem.length ) {
            
this._close();
            
this.focuseventnewItem );
        }
    },

    
expand: function( event ) {
        var 
newItem this.active &&
            
this.active
                
.children".ui-menu " )
                .
children".ui-menu-item" )
                .
first();

        if ( 
newItem && newItem.length ) {
            
this._opennewItem.parent() );

            
// Delay so Firefox will not hide activedescendant change in expanding submenu from AT
            
this._delay(function() {
                
this.focuseventnewItem );
            });
        }
    },

    
next: function( event ) {
        
this._move"next""first"event );
    },

    
previous: function( event ) {
        
this._move"prev""last"event );
    },

    
isFirstItem: function() {
        return 
this.active && !this.active.prevAll".ui-menu-item" ).length;
    },

    
isLastItem: function() {
        return 
this.active && !this.active.nextAll".ui-menu-item" ).length;
    },

    
_move: function( directionfilterevent ) {
        var 
next;
        if ( 
this.active ) {
            if ( 
direction === "first" || direction === "last" ) {
                
next this.active
                    
direction === "first" "prevAll" "nextAll" ]( ".ui-menu-item" )
                    .
eq( -);
            } else {
                
next this.active
                    
direction "All" ]( ".ui-menu-item" )
                    .
eq);
            }
        }
        if ( !
next || !next.length || !this.active ) {
            
next this.activeMenu.children".ui-menu-item" )[ filter ]();
        }

        
this.focuseventnext );
    },

    
nextPage: function( event ) {
        var 
itembaseheight;

        if ( !
this.active ) {
            
this.nextevent );
            return;
        }
        if ( 
this.isLastItem() ) {
            return;
        }
        if ( 
this._hasScroll() ) {
            
base this.active.offset().top;
            
height this.element.height();
            
this.active.nextAll".ui-menu-item" ).each(function() {
                
item = $( this );
                return 
item.offset().top base height 0;
            });

            
this.focuseventitem );
        } else {
            
this.focuseventthis.activeMenu.children".ui-menu-item" )
                [ !
this.active "first" "last" ]() );
        }
    },

    
previousPage: function( event ) {
        var 
itembaseheight;
        if ( !
this.active ) {
            
this.nextevent );
            return;
        }
        if ( 
this.isFirstItem() ) {
            return;
        }
        if ( 
this._hasScroll() ) {
            
base this.active.offset().top;
            
height this.element.height();
            
this.active.prevAll".ui-menu-item" ).each(function() {
                
item = $( this );
                return 
item.offset().top base height 0;
            });

            
this.focuseventitem );
        } else {
            
this.focuseventthis.activeMenu.children".ui-menu-item" ).first() );
        }
    },

    
_hasScroll: function() {
        return 
this.element.outerHeight() < this.element.prop"scrollHeight" );
    },

    
select: function( event ) {
        
// TODO: It should never be possible to not have an active item at this
        // point, but the tests don't trigger mouseenter before click.
        
this.active this.active || $( event.target ).closest".ui-menu-item" );
        var 
ui = { itemthis.active };
        if ( !
this.active.has".ui-menu" ).length ) {
            
this.collapseAlleventtrue );
        }
        
this._trigger"select"eventui );
    }
});

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