158 this.setCaption(caption); |
158 this.setCaption(caption); |
159 this.setContent(content); |
159 this.setContent(content); |
160 |
160 |
161 // update style |
161 // update style |
162 this.updateStyleFromState(); |
162 this.updateStyleFromState(); |
163 } |
163 }; |
164 |
164 |
165 // Returns the enabled state. |
165 // Returns the enabled state. |
166 ContentPanel.prototype.isEnabled = function() { |
166 ContentPanel.prototype.isEnabled = function() { |
167 return this.enabled; |
167 return this.enabled; |
168 } |
168 }; |
169 |
169 |
170 // Sets the enabled state. |
170 // Sets the enabled state. |
171 ContentPanel.prototype.setEnabled = function(enabled) { |
171 ContentPanel.prototype.setEnabled = function(enabled) { |
172 uiLogger.debug("ContentPanel.setEnabled(" + enabled + ")"); |
172 uiLogger.debug("ContentPanel.setEnabled(" + enabled + ")"); |
173 |
173 |
195 } |
195 } |
196 } |
196 } |
197 |
197 |
198 // update style |
198 // update style |
199 this.updateStyleFromState(); |
199 this.updateStyleFromState(); |
200 } |
200 }; |
201 |
201 |
202 // Returns the caption; null if none. |
202 // Returns the caption; null if none. |
203 ContentPanel.prototype.getCaption = function() { |
203 ContentPanel.prototype.getCaption = function() { |
204 return this.caption; |
204 return this.caption; |
205 } |
205 }; |
206 |
206 |
207 // Sets the caption; null if none. |
207 // Sets the caption; null if none. |
208 ContentPanel.prototype.setCaption = function(caption) { |
208 ContentPanel.prototype.setCaption = function(caption) { |
209 // bail out if the caption text element has not been created |
209 // bail out if the caption text element has not been created |
210 // this is to prevent the superclass init calling this before |
210 // this is to prevent the superclass init calling this before |
221 this.caption = caption; |
221 this.caption = caption; |
222 this.captionTextElement.innerHTML = (caption == null) ? "" : caption; |
222 this.captionTextElement.innerHTML = (caption == null) ? "" : caption; |
223 |
223 |
224 // update style |
224 // update style |
225 this.updateStyleFromState(); |
225 this.updateStyleFromState(); |
226 } |
226 }; |
227 |
227 |
228 // Returns the content. |
228 // Returns the content. |
229 ContentPanel.prototype.getContent = function() { |
229 ContentPanel.prototype.getContent = function() { |
230 return this.contentElement.innerHTML; |
230 return this.contentElement.innerHTML; |
231 } |
231 }; |
232 |
232 |
233 // Sets the content. |
233 // Sets the content. |
234 ContentPanel.prototype.setContent = function(content) { |
234 ContentPanel.prototype.setContent = function(content) { |
235 uiLogger.debug("ContentPanel.setContent(" + content + ")"); |
235 uiLogger.debug("ContentPanel.setContent(" + content + ")"); |
236 this.contentElement.innerHTML = (content == null) ? "" : content; |
236 this.contentElement.innerHTML = (content == null) ? "" : content; |
237 } |
237 }; |
238 |
238 |
239 // Returns the focusable state for the control. |
239 // Returns the focusable state for the control. |
240 ContentPanel.prototype.isFocusable = function() { |
240 ContentPanel.prototype.isFocusable = function() { |
241 // a content panel is focusable if it's foldable and enabled |
241 // a content panel is focusable if it's foldable and enabled |
242 return (this.foldable && this.enabled); |
242 return (this.foldable && this.enabled); |
243 } |
243 }; |
244 |
244 |
245 // Sets the focused state for the control. |
245 // Sets the focused state for the control. |
246 // Note: This may not always succeed. |
246 // Note: This may not always succeed. |
247 ContentPanel.prototype.setFocused = function(focused) { |
247 ContentPanel.prototype.setFocused = function(focused) { |
248 uiLogger.debug("ContentPanel.setFocused(" + focused + ")"); |
248 uiLogger.debug("ContentPanel.setFocused(" + focused + ")"); |
253 this.captionLinkElement.blur(); |
253 this.captionLinkElement.blur(); |
254 } |
254 } |
255 } |
255 } |
256 // note that this.focused gets set as a result of focusStateChanged() being called |
256 // note that this.focused gets set as a result of focusStateChanged() being called |
257 // rather than setting it explicitly here |
257 // rather than setting it explicitly here |
258 } |
258 }; |
259 |
259 |
260 // Returns the expanded state. |
260 // Returns the expanded state. |
261 ContentPanel.prototype.isExpanded = function() { |
261 ContentPanel.prototype.isExpanded = function() { |
262 return this.expanded; |
262 return this.expanded; |
263 } |
263 }; |
264 |
264 |
265 // Sets the expanded state. |
265 // Sets the expanded state. |
266 ContentPanel.prototype.setExpanded = function(expanded) { |
266 ContentPanel.prototype.setExpanded = function(expanded) { |
267 uiLogger.debug("ContentPanel.setExpanded(" + expanded + ")"); |
267 uiLogger.debug("ContentPanel.setExpanded(" + expanded + ")"); |
268 |
268 |
305 // notify event listeners |
305 // notify event listeners |
306 this.fireEvent(this.createEvent("ExpandedStateChanged", this.expanded)); |
306 this.fireEvent(this.createEvent("ExpandedStateChanged", this.expanded)); |
307 |
307 |
308 // update the style |
308 // update the style |
309 this.updateStyleFromState(); |
309 this.updateStyleFromState(); |
310 } |
310 }; |
311 |
311 |
312 // Returns the absolute position (y) of the given element. |
312 // Returns the absolute position (y) of the given element. |
313 ContentPanel.prototype.getAbsoluteTop = function(element) { |
313 ContentPanel.prototype.getAbsoluteTop = function(element) { |
314 // traverse from element to root and add top-offset |
314 // traverse from element to root and add top-offset |
315 // for each element we find on the way |
315 // for each element we find on the way |
317 while (element != null) { |
317 while (element != null) { |
318 absTop += element.offsetTop; |
318 absTop += element.offsetTop; |
319 element = element.offsetParent; |
319 element = element.offsetParent; |
320 } |
320 } |
321 return absTop; |
321 return absTop; |
322 } |
322 }; |
323 |
323 |
324 // Callback for when the caption is clicked. |
324 // Callback for when the caption is clicked. |
325 ContentPanel.prototype.captionClicked = function() { |
325 ContentPanel.prototype.captionClicked = function() { |
326 uiLogger.debug("ContentPanel.captionClicked()"); |
326 uiLogger.debug("ContentPanel.captionClicked()"); |
327 |
327 |
333 } |
333 } |
334 |
334 |
335 // toggle the expanded state |
335 // toggle the expanded state |
336 this.setExpanded(!this.expanded); |
336 this.setExpanded(!this.expanded); |
337 } |
337 } |
338 } |
338 }; |
339 |
339 |
340 // Updates the style of the control to reflects the state of the control. |
340 // Updates the style of the control to reflects the state of the control. |
341 ContentPanel.prototype.updateStyleFromState = function() { |
341 ContentPanel.prototype.updateStyleFromState = function() { |
342 uiLogger.debug("ContentPanel.updateStyleFromState()"); |
342 uiLogger.debug("ContentPanel.updateStyleFromState()"); |
343 |
343 |
362 // set the content caption text class names |
362 // set the content caption text class names |
363 this.setClassName(this.captionTextElement, "ContentPanelCaptionText ContentPanelCaptionText" + stateName); |
363 this.setClassName(this.captionTextElement, "ContentPanelCaptionText ContentPanelCaptionText" + stateName); |
364 |
364 |
365 // set the content element class names |
365 // set the content element class names |
366 this.setClassName(this.contentElement, "ContentPanelContent"); |
366 this.setClassName(this.contentElement, "ContentPanelContent"); |
367 } |
367 }; |