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_3.js
98 lines (77 loc) · 2.18 KB
/
blocks_3.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
(function() {
"use strict";
angular
.module("AnimationChainsApp", [ 'ng', 'gsTimelines' ])
.controller("AnimationController", AnimationController );
/**
* MainController
* @param $scope
* @param $timeline
* @constructor
*/
function AnimationController($scope, $timeline, $log) {
var progress = {
main : {
start : "--",
done: "--"
}
};
$scope.animating = false;
$scope.progress = angular.extend({}, progress);
$scope.animate = startAnimation;
$scope.reset = resetAnimations;
// ****************************
// Internal Methods
// ****************************
/**
* Reset animations and enable buttons
*/
function resetAnimations() {
var gotoStart = function(animation){
animation.progress(0).pause();
};
$scope.elapsedTime = "";
$scope.progress = angular.extend({}, progress);
$timeline("main").then( gotoStart );
}
/**
* Start animation sequences
*/
function startAnimation() {
$scope.reset();
$scope.animating=true;
$timeline( "main", callbacks() ).then( function(animation) {
var message = "AnimationController::start( restarting '{data.id}' )";
$log.debug(message.supplant(animation));
animation.restart();
});
}
/**
* Create `onStart` and `onComplete` callbacks for
* the gs-timeline instance.
*
* @param id String timeline ID
* @returns {{onStart: Function, onComplete: Function}}
*/
function callbacks() {
var id = "main";
var startedAt = Date.now();
return {
onStart : function( ){
$scope.$apply(function(){
$log.debug("onStart( '{0}' )".supplant([id]) );
$scope.progress[id]["start"] = "running...";
});
},
onComplete : function( tl ){
$log.debug("onComplete( '{0}' )".supplant([id]) );
$scope.$apply(function(){
$scope.progress[id]["done"] = "finished";
$scope.animating=false;
$scope.elapsedTime = (Date.now() - startedAt);
});
}
}
}
}
})();