/* jQuery autoComplete v1.0.7 Copyright (c) 2014 Simon Steinberger / Pixabay GitHub: https://github.com/Pixabay/jQuery-autoComplete License: http://www.opensource.org/licenses/mit-license.php */ (function($){ $.fn.autoCompleteIq = function(options){ var o = $.extend({}, $.fn.autoCompleteIq.defaults, options); // public methods if (typeof options == 'string') { this.each(function(){ var that = $(this); if (options == 'destroy') { that.off('blur.autocomplete focus.autocomplete keydown.autocomplete keyup.autocomplete'); if (that.data('autocomplete')) that.attr('autocomplete', that.data('autocomplete')); else that.removeAttr('autocomplete'); $(that.data('sc')).remove(); that.removeData('sc').removeData('autocomplete'); } }); return this; } return this.each(function(){ var that = $(this); // sc = 'suggestions container' that.sc = $('
'); that.data('sc', that.sc).data('autocomplete', that.attr('autocomplete')); that.attr('autocomplete', 'off'); that.cache = {}; that.last_val = ''; that.updateSC = function(resize, next){ that.sc.show(); }; that.sc.insertAfter(that.parent()); that.sc.on('mouseleave', '.autocomplete-suggestion', function (){ $('.autocomplete-suggestion.selected').removeClass('selected'); }); that.sc.on('mouseenter', '.autocomplete-suggestion', function (){ $('.autocomplete-suggestion.selected').removeClass('selected'); $(this).addClass('selected'); }); that.sc.on('mousedown click', '.autocomplete-suggestion', function (e){ var item = $(this), v = item.data('val'); if (v || item.hasClass('autocomplete-suggestion')) { // else outside click that.val(v); o.onSelect(e, v, item); that.sc.hide(); } return false; }); that.on('blur.autocomplete', function(){ that.sc.hide(); }); if (!o.minChars) that.on('focus.autocomplete', function(){ that.last_val = '\n'; that.trigger('keyup.autocomplete'); }); function suggest(data){ var val = that.val(); that.cache[val] = data; if (data.length && val.length >= o.minChars) { var s = ''; for (var i=0;i