mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 12:43:45 +08:00
a1e77aa2ed
Previously, the site setting was only effective on the client side of things. Once the site setting was been reached, all oneboxes are not rendered. This commit changes it such that the site setting is respected both on the client and server side. The first N oneboxes are rendered and once the limit has been reached, subsequent oneboxes will not be rendered.
35 lines
940 B
Plaintext
35 lines
940 B
Plaintext
let _cache = {};
|
|
|
|
export const INLINE_ONEBOX_LOADING_CSS_CLASS =
|
|
"<%= CookedPostProcessor::INLINE_ONEBOX_LOADING_CSS_CLASS %>";
|
|
|
|
export const INLINE_ONEBOX_CSS_CLASS =
|
|
"<%= CookedPostProcessor::INLINE_ONEBOX_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)
|
|
.addClass(INLINE_ONEBOX_CSS_CLASS)
|
|
.removeClass(INLINE_ONEBOX_LOADING_CSS_CLASS);
|
|
});
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
export function cachedInlineOnebox(url) {
|
|
return _cache[url];
|
|
}
|