From 542e0b782e5d85f2857dc7db8247c7798b62b1a2 Mon Sep 17 00:00:00 2001 From: yqjiang Date: Fri, 7 Jun 2013 09:47:12 -0300 Subject: [PATCH] see more No. result if have more results --- targets/solr_site/js/solr_site_results.js | 54 +++++++++++++------ .../solr_site/roblib_search_solr_site.module | 6 +-- 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/targets/solr_site/js/solr_site_results.js b/targets/solr_site/js/solr_site_results.js index 70290ba..6cfb919 100644 --- a/targets/solr_site/js/solr_site_results.js +++ b/targets/solr_site/js/solr_site_results.js @@ -1,22 +1,46 @@ -Drupal.behaviors.roblib_search_solr_site= { - attach: function(context, settings) { +Drupal.behaviors.roblib_search_solr_site = { + attach: function(context, settings) { url = settings.roblib_search_solr_site.search_url; jQuery.getJSON(url, function(data) { - var items = []; - if(data.length < 1){ - jQuery('#' + 'roblib-search-content-solr-site').empty().append('No Results'); + var items = []; + if (data.length < 1) { + jQuery('#' + 'roblib-search-content-solr-site').empty().append('No Results'); } else { - jQuery.each(data.response.docs, function(key, val) { - items.push('
'); - items.push('
'); - items.push('' + val.label + ''); - items.push('
') - items.push('
'); - }); - } - jQuery('#roblib-search-content-solr-site').empty().append(items.join('')); + jQuery.each(data.response.docs, function(key, val) { + items.push('
\n\ +
'); + }); + var number = parseInt(data.rows); + jQuery('#' + 'roblib-search-content-solr-site').empty(); + items = showMoreItems(items, number); + + } }); } - + } +function showMoreItems(items, number) { + + for (var i = 0; i < number; i++) { + jQuery('#' + 'roblib-search-content-solr-site').append(items.pop()); + } + + if (items.length > 0) + { + + jQuery('#roblib-search-solr-site-more').empty().append('see ' + items.length + ' more results'); + jQuery('#see_more_result').click(function() { + items = showMoreItems(items, number); + }); + } + else + { + jQuery('#roblib-search-solr-site-more').empty().append('no more results'); + } + + + + return items; +} \ No newline at end of file diff --git a/targets/solr_site/roblib_search_solr_site.module b/targets/solr_site/roblib_search_solr_site.module index e062593..c416154 100644 --- a/targets/solr_site/roblib_search_solr_site.module +++ b/targets/solr_site/roblib_search_solr_site.module @@ -162,12 +162,12 @@ function roblib_search_solr_site_get_results($query) { $data = array( 'wt' => 'json', 'q' => $query, - 'rows' => $num_results, ); $url = url($solr_url.'/select', array('query' => $data)); $results = drupal_http_request($url); - - return $results->data; + $temp = substr($results->data, 1); + $out = '{"rows":"'.$num_results.'",'.$temp; + return $out; } /**