Created
April 10, 2016 07:25
-
-
Save ljanecek/3de39c2a38941d3b8ba5d03159eb2b1d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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