mirror of
https://github.com/discourse/discourse.git
synced 2025-04-26 13:04:27 +08:00
FIX: add option for the oneboxer to be synchronous
This commit is contained in:
parent
6461021046
commit
bf9e59eda9
app/assets/javascripts
@ -60,7 +60,7 @@ export default Ember.Component.extend({
|
|||||||
const link = document.createElement('a');
|
const link = document.createElement('a');
|
||||||
link.href = this.get('composer.title');
|
link.href = this.get('composer.title');
|
||||||
|
|
||||||
let loadOnebox = load(link, false, ajax, this.currentUser.id);
|
let loadOnebox = load(link, false, ajax, this.currentUser.id, true);
|
||||||
|
|
||||||
if (loadOnebox && loadOnebox.then) {
|
if (loadOnebox && loadOnebox.then) {
|
||||||
loadOnebox.then( () => {
|
loadOnebox.then( () => {
|
||||||
|
@ -11,7 +11,7 @@ function loadNext(ajax) {
|
|||||||
|
|
||||||
let timeoutMs = 150;
|
let timeoutMs = 150;
|
||||||
let removeLoading = true;
|
let removeLoading = true;
|
||||||
const { url, refresh, elem, userId } = loadingQueue.shift();
|
const { url, refresh, $elem, userId } = loadingQueue.shift();
|
||||||
|
|
||||||
// Retrieve the onebox
|
// Retrieve the onebox
|
||||||
return ajax("/onebox", {
|
return ajax("/onebox", {
|
||||||
@ -20,32 +20,32 @@ function loadNext(ajax) {
|
|||||||
cache: true
|
cache: true
|
||||||
}).then(html => {
|
}).then(html => {
|
||||||
localCache[url] = html;
|
localCache[url] = html;
|
||||||
elem.replaceWith(html);
|
$elem.replaceWith(html);
|
||||||
}, result => {
|
}, result => {
|
||||||
if (result && result.jqXHR && result.jqXHR.status === 429) {
|
if (result && result.jqXHR && result.jqXHR.status === 429) {
|
||||||
timeoutMs = 2000;
|
timeoutMs = 2000;
|
||||||
removeLoading = false;
|
removeLoading = false;
|
||||||
loadingQueue.unshift({ url, refresh, elem, userId });
|
loadingQueue.unshift({ url, refresh, $elem, userId });
|
||||||
} else {
|
} else {
|
||||||
failedCache[url] = true;
|
failedCache[url] = true;
|
||||||
}
|
}
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
timeout = Ember.run.later(() => loadNext(ajax), timeoutMs);
|
timeout = Ember.run.later(() => loadNext(ajax), timeoutMs);
|
||||||
if (removeLoading) {
|
if (removeLoading) {
|
||||||
elem.removeClass('loading-onebox');
|
$elem.removeClass('loading-onebox');
|
||||||
elem.data('onebox-loaded');
|
$elem.data('onebox-loaded');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform a lookup of a onebox based an anchor element.
|
// Perform a lookup of a onebox based an anchor $element.
|
||||||
// It will insert a loading indicator and remove it when the loading is complete or fails.
|
// It will insert a loading indicator and remove it when the loading is complete or fails.
|
||||||
export function load(e, refresh, ajax, userId) {
|
export function load(e, refresh, ajax, userId, synchronous) {
|
||||||
const elem = $(e);
|
const $elem = $(e);
|
||||||
|
|
||||||
// If the onebox has loaded or is loading, return
|
// If the onebox has loaded or is loading, return
|
||||||
if (elem.data('onebox-loaded')) return;
|
if ($elem.data('onebox-loaded')) return;
|
||||||
if (elem.hasClass('loading-onebox')) return;
|
if ($elem.hasClass('loading-onebox')) return;
|
||||||
|
|
||||||
const url = e.href;
|
const url = e.href;
|
||||||
|
|
||||||
@ -61,16 +61,16 @@ export function load(e, refresh, ajax, userId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add the loading CSS class
|
// Add the loading CSS class
|
||||||
elem.addClass('loading-onebox');
|
$elem.addClass('loading-onebox');
|
||||||
|
|
||||||
// Add to the loading queue
|
// Add to the loading queue
|
||||||
loadingQueue.push({ url, refresh, elem, userId });
|
loadingQueue.push({ url, refresh, $elem, userId });
|
||||||
|
|
||||||
// Load next url in queue
|
// Load next url in queue
|
||||||
if (timeout) {
|
if (synchronous) {
|
||||||
return Ember.run.later(() => loadNext(ajax), 150);
|
|
||||||
} else {
|
|
||||||
return loadNext(ajax);
|
return loadNext(ajax);
|
||||||
|
} else {
|
||||||
|
timeout = timeout || Ember.run.later(() => loadNext(ajax), 150);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user