mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Merge branch 'master' of github.com:jquery/jquery-ui
This commit is contained in:
commit
319c5eb2c1
@ -16,7 +16,7 @@
|
||||
<style>
|
||||
.ui-button { margin-left: -1px; }
|
||||
.ui-button-icon-only .ui-button-text { padding: 0.35em; }
|
||||
.ui-autocomplete-input { margin: 0; padding: 0.48em 0 0.47em 0.45em; }
|
||||
.ui-autocomplete-input { margin: 0; padding: 0.4em 0 0.4em 0.45em; }
|
||||
</style>
|
||||
<script>
|
||||
(function( $ ) {
|
||||
@ -26,6 +26,32 @@
|
||||
select = this.element.hide(),
|
||||
selected = select.children( ":selected" ),
|
||||
value = selected.val() ? selected.text() : "";
|
||||
|
||||
function removeIfInvalid(element) {
|
||||
var value = $( element ).val(),
|
||||
matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( value ) + "$", "i" ),
|
||||
valid = false;
|
||||
select.children( "option" ).each(function() {
|
||||
if ( $( this ).text().match( matcher ) ) {
|
||||
this.selected = valid = true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if ( !valid ) {
|
||||
// remove invalid value, as it didn't match anything
|
||||
$( element )
|
||||
.val( "" )
|
||||
.attr( "title", value + " didn't match any item" )
|
||||
.tooltip( "open" );
|
||||
select.val( "" );
|
||||
setTimeout(function() {
|
||||
input.tooltip( "close" ).attr( "title", "" );
|
||||
}, 2500 );
|
||||
input.data( "autocomplete" ).term = "";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
var input = this.input = $( "<input>" )
|
||||
.insertAfter( select )
|
||||
.val( value )
|
||||
@ -57,30 +83,8 @@
|
||||
});
|
||||
},
|
||||
change: function( event, ui ) {
|
||||
if ( !ui.item ) {
|
||||
var value = $( this ).val(),
|
||||
matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( value ) + "$", "i" ),
|
||||
valid = false;
|
||||
select.children( "option" ).each(function() {
|
||||
if ( $( this ).text().match( matcher ) ) {
|
||||
this.selected = valid = true;
|
||||
return false;
|
||||
}
|
||||
});
|
||||
if ( !valid ) {
|
||||
// remove invalid value, as it didn't match anything
|
||||
$( this )
|
||||
.val( "" )
|
||||
.attr( "title", value + " didn't match any item" )
|
||||
.tooltip( "open" );
|
||||
select.val( "" );
|
||||
setTimeout(function() {
|
||||
input.tooltip( "close" ).attr( "title", "" );
|
||||
}, 2500 );
|
||||
input.data( "autocomplete" ).term = "";
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ( !ui.item )
|
||||
return removeIfInvalid( this );
|
||||
}
|
||||
})
|
||||
.addClass( "ui-widget ui-widget-content ui-corner-left" );
|
||||
@ -109,6 +113,7 @@
|
||||
// close if already visible
|
||||
if ( input.autocomplete( "widget" ).is( ":visible" ) ) {
|
||||
input.autocomplete( "close" );
|
||||
removeIfInvalid( input );
|
||||
return;
|
||||
}
|
||||
|
||||
@ -124,10 +129,9 @@
|
||||
.tooltip({
|
||||
position: {
|
||||
of: this.button
|
||||
}
|
||||
})
|
||||
.tooltip( "widget" )
|
||||
.addClass( "ui-state-highlight" );
|
||||
},
|
||||
tooltipClass: "ui-state-highlight"
|
||||
});
|
||||
},
|
||||
|
||||
destroy: function() {
|
||||
|
@ -203,4 +203,20 @@ test("cancel select", function() {
|
||||
}, 50);
|
||||
});
|
||||
|
||||
test("blur without selection", function() {
|
||||
expect(1);
|
||||
var ac = $("#autocomplete").autocomplete({
|
||||
delay: 0,
|
||||
source: data
|
||||
});
|
||||
stop();
|
||||
ac.val("j").keydown();
|
||||
setTimeout(function() {
|
||||
$( ".ui-menu-item" ).first().simulate("mouseover");
|
||||
ac.simulate("keydown", { keyCode: $.ui.keyCode.TAB });
|
||||
same( ac.val(), "j" );
|
||||
start();
|
||||
}, 50);
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
|
28
ui/jquery.ui.autocomplete.js
vendored
28
ui/jquery.ui.autocomplete.js
vendored
@ -62,6 +62,7 @@ $.widget( "ui.autocomplete", {
|
||||
})
|
||||
.bind( "keydown.autocomplete", function( event ) {
|
||||
if ( self.options.disabled || self.element.attr( "readonly" ) ) {
|
||||
suppressKeyPress = true;
|
||||
return;
|
||||
}
|
||||
|
||||
@ -69,17 +70,21 @@ $.widget( "ui.autocomplete", {
|
||||
var keyCode = $.ui.keyCode;
|
||||
switch( event.keyCode ) {
|
||||
case keyCode.PAGE_UP:
|
||||
suppressKeyPress = true;
|
||||
self._move( "previousPage", event );
|
||||
break;
|
||||
case keyCode.PAGE_DOWN:
|
||||
suppressKeyPress = true;
|
||||
self._move( "nextPage", event );
|
||||
break;
|
||||
case keyCode.UP:
|
||||
suppressKeyPress = true;
|
||||
self._move( "previous", event );
|
||||
// prevent moving cursor to beginning of text field in some browsers
|
||||
event.preventDefault();
|
||||
break;
|
||||
case keyCode.DOWN:
|
||||
suppressKeyPress = true;
|
||||
self._move( "next", event );
|
||||
// prevent moving cursor to end of text field in some browsers
|
||||
event.preventDefault();
|
||||
@ -121,7 +126,29 @@ $.widget( "ui.autocomplete", {
|
||||
if ( suppressKeyPress ) {
|
||||
suppressKeyPress = false;
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
// replicate some key handlers to allow them to repeat in Firefox and Opera
|
||||
var keyCode = $.ui.keyCode;
|
||||
switch( event.keyCode ) {
|
||||
case keyCode.PAGE_UP:
|
||||
self._move( "previousPage", event );
|
||||
break;
|
||||
case keyCode.PAGE_DOWN:
|
||||
self._move( "nextPage", event );
|
||||
break;
|
||||
case keyCode.UP:
|
||||
self._move( "previous", event );
|
||||
// prevent moving cursor to beginning of text field in some browsers
|
||||
event.preventDefault();
|
||||
break;
|
||||
case keyCode.DOWN:
|
||||
self._move( "next", event );
|
||||
// prevent moving cursor to end of text field in some browsers
|
||||
event.preventDefault();
|
||||
break;
|
||||
}
|
||||
})
|
||||
.bind( "focus.autocomplete", function() {
|
||||
if ( self.options.disabled ) {
|
||||
@ -338,6 +365,7 @@ $.widget( "ui.autocomplete", {
|
||||
this.menu.element.hide();
|
||||
this.menu.blur();
|
||||
this._trigger( "close", event );
|
||||
this.menu.isNewMenu = true;
|
||||
}
|
||||
},
|
||||
|
||||
|
4
ui/jquery.ui.menu.js
vendored
4
ui/jquery.ui.menu.js
vendored
@ -18,6 +18,7 @@ var idIncrement = 0;
|
||||
$.widget("ui.menu", {
|
||||
defaultElement: "<ul>",
|
||||
delay: 150,
|
||||
isNewMenu: true,
|
||||
options: {
|
||||
position: {
|
||||
my: "left top",
|
||||
@ -54,7 +55,8 @@ $.widget("ui.menu", {
|
||||
self.select( event );
|
||||
})
|
||||
.bind( "mouseover.menu", function( event ) {
|
||||
if ( self.options.disabled ) {
|
||||
if ( self.options.disabled || self.isNewMenu ) {
|
||||
self.isNewMenu = false;
|
||||
return;
|
||||
}
|
||||
var target = $( event.target ).closest( ".ui-menu-item" );
|
||||
|
Loading…
Reference in New Issue
Block a user