/** * Plugin functions file and typeahead * */ (function($) { //Autocompletes if (als.als_search_behavior == 'suggest') { var engine = new Bloodhound({ remote: { url: als.ajaxurl + '?s=%Q&action=alsgetsuggestions&nextNonce=' + als.nextNonce, wildcard: '%Q' }, queryTokenizer: Bloodhound.tokenizers.whitespace, datumTokenizer: Bloodhound.tokenizers.whitespace }); $('input[name="s"]') .typeahead({ minLength: 1, highlight: true }, { name: 'als-suggestions', source: engine, limit: 5, templates: { //header, footer empty: [ '
', 'No suggestions', '
' ].join('\n'), pending: '
', } }) .bind( 'typeahead:render', function(e) { var input = $(e.target); var width = input.css("width"); input.siblings('.tt-menu').css({ width: width }); } ); } //Live Search //Url = als.ajaxurl + '?s=%Q&action=alsgetresults&nextNonce=' + als.nextNonce //Loader =
//Livesearch if (als.als_search_behavior == 'live') { var searchengine = new Bloodhound({ remote: { url: als.ajaxurl + '?s=%Q&action=alsgetresults&nextNonce=' + als.nextNonce, wildcard: '%Q' }, queryTokenizer: Bloodhound.tokenizers.whitespace, datumTokenizer: Bloodhound.tokenizers.whitespace }); $('input[name="s"]') .typeahead({ minLength: 1, highlight: true }, { name: 'als-live', display: 'title', source: searchengine, limit: 10, templates: { //header, footer empty: [ '
', 'No matching posts', '
' ].join('\n'), pending: '
', suggestion: function(data) { return [ '
', '

', data.title, '

', '
', data.snippet, '
', '
' ].join('\n') } } }) .bind( 'typeahead:render', function(e) { var input = $(e.target); var width = input.css("width"); input.siblings('.tt-menu').css({ width: width }); } ).bind( 'typeahead:select', function(e, _post) { window.location = _post.url; } ); } })(jQuery);