Skip to content
Permalink
Browse files

Menu: Implemented destroy method and disabled option, modified test t…

…o pass html-compare-destroy test and extended default visual test for testing destroy and disabled features
  • Loading branch information...
jzaefferer committed Jun 18, 2010
1 parent 921e40f commit b376fa8dda91aefb50c7a5a7d9ab8dace9eccd0d
Showing with 56 additions and 15 deletions.
  1. +6 −6 tests/unit/menu/menu.html
  2. +21 −5 tests/visual/menu/menu.html
  3. +29 −4 ui/jquery.ui.menu.js
@@ -59,12 +59,12 @@ <h2 id="qunit-userAgent"></h2>

<div id="main" class="mainOnMoon">

<ul id="menu1">
<li><a href="#">Aberdeen</a></li>
<li><a href="#">Ada</a></li>
<li><a href="#">Adamsville</a></li>
<li><a href="#">Addyston</a></li>
<li><a href="#">Adelphi</a></li>
<ul class="foo" id="menu1">
<li class="foo"><a class="foo" href="#">Aberdeen</a></li>
<li class="foo"><a class="foo" href="#">Ada</a></li>
<li class="foo"><a class="foo" href="#">Adamsville</a></li>
<li class="foo"><a class="foo" href="#">Addyston</a></li>
<li class="foo"><a class="foo" href="#">Adelphi</a></li>
</ul>
<div id="log"></div>

@@ -17,12 +17,25 @@
top: 10
}).appendTo(document.body).themeswitcher();
$("#menu1, #menu2").menu({
select: function(event, ui) {
$("<div/>").text("Selected: " + ui.item.text()).appendTo("#log");
}
});
function create() {
menus.menu({
select: function(event, ui) {
$("<div/>").text("Selected: " + ui.item.text()).appendTo("#log");
}
});
}
var menus = $("#menu1, #menu2");
create();
$("#toggle-destroy").toggle(function() {
menus.menu("destroy");
}, create);
$("#toggle-disable").toggle(function() {
menus.menu("disable");
}, function() {
menus.menu("enable");
});
});
</script>
<style>
@@ -87,5 +100,8 @@
<div id="log" style="height: 400px; width: 300px; overflow: auto;" class="ui-widget-content"></div>
</div>

<button id="toggle-disable">Disable / Enable</button>
<button id="toggle-destroy">Destroy / Create</button>

</body>
</html>
@@ -23,6 +23,9 @@ $.widget("ui.menu", {
"aria-activedescendant": "ui-active-menuitem"
})
.click(function( event ) {
if (self.options.disabled) {
return false;
}
if ( !$( event.target ).closest( ".ui-menu-item a" ).length ) {
return;
}
@@ -36,6 +39,9 @@ $.widget("ui.menu", {
this.options.input = this.element.attr("tabindex", 0);
}
this.options.input.bind("keydown.menu", function(event) {
if (self.options.disabled) {
return;
}
switch (event.keyCode) {
case $.ui.keyCode.PAGE_UP:
self.previousPage();
@@ -67,8 +73,21 @@ $.widget("ui.menu", {
},

destroy: function() {
// TODO implement destroy
$.Widget.prototype.apply(this, arguments);
$.Widget.prototype.destroy.apply(this, arguments);

this.element
.removeClass("ui-menu ui-widget ui-widget-content ui-corner-all")
.removeAttr("tabindex")
.removeAttr("role")
.removeAttr("aria-activedescendant");

this.element.children(".ui-menu-item")
.removeClass("ui-menu-item")
.removeAttr("role")
.children("a")
.removeClass("ui-corner-all")
.removeAttr("tabindex")
.unbind(".menu");
},

refresh: function() {
@@ -83,10 +102,16 @@ $.widget("ui.menu", {
.addClass("ui-corner-all")
.attr("tabindex", -1)
// mouseenter doesn't work with event delegation
.mouseenter(function( event ) {
.bind("mouseenter.menu", function( event ) {
if (self.options.disabled) {
return;
}
self.activate( event, $(this).parent() );
})
.mouseleave(function() {
.bind("mouseleave.menu", function() {
if (self.options.disabled) {
return;
}
self.deactivate();
});
},

0 comments on commit b376fa8

Please sign in to comment.
You can’t perform that action at this time.