Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Removing JQuery's dependency from the preloading image with promises code described here : http://www.bennadel.com/blog/2597-preloading-images-in-angularjs-with-promises.htm

View vanilla-preloader
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
loadImageLocation: function loadImageLocation(imageLocation) {
 
var preloader = this;
 
 
var _onLoadHandler = function(event) {
 
// Since the load event is asynchronous, we have to
// tell AngularJS that something changed.
$rootScope.$apply(
function() {
 
preloader.handleImageLoad(event.target.src);
 
// Clean up object reference to help with the
// garbage collection in the closure.
preloader = image = event = null;
 
}
);
this.onload = null;
this.onerror = null;
};
var _onErrorHandler = function(event) {
// Since the load event is asynchronous, we have to
// tell AngularJS that something changed.
$rootScope.$apply(
function() {
 
preloader.handleImageError(event.target.src);
 
// Clean up object reference to help with the
// garbage collection in the closure.
preloader = image = event = null;
 
}
);
this.onload = null;
this.onerror = null;
 
};
// When it comes to creating the image object, it is critical that
// we bind the event handlers BEFORE we actually set the image
// source. Failure to do so will prevent the events from proper
// triggering in some browsers.
var image = new Image();
 
//Attach the loading event to the _onLoadHandler function
image.onload = _onLoadHandler;
 
//Attach the error event to the _onErrorHandler function
image.onerror = _onErrorHandler;
 
image.src = imageLocation;
 
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.