FIX: add option for the oneboxer to be synchronous
This commit is contained in:
parent
6461021046
commit
bf9e59eda9
|
@ -60,7 +60,7 @@ export default Ember.Component.extend({
|
|||
const link = document.createElement('a');
|
||||
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) {
|
||||
loadOnebox.then( () => {
|
||||
|
|
|
@ -11,7 +11,7 @@ function loadNext(ajax) {
|
|||
|
||||
let timeoutMs = 150;
|
||||
let removeLoading = true;
|
||||
const { url, refresh, elem, userId } = loadingQueue.shift();
|
||||
const { url, refresh, $elem, userId } = loadingQueue.shift();
|
||||
|
||||
// Retrieve the onebox
|
||||
return ajax("/onebox", {
|
||||
|
@ -20,32 +20,32 @@ function loadNext(ajax) {
|
|||
cache: true
|
||||
}).then(html => {
|
||||
localCache[url] = html;
|
||||
elem.replaceWith(html);
|
||||
$elem.replaceWith(html);
|
||||
}, result => {
|
||||
if (result && result.jqXHR && result.jqXHR.status === 429) {
|
||||
timeoutMs = 2000;
|
||||
removeLoading = false;
|
||||
loadingQueue.unshift({ url, refresh, elem, userId });
|
||||
loadingQueue.unshift({ url, refresh, $elem, userId });
|
||||
} else {
|
||||
failedCache[url] = true;
|
||||
}
|
||||
}).finally(() => {
|
||||
timeout = Ember.run.later(() => loadNext(ajax), timeoutMs);
|
||||
if (removeLoading) {
|
||||
elem.removeClass('loading-onebox');
|
||||
elem.data('onebox-loaded');
|
||||
$elem.removeClass('loading-onebox');
|
||||
$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.
|
||||
export function load(e, refresh, ajax, userId) {
|
||||
const elem = $(e);
|
||||
export function load(e, refresh, ajax, userId, synchronous) {
|
||||
const $elem = $(e);
|
||||
|
||||
// If the onebox has loaded or is loading, return
|
||||
if (elem.data('onebox-loaded')) return;
|
||||
if (elem.hasClass('loading-onebox')) return;
|
||||
if ($elem.data('onebox-loaded')) return;
|
||||
if ($elem.hasClass('loading-onebox')) return;
|
||||
|
||||
const url = e.href;
|
||||
|
||||
|
@ -61,16 +61,16 @@ export function load(e, refresh, ajax, userId) {
|
|||
}
|
||||
|
||||
// Add the loading CSS class
|
||||
elem.addClass('loading-onebox');
|
||||
$elem.addClass('loading-onebox');
|
||||
|
||||
// Add to the loading queue
|
||||
loadingQueue.push({ url, refresh, elem, userId });
|
||||
loadingQueue.push({ url, refresh, $elem, userId });
|
||||
|
||||
// Load next url in queue
|
||||
if (timeout) {
|
||||
return Ember.run.later(() => loadNext(ajax), 150);
|
||||
} else {
|
||||
if (synchronous) {
|
||||
return loadNext(ajax);
|
||||
} else {
|
||||
timeout = timeout || Ember.run.later(() => loadNext(ajax), 150);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue