2010-04-21 19:01:08 +00:00
|
|
|
/*
|
|
|
|
* jQuery UI Menu @VERSION
|
|
|
|
*
|
2011-01-17 14:13:18 +00:00
|
|
|
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
|
2010-07-09 13:31:53 +00:00
|
|
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
|
* http://jquery.org/license
|
2010-04-21 19:01:08 +00:00
|
|
|
*
|
|
|
|
* http://docs.jquery.com/UI/Menu
|
|
|
|
*
|
|
|
|
* Depends:
|
|
|
|
* jquery.ui.core.js
|
2010-07-09 13:31:53 +00:00
|
|
|
* jquery.ui.widget.js
|
2010-04-21 19:01:08 +00:00
|
|
|
*/
|
|
|
|
(function($) {
|
2010-11-16 19:35:08 +00:00
|
|
|
|
|
|
|
var idIncrement = 0;
|
2010-04-21 19:01:08 +00:00
|
|
|
|
|
|
|
$.widget("ui.menu", {
|
2011-01-23 22:55:53 +00:00
|
|
|
defaultElement: "<ul>",
|
2011-03-17 09:37:37 +00:00
|
|
|
delay: 150,
|
2011-05-09 21:22:11 +00:00
|
|
|
isNewMenu: true,
|
2011-02-24 11:05:20 +00:00
|
|
|
options: {
|
|
|
|
position: {
|
|
|
|
my: "left top",
|
|
|
|
at: "right top"
|
|
|
|
}
|
|
|
|
},
|
2010-04-21 19:01:08 +00:00
|
|
|
_create: function() {
|
|
|
|
var self = this;
|
2011-02-24 14:51:51 +00:00
|
|
|
this.activeMenu = this.element;
|
2010-11-16 19:35:08 +00:00
|
|
|
this.menuId = this.element.attr( "id" ) || "ui-menu-" + idIncrement++;
|
2011-04-20 15:18:15 +00:00
|
|
|
if (this.element.find(".ui-icon").length) {
|
|
|
|
this.element.addClass("ui-menu-icons");
|
|
|
|
}
|
2010-04-21 19:01:08 +00:00
|
|
|
this.element
|
2010-10-28 16:12:52 +00:00
|
|
|
.addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
|
2010-04-21 19:01:08 +00:00
|
|
|
.attr({
|
2010-11-16 19:35:08 +00:00
|
|
|
id: this.menuId,
|
2011-04-15 17:18:38 +00:00
|
|
|
role: "menu"
|
2010-04-21 19:01:08 +00:00
|
|
|
})
|
2010-10-28 16:12:52 +00:00
|
|
|
.bind( "click.menu", function( event ) {
|
2011-03-15 18:02:18 +00:00
|
|
|
var item = $( event.target ).closest( ".ui-menu-item:has(a)" );
|
2010-10-28 16:11:55 +00:00
|
|
|
if ( self.options.disabled ) {
|
2010-06-18 08:57:20 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-03-15 18:02:18 +00:00
|
|
|
if ( !item.length ) {
|
2010-04-21 19:01:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// temporary
|
|
|
|
event.preventDefault();
|
2011-03-15 18:02:18 +00:00
|
|
|
// it's possible to click an item without hovering it (#7085)
|
|
|
|
if ( !self.active || ( self.active[ 0 ] !== item[ 0 ] ) ) {
|
|
|
|
self.focus( event, item );
|
|
|
|
}
|
2010-04-21 19:01:08 +00:00
|
|
|
self.select( event );
|
2010-10-28 16:11:55 +00:00
|
|
|
})
|
2010-10-28 16:12:52 +00:00
|
|
|
.bind( "mouseover.menu", function( event ) {
|
2011-05-09 21:22:11 +00:00
|
|
|
if ( self.options.disabled || self.isNewMenu ) {
|
|
|
|
self.isNewMenu = false;
|
2010-10-28 16:11:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var target = $( event.target ).closest( ".ui-menu-item" );
|
2011-02-24 14:51:51 +00:00
|
|
|
if ( target.length ) {
|
2011-02-24 09:06:08 +00:00
|
|
|
self.focus( event, target );
|
2010-10-28 16:11:55 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.bind("mouseout.menu", function( event ) {
|
|
|
|
if ( self.options.disabled ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var target = $( event.target ).closest( ".ui-menu-item" );
|
2011-02-24 14:51:51 +00:00
|
|
|
if ( target.length ) {
|
2011-02-24 09:06:08 +00:00
|
|
|
self.blur( event );
|
2010-10-28 16:11:55 +00:00
|
|
|
}
|
2010-10-28 16:12:52 +00:00
|
|
|
});
|
2010-04-21 19:01:08 +00:00
|
|
|
this.refresh();
|
2010-04-30 11:04:09 +00:00
|
|
|
|
2011-02-22 10:51:08 +00:00
|
|
|
this.element.attr( "tabIndex", 0 ).bind( "keydown.menu", function( event ) {
|
2010-10-28 16:12:52 +00:00
|
|
|
if ( self.options.disabled ) {
|
2010-06-18 08:57:20 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-10-28 16:12:52 +00:00
|
|
|
switch ( event.keyCode ) {
|
2010-04-30 11:04:09 +00:00
|
|
|
case $.ui.keyCode.PAGE_UP:
|
2011-02-24 14:51:51 +00:00
|
|
|
self.previousPage( event );
|
2010-04-30 11:04:09 +00:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
break;
|
|
|
|
case $.ui.keyCode.PAGE_DOWN:
|
2011-02-24 14:51:51 +00:00
|
|
|
self.nextPage( event );
|
2010-04-30 11:04:09 +00:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
break;
|
|
|
|
case $.ui.keyCode.UP:
|
2011-02-24 14:51:51 +00:00
|
|
|
self.previous( event );
|
2010-04-30 11:04:09 +00:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
break;
|
|
|
|
case $.ui.keyCode.DOWN:
|
2011-02-24 14:51:51 +00:00
|
|
|
self.next( event );
|
2010-04-30 11:04:09 +00:00
|
|
|
event.preventDefault();
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
break;
|
2011-02-24 14:51:51 +00:00
|
|
|
case $.ui.keyCode.LEFT:
|
|
|
|
if (self.left( event )) {
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
}
|
|
|
|
event.preventDefault();
|
|
|
|
break;
|
|
|
|
case $.ui.keyCode.RIGHT:
|
|
|
|
if (self.right( event )) {
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
}
|
|
|
|
event.preventDefault();
|
|
|
|
break;
|
2010-04-30 11:04:09 +00:00
|
|
|
case $.ui.keyCode.ENTER:
|
2011-04-22 18:22:56 +00:00
|
|
|
if (self.active.children("a[aria-haspopup='true']").length) {
|
|
|
|
if (self.right( event )) {
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
self.select( event );
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
}
|
2010-04-30 11:04:09 +00:00
|
|
|
event.preventDefault();
|
|
|
|
break;
|
2011-03-17 16:43:11 +00:00
|
|
|
case $.ui.keyCode.ESCAPE:
|
|
|
|
if ( self.left( event ) ) {
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
}
|
|
|
|
event.preventDefault();
|
|
|
|
break;
|
2011-02-24 09:40:12 +00:00
|
|
|
default:
|
2011-02-24 09:50:08 +00:00
|
|
|
event.stopPropagation();
|
2011-02-24 09:40:12 +00:00
|
|
|
clearTimeout(self.filterTimer);
|
|
|
|
var prev = self.previousFilter || "";
|
|
|
|
var character = String.fromCharCode(event.keyCode);
|
|
|
|
var skip = false;
|
|
|
|
if (character == prev) {
|
|
|
|
skip = true;
|
|
|
|
} else {
|
|
|
|
character = prev + character;
|
|
|
|
}
|
|
|
|
function escape(value) {
|
|
|
|
return value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
|
|
}
|
2011-04-20 13:35:40 +00:00
|
|
|
var match = self.activeMenu.children(".ui-menu-item").filter(function() {
|
2011-02-24 09:50:08 +00:00
|
|
|
return new RegExp("^" + escape(character), "i").test($(this).children("a").text());
|
2011-02-24 09:40:12 +00:00
|
|
|
});
|
|
|
|
var match = skip && match.index(self.active.next()) != -1 ? self.active.nextAll(".ui-menu-item") : match;
|
|
|
|
if (!match.length) {
|
|
|
|
character = String.fromCharCode(event.keyCode);
|
2011-04-20 13:35:40 +00:00
|
|
|
match = self.activeMenu.children(".ui-menu-item").filter(function() {
|
2011-02-24 09:50:08 +00:00
|
|
|
return new RegExp("^" + escape(character), "i").test($(this).children("a").text());
|
2011-02-24 09:40:12 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
if (match.length) {
|
|
|
|
self.focus(event, match);
|
|
|
|
if (match.length > 1) {
|
|
|
|
self.previousFilter = character;
|
|
|
|
self.filterTimer = setTimeout(function() {
|
|
|
|
delete self.previousFilter;
|
|
|
|
}, 1000);
|
|
|
|
} else {
|
|
|
|
delete self.previousFilter;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
delete self.previousFilter;
|
|
|
|
}
|
2010-04-30 11:04:09 +00:00
|
|
|
}
|
|
|
|
});
|
2010-04-21 19:01:08 +00:00
|
|
|
},
|
|
|
|
|
2011-01-14 22:11:22 +00:00
|
|
|
_destroy: function() {
|
2011-04-15 17:18:38 +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" )
|
|
|
|
.find("ul")
|
|
|
|
.andSelf()
|
2010-10-28 16:12:52 +00:00
|
|
|
.removeClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
|
|
|
|
.removeAttr( "role" )
|
2011-05-03 19:57:25 +00:00
|
|
|
.removeAttr("tabIndex")
|
2011-04-15 17:18:38 +00:00
|
|
|
.removeAttr( "aria-labelledby" )
|
|
|
|
.removeAttr( "aria-expanded" )
|
|
|
|
.removeAttr( "aria-hidden" )
|
|
|
|
.show();
|
2010-06-18 08:57:20 +00:00
|
|
|
|
2011-04-15 17:18:38 +00:00
|
|
|
//destroy menu items
|
|
|
|
this.element.find( ".ui-menu-item" )
|
|
|
|
.unbind( ".menu" )
|
2010-10-28 16:12:52 +00:00
|
|
|
.removeClass( "ui-menu-item" )
|
|
|
|
.removeAttr( "role" )
|
|
|
|
.children( "a" )
|
2011-02-14 11:06:04 +00:00
|
|
|
.removeClass( "ui-corner-all ui-state-hover" )
|
2010-10-28 16:12:52 +00:00
|
|
|
.removeAttr( "tabIndex" )
|
2011-04-15 17:18:38 +00:00
|
|
|
.removeAttr( "role" )
|
|
|
|
.removeAttr( "aria-haspopup" )
|
|
|
|
.removeAttr( "id" )
|
|
|
|
.children(".ui-icon").remove();
|
2010-04-30 08:21:40 +00:00
|
|
|
},
|
|
|
|
|
2010-04-21 19:01:08 +00:00
|
|
|
refresh: function() {
|
2011-04-15 17:18:38 +00:00
|
|
|
var self = this;
|
2011-02-24 11:05:20 +00:00
|
|
|
// initialize nested menus
|
|
|
|
var submenus = this.element.find("ul:not(.ui-menu)")
|
|
|
|
.addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
|
2011-04-15 17:18:38 +00:00
|
|
|
.attr("role", "menu")
|
2011-02-24 11:05:20 +00:00
|
|
|
.hide()
|
2011-04-15 17:18:38 +00:00
|
|
|
.attr("aria-hidden", "true")
|
|
|
|
.attr("aria-expanded", "false")
|
|
|
|
;
|
2011-02-24 11:05:20 +00:00
|
|
|
|
2010-04-21 19:01:08 +00:00
|
|
|
// don't refresh list items that are already adapted
|
2011-02-24 11:05:20 +00:00
|
|
|
var items = submenus.add(this.element).children( "li:not(.ui-menu-item):has(a)" )
|
2010-10-28 16:12:52 +00:00
|
|
|
.addClass( "ui-menu-item" )
|
2011-04-15 17:18:38 +00:00
|
|
|
.attr( "role", "presentation" );
|
2010-04-21 19:01:08 +00:00
|
|
|
|
2010-10-28 16:12:52 +00:00
|
|
|
items.children( "a" )
|
|
|
|
.addClass( "ui-corner-all" )
|
2011-04-15 17:18:38 +00:00
|
|
|
.attr( "tabIndex", -1 )
|
|
|
|
.attr( "role", "menuitem" )
|
|
|
|
.attr("id", function(i) {return self.element.attr("id") + "-" + i});
|
|
|
|
|
|
|
|
submenus.each(function() {
|
|
|
|
var menu = $(this);
|
|
|
|
var item = menu.prev("a")
|
|
|
|
item.attr("aria-haspopup", "true")
|
2011-04-26 20:05:44 +00:00
|
|
|
.prepend('<span class="ui-menu-icon ui-icon ui-icon-carat-1-e"></span>');
|
2011-04-15 17:18:38 +00:00
|
|
|
menu.attr("aria-labelledby", item.attr("id"));
|
|
|
|
});
|
2010-04-21 19:01:08 +00:00
|
|
|
},
|
|
|
|
|
2011-02-24 09:06:08 +00:00
|
|
|
focus: function( event, item ) {
|
2010-11-16 19:35:08 +00:00
|
|
|
var self = this;
|
2011-02-24 14:51:51 +00:00
|
|
|
|
2011-02-24 09:06:08 +00:00
|
|
|
this.blur();
|
2011-02-24 14:51:51 +00:00
|
|
|
|
2010-10-28 16:12:52 +00:00
|
|
|
if ( this._hasScroll() ) {
|
2010-10-28 17:15:27 +00:00
|
|
|
var borderTop = parseFloat( $.curCSS( this.element[0], "borderTopWidth", true) ) || 0,
|
|
|
|
paddingtop = parseFloat( $.curCSS( this.element[0], "paddingTop", true) ) || 0,
|
|
|
|
offset = item.offset().top - this.element.offset().top - borderTop - paddingtop,
|
2010-10-28 16:12:52 +00:00
|
|
|
scroll = this.element.attr( "scrollTop" ),
|
2010-10-28 17:15:27 +00:00
|
|
|
elementHeight = this.element.height(),
|
|
|
|
itemHeight = item.height();
|
|
|
|
if ( offset < 0 ) {
|
2010-10-28 16:12:52 +00:00
|
|
|
this.element.attr( "scrollTop", scroll + offset );
|
2010-10-28 17:15:27 +00:00
|
|
|
} else if ( offset + itemHeight > elementHeight ) {
|
|
|
|
this.element.attr( "scrollTop", scroll + offset - elementHeight + itemHeight );
|
2010-04-21 19:01:08 +00:00
|
|
|
}
|
|
|
|
}
|
2011-02-24 14:51:51 +00:00
|
|
|
|
2010-10-28 16:38:40 +00:00
|
|
|
this.active = item.first()
|
2010-10-28 16:12:52 +00:00
|
|
|
.children( "a" )
|
2011-02-24 09:12:20 +00:00
|
|
|
.addClass( "ui-state-focus" )
|
2010-04-21 19:01:08 +00:00
|
|
|
.end();
|
2011-04-15 17:18:38 +00:00
|
|
|
self.element.attr("aria-activedescendant", self.active.children("a").attr("id"))
|
2011-04-23 15:36:52 +00:00
|
|
|
|
|
|
|
// highlight active parent menu item, if any
|
|
|
|
this.active.parent().closest(".ui-menu-item").children("a:first").addClass("ui-state-active");
|
2011-03-17 09:37:37 +00:00
|
|
|
|
|
|
|
self.timer = setTimeout(function() {
|
|
|
|
self._close();
|
|
|
|
}, self.delay)
|
2011-02-24 14:51:51 +00:00
|
|
|
var nested = $(">ul", item);
|
|
|
|
if (nested.length && /^mouse/.test(event.type)) {
|
2011-03-17 09:37:37 +00:00
|
|
|
self._startOpening(nested);
|
2011-02-24 14:51:51 +00:00
|
|
|
}
|
|
|
|
this.activeMenu = item.parent();
|
|
|
|
|
2010-10-28 16:12:52 +00:00
|
|
|
this._trigger( "focus", event, { item: item } );
|
2010-04-21 19:01:08 +00:00
|
|
|
},
|
|
|
|
|
2011-02-24 09:06:08 +00:00
|
|
|
blur: function(event) {
|
2010-11-16 19:35:08 +00:00
|
|
|
if (!this.active) {
|
|
|
|
return;
|
|
|
|
}
|
2011-02-24 16:44:47 +00:00
|
|
|
|
2011-03-17 09:37:37 +00:00
|
|
|
clearTimeout(this.timer);
|
|
|
|
|
2011-02-24 09:12:20 +00:00
|
|
|
this.active.children( "a" ).removeClass( "ui-state-focus" );
|
2010-04-21 19:01:08 +00:00
|
|
|
this.active = null;
|
|
|
|
},
|
|
|
|
|
2011-03-17 09:37:37 +00:00
|
|
|
_startOpening: function(submenu) {
|
|
|
|
clearTimeout(this.timer);
|
|
|
|
var self = this;
|
|
|
|
self.timer = setTimeout(function() {
|
|
|
|
self._close();
|
|
|
|
self._open(submenu);
|
|
|
|
}, self.delay);
|
|
|
|
},
|
|
|
|
|
2011-02-24 14:51:51 +00:00
|
|
|
_open: function(submenu) {
|
2011-04-22 21:14:04 +00:00
|
|
|
clearTimeout(this.timer);
|
2011-04-15 17:18:38 +00:00
|
|
|
this.element.find(".ui-menu").not(submenu.parents()).hide().attr("aria-hidden", "true");
|
2011-02-24 14:51:51 +00:00
|
|
|
var position = $.extend({}, {
|
|
|
|
of: this.active
|
|
|
|
}, $.type(this.options.position) == "function"
|
|
|
|
? this.options.position(this.active)
|
|
|
|
: this.options.position
|
|
|
|
);
|
2011-04-15 17:18:38 +00:00
|
|
|
submenu.show().removeAttr("aria-hidden").attr("aria-expanded", "true").position(position);
|
2011-02-24 14:51:51 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
closeAll: function() {
|
2011-02-24 16:46:51 +00:00
|
|
|
this.element
|
2011-04-15 17:18:38 +00:00
|
|
|
.find("ul").hide().attr("aria-hidden", "true").attr("aria-expanded", "false").end()
|
2011-02-24 16:46:51 +00:00
|
|
|
.find("a.ui-state-active").removeClass("ui-state-active");
|
2011-02-24 14:51:51 +00:00
|
|
|
this.blur();
|
|
|
|
this.activeMenu = this.element;
|
|
|
|
},
|
|
|
|
|
|
|
|
_close: function() {
|
2011-02-24 16:44:47 +00:00
|
|
|
this.active.parent()
|
2011-04-15 17:18:38 +00:00
|
|
|
.find("ul").hide().attr("aria-hidden", "true").attr("aria-expanded", "false").end()
|
2011-02-24 16:44:47 +00:00
|
|
|
.find("a.ui-state-active").removeClass("ui-state-active");
|
2011-02-24 14:51:51 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
left: function(event) {
|
2011-04-15 17:18:38 +00:00
|
|
|
var newItem = this.active && this.active.parents("li:not(.ui-menubar-item)").first();
|
2011-02-24 14:51:51 +00:00
|
|
|
if (newItem && newItem.length) {
|
2011-04-15 17:18:38 +00:00
|
|
|
this.active.parent().attr("aria-hidden", "true").attr("aria-expanded", "false").hide();
|
2011-02-24 14:51:51 +00:00
|
|
|
this.focus(event, newItem);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
right: function(event) {
|
2011-04-15 17:18:38 +00:00
|
|
|
var self= this;
|
2011-02-24 14:51:51 +00:00
|
|
|
var newItem = this.active && this.active.children("ul").children("li").first();
|
|
|
|
if (newItem && newItem.length) {
|
|
|
|
this._open(newItem.parent());
|
|
|
|
var current = this.active;
|
2011-04-18 21:05:50 +00:00
|
|
|
//timeout so Firefox will not hide activedescendant change in expanding submenu from AT
|
2011-04-15 17:18:38 +00:00
|
|
|
setTimeout(function(){self.focus(event, newItem)}, 20);
|
2011-02-24 14:51:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-04-21 19:01:08 +00:00
|
|
|
next: function(event) {
|
2010-10-28 16:38:40 +00:00
|
|
|
this._move( "next", ".ui-menu-item", "first", event );
|
2010-04-21 19:01:08 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
previous: function(event) {
|
2010-10-28 16:38:40 +00:00
|
|
|
this._move( "prev", ".ui-menu-item", "last", event );
|
2010-04-21 19:01:08 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
first: 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
|
|
|
},
|
|
|
|
|
|
|
|
last: 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
|
|
|
},
|
|
|
|
|
2010-10-28 16:38:40 +00:00
|
|
|
_move: function(direction, edge, filter, event) {
|
2010-10-28 16:12:52 +00:00
|
|
|
if ( !this.active ) {
|
2011-02-24 14:51:51 +00:00
|
|
|
this.focus( event, this.activeMenu.children(edge)[filter]() );
|
2010-04-21 19:01:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-10-28 16:12:52 +00:00
|
|
|
var next = this.active[ direction + "All" ]( ".ui-menu-item" ).eq( 0 );
|
|
|
|
if ( next.length ) {
|
2011-02-24 09:06:08 +00:00
|
|
|
this.focus( event, next );
|
2010-04-21 19:01:08 +00:00
|
|
|
} else {
|
2011-02-24 14:51:51 +00:00
|
|
|
this.focus( event, this.activeMenu.children(edge)[filter]() );
|
2010-04-21 19:01:08 +00:00
|
|
|
}
|
|
|
|
},
|
2010-10-28 17:24:38 +00:00
|
|
|
|
2010-10-28 16:12:52 +00:00
|
|
|
nextPage: function( event ) {
|
|
|
|
if ( this._hasScroll() ) {
|
|
|
|
if ( !this.active || this.last() ) {
|
2011-02-24 14:51:51 +00:00
|
|
|
this.focus( event, this.activeMenu.children( ".ui-menu-item" ).first() );
|
2010-04-21 19:01:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
var base = this.active.offset().top,
|
|
|
|
height = this.element.height(),
|
2010-10-28 17:15:27 +00:00
|
|
|
result;
|
|
|
|
this.active.nextAll( ".ui-menu-item" ).each( function() {
|
2010-10-28 17:22:57 +00:00
|
|
|
result = $( this );
|
|
|
|
return $( this ).offset().top - base - height < 0;
|
2010-10-28 17:15:27 +00:00
|
|
|
});
|
|
|
|
|
2011-02-24 09:06:08 +00:00
|
|
|
this.focus( event, result );
|
2010-04-21 19:01:08 +00:00
|
|
|
} else {
|
2011-02-24 14:51:51 +00:00
|
|
|
this.focus( event, this.activeMenu.children( ".ui-menu-item" )
|
2010-10-28 17:22:57 +00:00
|
|
|
[ !this.active || this.last() ? "first" : "last" ]() );
|
2010-04-21 19:01:08 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-10-28 16:12:52 +00:00
|
|
|
previousPage: function( event ) {
|
|
|
|
if ( this._hasScroll() ) {
|
|
|
|
if ( !this.active || this.first() ) {
|
2011-02-24 14:51:51 +00:00
|
|
|
this.focus( event, this.activeMenu.children( ".ui-menu-item" ).last() );
|
2010-04-21 19:01:08 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
var base = this.active.offset().top,
|
2010-10-28 17:15:27 +00:00
|
|
|
height = this.element.height(),
|
|
|
|
result;
|
|
|
|
this.active.prevAll( ".ui-menu-item" ).each( function() {
|
2010-10-28 17:22:57 +00:00
|
|
|
result = $( this );
|
|
|
|
return $(this).offset().top - base + height > 0;
|
2010-10-28 17:15:27 +00:00
|
|
|
});
|
|
|
|
|
2011-02-24 09:06:08 +00:00
|
|
|
this.focus( event, result );
|
2010-04-21 19:01:08 +00:00
|
|
|
} else {
|
2011-02-24 14:51:51 +00:00
|
|
|
this.focus( event, this.activeMenu.children( ".ui-menu-item" )
|
2010-10-28 17:22:57 +00:00
|
|
|
[ !this.active || this.first() ? ":last" : ":first" ]() );
|
2010-04-21 19:01:08 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-06-19 14:59:27 +00:00
|
|
|
_hasScroll: function() {
|
2010-10-28 16:12:52 +00:00
|
|
|
return this.element.height() < this.element.attr( "scrollHeight" );
|
2010-04-21 19:01:08 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
select: function( event ) {
|
2011-02-24 14:51:51 +00:00
|
|
|
// save active reference before closeAll triggers blur
|
|
|
|
var ui = {
|
|
|
|
item: this.active
|
|
|
|
};
|
|
|
|
this.closeAll();
|
|
|
|
this._trigger( "select", event, ui );
|
2010-04-21 19:01:08 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-02-03 17:01:26 +00:00
|
|
|
$.ui.menu.version = "@VERSION";
|
|
|
|
|
2010-10-28 16:12:52 +00:00
|
|
|
}( jQuery ));
|