Skip to content

Commit

Permalink
Bump: v0.1.5
Browse files Browse the repository at this point in the history
compatible with Axios
  • Loading branch information
luventa committed Feb 19, 2017
1 parent 98d3bf9 commit 9b1827f
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 23 deletions.
42 changes: 32 additions & 10 deletions dist/vue-nprogress.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* nprogress v0.1.4
* nprogress v0.1.5
* https://github.com/vue-bulma/nprogress
* Released under the MIT License.
*/
Expand Down Expand Up @@ -80,17 +80,37 @@ function install(Vue) {
_this._nprogress = np;
np.init(_this);

var http = applyOnHttp && Vue.http;
if (http) {
http.interceptors.push(function (request, next) {
var showProgressBar = 'showProgressBar' in request ? request.showProgressBar : applyOnHttp;
if (showProgressBar) initProgress();
if (applyOnHttp) {
var http = Vue.http;
var axios = Vue.axios;

next(function (response) {
if (!showProgressBar) return response;
increase();
if (http) {
http.interceptors.push(function (request, next) {
var showProgressBar = 'showProgressBar' in request ? request.showProgressBar : applyOnHttp;
if (showProgressBar) initProgress();

next(function (response) {
if (!showProgressBar) return response;
increase();
});
});
});
} else if (axios) {
axios.interceptors.request.use(function (request) {
if (!('showProgressBar' in request)) request.showProgressBar = applyOnHttp;
if (request.showProgressBar) initProgress();
return request;
}, function (error) {
return Promise.reject(error);
});

axios.interceptors.response.use(function (response) {
if (response.config.showProgressBar) increase();
return response;
}, function (error) {
if (error.config && error.config.showProgressBar) increase();
return Promise.reject(error);
});
}
}

var router = applyOnRouter && _this.$options.router;
Expand Down Expand Up @@ -124,6 +144,8 @@ function NProgress(options) {

NProgress.install = install;

NProgress.start = function () {};

Object.assign(NProgress.prototype, nprogress, {
init: function (app) {
this.app = app;
Expand Down
4 changes: 2 additions & 2 deletions dist/vue-nprogress.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-nprogress",
"version": "0.1.4",
"version": "0.1.5",
"description": "Slim progress bars is based on nprogress for Ajax'y applications",
"repository": "vue-bulma/nprogress",
"scripts": {
Expand Down
44 changes: 34 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,37 @@ function install(Vue, options = {}) {
this._nprogress = np
np.init(this)

const http = applyOnHttp && Vue.http
if (http) {
http.interceptors.push((request, next) => {
const showProgressBar = 'showProgressBar' in request ? request.showProgressBar : applyOnHttp
if (showProgressBar) initProgress()

next(response => {
if (!showProgressBar) return response
increase()
if (applyOnHttp) {
const http = Vue.http
const axios = Vue.axios

if (http) {
http.interceptors.push((request, next) => {
const showProgressBar = 'showProgressBar' in request ? request.showProgressBar : applyOnHttp
if (showProgressBar) initProgress()

next(response => {
if (!showProgressBar) return response
increase()
})
})
})
} else if (axios) {
axios.interceptors.request.use((request) => {
if (!('showProgressBar' in request)) request.showProgressBar = applyOnHttp
if (request.showProgressBar) initProgress()
return request
}, (error) => {
return Promise.reject(error)
})

axios.interceptors.response.use((response) => {
if (response.config.showProgressBar) increase()
return response
}, (error) => {
if (error.config && error.config.showProgressBar) increase()
return Promise.reject(error)
})
}
}

const router = applyOnRouter && this.$options.router
Expand Down Expand Up @@ -101,6 +121,10 @@ function NProgress(options) {

NProgress.install = install

NProgress.start = function () {

}

Object.assign(NProgress.prototype, nprogress, {
init (app) {
this.app = app
Expand Down

0 comments on commit 9b1827f

Please sign in to comment.