Tizen 2.0 Release
[samples/web/Tenframe.git] / js / animation.js
1 /*
2  * Copyright (c) 2012, Intel Corporation.
3  *
4  * This program is licensed under the terms and conditions of the
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9
10 function Animation(id, startclass, ontime, property) {
11     var self = this;
12     self.id = id;
13     self.elem = document.getElementById(id);
14     self.offclass = self.elem.className;
15     self.onclass = self.offclass+" "+startclass;
16     self.ontime = ontime;
17     self.phase = "off";
18     if(property != undefined)
19     {
20         self.prop = property;
21         self.elem.addEventListener('webkitTransitionEnd', function(e) {
22             if(e.propertyName === self.prop)
23             {
24                 if(self.phase === "starting")
25                 {
26                     self.phase = "on";
27                     self.timer = setTimeout(function() {
28                         self.phase = "ending";
29                         self.elem.className = self.offclass;
30                     }, self.ontime);
31                 }
32                 else if(self.phase === "ending")
33                 {
34                     self.phase = "off";
35                     if(self.next&&self.next.begin)
36                         self.next.begin();
37                 }
38             }
39         }, false);
40     }
41 }
42
43 Animation.prototype.begin = function() {
44     var self = this;
45     self.phase = "starting";
46     setTimeout(function(){self.elem.className = self.onclass;}, 0);
47 };
48
49 Animation.prototype.clear = function() {
50     var self = this;
51     if(self.timer)
52         clearTimeout(self.timer);
53     self.phase = "off";
54     self.elem.className = self.offclass;
55     if(self.next&&self.next.clear)
56         self.next.clear();
57 };
58
59