2019-06-10 21:13:39 -04:00
|
|
|
const _cache = {};
|
2018-11-27 03:00:31 -05:00
|
|
|
|
2020-02-12 05:11:28 -05:00
|
|
|
export function applyInlineOneboxes(inline, ajax, opts) {
|
|
|
|
opts = opts || {};
|
|
|
|
|
2018-01-29 16:39:41 -05:00
|
|
|
Object.keys(inline).forEach((url) => {
|
|
|
|
// cache a blank locally, so we never trigger a lookup
|
|
|
|
_cache[url] = {};
|
|
|
|
});
|
|
|
|
|
2017-07-19 15:08:54 -04:00
|
|
|
return ajax("/inline-onebox", {
|
2020-02-12 05:11:28 -05:00
|
|
|
data: {
|
|
|
|
urls: Object.keys(inline),
|
|
|
|
category_id: opts.categoryId,
|
|
|
|
topic_id: opts.topicId,
|
|
|
|
},
|
2017-07-19 15:08:54 -04:00
|
|
|
}).then((result) => {
|
|
|
|
result["inline-oneboxes"].forEach((onebox) => {
|
2018-11-12 15:14:20 -05:00
|
|
|
if (onebox.title) {
|
|
|
|
_cache[onebox.url] = onebox;
|
|
|
|
let links = inline[onebox.url] || [];
|
|
|
|
links.forEach((link) => {
|
2019-06-10 21:13:39 -04:00
|
|
|
$(link)
|
|
|
|
.text(onebox.title)
|
2020-05-07 16:08:48 -04:00
|
|
|
.addClass("inline-onebox")
|
|
|
|
.removeClass("inline-onebox-loading");
|
2018-11-12 15:14:20 -05:00
|
|
|
});
|
|
|
|
}
|
2017-07-19 15:08:54 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export function cachedInlineOnebox(url) {
|
|
|
|
return _cache[url];
|
|
|
|
}
|
2019-06-10 21:13:39 -04:00
|
|
|
|
|
|
|
export function applyCachedInlineOnebox(url, onebox) {
|
|
|
|
return (_cache[url] = onebox);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function deleteCachedInlineOnebox(url) {
|
|
|
|
return delete _cache[url];
|
|
|
|
}
|