Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision |
dev:client_coding:javascript_api [2020/10/17 21:08] – [Batch Editing] dstillman | dev:client_coding:javascript_api [2022/07/02 18:22] – [Zotero Search Basics] dstillman |
---|
Non-window scope applies to lower-level code that doesn't have access to the DOM. This includes the core ''Zotero'' object, which contains all other non-window code, including the data layer used for retrieving and modifying library data. In Zotero, non-window code is contained within the ''xpcom'' subdirectory. | Non-window scope applies to lower-level code that doesn't have access to the DOM. This includes the core ''Zotero'' object, which contains all other non-window code, including the data layer used for retrieving and modifying library data. In Zotero, non-window code is contained within the ''xpcom'' subdirectory. |
| |
Overlays and windows in Zotero can import the core ''Zotero'' object via the include.js script. Zotero methods can then be called from anywhere within the window's scope simply by calling, for example, ''var item = Zotero.Items.get(1);''. | Windows in Zotero can import the core ''Zotero'' object via the include.js script. Zotero methods can then be called from anywhere within the window's scope simply by calling, for example, ''var item = Zotero.Items.get(1);''. |
| |
To access Zotero functionality from your own extension, you will need access to the core ''Zotero'' object. If your extension operates within the main browser overlay, you already have access to the ''Zotero'' object and don’t need to take further steps. Otherwise, you can import the Zotero object into other windows by including the script %%chrome://zotero/content/include.js%% within an HTML or XUL file: | To access Zotero functionality from your own extension, you will need access to the core ''Zotero'' object. If your extension operates within the main Zotero window, you already have access to the ''Zotero'' object and don’t need to take further steps. Otherwise, you can import the Zotero object into other windows by including the script %%chrome://zotero/content/include.js%% within an HTML or XUL file: |
| |
<code html> | <code html> |
] | ] |
); | ); |
var itemID = await item.save(); | var itemID = await item.saveTx(); |
return itemID; | return itemID; |
</code> | </code> |
s.addCondition('collection', 'is', collectionKey); // e.g., 'C72FDAP2' | s.addCondition('collection', 'is', collectionKey); // e.g., 'C72FDAP2' |
s.addCondition('savedSearch', 'is', savedSearchKey); | s.addCondition('savedSearch', 'is', savedSearchKey); |
| </code> |
| |
| === Search by creator === |
| |
| <code javascript> |
| var name = 'smith'; |
| s.addCondition('creator', 'contains', name); |
</code> | </code> |
| |
return fulltext; | return fulltext; |
</code> | </code> |
| |
| ==== File I/O ==== |
| |
| === Getting the contents of a file === |
| |
| <code javascript> |
| var path = '/Users/user/Desktop/data.json'; |
| var data = await Zotero.File.getContentsAsync(path); |
| </code> |
| |
| === Saving data to a file === |
| |
| <code javascript> |
| var path = '/Users/user/Desktop/file.txt'; |
| var data = "This is some text."; |
| await Zotero.File.putContentsAsync(path, data); |
| </code> |
| |
| |
==== To Do === | ==== To Do === |