Ghost/ghost/admin/models/base.js
Harry Wolff ba386f1e37 Have NProgress called for all ajax calls
fixes #2011

- rather than trigger NProgress for fetch calls
 I’ve moved it to be used for all sync calls

- issue #2011 was a result of NProgress only being
 called during a fetch() call, which when saving
 is not used - save() is.  Sync is used by all
 ajax calls.
2014-01-26 00:09:01 -05:00

32 lines
921 B
JavaScript

/*global window, document, setTimeout, Ghost, $, _, Backbone, JST, shortcut, NProgress */
(function () {
"use strict";
NProgress.configure({ showSpinner: false });
// 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.sync.call(this, method, model, options);
}
Ghost.ProgressModel = Backbone.Model.extend({
sync: wrapSync
});
Ghost.ProgressCollection = Backbone.Collection.extend({
sync: wrapSync
});
}());