Files
iD/modules/services/wikidata.js
Bryan Housel 053074d076 Export live binding for services in iD.services, fix init/reset
(closes #3324)

Previously we allowed devs to swap out services that they didn't need.
This became difficult now that ES6 exports are immutable bindings.
But we can wrap the immutable bindings themselves in a live object,
to get back the flexibility that we used to have.

This change also drops the `taginfo` accessor on Context, since devs who want
to swap out taginfo service with something else can now do so through the live
binding.  `iD.services.taginfo = myTaginfo()`
2016-10-14 10:38:09 -04:00

39 lines
1021 B
JavaScript

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