1(function( $ ) { 2 'use strict'; 3 4 /** 5 * All of the code for your public-facing JavaScript source 6 * should reside in this file. 7 * 8 * Note: It has been assumed you will write jQuery code here, so the 9 * $ function reference has been prepared for usage within the scope 10 * of this function. 11 * 12 * This enables you to define handlers, for when the DOM is ready: 13 * 14 * $(function() { 15 * 16 * }); 17 * 18 * When the window is loaded: 19 * 20 * $( window ).load(function() { 21 * 22 * }); 23 * 24 * ...and/or other possibilities. 25 * 26 * Ideally, it is not considered best practise to attach more than a 27 * single DOM-ready or window-load handler for a particular page. 28 * Although scripts in the WordPress core, Plugins and Themes may be 29 * practising this, we should strive to set a better example in our own work. 30 */ 31 $(document).ready( function() { 32 33 // create a function to actually fire the search 34 function bfdDoSearch(t) { 35 36 // do the ajax request for search 37 $.ajax({ 38 39 type: 'post', 40 url: bfd_js.ajaxurl, // the localized name of the file 41 data: { 42 action: 'bfd_ajax_download_search', // the wp_ajax_ hook name 43 search: t 44 }, 45 46 // what happens on success 47 success: function( result ) { 48 49 // if the ajax call returns no results 50 if( result === 'error' ) { 51 52 // set the html of the element with the class to no results 53 $( '.bfd-ajax-results' ).html( 'No results' ); 54 55 // we have results to display 56 } else { 57 58 // populate the results markup in the element with the class of bfd-ajax-results 59 $( '.bfd-ajax-results' ).html( result ); 60 61 } 62 63 } 64 65 }); 66 67 } 68 69 var thread = null; 70 71 // when the keyboard press is released in the input with the class bfd-search-input-box 72 $('.bfd-search-input-box').keyup(function() { 73 // clear our timeout variable - to start the timer again 74 clearTimeout(thread); 75 76 // set a variable to reference our current element ajax-search 77 var $this = $(this); 78 79 //clear result panel if the value is blank 80 if (!this.value.trim()) { 81 82 $('.bfd-ajax-results').html(''); 83 return; 84 85 } else { 86 87 // set a timeout to wait for a second before running the bfdDoSearch function 88 thread = setTimeout( 89 function() { 90 bfdDoSearch($this.val()) 91 }, 92 1000 93 ); 94 } 95 96 }); 97 98 }); 99})( jQuery );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.