Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save igolka97/79a716cfbdbadc56331c85b8086ac20d to your computer and use it in GitHub Desktop.
Save igolka97/79a716cfbdbadc56331c85b8086ac20d to your computer and use it in GitHub Desktop.
module.exports = {
http: function(cont, options, next) {
if (cont.$root.$get('nanobar.value') > 1) {
return false;
}
cont.$root.$get('nanobar').go(20)
var _options = {
url: options.url,
method: options.methos ? options.methos : 'GET',
jsonp: 'callback',
xhr: {
onprogress: function(e) {
if (e.lengthComputable && !cont._isBeingDestroyed) {
cont.$root.$set('nanobar.max', e.total);
cont.$root.$set('nanobar.value', e.loaded);
cont.$root.$get('nanobar').go(Math.round((100 / e.total) * e.loaded))
} else {
cont.$root.$set('nanobar.value', 0);
cont.$root.$get('nanobar').go(0)
this.abort()
}
},
onloadstart: function(e) {
cont.$root.$set('nanobar.value', 0);
},
onloadend: function(e) {
if(!cont._isDestroyed){
cont.$root.$set('nanobar.value', 0);
}
},
}
};
var _options = _.extend(options, _options);
cont.$http(_options).then(function(res) {
if(!cont._isDestroyed){
cont.$root.$set('nanobar.value', 0);
}
next(res.data)
}, function() {
next('error')
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment