$(document).ready(function () { // Live Search $.fn.liveSearch = function (option) { return this.each(function () { this.timer = null; this.items = new Array(); $.extend(this, option); $(this).attr('autocomplete', 'off'); // Blur $(this).on('blur', function () { setTimeout(function (object) { object.hide(); }, 200, this); }); // Keydown $(this).on('input', function (event) { this.request(); }); // Show this.show = function () { var pos = $('#search').position(); $(this).parent().parent().siblings('ul.dropdown-menu').css({ top : pos.top + $('#search').height(), width: $('#search').width(), left: pos.left }); $(this).parent().parent().siblings('ul.dropdown-menu').show(); }; // Hide this.hide = function () { $(this).parent().parent().siblings('ul.dropdown-menu').hide(); }; // Request this.request = function () { clearTimeout(this.timer); this.timer = setTimeout(function (object) { object.source($(object).val(), $.proxy(object.response, object)); }, 200, this); }; // Response this.response = function (json) { html = ''; if (json.length) { for (i = 0; i < json.length; i++) { this.items[json[i]['id']] = json[i]; } var count = json.length; for (i = 0; i < count; i++) { html += '