From d255746b535a8ec7a5615ec96358a6d1c238e844 Mon Sep 17 00:00:00 2001 From: Jacob Gable Date: Tue, 7 Jan 2014 18:56:00 -0600 Subject: [PATCH] Fix hanging loading bar on deleting a post Closes #1869 - Added an additional event listener for destroy event, then a listener on the model for the sync event to finish the progress bar loader --- core/client/views/blog.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/core/client/views/blog.js b/core/client/views/blog.js index bdc8024a539f..0cd360273db4 100644 --- a/core/client/views/blog.js +++ b/core/client/views/blog.js @@ -11,12 +11,23 @@ Ghost.Views.Blog = Ghost.View.extend({ initialize: function (options) { /*jslint unparam:true*/ + var self = this, + finishProgress = function () { + NProgress.done(); + }; + + // Basic collection request/sync flow progress bar handlers this.listenTo(this.collection, 'request', function () { NProgress.start(); }); - this.listenTo(this.collection, 'sync', function () { - NProgress.done(); + this.listenTo(this.collection, 'sync', finishProgress); + + // A special case because models that are destroyed are removed from the + // collection before the sync event fires and bubbles up + this.listenTo(this.collection, 'destroy', function (model) { + self.listenToOnce(model, 'sync', finishProgress); }); + this.addSubview(new PreviewContainer({ el: '.js-content-preview', collection: this.collection })).render(); this.addSubview(new ContentList({ el: '.js-content-list', collection: this.collection })).render(); }