Skip to content

Instantly share code, notes, and snippets.

@lawlesst
Created December 6, 2011 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lawlesst/1438617 to your computer and use it in GitHub Desktop.
Save lawlesst/1438617 to your computer and use it in GitHub Desktop.
Brown Sciverse Vufind gadget
<Module><ModulePrefs title="VuFindGadget"
description="&lt;p&gt;This application will search the Brown University collections and display relevant results alongside search
results from SciVerse Hub and ScienceDirect. Clicking on a result will take the user to the Brown University library
website, where more results and services will be available.&lt;/p&gt;
&lt;br/&gt;
&lt;p&gt;The application was built from the &lt;a href=&quot;http://www.applications.sciverse.com/action/appDetail/293706&quot;&gt;VuFind Template app&lt;/a&gt; for SciVerse developed at Villanova University. If your institution uses VuFind to power its library catalog a version of this application is easy to create for your institution. Learn more about the VuFind Template app to see if such an app on SciVerse can help your institution. Please contact &lt;a href=&quot;http://www.applications.sciverse.com/action/contactus&quot;&gt;Elsevier&lt;/a&gt; to learn more.&lt;/p&gt;
">
<Require feature="sciverse"/>
<Require feature="opensocial-0.9"/>
<Require feature="dynamic-height"/>
</ModulePrefs>
<UserPref name="searchTerms" datatype="hidden"/>
<UserPref name="logoUrl" datatype="string"
default_value="http://library.brown.edu/images/identity/BUL_1line_170x30px.png"/>
<UserPref name="logoLink" datatype="string" default_value="http://library.brown.edu"/>
<UserPref name="baseUrl" datatype="string" default_value="http://library.brown.edu/find"/>
<UserPref name="catalogName" datatype="string" default_value="Find"/><!-- Maximum number of results to show in the gadget (0 = no limit) -->
<UserPref name="resultLimit" datatype="string" default_value="10"/>
<Content type="url" view="canvas" href="__UP_baseUrl__/Search/Results?lookfor=__UP_searchTerms__"/>
<Content type="html" view="profile"> <!-- The code for Profile view is here. -->
<![CDATA[
<style>
#resultsList{
padding-left:3px;
}
#resultsList li{
padding-bottom:4px;
padding-top:4px;
border-bottom:1px solid #D8D8D8;
font-size:12px;
list-style:none;
}
#resultsLink a {
margin-left: 20px;
color: #2B0A06;
font-size: 14px;
text-decoration: none;
};
#resultsLink a:hover {
text-decoration: underline;
};
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
//start doing everything
gadgets.sciverse.getContextInfo(contextCallback);
//get search query, send it on to VuFind function
function contextCallback(obj){
k = obj.searchTerms;
getVu2(k);
};
function getVu2(query){
var params = {};
params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
params[gadgets.io.RequestParameters.NUM_ENTRIES] = 20;
params[gadgets.io.RequestParameters.GET_SUMMARIES] = false;
var prefs = new _IG_Prefs();
var url = prefs.getString('baseUrl') + "/Search/Results?view=rss&skip_rss_sort=1&lookfor=" + escape(query);
gadgets.sciverse.makeRequest(url, response, params);
}
//The channel. This will contain all the items and some info about the channel itself
var channel;
// Callback function to process the response
//response should be xml.
function response(obj) {
// process 504 errors:
if (obj.rc && obj.rc == 504) {
createErrorView();
}
var xmlDoc = $.parseXML(obj.text);
var $xml = $(xmlDoc);
//find and create the channel
$xml.find("channel").each( function(){
channel = {
items:new Array(),
title: $(this).find("title").text(),
link: $(this).find("link").first().text(),
description: $(this).find("description").text()
}
});
//find all the items under the channel and process them. All these tags are contained in the <item> tag
$xml.find("item").each( function(){
//for each <item> tag, parse the known tags in it
//this is done because the content type FEED doesn't return custom namespace tags. through the shindig framework
//create the item
var item = {
title: $(this).find("title").text(),
link: $(this).find("link").text(),
description: $(this).find("description").text(),
pubDate: $(this).find("pubDate").text(),
author: $(this).find("author").text(),
category: $(this).find("category").text(),
guid: $(this).find("guid").text(),
source: $(this).find("source").text(),
comments: $(this).find("source").text(),
enclosure: $(this).find("source").text(),
dc_date: $(this).find("[nodeName='dc:date']").text(),
dc_title : $(this).find("[nodeName='dc:title']").text(),
dc_creator : $(this).find("[nodeName='dc:creator']").text(),
dc_subject : $(this).find("[nodeName='dc:subject']").text(),
dc_description : $(this).find("[nodeName='dc:description']").text(),
dc_publisher : $(this).find("[nodeName='dc:publisher']").text(),
dc_contributor: $(this).find("[nodeName='dc:contributor']").text(),
dc_type : $(this).find("[nodeName='dc:type']").text(),
dc_format : $(this).find("[nodeName='dc:format']").text(),
dc_identifier : $(this).find("[nodeName='dc:identifier']").text(),
dc_source : $(this).find("[nodeName='dc:source']").text(),
dc_language : $(this).find("[nodeName='dc:language']").text(),
dc_relation : $(this).find("[nodeName='dc:relation']").text(),
dc_coverage : $(this).find("[nodeName='dc:coverage']").text(),
dc_rights: $(this).find("[nodeName='dc:rights']").text()
}
if (item.link.length > 0) {
channel.items.push(item);
}
});
//create the html
createView();
gadgets.window.adjustHeight("400px");
}
// function that will create HTML for error scenario
function createErrorView()
{
$("#results").html('Results currently unavailable.');
}
//function that will actually create the html to show. right now its very specific as to what it renders
//the idea here is to have <ul>
// <li>
// link
// <div>extra info</div>
// </li>
// ....
// <li>
// link
// <div>extra info</div>
// </li>
// </ul>
function createView(){
var listhtml = "<ul id='resultsList'>";
if(channel.link){
// Attempt to parse a result count out of the channel description;
// leave the count blank if we fail (in case the VuFind we are talking
// to has been customized in some way).
var resultCount = "";
if (channel.description) {
var tmp = channel.description.split(' of ');
if (tmp.length > 1) {
tmp = parseInt(tmp[1].replace(' found.', ''));
if (tmp > 0) {
resultCount = tmp;
}
}
}
listhtml = "<div id='resultsLink'><a target='_vufind' href='"+ channel.link.replace('view=rss', 'view=')+"'>See All " + resultCount + " Results</a></div>" + listhtml;
}
var items = channel.items;
//build the list. didn't use ol because it adds some weird padding and space is at a premium, so we counted on our own.
if(items && items.length > 0){
var prefs = new _IG_Prefs();
var resultLimit = parseInt(prefs.getString('resultLimit'));
if (resultLimit <= 0 || resultLimit > items.length) {
resultLimit = items.length;
}
for(var i = 0; i < resultLimit; i++){
var item = items[i];
var itext = i + 1;
var li = "<li class='item'>";
//if there is a link, build it, if not, show it as a title.
if(item.link){
if(item.title){
li += itext + ". <a target='_vufind' href='"+item.link+"'>" + item.title + "</a>";
}
}else if(item.title){
li += itext + ".<div>" + item.title + "</div>";
}
if(item.dc_creator){li += "<div>" + item.dc_creator + "</div>";}
//this is just extra fields to show. it would render each field with a | between.
var moreInfo = "";
if(item.dc_date){moreInfo += item.dc_date;}
if(item.dc_format){
if(moreInfo.length > 0){moreInfo += " | ";}
moreInfo += item.dc_format;
}
//add the more infor and close up the li.
li += "<div>"+moreInfo+"</div></li>";
listhtml += li;
}
} else {
listhtml += "<li class='item'>No items found.</li>";
}
listhtml += "</ul>";
$("#results").html(listhtml);
}
</script>
<!-- Logo will render here. The user prefs above get written here. LogoLink will take the user to the specified site when clicked. logoUrl is the location of the image. -->
<div id="logo"><a target="_homepage" href="__UP_logoLink__"><img src="__UP_logoUrl__" border="0" style="max-width:200px;"/></a></div>
<!-- list of results goes here-->
<div id="results">Searching __UP_catalogName__...</div>
]]>
</Content></Module>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment