-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathangular-skycons.js
More file actions
78 lines (65 loc) · 2.29 KB
/
angular-skycons.js
File metadata and controls
78 lines (65 loc) · 2.29 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
var angularSkycons = angular.module( "angular-skycons", [] );
angularSkycons.directive( "skycon", function () {
return {
restrict: "E",
replace: true,
scope: {
icon: "=",
size: "=",
animated: "=",
color: "="
},
link: function ( scope, element, attrs ) {
// make a canvas for our icon
var canvas = document.createElement( "canvas" );
// set the CSS class from attribute
if ( !attrs.class ) {
canvas.className = "";
} else {
canvas.className = attrs.class;
}
// set default color if "color" attribute not present
var config = {
color: scope.color || "black"
};
var skycons = new Skycons( config );
// watch the size property from the controller
scope.$watch( "size", function ( newVal, oldVal ) {
if ( newVal ) {
canvas.height = newVal;
canvas.width = newVal;
} else {
canvas.height = scope.size || 64;
canvas.width = scope.size || 64;
}
}, true );
// add the animation
skycons.add( canvas, scope.icon );
// watch the icon property from the controller for changes
scope.$watch( "icon", function () {
skycons.set( canvas, scope.icon );
}, true );
// watch the color property from the controller for changes
scope.$watch( "color", function () {
skycons.color = scope.color;
}, true );
if (scope.animated === "false" || scope.animated === false) {
skycons.pause();
}
else {
skycons.play();
}
if ( element[0].nodeType === 8 ) {
element.replaceWith( canvas );
} else {
element[0].appendChild( canvas );
}
scope.$on("$destroy", function () {
skycons.remove(canvas);
if (skycons.list.length === 0) {
skycons.pause(canvas);
}
});
}
};
} );