Selectmenu: revert initial refresh method changes (with unit tests)

This reverts commit 27049fc5dc and d83e169424
This commit is contained in:
Felix Nagel 2012-01-22 14:12:52 +01:00
parent d83e169424
commit 725023e30d
4 changed files with 15 additions and 27 deletions

View File

@ -53,7 +53,6 @@ $.each([
equals( button.text(), selected.text(), "inital button text" );
link.simulate( "focus" );
link.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
equals( element.find("option:selected").val(), selected.next("option").val() , "after keydown original select state" );
equals( button.text(), selected.next("option").text(), "after keydown button text" );

View File

@ -22,11 +22,9 @@ test("change", function () {
var widget = this.element.selectmenu("widget"),
menu = widget.filter(".ui-selectmenu-menu"),
button = widget.filter(".ui-selectmenu-button"),
link = button.find("a"),
value = this.element.find("option").first().text();
link.simulate( "focus" );
link.simulate( "click" );
button.find("a").simulate( "click" );
menu.find("a").first().simulate( "mouseover" ).simulate( "click" );
});
@ -42,11 +40,6 @@ test("close", function () {
}
});
var widget = this.element.selectmenu("widget"),
button = widget.filter(".ui-selectmenu-button"),
link = button.find("a");
link.simulate( "focus" );
this.element.selectmenu("open").selectmenu("close");
});
@ -70,11 +63,9 @@ test("focus", function () {
var widget = this.element.selectmenu("widget"),
button = widget.filter(".ui-selectmenu-button"),
link = button.find("a"),
menu = widget.filter(".ui-selectmenu-menu");
link.simulate( "focus" );
link.simulate( "click" );
button.find("a").simulate( "click" );
menu.find(".ui-menu-item").simulate("mouseover");
});
@ -90,11 +81,6 @@ test("open", function () {
}
});
var widget = this.element.selectmenu("widget"),
button = widget.filter(".ui-selectmenu-button"),
link = button.find("a");
link.simulate( "focus" );
this.element.selectmenu("open");
});
@ -113,11 +99,9 @@ test("select", function () {
var widget = this.element.selectmenu("widget"),
button = widget.filter(".ui-selectmenu-button"),
link = button.find("a"),
menu = widget.filter(".ui-selectmenu-menu");
link.simulate( "focus" );
link.simulate( "click" );
button.find("a").simulate( "click" );
menu.find("a").first().simulate( "mouseover" ).simulate("click");
});

View File

@ -23,7 +23,6 @@ test("dropdown: CSS styles", function () {
menu = widget.filter(".ui-selectmenu-menu"),
ul = widget.find("ul");
link.simulate( "focus" );
this.element.selectmenu("open");
ok( link.hasClass("ui-corner-top") && !link.hasClass("ui-corner-all"), "button styles dropdown");
ok( ul.hasClass("ui-corner-bottom") && !ul.hasClass("ui-corner-all"), "menu styles dropdown");

View File

@ -185,6 +185,12 @@ $.widget( "ui.selectmenu", {
open: function( event ) {
if ( !this.options.disabled ) {
// init menu when initial opened
if ( !this.wasOpen ) {
this.refresh();
this.wasOpen = true;
}
var currentItem = this._getSelectedItem();
this._toggleButtonStyle();
@ -269,6 +275,11 @@ $.widget( "ui.selectmenu", {
},
_move: function( direction, event ) {
// init menu when not done yet
if ( !this.wasOpen ) {
this.refresh();
this.wasOpen = true;
}
if ( direction == "first" || direction == "last" ) {
// set focus manually for first or last item
this.menu.menu( "focus", event, this.menu.find( "li" ).not( '.ui-selectmenu-optgroup' )[ direction ]() );
@ -300,11 +311,6 @@ $.widget( "ui.selectmenu", {
},
_buttonEvents: {
focus: function( event ) {
// init Menu on first focus
this.refresh();
this.button.unbind( "focus." + this.widgetName )
},
click: function( event ) {
this._toggle( event );
event.preventDefault();