Replaced `Em.run.next` with the more proper `Em.run.schedule('afterRender')`
when we are waiting for rendering to finish.
This commit is contained in:
parent
a3dce9afd7
commit
b794830a25
|
@ -128,9 +128,9 @@ Discourse.Development = {
|
||||||
if (this.get('templateName') === templateName) {
|
if (this.get('templateName') === templateName) {
|
||||||
this.set('templateName', 'empty');
|
this.set('templateName', 'empty');
|
||||||
this.rerender();
|
this.rerender();
|
||||||
return Em.run.next(function() {
|
Em.run.schedule('afterRender', function() {
|
||||||
_this.set('templateName', templateName);
|
_this.set('templateName', templateName);
|
||||||
return _this.rerender();
|
_this.rerender();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -20,7 +20,7 @@ Discourse.ApplicationController = Discourse.Controller.extend({
|
||||||
if (window._gaq === undefined) { return; }
|
if (window._gaq === undefined) { return; }
|
||||||
|
|
||||||
if(this.afterFirstHit) {
|
if(this.afterFirstHit) {
|
||||||
Em.run.next(function(){
|
Em.run.schedule('afterRender', function() {
|
||||||
_gaq.push(['_trackPageview']);
|
_gaq.push(['_trackPageview']);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -84,7 +84,8 @@ Discourse.QuoteButtonController = Discourse.Controller.extend({
|
||||||
var markerOffset = $(markerElement).offset(),
|
var markerOffset = $(markerElement).offset(),
|
||||||
$quoteButton = $('.quote-button');
|
$quoteButton = $('.quote-button');
|
||||||
|
|
||||||
Em.run.next(function(){
|
|
||||||
|
Em.run.schedule('afterRender', function() {
|
||||||
$quoteButton.offset({
|
$quoteButton.offset({
|
||||||
top: markerOffset.top - $quoteButton.outerHeight() - 5,
|
top: markerOffset.top - $quoteButton.outerHeight() - 5,
|
||||||
left: markerOffset.left
|
left: markerOffset.left
|
||||||
|
|
|
@ -246,7 +246,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
|
||||||
loadPosts: function(opts) {
|
loadPosts: function(opts) {
|
||||||
var topicController = this;
|
var topicController = this;
|
||||||
this.get('content').loadPosts(opts).then(function () {
|
this.get('content').loadPosts(opts).then(function () {
|
||||||
Em.run.next(function () { topicController.updateBottomBar(); });
|
Em.run.scheduleOnce('afterRender', topicController, 'updateBottomBar');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -276,7 +276,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
|
||||||
posts.pushObject(Discourse.Post.create(p, topic));
|
posts.pushObject(Discourse.Post.create(p, topic));
|
||||||
});
|
});
|
||||||
|
|
||||||
Em.run.next(function () { topicController.updateBottomBar(); });
|
Em.run.scheduleOnce('afterRender', topicController, 'updateBottomBar');
|
||||||
|
|
||||||
topicController.set('filtered_posts_count', result.filtered_posts_count);
|
topicController.set('filtered_posts_count', result.filtered_posts_count);
|
||||||
topicController.set('loadingBelow', false);
|
topicController.set('loadingBelow', false);
|
||||||
|
|
|
@ -40,7 +40,7 @@ Discourse.ChooseTopicView = Discourse.View.extend({
|
||||||
var topicId = Em.get(topic, 'id');
|
var topicId = Em.get(topic, 'id');
|
||||||
this.set('selectedTopicId', topicId);
|
this.set('selectedTopicId', topicId);
|
||||||
|
|
||||||
Em.run.next(function() {
|
Em.run.schedule('afterRender', function () {
|
||||||
$('#choose-topic-' + topicId).prop('checked', 'true');
|
$('#choose-topic-' + topicId).prop('checked', 'true');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ Discourse.ComposerView = Discourse.View.extend({
|
||||||
|
|
||||||
resize: function() {
|
resize: function() {
|
||||||
// this still needs to wait on animations, need a clean way to do that
|
// this still needs to wait on animations, need a clean way to do that
|
||||||
return Em.run.next(null, function() {
|
return Em.run.schedule('afterRender', function() {
|
||||||
var replyControl = $('#reply-control');
|
var replyControl = $('#reply-control');
|
||||||
var h = replyControl.height() || 0;
|
var h = replyControl.height() || 0;
|
||||||
var sizePx = "" + h + "px";
|
var sizePx = "" + h + "px";
|
||||||
|
@ -263,7 +263,7 @@ Discourse.ComposerView = Discourse.View.extend({
|
||||||
// cf. https://github.com/blueimp/jQuery-File-Upload/wiki/API#how-to-cancel-an-upload
|
// cf. https://github.com/blueimp/jQuery-File-Upload/wiki/API#how-to-cancel-an-upload
|
||||||
var jqXHR = data.xhr();
|
var jqXHR = data.xhr();
|
||||||
// need to wait for the link to show up in the DOM
|
// need to wait for the link to show up in the DOM
|
||||||
Em.run.next(function() {
|
Em.run.schedule('afterRender', function() {
|
||||||
// bind on the click event on the cancel link
|
// bind on the click event on the cancel link
|
||||||
$('#cancel-image-upload').on('click', function() {
|
$('#cancel-image-upload').on('click', function() {
|
||||||
// cancel the upload
|
// cancel the upload
|
||||||
|
@ -334,9 +334,11 @@ Discourse.ComposerView = Discourse.View.extend({
|
||||||
caretPosition = Discourse.Utilities.caretPosition(ctrl),
|
caretPosition = Discourse.Utilities.caretPosition(ctrl),
|
||||||
current = this.get('content.reply');
|
current = this.get('content.reply');
|
||||||
this.set('content.reply', current.substring(0, caretPosition) + text + current.substring(caretPosition, current.length));
|
this.set('content.reply', current.substring(0, caretPosition) + text + current.substring(caretPosition, current.length));
|
||||||
return Em.run.next(function() {
|
|
||||||
return Discourse.Utilities.setCaretPosition(ctrl, caretPosition + text.length);
|
Em.run.schedule('afterRender', function() {
|
||||||
|
Discourse.Utilities.setCaretPosition(ctrl, caretPosition + text.length);
|
||||||
});
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Uses javascript to get the image sizes from the preview, if present
|
// Uses javascript to get the image sizes from the preview, if present
|
||||||
|
|
|
@ -17,9 +17,7 @@ Discourse.ListTopicsView = Discourse.View.extend(Discourse.Scrolling, {
|
||||||
insertedCount: (function() {
|
insertedCount: (function() {
|
||||||
var inserted;
|
var inserted;
|
||||||
inserted = this.get('controller.inserted');
|
inserted = this.get('controller.inserted');
|
||||||
if (!inserted) {
|
if (!inserted) return 0;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
return inserted.length;
|
return inserted.length;
|
||||||
}).property('controller.inserted.@each'),
|
}).property('controller.inserted.@each'),
|
||||||
|
|
||||||
|
@ -36,24 +34,26 @@ Discourse.ListTopicsView = Discourse.View.extend(Discourse.Scrolling, {
|
||||||
}).property('loading', 'controller.content.more_topics_url'),
|
}).property('loading', 'controller.content.more_topics_url'),
|
||||||
|
|
||||||
didInsertElement: function() {
|
didInsertElement: function() {
|
||||||
var eyeline, scrollPos,
|
|
||||||
_this = this;
|
|
||||||
this.bindScrolling();
|
this.bindScrolling();
|
||||||
eyeline = new Discourse.Eyeline('.topic-list-item');
|
var eyeline = new Discourse.Eyeline('.topic-list-item');
|
||||||
|
|
||||||
|
var listTopicsView = this;
|
||||||
eyeline.on('sawBottom', function() {
|
eyeline.on('sawBottom', function() {
|
||||||
return _this.loadMore();
|
listTopicsView.loadMore();
|
||||||
});
|
});
|
||||||
if (scrollPos = Discourse.get('transient.topicListScrollPos')) {
|
|
||||||
Em.run.next(function() {
|
var scrollPos = Discourse.get('transient.topicListScrollPos');
|
||||||
return $('html, body').scrollTop(scrollPos);
|
if (scrollPos) {
|
||||||
|
Em.run.schedule('afterRender', function() {
|
||||||
|
$('html, body').scrollTop(scrollPos);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Em.run.next(function() {
|
Em.run.schedule('afterRender', function() {
|
||||||
return $('html, body').scrollTop(0);
|
$('html, body').scrollTop(0);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.set('eyeline', eyeline);
|
this.set('eyeline', eyeline);
|
||||||
return this.set('currentTopicId', null);
|
this.set('currentTopicId', null);
|
||||||
},
|
},
|
||||||
|
|
||||||
loadMore: function() {
|
loadMore: function() {
|
||||||
|
@ -66,7 +66,9 @@ Discourse.ListTopicsView = Discourse.View.extend(Discourse.Scrolling, {
|
||||||
promise.then(function(hasMoreResults) {
|
promise.then(function(hasMoreResults) {
|
||||||
listTopicsView.set('loadedMore', true);
|
listTopicsView.set('loadedMore', true);
|
||||||
listTopicsView.set('loading', false);
|
listTopicsView.set('loading', false);
|
||||||
Em.run.next(function() { listTopicsView.saveScrollPos(); });
|
Em.run.schedule('afterRender', function() {
|
||||||
|
listTopicsView.saveScrollPos();
|
||||||
|
});
|
||||||
if (!hasMoreResults) {
|
if (!hasMoreResults) {
|
||||||
listTopicsView.get('eyeline').flushRest();
|
listTopicsView.get('eyeline').flushRest();
|
||||||
}
|
}
|
||||||
|
|
|
@ -278,11 +278,11 @@ Discourse.CreateAccountView = Discourse.ModalBodyView.extend({
|
||||||
didInsertElement: function(e) {
|
didInsertElement: function(e) {
|
||||||
// allows the submission the form when pressing 'ENTER' on *any* text input field
|
// allows the submission the form when pressing 'ENTER' on *any* text input field
|
||||||
// but only when the submit button is enabled
|
// but only when the submit button is enabled
|
||||||
var _this = this;
|
var createAccountView = this;
|
||||||
return Em.run.next(function() {
|
Em.run.schedule('afterRender', function() {
|
||||||
return $("input[type='text'], input[type='password']").keydown(function(e) {
|
$("input[type='text'], input[type='password']").keydown(function(e) {
|
||||||
if (_this.get('submitDisabled') === false && e.keyCode === 13) {
|
if (createAccountView.get('submitDisabled') === false && e.keyCode === 13) {
|
||||||
return _this.createAccount();
|
createAccountView.createAccount();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -35,7 +35,7 @@ Discourse.FlagView = Discourse.ModalBodyView.extend({
|
||||||
this.set('postActionTypeId', action.id);
|
this.set('postActionTypeId', action.id);
|
||||||
this.set('isCustomFlag', action.is_custom_flag);
|
this.set('isCustomFlag', action.is_custom_flag);
|
||||||
this.set('selected', action);
|
this.set('selected', action);
|
||||||
Em.run.next(function() {
|
Em.run.schedule('afterRender', function() {
|
||||||
$('#radio_' + action.name_key).prop('checked', 'true');
|
$('#radio_' + action.name_key).prop('checked', 'true');
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
|
@ -45,7 +45,7 @@ Discourse.FlagView = Discourse.ModalBodyView.extend({
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
|
||||||
var action = this.get('selected');
|
var action = this.get('selected');
|
||||||
var postAction = this.get('post.actionByName.' + (action.get('name_key')));
|
var postAction = this.get('post.actionByName.' + (action.get('name_key')));
|
||||||
|
|
||||||
var actionType = Discourse.get('site').postActionTypeById(this.get('postActionTypeId'));
|
var actionType = Discourse.get('site').postActionTypeById(this.get('postActionTypeId'));
|
||||||
if (postAction) {
|
if (postAction) {
|
||||||
|
|
|
@ -33,9 +33,9 @@ Discourse.InviteModalView = Discourse.ModalBodyView.extend({
|
||||||
}).property('email'),
|
}).property('email'),
|
||||||
|
|
||||||
didInsertElement: function() {
|
didInsertElement: function() {
|
||||||
var _this = this;
|
var inviteModalView = this;
|
||||||
Em.run.next(function() {
|
Em.run.schedule('afterRender', function() {
|
||||||
_this.$('input').focus();
|
inviteModalView.$('input').focus();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -25,9 +25,9 @@ Discourse.InvitePrivateModalView = Discourse.ModalBodyView.extend({
|
||||||
}).property('saving'),
|
}).property('saving'),
|
||||||
|
|
||||||
didInsertElement: function() {
|
didInsertElement: function() {
|
||||||
var _this = this;
|
var invitePrivateModalView = this;
|
||||||
return Em.run.next(function() {
|
Em.run.schedule('afterRender', function() {
|
||||||
return _this.$('input').focus();
|
invitePrivateModalView.$('input').focus();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -39,11 +39,11 @@ Discourse.InvitePrivateModalView = Discourse.ModalBodyView.extend({
|
||||||
this.get('topic').inviteUser(this.get('emailOrUsername')).then(function() {
|
this.get('topic').inviteUser(this.get('emailOrUsername')).then(function() {
|
||||||
// Success
|
// Success
|
||||||
_this.set('saving', false);
|
_this.set('saving', false);
|
||||||
return _this.set('finished', true);
|
_this.set('finished', true);
|
||||||
}, function() {
|
}, function() {
|
||||||
// Failure
|
// Failure
|
||||||
_this.set('error', true);
|
_this.set('error', true);
|
||||||
return _this.set('saving', false);
|
_this.set('saving', false);
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -161,7 +161,7 @@ Discourse.LoginView = Discourse.ModalBodyView.extend({
|
||||||
this.set('loginPassword', $('#hidden-login-form input[name=password]').val());
|
this.set('loginPassword', $('#hidden-login-form input[name=password]').val());
|
||||||
|
|
||||||
var loginView = this;
|
var loginView = this;
|
||||||
Em.run.next(function() {
|
Em.run.schedule('afterRender', function() {
|
||||||
$('#login-account-password').keydown(function(e) {
|
$('#login-account-password').keydown(function(e) {
|
||||||
if (e.keyCode === 13) {
|
if (e.keyCode === 13) {
|
||||||
loginView.login();
|
loginView.login();
|
||||||
|
|
|
@ -11,7 +11,9 @@ Discourse.ModalBodyView = Discourse.View.extend({
|
||||||
// Focus on first element
|
// Focus on first element
|
||||||
didInsertElement: function() {
|
didInsertElement: function() {
|
||||||
var modalBodyView = this;
|
var modalBodyView = this;
|
||||||
Em.run.next(function() { modalBodyView.$('form input:first').focus(); });
|
Em.run.schedule('afterRender', function() {
|
||||||
|
modalBodyView.$('form input:first').focus();
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Pass the errors to our errors view
|
// Pass the errors to our errors view
|
||||||
|
|
|
@ -26,7 +26,7 @@ Discourse.ModalView = Ember.ContainerView.extend({
|
||||||
var modalView = this;
|
var modalView = this;
|
||||||
if (view) {
|
if (view) {
|
||||||
$('#modal-alert').hide();
|
$('#modal-alert').hide();
|
||||||
Em.run.next(function() { modalView.$().modal('show'); });
|
Em.run.schedule('afterRender', function() { modalView.$().modal('show'); });
|
||||||
}
|
}
|
||||||
}.observes('controller.currentView')
|
}.observes('controller.currentView')
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,9 @@ Discourse.PostView = Discourse.View.extend({
|
||||||
// If the cooked content changed, add the quote controls
|
// If the cooked content changed, add the quote controls
|
||||||
cookedChanged: function() {
|
cookedChanged: function() {
|
||||||
var postView = this;
|
var postView = this;
|
||||||
Em.run.next(function() { postView.insertQuoteControls(); });
|
Em.run.schedule('afterRender', function() {
|
||||||
|
postView.insertQuoteControls();
|
||||||
|
});
|
||||||
}.observes('post.cooked'),
|
}.observes('post.cooked'),
|
||||||
|
|
||||||
init: function() {
|
init: function() {
|
||||||
|
|
|
@ -13,14 +13,13 @@ Discourse.RepliesView = Ember.CollectionView.extend({
|
||||||
itemViewClass: Discourse.EmbeddedPostView,
|
itemViewClass: Discourse.EmbeddedPostView,
|
||||||
|
|
||||||
repliesShown: (function() {
|
repliesShown: (function() {
|
||||||
var $this;
|
var $this = this.$();
|
||||||
$this = this.$();
|
|
||||||
if (this.get('parentView.repliesShown')) {
|
if (this.get('parentView.repliesShown')) {
|
||||||
Em.run.next(function() {
|
Em.run.schedule('afterRender', function() {
|
||||||
$this.slideDown();
|
$this.slideDown();
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
Em.run.next(function() {
|
Em.run.schedule('afterRender', function() {
|
||||||
$this.slideUp();
|
$this.slideUp();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,9 +29,9 @@ Discourse.UserStreamView = Discourse.View.extend(Discourse.Scrolling, {
|
||||||
this.set('loading', true);
|
this.set('loading', true);
|
||||||
|
|
||||||
var userStreamView = this;
|
var userStreamView = this;
|
||||||
return this.get('controller.content').loadMoreUserActions().then(function() {
|
this.get('controller.content').loadMoreUserActions().then(function() {
|
||||||
userStreamView.set('loading', false);
|
userStreamView.set('loading', false);
|
||||||
Em.run.next(function() {
|
Em.run.schedule('afterRender', function() {
|
||||||
$userStreamBottom.data('loading', null);
|
$userStreamBottom.data('loading', null);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue