-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathng-img-preload.js
39 lines (34 loc) · 1.11 KB
/
ng-img-preload.js
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
(function(angular){
"use strict";
angular
.module("ng.img.preloader", [])
.directive("replaceWith", function(){
return {
restrict: "A",
replace: false,
link: function(scope, elem, attrs){
var elemCopy = angular.copy(elem);
elemCopy.one("load", function(){
angular.element(elem).replaceWith(elemCopy);
});
elemCopy.attr('src', attrs.imagePreloader);
elemCopy.on("error", function(){
var fallback = angular.isDefined(attrs.fallback) ? attrs.fallback : null;
angular.element(elem).attr("src", fallback);
});
}
}
})
.directive("replaceFade", function(){
return {
restrict: "A",
replace: false,
link: link
};
function link(scope, elem, attrs){
console.log("Hey");
}
})
})(angular);
// Dir 1 -> src:placeholder, imgUrl:actualUrl - > replace img on load
// Dir 2 -> src:actual-img, fallback:placeholder.png