-
-
Save villadsen/42277 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CmdUtils.CreateCommand({ | |
name: ["summa"], | |
arguments: [ {role: 'object', nountype: noun_arb_text, label: 'your query'}], | |
preview: function(pblock, args) { | |
pblock.innerHTML = "Search Summa"; | |
var query = args.object; | |
if (query.text != "") { | |
pblock.innerHTML = "Searching Summa: <strong>" + query.text + "</strong>"; | |
var baseUrl = "http://www.statsbiblioteket.dk/search/opensearch.jsp"; | |
var params = {query: query.text, start: 1, number: 5}; | |
jQuery.get( baseUrl, params, function( resultRSS ) { | |
pblock.innerHTML += " (<em>" + resultRSS.getElementsByTagName("opensearch:totalResults")[0].childNodes[0].nodeValue + "</em>)"; | |
pblock.innerHTML += "<br /><br />"; | |
var items = resultRSS.getElementsByTagName("item"); | |
for(var i=0; i<=items.length; i++) { | |
var title = items[i].getElementsByTagName("title")[0].childNodes[0].nodeValue; | |
var description = items[i].getElementsByTagName("description")[0].childNodes[0].nodeValue; | |
var link = items[i].getElementsByTagName("link")[0].childNodes[0].nodeValue; | |
pblock.innerHTML += "<a style=\"text-decoration: underline; color: blue;\" href=\"" + link + "\">" + title + "</a>"; | |
pblock.innerHTML += "<br />"; | |
pblock.innerHTML += "<small>" + description + "</small>"; | |
pblock.innerHTML += "<br />"; | |
} | |
}, "xml"); | |
} | |
}, | |
execute: function(args) { | |
var url = "http://www.statsbiblioteket.dk/search/index.jsp"; | |
var replaceUrl = "http://www.statsbiblioteket.dk/search/index.jsp?query={QUERY}&first_search=true&action=classic"; | |
var urlString = url; | |
var query = args.object; | |
if (query.text != "") { | |
urlString = replaceUrl.replace("{QUERY}", query.text); | |
} | |
Utils.openUrlInBrowser(urlString); | |
} | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment