discourse/app/assets/javascripts/pretty-text/inline-oneboxer.js.es6
Sam f946db4afe FIX: inline oneboxer min title length of 2
also: cache mini onebox misses as well to cut down traffic
2018-01-30 08:40:04 +11:00

26 lines
581 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 => {
_cache[onebox.url] = onebox;
let links = inline[onebox.url] || [];
links.forEach(link => {
link.text(onebox.title);
});
});
});
};
export function cachedInlineOnebox(url) {
return _cache[url];
}