2012-02-27 00:49:51 +00:00
|
|
|
/*!
|
2010-04-21 19:01:08 +00:00
|
|
|
* jQuery UI Menu @VERSION
|
2012-07-04 13:08:08 +00:00
|
|
|
* http://jqueryui.com
|
2011-06-10 10:20:45 +00:00
|
|
|
*
|
2014-12-21 18:27:43 +00:00
|
|
|
* Copyright jQuery Foundation and other contributors
|
2012-08-09 14:13:24 +00:00
|
|
|
* Released under the MIT license.
|
2010-07-09 13:31:53 +00:00
|
|
|
* http://jquery.org/license
|
2010-04-21 19:01:08 +00:00
|
|
|
*/
|
2014-10-30 19:55:08 +00:00
|
|
|
|
|
|
|
//>>label: Menu
|
|
|
|
//>>group: Widgets
|
|
|
|
//>>description: Creates nestable menus.
|
|
|
|
//>>docs: http://api.jqueryui.com/menu/
|
|
|
|
//>>demos: http://jqueryui.com/menu/
|
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
(function( factory ) {
|
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
|
|
|
|
// AMD. Register as an anonymous module.
|
|
|
|
define([
|
|
|
|
"jquery",
|
2013-12-02 18:36:12 +00:00
|
|
|
"./core",
|
|
|
|
"./widget",
|
|
|
|
"./position"
|
2013-07-12 16:40:48 +00:00
|
|
|
], factory );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Browser globals
|
|
|
|
factory( jQuery );
|
|
|
|
}
|
|
|
|
}(function( $ ) {
|
2011-06-10 10:20:45 +00:00
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
return $.widget( "ui.menu", {
|
2011-05-28 19:39:55 +00:00
|
|
|
version: "@VERSION",
|
2011-01-23 22:55:53 +00:00
|
|
|
defaultElement: "<ul>",
|
2011-12-20 17:49:48 +00:00
|
|
|
delay: 300,
|
2011-02-24 11:05:20 +00:00
|
|
|
options: {
|
2012-07-12 15:23:33 +00:00
|
|
|
icons: {
|
2014-11-03 17:08:06 +00:00
|
|
|
submenu: "ui-icon-caret-1-e"
|
2012-07-12 15:23:33 +00:00
|
|
|
},
|
2013-09-25 04:46:59 +00:00
|
|
|
items: "> *",
|
2011-12-01 18:39:16 +00:00
|
|
|
menus: "ul",
|
2011-02-24 11:05:20 +00:00
|
|
|
position: {
|
2014-10-25 16:18:17 +00:00
|
|
|
my: "left top",
|
2011-02-24 11:05:20 +00:00
|
|
|
at: "right top"
|
2012-02-27 04:52:38 +00:00
|
|
|
},
|
2012-05-15 12:07:35 +00:00
|
|
|
role: "menu",
|
2012-02-27 04:52:38 +00:00
|
|
|
|
|
|
|
// callbacks
|
|
|
|
blur: null,
|
|
|
|
focus: null,
|
|
|
|
select: null
|
2011-02-24 11:05:20 +00:00
|
|
|
},
|
2012-06-18 16:33:52 +00:00
|
|
|
|
2010-04-21 19:01:08 +00:00
|
|
|
_create: function() {
|
2011-02-24 14:51:51 +00:00
|
|
|
this.activeMenu = this.element;
|
2013-12-03 20:54:08 +00:00
|
|
|
|
|
|
|
// Flag used to prevent firing of the click handler
|
2012-12-30 02:08:05 +00:00
|
|
|
// as the event bubbles up through nested menus
|
2012-12-28 03:06:06 +00:00
|
|
|
this.mouseHandled = false;
|
2010-04-21 19:01:08 +00:00
|
|
|
this.element
|
2012-05-30 01:59:03 +00:00
|
|
|
.uniqueId()
|
2013-10-24 18:04:00 +00:00
|
|
|
.addClass( "ui-menu ui-widget ui-widget-content" )
|
2012-05-25 01:15:55 +00:00
|
|
|
.toggleClass( "ui-menu-icons", !!this.element.find( ".ui-icon" ).length )
|
2010-04-21 19:01:08 +00:00
|
|
|
.attr({
|
2012-05-15 12:07:35 +00:00
|
|
|
role: this.options.role,
|
2012-04-10 12:39:18 +00:00
|
|
|
tabIndex: 0
|
2013-12-03 20:54:08 +00:00
|
|
|
});
|
2012-04-10 12:39:18 +00:00
|
|
|
|
2012-01-22 17:24:49 +00:00
|
|
|
if ( this.options.disabled ) {
|
2012-04-16 12:02:28 +00:00
|
|
|
this.element
|
|
|
|
.addClass( "ui-state-disabled" )
|
|
|
|
.attr( "aria-disabled", "true" );
|
2012-01-22 17:24:49 +00:00
|
|
|
}
|
2012-04-10 12:39:18 +00:00
|
|
|
|
2012-06-13 12:00:45 +00:00
|
|
|
this._on({
|
2011-11-24 04:37:55 +00:00
|
|
|
// Prevent focus from sticking to links inside menu after clicking
|
|
|
|
// them (focus should always stay on UL during navigation).
|
2013-09-18 04:22:33 +00:00
|
|
|
"mousedown .ui-menu-item": function( event ) {
|
2011-11-24 04:37:55 +00:00
|
|
|
event.preventDefault();
|
|
|
|
},
|
2013-09-18 04:22:33 +00:00
|
|
|
"click .ui-menu-item": function( event ) {
|
|
|
|
var target = $( event.target );
|
2012-12-28 03:06:06 +00:00
|
|
|
if ( !this.mouseHandled && target.not( ".ui-state-disabled" ).length ) {
|
2012-07-13 03:45:56 +00:00
|
|
|
this.select( event );
|
2013-08-02 10:51:04 +00:00
|
|
|
|
|
|
|
// Only set the mouseHandled flag if the event will bubble, see #9469.
|
|
|
|
if ( !event.isPropagationStopped() ) {
|
|
|
|
this.mouseHandled = true;
|
|
|
|
}
|
|
|
|
|
2012-07-31 05:00:07 +00:00
|
|
|
// Open submenu on click
|
2012-09-05 20:07:36 +00:00
|
|
|
if ( target.has( ".ui-menu" ).length ) {
|
2012-07-31 05:00:07 +00:00
|
|
|
this.expand( event );
|
2013-08-26 05:06:44 +00:00
|
|
|
} else if ( !this.element.is( ":focus" ) && $( this.document[ 0 ].activeElement ).closest( ".ui-menu" ).length ) {
|
|
|
|
|
2012-07-31 05:00:07 +00:00
|
|
|
// Redirect focus to the menu
|
2012-09-05 20:07:36 +00:00
|
|
|
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 === 1 ) {
|
|
|
|
clearTimeout( this.timer );
|
|
|
|
}
|
2012-07-13 18:36:00 +00:00
|
|
|
}
|
2012-02-03 22:12:37 +00:00
|
|
|
}
|
2011-07-28 13:47:32 +00:00
|
|
|
},
|
2012-04-20 04:49:33 +00:00
|
|
|
"mouseenter .ui-menu-item": function( event ) {
|
2014-08-27 16:27:06 +00:00
|
|
|
// Ignore mouse events while typeahead is active, see #10458.
|
|
|
|
// Prevents focusing the wrong item when typeahead causes a scroll while the mouse
|
|
|
|
// is over an item in the menu
|
|
|
|
if ( this.previousFilter ) {
|
|
|
|
return;
|
|
|
|
}
|
2011-11-30 14:39:10 +00:00
|
|
|
var target = $( event.currentTarget );
|
2012-04-10 12:39:18 +00:00
|
|
|
// 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
|
2014-10-25 16:18:17 +00:00
|
|
|
target.siblings().children( ".ui-state-active" ).removeClass( "ui-state-active" );
|
|
|
|
|
2011-11-30 14:39:10 +00:00
|
|
|
this.focus( event, target );
|
2011-07-28 13:47:32 +00:00
|
|
|
},
|
2012-05-25 01:15:55 +00:00
|
|
|
mouseleave: "collapseAll",
|
2011-09-22 18:56:53 +00:00
|
|
|
"mouseleave .ui-menu": "collapseAll",
|
2012-09-05 20:07:36 +00:00
|
|
|
focus: function( event, keepActiveItem ) {
|
2012-06-18 16:33:52 +00:00
|
|
|
// If there's already an active item, keep it active
|
2012-07-10 04:20:43 +00:00
|
|
|
// If not, activate the first item
|
2013-09-25 04:46:59 +00:00
|
|
|
var item = this.active || this.element.find( this.options.items ).eq( 0 );
|
2012-07-10 04:20:43 +00:00
|
|
|
|
2012-09-05 20:07:36 +00:00
|
|
|
if ( !keepActiveItem ) {
|
|
|
|
this.focus( event, item );
|
|
|
|
}
|
2011-07-28 13:47:32 +00:00
|
|
|
},
|
2011-09-22 18:56:53 +00:00
|
|
|
blur: function( event ) {
|
2012-04-10 12:39:18 +00:00
|
|
|
this._delay(function() {
|
|
|
|
if ( !$.contains( this.element[0], this.document[0].activeElement ) ) {
|
2011-09-22 18:56:53 +00:00
|
|
|
this.collapseAll( event );
|
|
|
|
}
|
2012-04-10 12:39:18 +00:00
|
|
|
});
|
|
|
|
},
|
2012-05-25 01:15:55 +00:00
|
|
|
keydown: "_keydown"
|
2011-07-28 13:47:32 +00:00
|
|
|
});
|
|
|
|
|
2010-04-21 19:01:08 +00:00
|
|
|
this.refresh();
|
2011-06-10 10:20:45 +00:00
|
|
|
|
2012-06-18 16:33:52 +00:00
|
|
|
// Clicks outside of a menu collapse any open menus
|
2012-06-13 12:00:45 +00:00
|
|
|
this._on( this.document, {
|
2011-07-10 04:30:35 +00:00
|
|
|
click: function( event ) {
|
2013-08-01 01:20:13 +00:00
|
|
|
if ( this._closeOnDocumentClick( event ) ) {
|
2011-07-19 21:15:59 +00:00
|
|
|
this.collapseAll( event );
|
2011-07-10 04:30:35 +00:00
|
|
|
}
|
2012-07-13 03:45:56 +00:00
|
|
|
|
|
|
|
// Reset the mouseHandled flag
|
2012-12-28 03:06:06 +00:00
|
|
|
this.mouseHandled = false;
|
2011-07-10 04:30:35 +00:00
|
|
|
}
|
|
|
|
});
|
2010-04-21 19:01:08 +00:00
|
|
|
},
|
2011-06-10 10:20:45 +00:00
|
|
|
|
2011-01-14 22:11:22 +00:00
|
|
|
_destroy: function() {
|
2012-06-18 16:33:52 +00:00
|
|
|
// Destroy (sub)menus
|
2010-06-18 08:57:20 +00:00
|
|
|
this.element
|
2011-04-15 17:18:38 +00:00
|
|
|
.removeAttr( "aria-activedescendant" )
|
2012-12-14 16:13:46 +00:00
|
|
|
.find( ".ui-menu" ).addBack()
|
2013-12-03 11:50:25 +00:00
|
|
|
.removeClass( "ui-menu ui-widget ui-widget-content ui-menu-icons ui-front" )
|
2012-04-10 12:39:18 +00:00
|
|
|
.removeAttr( "role" )
|
|
|
|
.removeAttr( "tabIndex" )
|
|
|
|
.removeAttr( "aria-labelledby" )
|
|
|
|
.removeAttr( "aria-expanded" )
|
|
|
|
.removeAttr( "aria-hidden" )
|
2012-05-30 01:59:03 +00:00
|
|
|
.removeAttr( "aria-disabled" )
|
|
|
|
.removeUniqueId()
|
2012-12-04 14:21:16 +00:00
|
|
|
.show();
|
2012-04-10 12:39:18 +00:00
|
|
|
|
2012-06-18 16:33:52 +00:00
|
|
|
// Destroy menu items
|
2011-04-15 17:18:38 +00:00
|
|
|
this.element.find( ".ui-menu-item" )
|
2010-10-28 16:12:52 +00:00
|
|
|
.removeClass( "ui-menu-item" )
|
|
|
|
.removeAttr( "role" )
|
2012-05-30 01:59:03 +00:00
|
|
|
.removeAttr( "aria-disabled" )
|
2014-10-25 16:18:17 +00:00
|
|
|
.children( ".ui-menu-item-wrapper" )
|
|
|
|
.removeUniqueId()
|
|
|
|
.removeClass( "ui-menu-item-wrapper ui-state-hover" )
|
|
|
|
.removeAttr( "tabIndex" )
|
|
|
|
.removeAttr( "role" )
|
|
|
|
.removeAttr( "aria-haspopup" )
|
|
|
|
.children().each(function() {
|
|
|
|
var elem = $( this );
|
2014-11-03 17:08:06 +00:00
|
|
|
if ( elem.data( "ui-menu-submenu-caret" ) ) {
|
2014-10-25 16:18:17 +00:00
|
|
|
elem.remove();
|
|
|
|
}
|
|
|
|
});
|
2012-06-01 05:03:16 +00:00
|
|
|
|
2012-06-18 16:33:52 +00:00
|
|
|
// Destroy menu dividers
|
2012-06-01 05:03:16 +00:00
|
|
|
this.element.find( ".ui-menu-divider" ).removeClass( "ui-menu-divider ui-widget-content" );
|
2012-04-10 12:39:18 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_keydown: function( event ) {
|
2014-08-29 12:18:47 +00:00
|
|
|
var match, prev, character, skip,
|
2012-05-25 01:15:55 +00:00
|
|
|
preventDefault = true;
|
|
|
|
|
2012-04-10 12:39:18 +00:00
|
|
|
switch ( event.keyCode ) {
|
|
|
|
case $.ui.keyCode.PAGE_UP:
|
|
|
|
this.previousPage( event );
|
|
|
|
break;
|
|
|
|
case $.ui.keyCode.PAGE_DOWN:
|
|
|
|
this.nextPage( event );
|
|
|
|
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.previous( event );
|
|
|
|
break;
|
|
|
|
case $.ui.keyCode.DOWN:
|
|
|
|
this.next( event );
|
|
|
|
break;
|
|
|
|
case $.ui.keyCode.LEFT:
|
2012-04-14 19:33:48 +00:00
|
|
|
this.collapse( event );
|
2012-04-10 12:39:18 +00:00
|
|
|
break;
|
|
|
|
case $.ui.keyCode.RIGHT:
|
2012-09-05 20:07:36 +00:00
|
|
|
if ( this.active && !this.active.is( ".ui-state-disabled" ) ) {
|
2012-04-19 02:30:07 +00:00
|
|
|
this.expand( event );
|
|
|
|
}
|
2012-04-10 12:39:18 +00:00
|
|
|
break;
|
|
|
|
case $.ui.keyCode.ENTER:
|
2012-05-22 14:01:40 +00:00
|
|
|
case $.ui.keyCode.SPACE:
|
|
|
|
this._activate( event );
|
2012-04-10 12:39:18 +00:00
|
|
|
break;
|
|
|
|
case $.ui.keyCode.ESCAPE:
|
2012-04-14 19:33:48 +00:00
|
|
|
this.collapse( event );
|
2012-04-10 12:39:18 +00:00
|
|
|
break;
|
|
|
|
default:
|
2012-05-25 01:15:55 +00:00
|
|
|
preventDefault = false;
|
|
|
|
prev = this.previousFilter || "";
|
|
|
|
character = String.fromCharCode( event.keyCode );
|
|
|
|
skip = false;
|
|
|
|
|
2012-04-10 12:39:18 +00:00
|
|
|
clearTimeout( this.filterTimer );
|
|
|
|
|
|
|
|
if ( character === prev ) {
|
|
|
|
skip = true;
|
|
|
|
} else {
|
|
|
|
character = prev + character;
|
|
|
|
}
|
2012-05-25 01:15:55 +00:00
|
|
|
|
2014-08-29 12:18:47 +00:00
|
|
|
match = this._filterMenuItems( character );
|
2012-05-25 01:15:55 +00:00
|
|
|
match = skip && match.index( this.active.next() ) !== -1 ?
|
|
|
|
this.active.nextAll( ".ui-menu-item" ) :
|
2012-04-10 12:39:18 +00:00
|
|
|
match;
|
2012-05-25 01:15:55 +00:00
|
|
|
|
2012-06-01 04:03:51 +00:00
|
|
|
// 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
|
2012-04-10 12:39:18 +00:00
|
|
|
if ( !match.length ) {
|
2012-05-25 01:15:55 +00:00
|
|
|
character = String.fromCharCode( event.keyCode );
|
2014-08-29 12:18:47 +00:00
|
|
|
match = this._filterMenuItems( character );
|
2012-04-10 12:39:18 +00:00
|
|
|
}
|
2012-05-25 01:15:55 +00:00
|
|
|
|
2012-04-10 12:39:18 +00:00
|
|
|
if ( match.length ) {
|
|
|
|
this.focus( event, match );
|
2014-10-03 14:01:51 +00:00
|
|
|
this.previousFilter = character;
|
|
|
|
this.filterTimer = this._delay(function() {
|
2012-04-10 12:39:18 +00:00
|
|
|
delete this.previousFilter;
|
2014-10-03 14:01:51 +00:00
|
|
|
}, 1000 );
|
2012-04-10 12:39:18 +00:00
|
|
|
} else {
|
|
|
|
delete this.previousFilter;
|
|
|
|
}
|
|
|
|
}
|
2012-05-25 01:15:55 +00:00
|
|
|
|
|
|
|
if ( preventDefault ) {
|
|
|
|
event.preventDefault();
|
|
|
|
}
|
2010-04-30 08:21:40 +00:00
|
|
|
},
|
2011-06-10 10:20:45 +00:00
|
|
|
|
2012-05-22 14:01:40 +00:00
|
|
|
_activate: function( event ) {
|
|
|
|
if ( !this.active.is( ".ui-state-disabled" ) ) {
|
2014-10-25 16:18:17 +00:00
|
|
|
if ( this.active.children( "[aria-haspopup='true']" ).length ) {
|
2012-05-22 14:01:40 +00:00
|
|
|
this.expand( event );
|
|
|
|
} else {
|
|
|
|
this.select( event );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-04-21 19:01:08 +00:00
|
|
|
refresh: function() {
|
2014-01-08 17:15:04 +00:00
|
|
|
var menus, items,
|
|
|
|
that = this,
|
2012-07-12 15:23:33 +00:00
|
|
|
icon = this.options.icons.submenu,
|
2014-01-08 17:15:04 +00:00
|
|
|
submenus = this.element.find( this.options.menus );
|
2012-11-05 17:37:48 +00:00
|
|
|
|
2013-06-13 20:47:07 +00:00
|
|
|
this.element.toggleClass( "ui-menu-icons", !!this.element.find( ".ui-icon" ).length );
|
|
|
|
|
2012-11-05 17:37:48 +00:00
|
|
|
// Initialize nested menus
|
|
|
|
submenus.filter( ":not(.ui-menu)" )
|
2013-12-03 11:50:25 +00:00
|
|
|
.addClass( "ui-menu ui-widget ui-widget-content ui-front" )
|
2012-11-05 17:37:48 +00:00
|
|
|
.hide()
|
|
|
|
.attr({
|
|
|
|
role: this.options.role,
|
|
|
|
"aria-hidden": "true",
|
|
|
|
"aria-expanded": "false"
|
|
|
|
})
|
|
|
|
.each(function() {
|
|
|
|
var menu = $( this ),
|
2014-10-25 16:18:17 +00:00
|
|
|
item = menu.prev(),
|
2014-11-03 17:08:06 +00:00
|
|
|
submenuCaret = $( "<span>" )
|
2012-11-05 17:37:48 +00:00
|
|
|
.addClass( "ui-menu-icon ui-icon " + icon )
|
2014-11-03 17:08:06 +00:00
|
|
|
.data( "ui-menu-submenu-caret", true );
|
2012-11-05 17:37:48 +00:00
|
|
|
|
|
|
|
item
|
|
|
|
.attr( "aria-haspopup", "true" )
|
2014-11-03 17:08:06 +00:00
|
|
|
.prepend( submenuCaret );
|
2012-11-05 17:37:48 +00:00
|
|
|
menu.attr( "aria-labelledby", item.attr( "id" ) );
|
|
|
|
});
|
2011-06-10 10:20:45 +00:00
|
|
|
|
2012-04-07 20:38:27 +00:00
|
|
|
menus = submenus.add( this.element );
|
2013-09-25 04:46:59 +00:00
|
|
|
items = menus.find( this.options.items );
|
2012-04-07 20:38:27 +00:00
|
|
|
|
2013-09-25 04:46:59 +00:00
|
|
|
// Initialize menu-items containing spaces and/or dashes only as dividers
|
|
|
|
items.not( ".ui-menu-item" ).each(function() {
|
2012-05-25 04:44:51 +00:00
|
|
|
var item = $( this );
|
2013-12-18 18:29:41 +00:00
|
|
|
if ( that._isDivider( item ) ) {
|
2012-05-25 04:44:51 +00:00
|
|
|
item.addClass( "ui-widget-content ui-menu-divider" );
|
|
|
|
}
|
|
|
|
});
|
2012-04-16 12:02:28 +00:00
|
|
|
|
2013-09-18 04:22:33 +00:00
|
|
|
// Don't refresh list items that are already adapted
|
2013-09-25 04:46:59 +00:00
|
|
|
items.not( ".ui-menu-item, .ui-menu-divider" )
|
2013-09-18 04:22:33 +00:00
|
|
|
.addClass( "ui-menu-item" )
|
2014-10-25 16:18:17 +00:00
|
|
|
.children()
|
|
|
|
.not( ".ui-menu" )
|
|
|
|
.addClass( "ui-menu-item-wrapper" )
|
|
|
|
.uniqueId()
|
|
|
|
.attr({
|
|
|
|
tabIndex: -1,
|
|
|
|
role: this._itemRole()
|
|
|
|
});
|
2013-09-18 04:22:33 +00:00
|
|
|
|
2012-06-18 16:33:52 +00:00
|
|
|
// Add aria-disabled attribute to any disabled menu item
|
2013-09-25 04:46:59 +00:00
|
|
|
items.filter( ".ui-state-disabled" ).attr( "aria-disabled", "true" );
|
2012-04-07 20:38:27 +00:00
|
|
|
|
2012-08-27 12:05:27 +00:00
|
|
|
// If the active item has been removed, blur the menu
|
|
|
|
if ( this.active && !$.contains( this.element[ 0 ], this.active[ 0 ] ) ) {
|
|
|
|
this.blur();
|
|
|
|
}
|
2010-04-21 19:01:08 +00:00
|
|
|
},
|
|
|
|
|
2012-05-15 12:07:35 +00:00
|
|
|
_itemRole: function() {
|
|
|
|
return {
|
|
|
|
menu: "menuitem",
|
|
|
|
listbox: "option"
|
|
|
|
}[ this.options.role ];
|
|
|
|
},
|
|
|
|
|
2012-12-27 16:23:25 +00:00
|
|
|
_setOption: function( key, value ) {
|
|
|
|
if ( key === "icons" ) {
|
|
|
|
this.element.find( ".ui-menu-icon" )
|
|
|
|
.removeClass( this.options.icons.submenu )
|
|
|
|
.addClass( value.submenu );
|
|
|
|
}
|
2013-03-14 23:08:21 +00:00
|
|
|
if ( key === "disabled" ) {
|
|
|
|
this.element
|
|
|
|
.toggleClass( "ui-state-disabled", !!value )
|
|
|
|
.attr( "aria-disabled", value );
|
|
|
|
}
|
2012-12-27 16:23:25 +00:00
|
|
|
this._super( key, value );
|
|
|
|
},
|
|
|
|
|
2011-02-24 09:06:08 +00:00
|
|
|
focus: function( event, item ) {
|
2012-05-21 14:42:14 +00:00
|
|
|
var nested, focused;
|
2012-04-19 14:29:55 +00:00
|
|
|
this.blur( event, event && event.type === "focus" );
|
2011-06-10 10:20:45 +00:00
|
|
|
|
2012-05-21 14:42:14 +00:00
|
|
|
this._scrollIntoView( item );
|
2011-12-15 19:28:33 +00:00
|
|
|
|
2012-04-10 12:39:18 +00:00
|
|
|
this.active = item.first();
|
2015-01-19 16:00:57 +00:00
|
|
|
focused = this.active.children( ".ui-menu-item-wrapper" ).addClass( "ui-state-active" );
|
2014-10-25 16:18:17 +00:00
|
|
|
|
2012-06-18 16:33:52 +00:00
|
|
|
// Only update aria-activedescendant if there's a role
|
2012-05-15 12:07:35 +00:00
|
|
|
// otherwise we assume focus is managed elsewhere
|
|
|
|
if ( this.options.role ) {
|
|
|
|
this.element.attr( "aria-activedescendant", focused.attr( "id" ) );
|
|
|
|
}
|
2011-04-23 15:36:52 +00:00
|
|
|
|
2012-06-18 16:33:52 +00:00
|
|
|
// Highlight active parent menu item, if any
|
2012-05-25 01:15:55 +00:00
|
|
|
this.active
|
|
|
|
.parent()
|
2014-10-25 16:18:17 +00:00
|
|
|
.closest( ".ui-menu-item" )
|
|
|
|
.children( ".ui-menu-item-wrapper" )
|
|
|
|
.addClass( "ui-state-active" );
|
2011-06-10 10:20:45 +00:00
|
|
|
|
2012-05-18 19:34:47 +00:00
|
|
|
if ( event && event.type === "keydown" ) {
|
2012-05-09 04:57:56 +00:00
|
|
|
this._close();
|
|
|
|
} else {
|
|
|
|
this.timer = this._delay(function() {
|
2012-05-09 04:53:14 +00:00
|
|
|
this._close();
|
|
|
|
}, this.delay );
|
2012-05-09 04:57:56 +00:00
|
|
|
}
|
2011-06-10 10:20:45 +00:00
|
|
|
|
2012-06-18 16:33:52 +00:00
|
|
|
nested = item.children( ".ui-menu" );
|
2013-06-21 00:40:00 +00:00
|
|
|
if ( nested.length && event && ( /^mouse/.test( event.type ) ) ) {
|
2011-09-12 21:52:17 +00:00
|
|
|
this._startOpening(nested);
|
2011-02-24 14:51:51 +00:00
|
|
|
}
|
|
|
|
this.activeMenu = item.parent();
|
2011-06-10 10:20:45 +00:00
|
|
|
|
2010-10-28 16:12:52 +00:00
|
|
|
this._trigger( "focus", event, { item: item } );
|
2010-04-21 19:01:08 +00:00
|
|
|
},
|
|
|
|
|
2012-05-21 14:42:14 +00:00
|
|
|
_scrollIntoView: function( item ) {
|
|
|
|
var borderTop, paddingTop, offset, scroll, elementHeight, itemHeight;
|
|
|
|
if ( this._hasScroll() ) {
|
|
|
|
borderTop = parseFloat( $.css( this.activeMenu[0], "borderTopWidth" ) ) || 0;
|
|
|
|
paddingTop = parseFloat( $.css( this.activeMenu[0], "paddingTop" ) ) || 0;
|
|
|
|
offset = item.offset().top - this.activeMenu.offset().top - borderTop - paddingTop;
|
|
|
|
scroll = this.activeMenu.scrollTop();
|
|
|
|
elementHeight = this.activeMenu.height();
|
2014-05-06 13:06:05 +00:00
|
|
|
itemHeight = item.outerHeight();
|
2012-05-21 14:42:14 +00:00
|
|
|
|
|
|
|
if ( offset < 0 ) {
|
|
|
|
this.activeMenu.scrollTop( scroll + offset );
|
|
|
|
} else if ( offset + itemHeight > elementHeight ) {
|
|
|
|
this.activeMenu.scrollTop( scroll + offset - elementHeight + itemHeight );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-04-14 19:33:48 +00:00
|
|
|
blur: function( event, fromFocus ) {
|
|
|
|
if ( !fromFocus ) {
|
|
|
|
clearTimeout( this.timer );
|
|
|
|
}
|
2011-12-20 17:49:48 +00:00
|
|
|
|
2011-06-10 12:23:01 +00:00
|
|
|
if ( !this.active ) {
|
2010-11-16 19:35:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-06-10 10:20:45 +00:00
|
|
|
|
2015-01-19 16:00:57 +00:00
|
|
|
this.active.children( ".ui-menu-item-wrapper" ).removeClass( "ui-state-active" );
|
2010-04-21 19:01:08 +00:00
|
|
|
this.active = null;
|
2011-07-19 21:15:59 +00:00
|
|
|
|
|
|
|
this._trigger( "blur", event, { item: this.active } );
|
2010-04-21 19:01:08 +00:00
|
|
|
},
|
|
|
|
|
2011-06-10 12:23:01 +00:00
|
|
|
_startOpening: function( submenu ) {
|
|
|
|
clearTimeout( this.timer );
|
2011-07-14 15:10:28 +00:00
|
|
|
|
|
|
|
// Don't open if already open fixes a Firefox bug that caused a .5 pixel
|
2014-11-03 17:08:06 +00:00
|
|
|
// shift in the submenu position when mousing over the caret icon
|
2011-07-14 15:10:28 +00:00
|
|
|
if ( submenu.attr( "aria-hidden" ) !== "true" ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-04-10 12:39:18 +00:00
|
|
|
this.timer = this._delay(function() {
|
2011-09-12 21:52:17 +00:00
|
|
|
this._close();
|
|
|
|
this._open( submenu );
|
|
|
|
}, this.delay );
|
2011-03-17 09:37:37 +00:00
|
|
|
},
|
2011-06-10 10:20:45 +00:00
|
|
|
|
2011-06-10 12:23:01 +00:00
|
|
|
_open: function( submenu ) {
|
2012-05-25 01:15:55 +00:00
|
|
|
var position = $.extend({
|
|
|
|
of: this.active
|
2012-07-10 15:52:09 +00:00
|
|
|
}, this.options.position );
|
2012-05-25 01:15:55 +00:00
|
|
|
|
2011-06-10 12:23:01 +00:00
|
|
|
clearTimeout( this.timer );
|
2012-06-18 16:33:52 +00:00
|
|
|
this.element.find( ".ui-menu" ).not( submenu.parents( ".ui-menu" ) )
|
2011-06-10 12:23:01 +00:00
|
|
|
.hide()
|
|
|
|
.attr( "aria-hidden", "true" );
|
|
|
|
|
2012-04-10 12:39:18 +00:00
|
|
|
submenu
|
|
|
|
.show()
|
2011-06-10 12:23:01 +00:00
|
|
|
.removeAttr( "aria-hidden" )
|
|
|
|
.attr( "aria-expanded", "true" )
|
|
|
|
.position( position );
|
2011-02-24 14:51:51 +00:00
|
|
|
},
|
2011-06-10 10:20:45 +00:00
|
|
|
|
2011-09-22 18:56:53 +00:00
|
|
|
collapseAll: function( event, all ) {
|
2011-12-20 17:49:48 +00:00
|
|
|
clearTimeout( this.timer );
|
2012-04-10 12:39:18 +00:00
|
|
|
this.timer = this._delay(function() {
|
2012-06-18 16:33:52 +00:00
|
|
|
// If we were passed an event, look for the submenu that contains the event
|
2011-12-20 17:49:48 +00:00
|
|
|
var currentMenu = all ? this.element :
|
|
|
|
$( event && event.target ).closest( this.element.find( ".ui-menu" ) );
|
2011-09-22 18:56:53 +00:00
|
|
|
|
2012-06-18 16:33:52 +00:00
|
|
|
// If we found no valid submenu ancestor, use the main menu to close all sub menus anyway
|
2011-12-20 17:49:48 +00:00
|
|
|
if ( !currentMenu.length ) {
|
|
|
|
currentMenu = this.element;
|
|
|
|
}
|
2011-06-10 12:23:01 +00:00
|
|
|
|
2011-12-20 17:49:48 +00:00
|
|
|
this._close( currentMenu );
|
2011-09-12 13:43:49 +00:00
|
|
|
|
2011-12-20 17:49:48 +00:00
|
|
|
this.blur( event );
|
|
|
|
this.activeMenu = currentMenu;
|
2012-04-10 12:39:18 +00:00
|
|
|
}, this.delay );
|
2011-02-24 14:51:51 +00:00
|
|
|
},
|
2011-06-10 10:20:45 +00:00
|
|
|
|
2011-09-22 18:56:53 +00:00
|
|
|
// 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
|
2011-09-12 13:43:49 +00:00
|
|
|
_close: function( startMenu ) {
|
2011-09-14 15:29:36 +00:00
|
|
|
if ( !startMenu ) {
|
2011-09-12 13:43:49 +00:00
|
|
|
startMenu = this.active ? this.active.parent() : this.element;
|
|
|
|
}
|
|
|
|
|
|
|
|
startMenu
|
2011-09-14 15:29:36 +00:00
|
|
|
.find( ".ui-menu" )
|
2011-06-10 12:23:01 +00:00
|
|
|
.hide()
|
|
|
|
.attr( "aria-hidden", "true" )
|
|
|
|
.attr( "aria-expanded", "false" )
|
|
|
|
.end()
|
2015-01-19 16:00:57 +00:00
|
|
|
.find( ".ui-state-active" ).not( ".ui-menu-item-wrapper" )
|
2012-04-10 12:39:18 +00:00
|
|
|
.removeClass( "ui-state-active" );
|
2011-02-24 14:51:51 +00:00
|
|
|
},
|
|
|
|
|
2013-08-01 01:20:13 +00:00
|
|
|
_closeOnDocumentClick: function( event ) {
|
|
|
|
return !$( event.target ).closest( ".ui-menu" ).length;
|
|
|
|
},
|
|
|
|
|
2013-12-18 18:29:41 +00:00
|
|
|
_isDivider: function( item ) {
|
2014-01-08 17:15:04 +00:00
|
|
|
|
|
|
|
// Match hyphen, em dash, en dash
|
2013-12-18 18:29:41 +00:00
|
|
|
return !/[^\-\u2014\u2013\s]/.test( item.text() );
|
|
|
|
},
|
|
|
|
|
2011-07-05 15:02:33 +00:00
|
|
|
collapse: function( event ) {
|
2012-04-10 12:39:18 +00:00
|
|
|
var newItem = this.active &&
|
|
|
|
this.active.parent().closest( ".ui-menu-item", this.element );
|
2011-06-10 12:23:01 +00:00
|
|
|
if ( newItem && newItem.length ) {
|
2011-09-12 13:43:49 +00:00
|
|
|
this._close();
|
2011-06-10 12:23:01 +00:00
|
|
|
this.focus( event, newItem );
|
2011-02-24 14:51:51 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2011-07-05 15:02:33 +00:00
|
|
|
expand: function( event ) {
|
2012-04-10 12:39:18 +00:00
|
|
|
var newItem = this.active &&
|
|
|
|
this.active
|
|
|
|
.children( ".ui-menu " )
|
2013-09-25 04:46:59 +00:00
|
|
|
.find( this.options.items )
|
2012-04-10 12:39:18 +00:00
|
|
|
.first();
|
2011-06-10 12:23:01 +00:00
|
|
|
|
|
|
|
if ( newItem && newItem.length ) {
|
|
|
|
this._open( newItem.parent() );
|
2011-06-10 10:20:45 +00:00
|
|
|
|
2012-06-18 16:33:52 +00:00
|
|
|
// Delay so Firefox will not hide activedescendant change in expanding submenu from AT
|
2012-04-10 12:39:18 +00:00
|
|
|
this._delay(function() {
|
2011-09-12 21:52:17 +00:00
|
|
|
this.focus( event, newItem );
|
2012-07-13 18:36:00 +00:00
|
|
|
});
|
2011-02-24 14:51:51 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-02-06 20:13:45 +00:00
|
|
|
next: function( event ) {
|
2011-07-25 14:13:13 +00:00
|
|
|
this._move( "next", "first", event );
|
2010-04-21 19:01:08 +00:00
|
|
|
},
|
|
|
|
|
2012-02-06 20:13:45 +00:00
|
|
|
previous: function( event ) {
|
2011-07-25 14:13:13 +00:00
|
|
|
this._move( "prev", "last", event );
|
2010-04-21 19:01:08 +00:00
|
|
|
},
|
|
|
|
|
2011-12-23 15:48:14 +00:00
|
|
|
isFirstItem: function() {
|
2010-10-28 16:12:52 +00:00
|
|
|
return this.active && !this.active.prevAll( ".ui-menu-item" ).length;
|
2010-04-21 19:01:08 +00:00
|
|
|
},
|
|
|
|
|
2011-12-23 15:48:14 +00:00
|
|
|
isLastItem: function() {
|
2010-10-28 16:12:52 +00:00
|
|
|
return this.active && !this.active.nextAll( ".ui-menu-item" ).length;
|
2010-04-21 19:01:08 +00:00
|
|
|
},
|
|
|
|
|
2011-07-25 14:13:13 +00:00
|
|
|
_move: function( direction, filter, event ) {
|
|
|
|
var next;
|
2012-02-06 20:12:56 +00:00
|
|
|
if ( this.active ) {
|
|
|
|
if ( direction === "first" || direction === "last" ) {
|
2012-04-10 12:39:18 +00:00
|
|
|
next = this.active
|
|
|
|
[ direction === "first" ? "prevAll" : "nextAll" ]( ".ui-menu-item" )
|
|
|
|
.eq( -1 );
|
2012-02-06 20:12:56 +00:00
|
|
|
} else {
|
2012-04-10 12:39:18 +00:00
|
|
|
next = this.active
|
|
|
|
[ direction + "All" ]( ".ui-menu-item" )
|
|
|
|
.eq( 0 );
|
2012-02-06 20:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
2012-02-06 21:16:08 +00:00
|
|
|
if ( !next || !next.length || !this.active ) {
|
2013-09-25 04:46:59 +00:00
|
|
|
next = this.activeMenu.find( this.options.items )[ filter ]();
|
2011-07-25 14:13:13 +00:00
|
|
|
}
|
|
|
|
|
2012-02-06 20:12:56 +00:00
|
|
|
this.focus( event, next );
|
2010-04-21 19:01:08 +00:00
|
|
|
},
|
2011-06-10 10:20:45 +00:00
|
|
|
|
2010-10-28 16:12:52 +00:00
|
|
|
nextPage: function( event ) {
|
2012-06-18 16:33:52 +00:00
|
|
|
var item, base, height;
|
|
|
|
|
2011-12-15 18:43:28 +00:00
|
|
|
if ( !this.active ) {
|
2012-06-18 16:33:52 +00:00
|
|
|
this.next( event );
|
2011-12-15 18:43:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-12-23 15:48:14 +00:00
|
|
|
if ( this.isLastItem() ) {
|
2011-12-15 18:43:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-10-28 16:12:52 +00:00
|
|
|
if ( this._hasScroll() ) {
|
2012-06-18 16:33:52 +00:00
|
|
|
base = this.active.offset().top;
|
|
|
|
height = this.element.height();
|
2012-04-17 04:30:33 +00:00
|
|
|
this.active.nextAll( ".ui-menu-item" ).each(function() {
|
2012-06-18 16:33:52 +00:00
|
|
|
item = $( this );
|
|
|
|
return item.offset().top - base - height < 0;
|
2010-10-28 17:15:27 +00:00
|
|
|
});
|
|
|
|
|
2012-06-18 16:33:52 +00:00
|
|
|
this.focus( event, item );
|
2010-04-21 19:01:08 +00:00
|
|
|
} else {
|
2013-09-25 04:46:59 +00:00
|
|
|
this.focus( event, this.activeMenu.find( this.options.items )
|
2011-07-25 14:13:13 +00:00
|
|
|
[ !this.active ? "first" : "last" ]() );
|
2010-04-21 19:01:08 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-10-28 16:12:52 +00:00
|
|
|
previousPage: function( event ) {
|
2012-06-18 16:33:52 +00:00
|
|
|
var item, base, height;
|
2011-12-15 18:43:28 +00:00
|
|
|
if ( !this.active ) {
|
2012-06-18 16:33:52 +00:00
|
|
|
this.next( event );
|
2011-12-15 18:43:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-12-23 15:48:14 +00:00
|
|
|
if ( this.isFirstItem() ) {
|
2011-12-15 18:43:28 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-10-28 16:12:52 +00:00
|
|
|
if ( this._hasScroll() ) {
|
2012-06-18 16:33:52 +00:00
|
|
|
base = this.active.offset().top;
|
|
|
|
height = this.element.height();
|
2012-04-17 04:30:33 +00:00
|
|
|
this.active.prevAll( ".ui-menu-item" ).each(function() {
|
2012-06-18 16:33:52 +00:00
|
|
|
item = $( this );
|
|
|
|
return item.offset().top - base + height > 0;
|
2010-10-28 17:15:27 +00:00
|
|
|
});
|
|
|
|
|
2012-06-18 16:33:52 +00:00
|
|
|
this.focus( event, item );
|
2010-04-21 19:01:08 +00:00
|
|
|
} else {
|
2013-09-25 04:46:59 +00:00
|
|
|
this.focus( event, this.activeMenu.find( this.options.items ).first() );
|
2010-04-21 19:01:08 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-06-19 14:59:27 +00:00
|
|
|
_hasScroll: function() {
|
2011-12-15 18:43:28 +00:00
|
|
|
return this.element.outerHeight() < this.element.prop( "scrollHeight" );
|
2010-04-21 19:01:08 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
select: function( event ) {
|
2012-09-05 20:07:36 +00:00
|
|
|
// 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 = { item: this.active };
|
|
|
|
if ( !this.active.has( ".ui-menu" ).length ) {
|
2012-07-31 05:00:07 +00:00
|
|
|
this.collapseAll( event, true );
|
|
|
|
}
|
2011-02-24 14:51:51 +00:00
|
|
|
this._trigger( "select", event, ui );
|
2014-08-29 12:18:47 +00:00
|
|
|
},
|
|
|
|
|
2014-10-25 16:18:17 +00:00
|
|
|
_filterMenuItems: function( character ) {
|
2014-08-29 12:18:47 +00:00
|
|
|
var escapedCharacter = character.replace( /[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&" ),
|
|
|
|
regex = new RegExp( "^" + escapedCharacter, "i" );
|
|
|
|
|
|
|
|
return this.activeMenu
|
|
|
|
.find( this.options.items )
|
|
|
|
|
|
|
|
// Only match on items, not dividers or other content (#10571)
|
|
|
|
.filter( ".ui-menu-item" )
|
|
|
|
.filter(function() {
|
2014-10-25 16:18:17 +00:00
|
|
|
return regex.test(
|
|
|
|
$.trim( $( this ).children( ".ui-menu-item-wrapper" ).text() ) );
|
2014-08-29 12:18:47 +00:00
|
|
|
});
|
2010-04-21 19:01:08 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
}));
|