discourse/app/assets/javascripts/pretty-text/inline-oneboxer.js.es6
2018-11-13 01:44:20 +05:30

27 lines
622 B
JavaScript

let _cache = {};
export function applyInlineOneboxes(inline, ajax) {
Object.keys(inline).forEach(url => {
// cache a blank locally, so we never trigger a lookup
_cache[url] = {};
});
return ajax("/inline-onebox", {
data: { urls: Object.keys(inline) }
}).then(result => {
result["inline-oneboxes"].forEach(onebox => {
if (onebox.title) {
_cache[onebox.url] = onebox;
let links = inline[onebox.url] || [];
links.forEach(link => {
link.text(onebox.title);
});
}
});
});
}
export function cachedInlineOnebox(url) {
return _cache[url];
}