|
1 | 1 | # Zotero-JavaScript-Search-Client |
2 | | -Example HTML, CSS, and JavaScript for searching for items within a public Zotero user or group library |
| 2 | +Example HTML, CSS, and JavaScript for searching for items within a public Zotero |
| 3 | +user or group library |
| 4 | + |
| 5 | +Some live demos: |
| 6 | + |
| 7 | +* [Basic example](minimal.html) |
| 8 | +* [Complete example](complete.html) |
3 | 9 |
|
4 | 10 | ## Motivation |
5 | 11 |
|
6 | 12 | To help users discover your publications, you can add them to an online database like Zotero and then present a search interface to that database on your website. Modules for doing so have been written for WordPress and Drupal, but I hadn't seen one for static HTML sites, so I wrote this example to test how feasible a static HTML Zotero client would be to implement. |
7 | 13 |
|
8 | | -For usage and examples, see [the documentation](https://ble-lter.github.io/Zotero-JavaScript-Search-Client/). |
| 14 | +## Usage |
| 15 | + |
| 16 | +Open the zotero.html file in your browser and enter a search term like |
| 17 | +`coastal`. Click the search button and see results as formatted by Zotero to the page. |
| 18 | + |
| 19 | +You can click Search with no terms specified to show the entire catalog, which is the default behavior when you load the page. |
| 20 | + |
| 21 | +Zotero limits the number of results returned in a single request, so the page supports pagination to get additional results. |
| 22 | + |
| 23 | +To use this for your own project, you will need a free Zotero account into which you include your publications, and obviously you'll need to adapt the HTML, CSS, etc., for your particular website. |
| 24 | + |
| 25 | +## Customization |
| 26 | + |
| 27 | +The code finds elements via their HTML id attribute values, so in general you'll |
| 28 | +want to start with one of the example HTML documents and adapt it to your needs. |
| 29 | + |
| 30 | +To change parameters such as how many search results to show at a time, see the |
| 31 | +`ZOTERO_CONFIG` variable in `zotero.js`. See comments in the code for a brief |
| 32 | +explanation and example values, or the text below for additional details. |
| 33 | + |
| 34 | +### What To Search |
| 35 | + |
| 36 | +You can search a user library, a group, or a collection within a user library or |
| 37 | +group. |
| 38 | + |
| 39 | +* `zotId` - The user or group identifier. You can find your group identifier by |
| 40 | + browsing to your group page and copying the number in the URL. To find your |
| 41 | + user identifier, click **Settings**, and then click **Feeds/API**. |
| 42 | +* `zotIdType` - Indicates whether `zotId` is for a `group` or a `user`. |
| 43 | +* `collectionKey` - Supply a value for this if you want to limit search to a |
| 44 | + particular collection. Otherwise leave it as an empty string, "". You can |
| 45 | + find your collection identifier by browsing to the collection's page and copying the |
| 46 | + collection key from the URL. |
| 47 | +* `filterTags` - Use this to restrict results to items matching this tag filter, |
| 48 | + or leave the value as an emptry string, "", if no tag filtering is desired. |
| 49 | + Since the Zotero API supports several ways of writing a tag filter, the entire tag parameter including the preceeding ampersand is required for |
| 50 | + this value, as in `&tag=FeaturedArticle`. See the [API |
| 51 | + documentation](https://www.zotero.org/support/dev/web_api/v3/basics) for |
| 52 | + examples. |
| 53 | + |
| 54 | +### Results Table |
| 55 | + |
| 56 | +Results are displayed in a table with up to four columns: `Year`, `Citation`, |
| 57 | +`Item Type`, and a special column (we'll refer to it as `ShowTags`) showing the |
| 58 | +presence of particular tags. |
| 59 | + |
| 60 | +* `resultsElementId` - The id of the HTML element to contain the results table. |
| 61 | + This element must already exist in your HTML document. |
| 62 | +* `includeCols` - Array of column names to include in the output table, other than |
| 63 | + `Citation` which is always included. The full set is `Year`, `Type`, and |
| 64 | + `ShowTags`. If you leave a column name out in this array, then it will not |
| 65 | + appear in the result table. If you leave all columns out (i.e., the array is |
| 66 | + empty), then only the citations are shown, and no column header is shown. |
| 67 | +* `showTags`: Array of tags to show, if present, for each result item. Use this |
| 68 | + to categorize your items if Zotero doesn't support the categories you need out |
| 69 | + of the box. For example, you could tag your items based on their relationship |
| 70 | + to your LTER site, indicating whether the item is a foundational paper for the |
| 71 | + site (`Fondational`), was funded by the site (`LTER-Funded`), or was written by someone outside of your site |
| 72 | + who used your site's data (`LTER-Enabled`). If an item has one of the tags |
| 73 | + you specify, the tag will be shown in the `ShowTags` column. Obviously, if you |
| 74 | + want to use this functionality, make sure the text `ShowTags` is included in |
| 75 | + `includeCols`. |
| 76 | +* `showTagColName` - The name to be used for the `ShowTags` column in the |
| 77 | + results table, since I can't predict what kind of categories your tags |
| 78 | + represent. `Relationship to LTER Site` would work for the example tags |
| 79 | + mentioned above. |
| 80 | +* `style` - The bibliography display style for the citations, e.g., apa. Leave |
| 81 | + blank for the default which is chicago-note-bibliography. |
| 82 | + |
| 83 | +### Result Counts and Pagination |
| 84 | + |
| 85 | +You can provide HTML id attribute values for elements that will contain result |
| 86 | +counts, pagination links, and so on. In general, if you do not want to show one |
| 87 | +of these elements, then provide an empty string, "", as the identifier. If the |
| 88 | +code does not find a matching element, it will skip it. |
| 89 | + |
| 90 | +* `limit` - Max number of results to retrieve per page. A value of 10 is a good |
| 91 | + starting point. As you approach 100, Zotero gets awfully slow. |
| 92 | +* `urlElementId` - Supply this if your HTML document has an element in which |
| 93 | + you'd like to display the URL that was used to fetch results from Zotero. |
| 94 | +* `countElementId` - Element in your HTML document for showing the total number |
| 95 | + of results. |
| 96 | +* `pagesTopElementId` - Element to display result page links above results. |
| 97 | +* `pagesBotElementId` - Element to display result page links below results. |
| 98 | +* `showPages` - Max number of page links to show. The code assumes this is an |
| 99 | + odd number! |
| 100 | + |
| 101 | +### Advanced Search Controls |
| 102 | + |
| 103 | +The Zotero API has very limited advanced search functionality, though the |
| 104 | +developers say they are planning to add more features. Currently you |
| 105 | +can only filter by item type. Thus, `zotero.html` includes a collapsible |
| 106 | +**Advanced** section in which the user can choose to filter by item type. See |
| 107 | +the HTML if you're curious, but for now I suggest leaving the advanced section |
| 108 | +out until more advanced functionality is supported. |
| 109 | + |
| 110 | +### Sorting |
| 111 | + |
| 112 | +The Zotero API supports sorting results. If you want to allow the user to sort |
| 113 | +results, you must include an HTML `select` control with the identifier |
| 114 | +`visibleSort` and with options matching the allowable Zotero sort values. See |
| 115 | +the section on sorting and pagination parameters in the [Zotero API |
| 116 | +documentation](https://www.zotero.org/support/dev/web_api/v3/basics) for |
| 117 | +allowable values. See `zotero.html` for an example of what the `select` element |
| 118 | +should look like. This element should be contained within a `div` element, |
| 119 | +which is used to hide the control if no results were returned from the search. |
| 120 | + |
| 121 | +If you do not want to allow the user to change the sorting option, then leave |
| 122 | +these HTML elements out of your document. |
| 123 | + |
| 124 | +* `sortDiv` - Identifier of the HTML element containing the `select` control |
| 125 | + allowing interactive sort options. |
0 commit comments