33"use strict" ;
44
55var ZOTERO_CONFIG = {
6- "publicGroupId" : "2055673" , // ID of public group to search in Zotero
6+ "zotId" : "2055673" , // ID of group or user library to search in Zotero
7+ "zotIdType" : "group" , // group or user
8+ "collectionKey" : "" , // Key of collection within library to search, or "" if no collection.
79 "limit" : 10 , // Max number of results to retrieve per page
810 "resultsElementId" : "searchResults" , // Element to contain results
911 "urlElementId" : "searchUrl" , // Element to display search URL
@@ -50,7 +52,7 @@ function parseZoteroResults(resultText) {
5052}
5153
5254
53- function show_loading ( isLoading ) {
55+ function showLoading ( isLoading ) {
5456 var x = document . getElementById ( "loading-div" ) ;
5557 if ( isLoading ) {
5658 document . body . style . cursor = "wait" ;
@@ -64,7 +66,7 @@ function show_loading(isLoading) {
6466
6567// Function to call if CORS request is successful
6668function successCallback ( headers , response ) {
67- show_loading ( false ) ;
69+ showLoading ( false ) ;
6870
6971 // Write results to page
7072 var resultHtml = parseZoteroResults ( response ) ;
@@ -92,7 +94,7 @@ function successCallback(headers, response) {
9294
9395// Function to call if CORS request fails
9496function errorCallback ( ) {
95- show_loading ( false ) ;
97+ showLoading ( false ) ;
9698 alert ( "There was an error making the request." ) ;
9799}
98100
@@ -108,14 +110,15 @@ function showUrl(url) {
108110
109111// Passes search URL and callbacks to CORS function
110112function searchZotero ( query , itemType , sort , start ) {
111- var base = "https://api.zotero.org/groups/" +
112- ZOTERO_CONFIG [ "publicGroupId" ] + "/items?v=3&include=bib" ;
113+ var zotId = ( ZOTERO_CONFIG [ "zotIdType" ] === "group" ) ? "groups/" + ZOTERO_CONFIG [ "zotId" ] : "users/" + ZOTERO_CONFIG [ "zotId" ] ;
114+ var collection = ( ZOTERO_CONFIG [ "collectionKey" ] === "" ) ? "/" : "/collections/" + ZOTERO_CONFIG [ "collectionKey" ] + "/" ;
115+ var base = "https://api.zotero.org/" + zotId + collection + "/items?v=3&include=bib,data" ;
113116 var params = "&q=" + encodeURI ( query ) + "&itemType=" + itemType +
114117 "&sort=" + sort + "&start=" + start ;
115118 var limit = "&limit=" + ZOTERO_CONFIG [ "limit" ] ;
116119 var url = base + params + limit ;
117120 showUrl ( url ) ;
118- show_loading ( true ) ;
121+ showLoading ( true ) ;
119122 makeCorsRequest ( url , successCallback , errorCallback ) ;
120123}
121124
0 commit comments