mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: preview up to 'max_oneboxes_per_post' oneboxes
We were counting all the oneboxes in the DOM instead of just the ones in the preview. Also refactored the logic to count up to 'max_oneboxes_per_post` instead of down to 0. That also ensured we don't load 11 oneboxes when the setting is limiting to 10.
This commit is contained in:
@@ -1026,39 +1026,37 @@ export default Ember.Component.extend({
|
|||||||
Ember.run.debounce(
|
Ember.run.debounce(
|
||||||
this,
|
this,
|
||||||
() => {
|
() => {
|
||||||
const inlineOneboxes = {};
|
|
||||||
const oneboxes = {};
|
const oneboxes = {};
|
||||||
|
const inlineOneboxes = {};
|
||||||
|
|
||||||
let oneboxLeft =
|
// Oneboxes = `a.onebox` -> `a.onebox-loading` -> `aside.onebox`
|
||||||
this.siteSettings.max_oneboxes_per_post -
|
// Inline Oneboxes = `a.inline-onebox-loading` -> `a.inline-onebox`
|
||||||
$(
|
|
||||||
`aside.onebox, a.${INLINE_ONEBOX_CSS_CLASS}, a.${LOADING_ONEBOX_CSS_CLASS}`
|
let loadedOneboxes = $preview.find(
|
||||||
).length;
|
`aside.onebox, a.${LOADING_ONEBOX_CSS_CLASS}, a.${INLINE_ONEBOX_CSS_CLASS}`
|
||||||
|
).length;
|
||||||
|
|
||||||
$preview
|
$preview
|
||||||
.find(`a.${INLINE_ONEBOX_LOADING_CSS_CLASS}, a.onebox`)
|
.find(`a.onebox, a.${INLINE_ONEBOX_LOADING_CSS_CLASS}`)
|
||||||
.each((_index, link) => {
|
.each((_, link) => {
|
||||||
const $link = $(link);
|
const $link = $(link);
|
||||||
const text = $link.text();
|
const text = $link.text();
|
||||||
|
|
||||||
const isInline =
|
const isInline =
|
||||||
$link.attr("class") === INLINE_ONEBOX_LOADING_CSS_CLASS;
|
$link.attr("class") === INLINE_ONEBOX_LOADING_CSS_CLASS;
|
||||||
|
const m = isInline ? inlineOneboxes : oneboxes;
|
||||||
|
|
||||||
const map = isInline ? inlineOneboxes : oneboxes;
|
if (loadedOneboxes < this.siteSettings.max_oneboxes_per_post) {
|
||||||
|
if (m[text] === undefined) {
|
||||||
if (oneboxLeft <= 0) {
|
m[text] = [];
|
||||||
if (map[text] !== undefined) {
|
loadedOneboxes++;
|
||||||
map[text].push(link);
|
}
|
||||||
|
m[text].push(link);
|
||||||
|
} else {
|
||||||
|
if (m[text] !== undefined) {
|
||||||
|
m[text].push(link);
|
||||||
} else if (isInline) {
|
} else if (isInline) {
|
||||||
$link.removeClass(INLINE_ONEBOX_LOADING_CSS_CLASS);
|
$link.removeClass(INLINE_ONEBOX_LOADING_CSS_CLASS);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (!map[text]) {
|
|
||||||
map[text] = [];
|
|
||||||
oneboxLeft--;
|
|
||||||
}
|
|
||||||
|
|
||||||
map[text].push(link);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1072,6 +1070,7 @@ export default Ember.Component.extend({
|
|||||||
},
|
},
|
||||||
450
|
450
|
||||||
);
|
);
|
||||||
|
|
||||||
// Short upload urls need resolution
|
// Short upload urls need resolution
|
||||||
resolveAllShortUrls(ajax);
|
resolveAllShortUrls(ajax);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user