Created
October 11, 2012 18:55
-
-
Save cristiangrojas/3874695 to your computer and use it in GitHub Desktop.
I'm using this custom autocomplete for actualito.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function(){ | |
$.widget('custom.actualito_autocomplete', $.ui.autocomplete, { | |
_renderMenu: function(ul, items){ | |
var that = this, | |
currencyCategory = ''; | |
$.each(items, function(index, item){ | |
if(item.type != currencyCategory){ | |
ul.append( "<li class='ui-autocomplete-category list_item_container filter'>" + item.type + "</li>" ); | |
currencyCategory = item.type; | |
} | |
that._renderItemData(ul, item, item.type); | |
}); | |
}, | |
selected: function(event, ui){ | |
var item = ui.item.data( "item.autocomplete" ); | |
} | |
}); | |
}); | |
$(function(){ | |
var accentMap = { | |
"á": "a", | |
"é": "e", | |
"í": "i", | |
"ó": "o", | |
"ú": "u", | |
"ü": "u" | |
}; | |
var normalize = function(term){ | |
var ret = ""; | |
for ( var i = 0; i < term.length; i++ ) { | |
ret += accentMap[ term.charAt(i) ] || term.charAt(i); | |
} | |
return ret; | |
}; | |
$('input.seeker-autocomplete').actualito_autocomplete({ | |
delay: 0, | |
minLength: 2, | |
source: function(request, response){ | |
var matcher = new RegExp( $.ui.autocomplete.escapeRegex( request.term ), "i" ); | |
response( $.grep( homepage_seeker, function( value ) { | |
value = value.label || value.value || value; | |
return matcher.test( value ) || matcher.test( normalize( value ) ); | |
}) ); | |
}, | |
select: function(event, ui){ | |
window.location = ui.item.url | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment