discourse/app/assets/javascripts/pretty-text/inline-oneboxer.js.es6

27 lines
622 B
Plaintext
Raw Normal View History

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", {
2018-06-15 23:03:24 +08:00
data: { urls: Object.keys(inline) }
}).then(result => {
2018-06-15 23:03:24 +08:00
result["inline-oneboxes"].forEach(onebox => {
if (onebox.title) {
_cache[onebox.url] = onebox;
let links = inline[onebox.url] || [];
links.forEach(link => {
link.text(onebox.title);
});
}
});
});
2018-06-15 23:03:24 +08:00
}
export function cachedInlineOnebox(url) {
return _cache[url];
}