diff options
author | Pierre Frisch | 2011-12-22 07:25:50 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-01-27 11:18:17 -0800 |
commit | b89a7ee8b956c96a1dcee995ea840feddc5d4b27 (patch) | |
tree | 0f3136ab0ecdbbbed6a83576581af0a53124d6f1 /node_modules/montage/ui/slot.reel | |
parent | 2401f05d1f4b94d45e4568b81fc73e67b969d980 (diff) | |
download | ninja-b89a7ee8b956c96a1dcee995ea840feddc5d4b27.tar.gz |
First commit of Ninja to ninja-internal
Signed-off-by: Valerio Virgillito <rmwh84@motorola.com>
Diffstat (limited to 'node_modules/montage/ui/slot.reel')
-rwxr-xr-x | node_modules/montage/ui/slot.reel/slot.js | 302 |
1 files changed, 302 insertions, 0 deletions
diff --git a/node_modules/montage/ui/slot.reel/slot.js b/node_modules/montage/ui/slot.reel/slot.js new file mode 100755 index 00000000..45c0ac1d --- /dev/null +++ b/node_modules/montage/ui/slot.reel/slot.js | |||
@@ -0,0 +1,302 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | /** | ||
7 | @module "montage/ui/slot.reel" | ||
8 | @requires montage/core/core | ||
9 | @requires montage/ui/component | ||
10 | */ | ||
11 | var Montage = require("montage").Montage, | ||
12 | Component = require("ui/component").Component; | ||
13 | /** | ||
14 | @class module:"montage/ui/slot.reel".Slot | ||
15 | @extends module:montage/ui/component.Component | ||
16 | */ | ||
17 | var Slot = exports.Slot = Montage.create(Component, /** @lends module:"montage/ui/slot.reel".Slot# */ { | ||
18 | |||
19 | hasTemplate: { | ||
20 | enumerable: false, | ||
21 | value: false | ||
22 | }, | ||
23 | /** | ||
24 | Description TODO | ||
25 | @type {Property} | ||
26 | @default null | ||
27 | */ | ||
28 | delegate: { | ||
29 | enumerable: false, | ||
30 | value: null | ||
31 | }, | ||
32 | /** | ||
33 | Description TODO | ||
34 | @type {Property} | ||
35 | @default null | ||
36 | */ | ||
37 | transition: { | ||
38 | enumerable: false, | ||
39 | value: null | ||
40 | }, | ||
41 | /** | ||
42 | Description TODO | ||
43 | @private | ||
44 | */ | ||
45 | _content: { | ||
46 | enumerable: false, | ||
47 | value: null | ||
48 | }, | ||
49 | /** | ||
50 | Description TODO | ||
51 | @private | ||
52 | */ | ||
53 | _contentToRemove: { | ||
54 | enumerable: false, | ||
55 | value: null | ||
56 | }, | ||
57 | /** | ||
58 | Description TODO | ||
59 | @private | ||
60 | */ | ||
61 | _contentToAppend: { | ||
62 | enumerable: false, | ||
63 | value: null | ||
64 | }, | ||
65 | /** | ||
66 | Description TODO | ||
67 | @private | ||
68 | */ | ||
69 | _contentHasChanged: { | ||
70 | enumerable: false, | ||
71 | value: true | ||
72 | }, | ||
73 | /** | ||
74 | Description TODO | ||
75 | @type {Function} | ||
76 | @default null | ||
77 | */ | ||
78 | content: { | ||
79 | enumerable: false, | ||
80 | get: function() { | ||
81 | return this._content; | ||
82 | }, | ||
83 | set: function(value) { | ||
84 | |||
85 | // if no change or busy drawing a switch, ignore this "new" value | ||
86 | if ((!!value && this._content === value)|| (!!this._contentToAppend && value === this._contentToAppend) || this._isSwitchingContent) { | ||
87 | return; | ||
88 | } | ||
89 | |||
90 | if (this._contentToAppend) { | ||
91 | // If we already had some content that was going to be appended, don't bother with it | ||
92 | // the new value we just received will supercede it | ||
93 | this._contentToAppend.needsDraw = false; | ||
94 | this._drawList = []; | ||
95 | } | ||
96 | |||
97 | // TODO if given a serialized component or something (a template) we should be able to handle that | ||
98 | |||
99 | this._contentToAppend = value; | ||
100 | |||
101 | if (this._contentToAppend && typeof this._contentToAppend.needsDraw !== "undefined") { | ||
102 | |||
103 | // If the incoming content was a component; make sure it has an element before we say it needs to draw | ||
104 | if (!this._contentToAppend.element) { | ||
105 | var nodeToAppend = document.createElement("div"); | ||
106 | nodeToAppend.id = "appendDiv"; | ||
107 | |||
108 | if (this.delegate && typeof this.delegate.slotElementForComponent === "function") { | ||
109 | nodeToAppend = this.delegate.slotElementForComponent(this, this._contentToAppend, nodeToAppend); | ||
110 | } | ||
111 | this._contentToAppend.element = nodeToAppend; | ||
112 | } | ||
113 | |||
114 | if (!this._contentToAppend.parentComponent) { | ||
115 | this._contentToAppend._cachedParentComponent = this; | ||
116 | } | ||
117 | |||
118 | // The child component will need to draw; this may trigger a draw for the slot itself | ||
119 | this._contentToAppend.needsDraw = true; | ||
120 | } | ||
121 | |||
122 | this.needsDraw = true; | ||
123 | this._contentToRemove = this._content; | ||
124 | this._contentHasChanged = true; | ||
125 | |||
126 | return value; | ||
127 | } | ||
128 | }, | ||
129 | /** | ||
130 | Description TODO | ||
131 | @private | ||
132 | */ | ||
133 | _isSwitchingContent: { | ||
134 | enumerable: false, | ||
135 | value: false | ||
136 | }, | ||
137 | |||
138 | childComponentWillPrepareForDraw: { | ||
139 | value: function(child) { | ||
140 | if (child.element.parentElement == null) { | ||
141 | // by the time a child component lets us know it's about to prepare to draw for the first time | ||
142 | // we know we need to append its element to our own element. | ||
143 | // This happens outside of any drawing for better or worse right now. | ||
144 | this._element.appendChild(child.element); | ||
145 | this.needsDraw = true; | ||
146 | } | ||
147 | } | ||
148 | }, | ||
149 | |||
150 | _canAppendContent: { | ||
151 | enumerable: false, | ||
152 | value: false | ||
153 | }, | ||
154 | |||
155 | canDraw: { | ||
156 | value: function() { | ||
157 | |||
158 | if (this._contentToAppend) { | ||
159 | if (typeof this._contentToAppend.needsDraw !== "undefined") { | ||
160 | this._canAppendContent = this._contentToAppend.canDraw(); | ||
161 | if (this._canAppendContent) { | ||
162 | this.needsDraw = true; | ||
163 | } | ||
164 | } else { | ||
165 | this._canAppendContent = true; | ||
166 | } | ||
167 | } else { | ||
168 | // No content to append, but we can render that situation (empty out the slot) | ||
169 | this._canAppendContent = true; | ||
170 | } | ||
171 | |||
172 | // We'll always offer to draw if asked to allow children to draw, but what the slot does when it draws | ||
173 | // will depend on the _canAppendContent flag determined at this point | ||
174 | return true; | ||
175 | } | ||
176 | }, | ||
177 | /** | ||
178 | Description TODO | ||
179 | @function | ||
180 | */ | ||
181 | draw: { | ||
182 | value: function() { | ||
183 | |||
184 | |||
185 | if (!this._canAppendContent) { | ||
186 | return; | ||
187 | } | ||
188 | |||
189 | // Prevent other switching while we're in the middle of rendering this current switch | ||
190 | this._isSwitchingContent = true; | ||
191 | |||
192 | var nodeToAppend, nodeToRemove, rangeToRemove; | ||
193 | |||
194 | // If there's no content currently inside the slot we need to have one for transition support which expects | ||
195 | // a start and an end node; but we want to make sure the node is included in the rangeToRemove | ||
196 | if (this._contentToRemove) { | ||
197 | if (this._contentToRemove.nodeType) { | ||
198 | // The content is a node itself; use this node | ||
199 | nodeToRemove = this._contentToRemove; | ||
200 | } else if (this._contentToRemove.element) { | ||
201 | // The content has an element property set; use the element | ||
202 | nodeToRemove = this._contentToRemove.element; | ||
203 | } | ||
204 | } else { | ||
205 | if (this.transition) { | ||
206 | nodeToRemove = document.createElement("div"); | ||
207 | nodeToRemove.id = "removeDiv"; | ||
208 | // Since we're trying to remove this node it's expected to be in the slot already; put it there | ||
209 | this._element.appendChild(nodeToRemove); | ||
210 | } | ||
211 | } | ||
212 | |||
213 | // If there is new content then whatever is in the slot currently needs to be removed | ||
214 | if (this._contentHasChanged) { | ||
215 | rangeToRemove = document.createRange(); | ||
216 | rangeToRemove.selectNodeContents(this._element); | ||
217 | } | ||
218 | |||
219 | // Figure out what node this slot is appending given the contentToAppend | ||
220 | if (this._contentToAppend) { | ||
221 | if (this._contentToAppend.nodeType) { | ||
222 | // The content is a node itself; use this node | ||
223 | nodeToAppend = this._contentToAppend; | ||
224 | } else if (this._contentToAppend.element) { | ||
225 |