You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
875 B
JavaScript
41 lines
875 B
JavaScript
$(function() {
|
|
var availableTags = [
|
|
"@gmail.com",
|
|
"@msn.com",
|
|
"@hotmail.com",
|
|
"@aol.com",
|
|
"@yahoo.com"
|
|
];
|
|
function split( val ) {
|
|
return val.split( /@\s*/ );
|
|
}
|
|
function extractLast( term ) {
|
|
return split( term ).pop();
|
|
}
|
|
|
|
$( ".autoemail" )
|
|
.bind( "keydown", function( event ) {
|
|
if ( event.keyCode === $.ui.keyCode.TAB &&
|
|
$( this ).data( "autocomplete" ).menu.active ) {
|
|
event.preventDefault();
|
|
}
|
|
})
|
|
.autocomplete({
|
|
minLength: 0,
|
|
source: function( request, response ) {
|
|
response( $.ui.autocomplete.filter(
|
|
availableTags, extractLast( request.term ) ) );
|
|
},
|
|
focus: function() {
|
|
return false;
|
|
},
|
|
select: function( event, ui ) {
|
|
var terms = split( this.value );
|
|
terms.pop();
|
|
terms.push( ui.item.value );
|
|
terms.push( "" );
|
|
this.value = terms.join( "" );
|
|
return false;
|
|
}
|
|
});
|
|
}); |