Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <li>
- <div class="ui-widget">
- <input id="search" placeholder="search...">
- </div>
- </li>
- <script>
- $(function() {
- $( "#search" ).autocomplete({
- source: function( request, response ) {
- $.ajax({
- url: "/get_search_results",
- dataType: "json",
- data: {
- search_query: request.term
- },
- success: function( data ) {
- /*response( data );*/
- response( $.map( data.search_results, function( item ) {
- return {
- label: item.title,
- value: item.link,
- logo: item.logo
- }
- }));
- },
- });
- },
- minLength: 3,
- select: function( event, ui ) {
- window.location.href = ui.item.value;
- }
- });
- /*
- * Add team logo to search results
- */
- $( "#search" ).data( "ui-autocomplete" )._renderItem = function( ul, item ) {
- var $li = $('<li>'),
- $img = $('<img>');
- $img.attr({
- class: "search-club-logo-small",
- src: item.logo,
- alt: item.label,
- onerror: "this.onerror=null;this.src='/static/logos/clubs/no_team_logo_32.png';"
- });
- $li.attr('data-value', item.label);
- $li.append('<a href="#">');
- $li.find('a').append($img).append(item.label);
- return $li.appendTo(ul);
- };
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement