User:BrandonXLF/Citoid
Citoid.js is a utility that returns a valid MediaWiki reference using mw:Citoid. After loading the script, the function getCitoidRef
takes a URL, DOI, ISBN, PMID, PMCID, or QID and returns a reference in the format {{cite...}}
through a jQuery Promise/Deferred object. The script can be loaded from https://wiki.riteme.site/w/index.php?title=User:BrandonXLF/Citoid.js&action=raw&ctype=text/javascript
. The source code can be found at User:BrandonXLF/Citoid.js. The output should be used within <ref>...</ref>
tags.
Documentation
[edit]This utility has one function scoped to the window, getCitoidRef
.
getCitoidRef
accepts a URL, DOI, ISBN, PMID, PMCID, or QID to get the reference of and returns a jQuery Promise object.
The Promise resolve (.done
) calls a function and provides two parameters, the reference and the source of the reference.
The Promise reject (.fail
) calls a function and provides one parameter, the text status for why the function failed.
The Promise notify (.progress
) calls a function and provides one parameter, the text status of the function.
Example
[edit]mw.loader.getScript('https://wiki.riteme.site/w/index.php?title=User:BrandonXLF/Citoid.js&action=raw&ctype=text/javascript').then(function(){
getCitoidRef('9781857800913').then(function(ref){
console.log(ref);
});
});
The example about will output (to the console):
{{Cite book|last=Hengi, B. I.|url=https://www.worldcat.org/oclc/44395047|title=Airlines remembered : over 200 airlines of the past, described and illustrated in colour|date=2000|publisher=Midland Pub|others=,Lewis, Neil.|isbn=1-85780-091-5|location=Leicester, England|oclc=44395047}}
This is the reference for the book with the ISBN 13 9781857800913.
Loading
[edit]The module should be loaded using mw.loader.load
or mw.loader.getScript
with a then statement that can use the function getCitoidRef
to generate a reference (see the example above). If you need to load several different scripts or gadgets, you can use jQuery.when
.