aboutsummaryrefslogtreecommitdiff
path: root/js/panels/Timeline/Span.reel/Span.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/panels/Timeline/Span.reel/Span.js')
-rw-r--r--js/panels/Timeline/Span.reel/Span.js175
1 files changed, 170 insertions, 5 deletions
diff --git a/js/panels/Timeline/Span.reel/Span.js b/js/panels/Timeline/Span.reel/Span.js
index bfa6aab8..91ce1cfb 100644
--- a/js/panels/Timeline/Span.reel/Span.js
+++ b/js/panels/Timeline/Span.reel/Span.js
@@ -4,8 +4,8 @@
4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4 (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5 </copyright> */ 5 </copyright> */
6 6
7var Montage = require("montage/core/core").Montage; 7var Montage = require("montage/core/core").Montage,
8var Component = require("montage/ui/component").Component; 8 Component = require("montage/ui/component").Component;
9 9
10var Span = exports.Span = Montage.create(Component, { 10var Span = exports.Span = Montage.create(Component, {
11 11
@@ -13,10 +13,10 @@ var Span = exports.Span = Montage.create(Component, {
13 value: true 13 value: true
14 }, 14 },
15 15
16 // BEGIN: Models
16 _spanWidth:{ 17 _spanWidth:{
17 value:0 18 value:0
18 }, 19 },
19
20 spanWidth:{ 20 spanWidth:{
21 serializable:true, 21 serializable:true,
22 get:function () { 22 get:function () {
@@ -27,16 +27,181 @@ var Span = exports.Span = Montage.create(Component, {
27 this.needsDraw = true; 27 this.needsDraw = true;
28 } 28 }
29 }, 29 },
30 30
31 _isHighlighted: {
32 value: false
33 },
34 isHighlighted: {
35 get: function() {
36 return this._isHighlighted;
37 },
38 set: function(newVal) {
39 if (newVal !== this._isHighlighted) {
40 this._isHighlighted = newVal;
41 this.needsDraw = true;
42 }
43 }
44 },
45
46 _areChoicesVisible: {
47 value: false
48 },
49 areChoicesVisible: {
50 get: function() {
51 return this._areChoicesVisible;
52 },
53 set: function(newVal) {
54 if (newVal !== this._areChoicesVisible) {
55 this._areChoicesVisible = newVal;
56 this.needsDraw = true;
57 }
58 }
59 },
60
61 _easing: {
62 value: "none"
63 },
64 easing: {
65 get: function() {
66 return this._easing;
67 },
68 set: function(newVal) {
69 if (newVal !== this._easing) {
70 if (typeof(newVal) === "undefined") {
71 newVal = "none";
72 }
73 this._easing = newVal;
74 this.parentComponent.setKeyframeEase(newVal);
75 this.needsDraw = true;
76 }
77 }
78 },
79
80 // BEGIN: draw cycle
81 prepareForDraw: {
82 value: function() {
83 this.init();
84 }
85 },
86
31 draw:{ 87 draw:{
32 value: function(){ 88 value: function(){
33 this.element.style.width = this.spanWidth + "px"; 89 this.element.style.width = this.spanWidth + "px";
90
91 if ((this.spanWidth <= 70) && (this.spanWidth >0)) {
92 var containerWidth = this.spanWidth -18,
93 choiceWidth;
94 if (containerWidth < 0) {
95 containerWidth = 0;
96 }
97 choiceWidth = containerWidth -3;
98 if (choiceWidth < 0) {
99 choiceWidth = 0;
100 }
101 this.container_easing.style.width = containerWidth + "px";
102 this.easing_choice.style.width = choiceWidth + "px";
103 this.easing_choice.style.overflow = "hidden";
104 }
105 if (this.spanWidth > 70) {
106 this.container_easing.setAttribute("style", "");
107 this.easing_choice.setAttribute("style", "");
108 }
109
110 // Highlight the span?
111 if (this.isHighlighted === true) {
112 this.element.classList.add("spanHighlight");
113 } else {
114 this.element.classList.remove("spanHighlight");
115 }
116
117 /*
118 // Hide or show the choices menu?
119 if (this.areChoicesVisible === true) {
120 this.easing_choices.style.display = "block";
121 } else {
122 this.easing_choices.style.display = "none";
123 }
124 */
125
126 // Change easing?
127 if (this.easing_choice.innerText !== this.easing) {
128 this.easing_choice.innerText = this.easing;
129 }
130
34 } 131 }
35 }, 132 },
36 133
134 // BEGIN: Controllers
135 init: {
136 value: function() {
137 this.easing_choice.addEventListener("click", this.handleEasingChoiceClick.bind(this), false);
138 //this.easing_choices.addEventListener("click", this.handleEasingChoicesClick.bind(this), false);
139
140 }
141 },
142
37 highlightSpan:{ 143 highlightSpan:{
38 value: function(){ 144 value: function(){
39 this.element.classList.add("spanHighlight"); 145 // Class add/remove should only be done in draw cycle.
146 // this.element.classList.add("spanHighlight");
147 this.isHighlighted = true;
40 } 148 }
149 },
150
151 handleEasingChoiceClick: {
152 value: function(event) {
153 event.stopPropagation();
154 //this.areChoicesVisible = true;
155 this.application.ninja.timeline.easingMenu.anchor = this.easing_choice;
156 this.application.ninja.timeline.easingMenu.currentChoice = event.currentTarget.innerText;
157
158 function findPos(obj) {
159 var objReturn = {};
160 objReturn.top = 0;
161 objReturn.left = 0;
162
163 if (obj.offsetParent) {
164
165 do {
166 objReturn.left += obj.offsetLeft;
167 objReturn.top += obj.offsetTop;
168
169 } while (obj = obj.offsetParent);
170 }
171 return objReturn;
172 }
173 var objPos = findPos(event.target);
174 this.application.ninja.timeline.easingMenu.top = objPos.top +38 - (this.application.ninja.timeline.layout_tracks.scrollTop);
175 this.application.ninja.timeline.easingMenu.left = objPos.left+18 - (this.application.ninja.timeline.layout_tracks.scrollLeft);
176 this.application.ninja.timeline.easingMenu.show();
177 this.application.ninja.timeline.easingMenu.callingComponent = this;
178 }
179 },
180 handleEasingChoicesClick: {
181 value: function(event) {
182 event.stopPropagation();
183
184 // Remove the pointer to ourselves
185 //this.application.ninja.timeline.currentOpenSpanMenu = false;
186
187 // Un-highlight the old choice and highlight the new choice
188 this.application.ninja.timeline.easingMenu.popup.contentEl.querySelector(".easing-selected").classList.remove("easing-selected");
189 event.target.classList.add("easing-selected");
190
191 // Set the easing
192 this.easing = event.target.dataset.ninjaEase;
193
194 // Unbind the event handler
195 this.application.ninja.timeline.easingMenu.popup.contentEl.removeEventListener("click");
196
197 // Hide the menu.
198 this.hideEasingMenu();
199 }
200 },
201 hideEasingMenu: {
202 value: function() {
203 //this.areChoicesVisible = false;
204 this.application.ninja.timeline.easingMenu.hide();
205 }
41 } 206 }
42}); 207});