Last active
September 9, 2015 21:28
-
-
Save bakpa79/f7296a1a0a6985fd480c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // inputEl is the search <input> element, | |
| //predictiveItemsEl is the container element for the predictive search list, | |
| //predictiveItemsListEl is the <ul> list itself. | |
| //I use this inside an object created from the search element. | |
| function submitPredictivetext(inputEl, predictiveItemsEl, predictiveItemsListEl) { | |
| var $this = jQuery(inputEl), | |
| thisValue = $this[0].value, | |
| thatValue=""; | |
| var timer = $this.data('timeout') || 500, | |
| inputTimeOut; | |
| // window.clearTimeout(inputTimeOut); | |
| inputTimeOut = window.setTimeout(function(){ | |
| thatValue = $this[0].value; | |
| console.log('fire service call with: ', thisValue, thatValue); | |
| if(thisValue == thatValue) { | |
| if ($this[0].selectionEnd > 2){ | |
| if (!predictiveItemsEl.hasClass('active')){ | |
| predictiveItemsEl.addClass('active'); | |
| } | |
| // Clear and reset the list | |
| predictiveItemsListEl.find('li').remove('li'); | |
| mkServices.predictiveSearchService({ | |
| 'searchQuery': this.value, | |
| 'predictiveListElement': predictiveItemsListEl | |
| }); | |
| } else if($this[0].selectionEnd <= 2 && predictiveItemsEl.hasClass('active')) { | |
| // Clear and reset the list | |
| predictiveItemsListEl.find('li').remove('li'); | |
| predictiveItemsEl.removeClass('active'); | |
| } | |
| } | |
| }, timer); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment