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:
Robin Ward 2013-05-20 12:20:10 -04:00
parent a3dce9afd7
commit b794830a25
17 changed files with 58 additions and 50 deletions

View File

@ -128,9 +128,9 @@ Discourse.Development = {
if (this.get('templateName') === templateName) {
this.set('templateName', 'empty');
this.rerender();
return Em.run.next(function() {
Em.run.schedule('afterRender', function() {
_this.set('templateName', templateName);
return _this.rerender();
_this.rerender();
});
}
});

View File

@ -20,7 +20,7 @@ Discourse.ApplicationController = Discourse.Controller.extend({
if (window._gaq === undefined) { return; }
if(this.afterFirstHit) {
Em.run.next(function(){
Em.run.schedule('afterRender', function() {
_gaq.push(['_trackPageview']);
});
} else {

View File

@ -84,7 +84,8 @@ Discourse.QuoteButtonController = Discourse.Controller.extend({
var markerOffset = $(markerElement).offset(),
$quoteButton = $('.quote-button');
Em.run.next(function(){
Em.run.schedule('afterRender', function() {
$quoteButton.offset({
top: markerOffset.top - $quoteButton.outerHeight() - 5,
left: markerOffset.left

View File

@ -246,7 +246,7 @@ Discourse.TopicController = Discourse.ObjectController.extend(Discourse.Selected
loadPosts: function(opts) {
var topicController = this;
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));
});
Em.run.next(function () { topicController.updateBottomBar(); });
Em.run.scheduleOnce('afterRender', topicController, 'updateBottomBar');
topicController.set('filtered_posts_count', result.filtered_posts_count);
topicController.set('loadingBelow', false);

View File

@ -40,7 +40,7 @@ Discourse.ChooseTopicView = Discourse.View.extend({
var topicId = Em.get(topic, 'id');
this.set('selectedTopicId', topicId);
Em.run.next(function() {
Em.run.schedule('afterRender', function () {
$('#choose-topic-' + topicId).prop('checked', 'true');
});

View File

@ -91,7 +91,7 @@ Discourse.ComposerView = Discourse.View.extend({
resize: function() {
// 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 h = replyControl.height() || 0;
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
var jqXHR = data.xhr();
// 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
$('#cancel-image-upload').on('click', function() {
// cancel the upload
@ -334,9 +334,11 @@ Discourse.ComposerView = Discourse.View.extend({
caretPosition = Discourse.Utilities.caretPosition(ctrl),
current = this.get('content.reply');
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

View File

@ -17,9 +17,7 @@ Discourse.ListTopicsView = Discourse.View.extend(Discourse.Scrolling, {
insertedCount: (function() {
var inserted;
inserted = this.get('controller.inserted');
if (!inserted) {
return 0;
}
if (!inserted) return 0;
return inserted.length;
}).property('controller.inserted.@each'),
@ -36,24 +34,26 @@ Discourse.ListTopicsView = Discourse.View.extend(Discourse.Scrolling, {
}).property('loading', 'controller.content.more_topics_url'),
didInsertElement: function() {
var eyeline, scrollPos,
_this = this;
this.bindScrolling();
eyeline = new Discourse.Eyeline('.topic-list-item');
var eyeline = new Discourse.Eyeline('.topic-list-item');
var listTopicsView = this;
eyeline.on('sawBottom', function() {
return _this.loadMore();
listTopicsView.loadMore();
});
if (scrollPos = Discourse.get('transient.topicListScrollPos')) {
Em.run.next(function() {
return $('html, body').scrollTop(scrollPos);
var scrollPos = Discourse.get('transient.topicListScrollPos');
if (scrollPos) {
Em.run.schedule('afterRender', function() {
$('html, body').scrollTop(scrollPos);
});
} else {
Em.run.next(function() {
return $('html, body').scrollTop(0);
Em.run.schedule('afterRender', function() {
$('html, body').scrollTop(0);
});
}
this.set('eyeline', eyeline);
return this.set('currentTopicId', null);
this.set('currentTopicId', null);
},
loadMore: function() {
@ -66,7 +66,9 @@ Discourse.ListTopicsView = Discourse.View.extend(Discourse.Scrolling, {
promise.then(function(hasMoreResults) {
listTopicsView.set('loadedMore', true);
listTopicsView.set('loading', false);
Em.run.next(function() { listTopicsView.saveScrollPos(); });
Em.run.schedule('afterRender', function() {
listTopicsView.saveScrollPos();
});
if (!hasMoreResults) {
listTopicsView.get('eyeline').flushRest();
}

View File

@ -278,11 +278,11 @@ Discourse.CreateAccountView = Discourse.ModalBodyView.extend({
didInsertElement: function(e) {
// allows the submission the form when pressing 'ENTER' on *any* text input field
// but only when the submit button is enabled
var _this = this;
return Em.run.next(function() {
return $("input[type='text'], input[type='password']").keydown(function(e) {
if (_this.get('submitDisabled') === false && e.keyCode === 13) {
return _this.createAccount();
var createAccountView = this;
Em.run.schedule('afterRender', function() {
$("input[type='text'], input[type='password']").keydown(function(e) {
if (createAccountView.get('submitDisabled') === false && e.keyCode === 13) {
createAccountView.createAccount();
}
});
});

View File

@ -35,7 +35,7 @@ Discourse.FlagView = Discourse.ModalBodyView.extend({
this.set('postActionTypeId', action.id);
this.set('isCustomFlag', action.is_custom_flag);
this.set('selected', action);
Em.run.next(function() {
Em.run.schedule('afterRender', function() {
$('#radio_' + action.name_key).prop('checked', 'true');
});
return false;

View File

@ -33,9 +33,9 @@ Discourse.InviteModalView = Discourse.ModalBodyView.extend({
}).property('email'),
didInsertElement: function() {
var _this = this;
Em.run.next(function() {
_this.$('input').focus();
var inviteModalView = this;
Em.run.schedule('afterRender', function() {
inviteModalView.$('input').focus();
});
},

View File

@ -25,9 +25,9 @@ Discourse.InvitePrivateModalView = Discourse.ModalBodyView.extend({
}).property('saving'),
didInsertElement: function() {
var _this = this;
return Em.run.next(function() {
return _this.$('input').focus();
var invitePrivateModalView = this;
Em.run.schedule('afterRender', function() {
invitePrivateModalView.$('input').focus();
});
},
@ -39,11 +39,11 @@ Discourse.InvitePrivateModalView = Discourse.ModalBodyView.extend({
this.get('topic').inviteUser(this.get('emailOrUsername')).then(function() {
// Success
_this.set('saving', false);
return _this.set('finished', true);
_this.set('finished', true);
}, function() {
// Failure
_this.set('error', true);
return _this.set('saving', false);
_this.set('saving', false);
});
return false;
}

View File

@ -161,7 +161,7 @@ Discourse.LoginView = Discourse.ModalBodyView.extend({
this.set('loginPassword', $('#hidden-login-form input[name=password]').val());
var loginView = this;
Em.run.next(function() {
Em.run.schedule('afterRender', function() {
$('#login-account-password').keydown(function(e) {
if (e.keyCode === 13) {
loginView.login();

View File

@ -11,7 +11,9 @@ Discourse.ModalBodyView = Discourse.View.extend({
// Focus on first element
didInsertElement: function() {
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

View File

@ -26,7 +26,7 @@ Discourse.ModalView = Ember.ContainerView.extend({
var modalView = this;
if (view) {
$('#modal-alert').hide();
Em.run.next(function() { modalView.$().modal('show'); });
Em.run.schedule('afterRender', function() { modalView.$().modal('show'); });
}
}.observes('controller.currentView')

View File

@ -35,7 +35,9 @@ Discourse.PostView = Discourse.View.extend({
// If the cooked content changed, add the quote controls
cookedChanged: function() {
var postView = this;
Em.run.next(function() { postView.insertQuoteControls(); });
Em.run.schedule('afterRender', function() {
postView.insertQuoteControls();
});
}.observes('post.cooked'),
init: function() {

View File

@ -13,14 +13,13 @@ Discourse.RepliesView = Ember.CollectionView.extend({
itemViewClass: Discourse.EmbeddedPostView,
repliesShown: (function() {
var $this;
$this = this.$();
var $this = this.$();
if (this.get('parentView.repliesShown')) {
Em.run.next(function() {
Em.run.schedule('afterRender', function() {
$this.slideDown();
});
} else {
Em.run.next(function() {
Em.run.schedule('afterRender', function() {
$this.slideUp();
});
}

View File

@ -29,9 +29,9 @@ Discourse.UserStreamView = Discourse.View.extend(Discourse.Scrolling, {
this.set('loading', true);
var userStreamView = this;
return this.get('controller.content').loadMoreUserActions().then(function() {
this.get('controller.content').loadMoreUserActions().then(function() {
userStreamView.set('loading', false);
Em.run.next(function() {
Em.run.schedule('afterRender', function() {
$userStreamBottom.data('loading', null);
});
});