Created
December 10, 2010 19:00
-
-
Save doxavore/736619 to your computer and use it in GitHub Desktop.
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
// jQuery barfs because $(empty).data("autocomplete") => undefined | |
$(".course-autocomplete").autocomplete({ | |
source: "/courses/autocomplete.json" | |
}).data("autocomplete")._renderItem = function(ul, item) { | |
return $("<li>") | |
.data("item.autocomplete", item) | |
.append("<a>" + item.name + "</a>") | |
.appendTo(ul); | |
}; | |
// jQuery likes but my fingers don't | |
$(".course-autocomplete").autocomplete({ | |
source: "/courses/autocomplete.json" | |
}); | |
if ($(".course-autocomplete").length) { | |
$(".course-autocomplete").data("autocomplete")._renderItem = function(ul, item) { | |
return $("<li>") | |
.data("item.autocomplete", item) | |
.append("<a>" + item.name + "</a>") | |
.appendTo(ul); | |
} | |
}; | |
// Acceptable compromise? | |
$(".course-autocomplete").autocomplete({ | |
source: "/courses/autocomplete.json" | |
}).each(function(i,elem) { | |
$(elem).data("autocomplete")._renderItem = function(ul, item) { | |
return $("<li>") | |
.data("item.autocomplete", item) | |
.append("<a>" + item.name + "</a>") | |
.appendTo(ul); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment