This repository has been archived by the owner on Nov 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
blocks_1.js
110 lines (88 loc) · 2.43 KB
/
blocks_1.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
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
angular
.module("app", ["ngAnimate"])
.controller("MainController", MainController)
.directive("animationStatus", animationStatus);
function MainController($scope) {
// View Model
var vm = this;
var orangeLookup = {};
var purpleLookup = {};
vm.status = {
running: false
};
vm.orangeBlock = [
{ name: "move", status: "--" },
{ name: "rotate", status: "--" },
{ name: "scale", status: "--" },
{ name: "fade", status: "--" }
];
vm.purpleBlock = [
{ name: "move", status: "--" },
{ name: "rotate", status: "--" },
{ name: "scale", status: "--" },
{ name: "fade", status: "--" }
];
vm.animate = startAnimations;
vm.reset = reset;
$scope.$on("animation-update", updateStatus);
activate();
/////////
function activate() {
// Creates a lookup object of the animation models above
// so we won't have to search for a key in those arrays
for (var i = 0; i < vm.orangeBlock.length; i++) {
orangeLookup[vm.orangeBlock[i].name] = vm.orangeBlock[i];
purpleLookup[vm.purpleBlock[i].name] = vm.purpleBlock[i];
}
}
function updateStatus(event, data) {
// Data here is passed from the animation module
if (data.lookup === "orangeLookup") {
orangeLookup[data.animation].status = data.status;
} else {
purpleLookup[data.animation].status = data.status;
}
}
function updateAll(status) {
// Resets the status property for the animations
vm.orangeBlock.forEach(function(animation) {
animation.status = status;
});
vm.purpleBlock.forEach(function(animation) {
animation.status = status;
});
}
function startAnimations() {
reset();
updateAll("Queued");
// Broadcast sends events DOWN your scope
$scope.$broadcast("start-animations");
}
function reset() {
updateAll("--");
$scope.$broadcast("reset-animations");
}
}
// Simple directive to display the
// animation models in a table
function animationStatus() {
return {
restrict: "EA",
scope: { animations: "=" },
template:
'<table>' +
' <thead>' +
' <tr>' +
' <th>Animation</th>' +
' <th>Status</th>' +
' </tr>' +
' </thead>' +
' <tbody>' +
' <tr ng-repeat="animation in animations">' +
' <td>{{animation.name}}</td>' +
' <td>{{animation.status}}</td>' +
' </tr>' +
' </tbody>' +
'</table>'
};
}