Browse Source

add see more result

2.x-ebsco
yqjiang 12 years ago
parent
commit
d1ab0cf955
  1. 37
      targets/cufts/js/cufts_results.js
  2. 24
      targets/cufts/roblib_search_cufts.module
  3. 2
      targets/cufts/theme/roblib-search-cufts.tpl.php
  4. 6
      targets/cufts/theme/theme.inc

37
targets/cufts/js/cufts_results.js

@ -1,22 +1,25 @@
Drupal.behaviors.roblib_search_cufts = {
attach: function(context, settings) {
$url = settings.roblib_search_cufts.search_url;
jQuery.getJSON($url, function(data) {
var items = [];
if(data.length < 1){
jQuery('#' + 'roblib-search-content-cufts').empty().append('No Results');
} else {
jQuery.each(data.journals, function(key, val) {
items.push('<div class ="roblib-search-row">');
items.push('<div class="roblib-title cufts">');
items.push('<a href = "'+val.url+'">'+val.title+'</a></div>');
items.push('</div>');
});
}
jQuery('#' + 'roblib-search-content-cufts').empty().append(items.join(''));
attach: function(context, settings) {
url = settings.roblib_search_cufts.search_url;
jQuery.getJSON(url, function(data) {
var items = [];
if (data.length < 1 || data.total_count == 0) {
jQuery('#' + 'roblib-search-content-cufts').empty().append('No Results');
} else {
jQuery.each(data.journals, function(key, val) {
items.push('<div class ="roblib-search-row">');
items.push('<div class="roblib-title cufts">');
items.push('<a href = "' + val.url + '">' + val.title + '</a></div>');
items.push('</div>');
});
}
var originURL = settings.roblib_search_cufts.url;
var originSuffix = settings.roblib_search_cufts.suffix;
var newSuffix = originSuffix.replace("&format=json", "");
jQuery('#' + 'roblib-search-content-cufts').empty().append(items.join(''));
jQuery('#' + 'roblib-search-cufts-more').empty().append('<a href="'+originURL+newSuffix+'">see all '+data.numOfResults+' results</a>');
});
}
}
}

24
targets/cufts/roblib_search_cufts.module

@ -115,7 +115,7 @@ function roblib_search_cufts_theme() {
'path' => $path . '/theme',
'file' => $file,
'template' => 'roblib-search-cufts',
'variables' => array('results' => NULL),
'variables' => array('result'=>NULL)
)
);
}
@ -175,17 +175,33 @@ function roblib_search_cufts_get_results($query = NULL) {
$url = variable_get('roblib_search_cufts_url', 'http://cufts2.lib.sfu.ca/CJDB/PCU/browse/show?');
$url_suffix = variable_get('roblib_search_cufts_search_suffix', 'browse_field=title&search_type=startswith&format=json&search_terms=');
$number_of_records = variable_get('roblib_search_cufts_num_results', '5');
$search_url = $url . $url_suffix . '"' . $query . '"' . '&submit=Search&per_page='.$number_of_records;
$search_url = $url . $url_suffix . $query . '&submit=Search';
//get the total number of result
$results = drupal_http_request($search_url);
if ($results->code == '200') {
$output = $results->data;
}
else {
$output = $results->status_message;
}
return $output;
$start_index = strpos($output,'"total_count":')+ strlen('"total_count":');
$end_index = strlen($output)-1;
$length=$end_index-$start_index;
$num_of_result = substr($output,$start_index,$length);
$search_url = $search_url . '&per_page='.$number_of_records;
$results = drupal_http_request($search_url);
if ($results->code == '200') {
$output = $results->data;
}
else {
$output = $results->status_message;
}
$output = str_replace('"total_count":', '"numOfResults":'.$num_of_result.',"total_count":',$output);
return $output;
}
/**

2
targets/cufts/theme/roblib-search-cufts.tpl.php

@ -21,4 +21,4 @@
<img src="<?php print (empty($spinner_path) ? ' ' : $spinner_path); ?>"/>
</div>
<div class ="roblib-search-more">Search all Journals</div>
<div class ="roblib-search-more" id="roblib-search-cufts-more">Search all Journals</div>

6
targets/cufts/theme/theme.inc

@ -18,8 +18,12 @@ function roblib_search_cufts_preprocess_roblib_search_cufts(&$variables) {
$spinner_path = $base_url . '/' . drupal_get_path('module', 'roblib_search') . '/img/'.'spinner.gif';
$variables['spinner_path'] = $spinner_path;
$search_url = $base_url .'/roblib_search/cufts/ajax/'.urlencode($query);
drupal_add_js(drupal_get_path('module', 'roblib_search_cufts') . '/js/cufts_results.js');
drupal_add_js(array('roblib_search_cufts' => array('search_url' => $search_url)), array('type' => 'setting'));
$url = variable_get('roblib_search_cufts_url', 'http://cufts2.lib.sfu.ca/CJDB/PCU/browse/show?');
$url_suffix = variable_get('roblib_search_cufts_search_suffix', 'browse_field=title&search_type=startswith&format=json&search_terms=').$query;
drupal_add_js(array('roblib_search_cufts' => array('search_url' => $search_url,'url'=>$url,'suffix'=>$url_suffix)), array('type' => 'setting'));
}
?>

Loading…
Cancel
Save