diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..506e98e --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,20 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +## [1.0.0] + +Initial version of Zoteroxy WP plugin. + +### Added + +- Shortcode for rendering list of library items provided by specified Zoteroxy API +- Support english and czech languages + +[Unreleased]: /../../compare/v1.0.0...develop +[1.0.0]: /../../tree/v1.0.0 \ No newline at end of file diff --git a/README.md b/README.md index 7341fa8..70244e5 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,32 @@ # zoteroxy-wp -WordPress plugin for displaying results provided by Zoteroxy API + +WordPress plugin for displaying results provided by [Zoteroxy API](https://github.com/CCMi-FIT/zoteroxy) + +## Installation + +You can install this WordPress plugin simply by placing the `zoteroxy-wp` directory +to your `/wp-content/plugins` directory. Then activate this plugin +in the WordPress administration. + +If you do not have access to the `plugins` directory, create a ZIP package with +`zoteroxy-wp` and upload it using WordPress administration interface. + +## Usage + +This plugin uses so-called *shortcode*: + +``` +[zoteroxy endpoint="..." lang="..."] +``` + +You can simply put this into your WordPress page (or post) wherever you need to. + +The arguments are: + +* `endpoint` = base URL of the used [Zoteroxy API](https://github.com/CCMi-FIT/zoteroxy) instance, e.g. `https://my.zoteroxy.tld` +* `lang` = optional language, currently supported: `en` (default), `cs` + +## License + +This project is licensed under the MIT License - see the [LICENSE](LICENSE) +file for more details diff --git a/zoteroxy-wp/script.js b/zoteroxy-wp/script.js new file mode 100644 index 0000000..47574da --- /dev/null +++ b/zoteroxy-wp/script.js @@ -0,0 +1,267 @@ +jQuery(document).ready(() => { + jQuery('.zoteroxy').each(function() { + const endpoint = jQuery(this).data('endpoint'); + const lang = jQuery(this).data('lang'); + initZoteroxy(endpoint, lang, this); + }); +}); + +function zoteroxyLang(lang) { + if (lang == 'cs') { + return { + pages: 'str.', + volume: 'sv.', + issue: 'č.', + link: 'Odkaz', + read: 'Číst', + }; + } else { + return { + pages: 'pp.', + volume: 'vol.', + issue: 'n.', + link: 'Link', + read: 'Read', + }; + } +} + +function initZoteroxy(endpoint, lang, $elem) { + const loader = jQuery('
').addClass('zoteroxy-loader'); + jQuery($elem).append(loader); + jQuery.ajax({ + url: `${endpoint}/collection`, + type: 'GET', + dataType: 'json', + headers: {'Accept': 'application/json'}, + success: function(data) { + loader.remove(); + jQuery($elem).append(processItems(endpoint, data, lang)); + } + }); +} + +function processItems(endpoint, data, lang) { + const strings = zoteroxyLang(lang); + console.log('Received data from Zoteroxy'); + console.log(data); + console.log('Rendering ...'); + const lst = jQuery('