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

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