Files
iD/modules/services/wikidata.js
Tom MacWright 6341d4e4b5 one-shot build (#3266)
* One-shot development

* Move jsonp to module
* Tooltip -> module
* Remove d3.jsonp
* Fix tooltip lint
* Load all libs but d3 itself with require
* Add top-level brfs

* Unformat intro graph
2016-08-10 15:25:19 -07:00

25 lines
820 B
JavaScript

import { jsonpRequest } from '../util/jsonp_request';
import { qsString } from '../util/index';
var wikidata = {},
endpoint = 'https://www.wikidata.org/w/api.php?';
export function init() {
// Given a Wikipedia language and article title, return an array of
// corresponding Wikidata entities.
wikidata.itemsByTitle = function(lang, title, callback) {
lang = lang || 'en';
jsonpRequest(endpoint + qsString({
action: 'wbgetentities',
format: 'json',
sites: lang.replace(/-/g, '_') + 'wiki',
titles: title,
languages: 'en', // shrink response by filtering to one language
callback: '{callback}'
}), function(data) {
callback(title, data.entities || {});
});
};
return wikidata;
}