X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/4fd0861aa9d51262d5afcdc40ea48e7ce7ec7aaa..4c18b61fad6628589a6bd1a64895868ce3409c94:/philo/contrib/sobol/static/sobol/ajax_search.js diff --git a/philo/contrib/sobol/static/sobol/ajax_search.js b/philo/contrib/sobol/static/sobol/ajax_search.js index d4885b6..33fdf4f 100644 --- a/philo/contrib/sobol/static/sobol/ajax_search.js +++ b/philo/contrib/sobol/static/sobol/ajax_search.js @@ -1,33 +1,40 @@ (function($){ - var sobol = window.sobol = {} - sobol.setup = function(){ + var sobol = window.sobol = {}; + sobol.search = function(){ var searches = sobol.searches = $('article.search'); - for (i=0;i"; - if(data['hasMoreResults'] && data['moreResultsURL']) s.innerHTML += ""; - } else { - $(s).addClass('empty') - s.innerHTML += "

No results found.

" - } + sobol.onSuccess($(s), data); }, error: function(data, textStatus, errorThrown){ - $(s).removeClass('loading'); - text = errorThrown ? errorThrown : textStatus ? textStatus : "Error occurred." - if (errorThrown) { - s.innerHTML += "

" + errorThrown + "

" - }; + sobol.onError($(s), textStatus, errorThrown); } }); }()); }; + } + sobol.onSuccess = function(ele, data){ + // hook for success! + ele.removeClass('loading') + if (data['results'].length) { + ele[0].innerHTML += "
" + data['results'].join("") + "
"; + if(data['hasMoreResults'] && data['moreResultsURL']) ele[0].innerHTML += ""; + } else { + ele.addClass('empty'); + ele[0].innerHTML += "

No results found.

"; + ele.slideUp(); + } }; - $(sobol.setup); + sobol.onError = function(ele, textStatus, errorThrown){ + // Hook for error... + ele.removeClass('loading'); + text = errorThrown ? errorThrown : textStatus ? textStatus : "Error occurred."; + ele[0].innerHTML += "

" + text + "

"; + }; + $(sobol.search); }(jQuery)); \ No newline at end of file