Removed json version of results from the ajax API. Improved checks for search existen...
[philo.git] / philo / contrib / sobol / static / sobol / ajax_search.js
1 (function($){
2         var sobol = window.sobol = {}
3         sobol.setup = function(){
4                 var searches = sobol.searches = $('article.search');
5                 for (i=0;i<searches.length;i++) {
6                         (function(){
7                                 var s = searches[i];
8                                 $.ajax({
9                                         url: s.getAttribute('data-url'),
10                                         dataType: 'json',
11                                         success: function(data){
12                                                 $(s).removeClass('loading')
13                                                 if (data['results'].length) {
14                                                         s.innerHTML += "<dl>" + data['results'].join("") + "</dl>";
15                                                         if(data['hasMoreResults'] && data['moreResultsURL']) s.innerHTML += "<footer><p><a href='" + data['moreResultsURL'] + "'>See more results</a></p></footer>";
16                                                 } else {
17                                                         $(s).addClass('empty')
18                                                         s.innerHTML += "<p>No results found.</p>"
19                                                 }
20                                         },
21                                         error: function(data, textStatus, errorThrown){
22                                                 $(s).removeClass('loading');
23                                                 text = errorThrown ? errorThrown : textStatus ? textStatus : "Error occurred."
24                                                 if (errorThrown) {
25                                                         s.innerHTML += "<p>" + errorThrown + "</p>"
26                                                 };
27                                         }
28                                 });
29                         }());
30                 };
31         };
32         $(sobol.setup);
33 }(jQuery));