diff --git a/static/js/my.js b/static/js/my.js index 6573ed5..f97b2f5 100644 --- a/static/js/my.js +++ b/static/js/my.js @@ -23,6 +23,54 @@ $(document).ajaxError(function (ev, jqXHR, ajaxSettings, thrownError) { }); +// SelectAjax +(function ($) { + $.fn.selectajax = function (opt) { + + var settings = $.extend( { + url : '/api' + }, opt); + + var selectbtn = this.children('button.selectajax-btn'); + var selectinp = this.children('input[type=text].selectajax-inp'); + var selecthid = this.children('input[type=hidden].selectajax-hid'); + var selectul = this.children('ul.selectajax-ul'); + + var selectajax_click = function(){ + var a = $(this).children('a'); + var hr = a.attr('href'); + var tx = a.text(); + selecthid.val(hr.substr(1)); + console.debug(tx); + selectbtn.text(tx).removeClass('hidden'); + selectinp.addClass('hidden').val(tx); + }; + + var refresh = function(){ + $.getJSON(settings.url, {'s': this.value}, function (r) { + selectul.empty(); + r.forEach(function (o) { + var li = $('