diff options
Diffstat (limited to 'js/panels/Panel.reel/Panel.js')
-rw-r--r-- | js/panels/Panel.reel/Panel.js | 233 |
1 files changed, 233 insertions, 0 deletions
diff --git a/js/panels/Panel.reel/Panel.js b/js/panels/Panel.reel/Panel.js new file mode 100644 index 00000000..efa287c5 --- /dev/null +++ b/js/panels/Panel.reel/Panel.js | |||
@@ -0,0 +1,233 @@ | |||
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 | var Montage = require("montage/core/core").Montage; | ||
8 | var Component = require("montage/ui/component").Component; | ||
9 | |||
10 | exports.Panel = Montage.create(Component, { | ||
11 | |||
12 | |||
13 | reelDidLoad: { | ||
14 | value: function() { | ||
15 | } | ||
16 | }, | ||
17 | |||
18 | collapsedHeight: { | ||
19 | value:26 | ||
20 | }, | ||
21 | |||
22 | _isFirstDraw: { | ||
23 | value:false | ||
24 | }, | ||
25 | |||
26 | _panelBase: { | ||
27 | value: null | ||
28 | }, | ||
29 | |||
30 | panelBase: { | ||
31 | get: function() | ||
32 | { | ||
33 | return this._panelBase; | ||
34 | }, | ||
35 | set: function(value) | ||
36 | { | ||
37 | this._panelBase = value; | ||
38 | this.needsDraw = true; | ||
39 | } | ||
40 | }, | ||
41 | |||
42 | _panelContent: { | ||
43 | value: null | ||
44 | }, | ||
45 | |||
46 | panelContent: { | ||
47 | get: function() | ||
48 | { | ||
49 | return this._panelContent; | ||
50 | }, | ||
51 | set: function(value) | ||
52 | { | ||
53 | if (this._panelContent === value) { | ||
54 | return; | ||
55 | } | ||
56 | this._panelContent = value; | ||
57 | this.needsDraw = true; | ||
58 | } | ||
59 | }, | ||
60 | |||
61 | collapseToggle: { | ||
62 | value: function() { | ||
63 | if (this.panelBase.forcedCollapse) { | ||
64 | this.panelBase.forcedCollapse = false; | ||
65 | this.panelBase.collapsed = false; | ||
66 | this.needsDraw = true; | ||
67 | |||
68 | } else { | ||
69 | this.panelBase.collapsed = !this.panelBase.collapsed; | ||
70 | this.needsDraw = true; | ||
71 | } | ||
72 | NJevent("panelCollapsed", this); | ||
73 | } | ||
74 | }, | ||
75 | |||
76 | closePanel: { | ||
77 | value: function() { | ||
78 | NJevent("panelClose", this); | ||
79 | } | ||
80 | }, | ||
81 | |||
82 | handleMouseover: { | ||
83 | value: function() { | ||
84 | this.element.draggable = true; | ||
85 | } | ||
86 | }, | ||
87 | |||
88 | handleMouseout: { | ||
89 | value: function() { | ||
90 | this.element.draggable = false; | ||
91 | } | ||
92 | }, | ||
93 | |||
94 | _resizer: { | ||
95 | value: null | ||
96 | }, | ||
97 | |||
98 | resizer: { | ||
99 | get: function() { | ||
100 | return this._resizer; | ||
101 | }, | ||
102 | set: function(val) { | ||
103 | this._resizer = val; | ||
104 | } | ||
105 | }, | ||
106 | |||
107 | |||
108 | resized: { | ||
109 | value: function() { | ||
110 | this.panelBase.contentHeight = parseInt(this.element.style.height); | ||
111 | this.needsDraw = true; | ||
112 | } | ||
113 | }, | ||
114 | |||
115 | //TODO: Find out why without This following function drop event wont fire ??? | ||
116 | handleEvent: { | ||
117 | value:function(e) { | ||
118 | e.preventDefault(); | ||
119 | e.stopImmediatePropagation(); | ||
120 | |||
121 | } | ||
122 | }, | ||
123 | |||
124 | captureDragover: { | ||
125 | value:function(e) { | ||
126 | e.preventDefault(); | ||
127 | e.stopImmediatePropagation(); | ||
128 | this.element.style.backgroundColor = "#917B56"; | ||
129 | } | ||
130 | }, | ||
131 | |||
132 | captureDragleave: { | ||
133 | value: function() { | ||
134 | this.element.style.backgroundColor = ""; | ||
135 | } | ||
136 | }, | ||
137 | |||
138 | handleDrop: { | ||
139 | value:function(e) { | ||
140 | e.stopPropagation(); // Stops some browsers from redirecting. | ||
141 | e.preventDefault(); | ||
142 | this.element.style.backgroundColor = ""; | ||
143 | NJevent("panelOrderChanged", this); | ||
144 | } | ||
145 | }, | ||
146 | |||
147 | handleDragstart: { | ||
148 | value:function(e) { | ||
149 | e.dataTransfer.effectAllowed = 'move'; | ||
150 | e.dataTransfer.setData('text/html', this.element.innerHTML); | ||
151 | NJevent("panelSelected", this); | ||
152 | } | ||
153 | }, | ||
154 | |||
155 | handleDragEnter: { | ||
156 | value: function(e) { | ||
157 | this.element.classList.add("over"); | ||
158 | } | ||
159 | }, | ||
160 | |||
161 | handleDragend: { | ||
162 | value:function() { | ||
163 | |||
164 | } | ||
165 | }, | ||
166 | |||
167 | |||
168 | prepareForDraw: { | ||
169 | value:function() { | ||
170 | if (!this._isFirstDraw) { | ||
171 | this._isFirstDraw = true; | ||
172 | |||
173 | // Initialize Panel | ||
174 | // Drag Drop Functions | ||
175 | this.element.addEventListener("drop", this, false); | ||
176 | this.element.addEventListener("dragover", this, true); | ||
177 | this.element.addEventListener("dragleave", this, true); | ||
178 | this.element.addEventListener("dragenter", this, false); | ||
179 | this.element.addEventListener("dragstart", this, false); | ||
180 | |||
181 | // Handle Functionality | ||
182 | this.element.getElementsByClassName("panelTitle")[0].addEventListener("mouseover", this, false); | ||
183 | this.element.getElementsByClassName("panelTitle")[0].addEventListener("mouseout", this, false); | ||
184 | // Arrow Collapse Button Initiate | ||
185 | this.element.getElementsByClassName("arrowIcon")[0].addEventListener("click", this.collapseToggle.bind(this), false); | ||
186 | // Close Button | ||
187 | this.element.getElementsByClassName("closeBtn")[0].addEventListener("click", this.closePanel.bind(this), false); | ||
188 | //Resized Event | ||
189 | if(typeof this.resizer.value == "number") this.panelBase.contentHeight = this.resizer.value; | ||
190 | this.resizer.element.addEventListener("mouseup",this.resized.bind(this),false); | ||
191 | } | ||
192 | } | ||
193 | }, | ||
194 | |||
195 | draw: { | ||
196 | value: function() { | ||
197 | //If the panel is set not to be visible. We dont bother doing anything else to it. till the next draw cycle that its set visible true | ||
198 | // Actually thinking about it now. this might not work. | ||
199 | if (!this.panelBase.visible) this.element.style.display = "none"; | ||
200 | else this.element.style.display = null; | ||
201 | |||
202 | //Draw if collapsed or not | ||
203 | if(this.panelBase.collapsed || this.panelBase.forcedCollapse) { | ||
204 | this.element.classList.add("collapsed"); | ||
205 | this.element.style.height = this.panelBase.collapsedHeight + "px"; | ||
206 | } | ||
207 | else { | ||
208 | this.element.classList.remove("collapsed"); | ||
209 | this.element.style.height = this.panelBase.contentHeight + "px"; | ||
210 | } | ||
211 | |||
212 | var pContentDiv = this.element.getElementsByClassName("panelObjects")[0]; | ||
213 | |||
214 | //Figure out Heights (min, max, and current) | ||
215 | if (this.panelBase.isStatic || this.panelBase.isLocked) { | ||
216 | this.element.style.minHeight = this.panelBase.contentHeight + "px"; | ||
217 | this.element.style.maxHeight = this.panelBase.contentHeight + "px"; | ||
218 | this.resizer.element.style.cursor = "default"; | ||
219 | } else { | ||
220 | this.element.style.minHeight = this.panelBase.minHeight + "px"; | ||
221 | this.element.style.maxHeight = ""; | ||
222 | this.resizer.element.style.cursor = null; | ||
223 | } | ||
224 | |||
225 | if (this.panelBase.scrollable) pContentDiv.style.overflow = "auto"; | ||
226 | else pContentDiv.style.overflow = "hidden"; | ||
227 | this.element.getElementsByClassName("panelTitle")[0].innerHTML = this.panelBase.panelName; | ||
228 | //pContentDiv.appendChild(this.panelBase.content); | ||
229 | this.panelContent.content = this.panelBase.content; | ||
230 | |||
231 | } | ||
232 | } | ||
233 | }); \ No newline at end of file | ||