Skip to content

Commit

Permalink
Merge pull request TryGhost#2032 from hswolff/fix-2011
Browse files Browse the repository at this point in the history
Have NProgress called for all ajax calls
  • Loading branch information
ErisDS committed Jan 26, 2014
2 parents 951385e + 0ea22ab commit 98d9012
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions core/client/models/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,29 @@
"use strict";
NProgress.configure({ showSpinner: false });

Ghost.ProgressModel = Backbone.Model.extend({

// Adds in a call to start a loading bar
// This is sets up a success function which completes the loading bar
fetch : function (options) {
options = options || {};

// Adds in a call to start a loading bar
// This is sets up a success function which completes the loading bar
function wrapSync(method, model, options) {
if (options !== undefined && _.isObject(options)) {
NProgress.start();

var self = this,
oldSuccess = options.success;

options.success = function () {
NProgress.done();
return oldSuccess.apply(self, arguments);
};

return Backbone.Model.prototype.fetch.call(this, options);
}
});

Ghost.ProgressCollection = Backbone.Collection.extend({

// Adds in a call to start a loading bar
// This is sets up a success function which completes the loading bar
fetch : function (options) {
options = options || {};
return Backbone.sync.call(this, method, model, options);
}

NProgress.start();

options.success = function () {
NProgress.done();
};
Ghost.ProgressModel = Backbone.Model.extend({
sync: wrapSync
});

return Backbone.Collection.prototype.fetch.call(this, options);
}
Ghost.ProgressCollection = Backbone.Collection.extend({
sync: wrapSync
});
}());

0 comments on commit 98d9012

Please sign in to comment.