mirror of
https://github.com/discourse/discourse.git
synced 2024-12-11 16:53:49 +08:00
30 lines
735 B
Plaintext
30 lines
735 B
Plaintext
let _cache = {};
|
|
|
|
export const INLINE_ONEBOX_LOADING_CSS_CLASS =
|
|
"<%= CookedPostProcessor::INLINE_ONEBOX_LOADING_CSS_CLASS %>";
|
|
|
|
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];
|
|
}
|