org.symbian.tools.wrttools/projecttemplates/WRTKit/UI/ContentPanel.js
author Eugene Ostroukhov <eugeneo@symbian.org>
Tue, 16 Mar 2010 18:01:11 -0700
changeset 273 b1f63c2c240c
parent 211 7b148352159e
permissions -rw-r--r--
Bug 2072 - Update .js files with EPL
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
210
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     1
/**
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     2
 * Copyright (c) 2009-2010 Symbian Foundation and/or its subsidiary(-ies).
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     3
 * All rights reserved.
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     4
 * This component and the accompanying materials are made available
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     6
 * which accompanies this distribution, and is available
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     8
 *
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
     9
 * Initial Contributors:
273
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    10
 * Nokia Corporation - initial contribution.
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    11
 * 
210
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
    12
 * Contributors:
273
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    13
 * 
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    14
 * Description:
b1f63c2c240c Bug 2072 - Update .js files with EPL
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 211
diff changeset
    15
 * 
210
0f7abfd6ae62 Fixed bug 2072: update .js files with EPL
tasneems@symbian.org
parents: 102
diff changeset
    16
 */
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    17
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    18
///////////////////////////////////////////////////////////////////////////////
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    19
// The ContentPanel class is a control for displaying content. The panel
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    20
// can be expanded and collapsed.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    21
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    22
// Constructor.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    23
function ContentPanel(id, caption, content, foldable, expanded) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    24
    if (id != UI_NO_INIT_ID) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    25
        this.init(id, caption, content, foldable, expanded);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    26
    }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    27
}
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    28
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    29
// ContentPanel inherits from Control.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    30
ContentPanel.prototype = new Control(UI_NO_INIT_ID);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    31
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    32
// The element hierarchy in a content panel is as follows:
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    33
//
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    34
// rootElement
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    35
//     assemblyElement
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    36
//         captionElement
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    37
//             foldToggleElement
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    38
//                 captionLinkElement
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    39
//                     captionTextElement
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    40
//     contentElement
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    41
//
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    42
// captionTextElement is moved under foldToggleElement if disabled
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    43
// or captionElement if not foldable
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    44
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    45
// The fold toggle element used for folding content panels.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    46
ContentPanel.prototype.foldToggleElement = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    47
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    48
// The caption link element of this control.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    49
ContentPanel.prototype.captionLinkElement = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    50
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    51
// The caption text element of this control.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    52
ContentPanel.prototype.captionTextElement = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    53
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    54
// The content element of this control.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    55
ContentPanel.prototype.contentElement = null;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    56
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    57
// The foldable state of this control.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    58
ContentPanel.prototype.foldable = false;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    59
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    60
// The expanded state of this control.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    61
ContentPanel.prototype.expanded = false;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    62
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    63
// Enabled status.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    64
ContentPanel.prototype.enabled = false;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    65
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    66
// Initializer - called from constructor.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    67
ContentPanel.prototype.init = function(id, caption, content, foldable, expanded) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    68
    uiLogger.debug("ContentPanel.init(" + id + ", " + caption + ", " + content + ", " + foldable + ", " + expanded + ")");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    69
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    70
    // call superclass initializer
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    71
    Control.prototype.init.call(this, id, caption);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    72
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    73
    // the control defaults to enabled
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    74
    this.enabled = true;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    75
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    76
    // create caption text element
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    77
    this.captionTextElement = document.createElement("span");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    78
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    79
    // disconnect the control element
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    80
    this.assemblyElement.removeChild(this.controlElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    81
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    82
    // set the foldable state
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    83
    this.foldable = foldable;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    84
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    85
    // is this a foldable content panel?
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    86
    if (foldable) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    87
        // create fold toggle element
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    88
        this.foldToggleElement = document.createElement("div");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    89
        this.captionElement.appendChild(this.foldToggleElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    90
        
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    91
        // create caption link and add to caption element
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    92
        this.captionLinkElement = document.createElement("a");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    93
        this.captionLinkElement.href = "JavaScript:void(0)";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    94
        this.foldToggleElement.appendChild(this.captionLinkElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    95
        
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    96
        // add the text element to the link element
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    97
        this.captionLinkElement.appendChild(this.captionTextElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    98
        
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
    99
        // bind event listeners
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   100
        var self = this;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   101
        this.captionLinkElement.addEventListener("focus", function() { self.focusStateChanged(true); }, false);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   102
        this.captionLinkElement.addEventListener("blur", function() { self.focusStateChanged(false); }, false);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   103
        this.foldToggleElement.addEventListener("mouseover", function() { self.hoverStateChanged(true); }, false);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   104
        this.foldToggleElement.addEventListener("mouseout", function() { self.hoverStateChanged(false); }, false);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   105
        this.foldToggleElement.addEventListener("mousedown", function(event) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   106
                                                                 self.captionClicked();
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   107
                                                                 event.stopPropagation();
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   108
                                                                 event.preventDefault();
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   109
                                                             }, true);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   110
        this.foldToggleElement.addEventListener("keydown", function(event) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   111
                                                               // center and enter trigger the action
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   112
                                                               if (event.keyCode == 0 || event.keyCode == 13) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   113
                                                                   self.captionClicked();
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   114
                                                                   event.stopPropagation();
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   115
                                                                   event.preventDefault();
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   116
                                                               }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   117
                                                           }, true);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   118
        
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   119
        this.expanded = expanded;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   120
    } else {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   121
        // since this is not a foldable panel the content should be expanded
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   122
        this.expanded = true;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   123
        
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   124
        // add the text element directly to the caption element
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   125
        this.captionElement.appendChild(this.captionTextElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   126
    }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   127
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   128
    // create content element
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   129
    this.contentElement = document.createElement("div");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   130
    this.contentElement.style.display = this.expanded ? "block" : "none";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   131
    this.rootElement.appendChild(this.contentElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   132
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   133
    // set caption, content and expanded state
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   134
    this.setCaption(caption);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   135
    this.setContent(content);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   136
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   137
    // update style
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   138
    this.updateStyleFromState();
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   139
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   140
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   141
// Returns the enabled state.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   142
ContentPanel.prototype.isEnabled = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   143
    return this.enabled;
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   144
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   145
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   146
// Sets the enabled state.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   147
ContentPanel.prototype.setEnabled = function(enabled) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   148
    uiLogger.debug("ContentPanel.setEnabled(" + enabled + ")");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   149
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   150
    // bail out early if there is no change in state
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   151
    if (this.enabled == enabled) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   152
        return;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   153
    }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   154
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   155
    // set the enabled state
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   156
    this.enabled = enabled;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   157
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   158
    // is this a foldable content?
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   159
    if (this.foldable) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   160
         // the caption link must be disabled
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   161
        if (this.enabled) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   162
            // diabled -> enabled
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   163
            this.foldToggleElement.removeChild(this.captionTextElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   164
            this.foldToggleElement.appendChild(this.captionLinkElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   165
            this.captionLinkElement.appendChild(this.captionTextElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   166
        } else {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   167
            // enabled -> diabled
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   168
            this.captionLinkElement.removeChild(this.captionTextElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   169
            this.foldToggleElement.removeChild(this.captionLinkElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   170
            this.foldToggleElement.appendChild(this.captionTextElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   171
        }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   172
    }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   173
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   174
    // update style
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   175
    this.updateStyleFromState();    
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   176
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   177
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   178
// Returns the caption; null if none.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   179
ContentPanel.prototype.getCaption = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   180
    return this.caption;
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   181
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   182
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   183
// Sets the caption; null if none.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   184
ContentPanel.prototype.setCaption = function(caption) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   185
    // bail out if the caption text element has not been created
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   186
    // this is to prevent the superclass init calling this before
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   187
    // we've initialized our custom caption
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   188
    if (this.captionTextElement == null)
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   189
        return;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   190
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   191
    uiLogger.debug("ContentPanel.setCaption(" + caption + ")");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   192
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   193
    // set the display style
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   194
    this.captionElement.style.display = (caption == null) ? "none" : "block";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   195
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   196
    // set the caption
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   197
    this.caption = caption;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   198
    this.captionTextElement.innerHTML = (caption == null) ? "" : caption;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   199
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   200
    // update style
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   201
    this.updateStyleFromState();
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   202
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   203
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   204
// Returns the content.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   205
ContentPanel.prototype.getContent = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   206
    return this.contentElement.innerHTML;
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   207
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   208
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   209
// Sets the content.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   210
ContentPanel.prototype.setContent = function(content) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   211
    uiLogger.debug("ContentPanel.setContent(" + content + ")");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   212
    this.contentElement.innerHTML = (content == null) ? "" : content;
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   213
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   214
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   215
// Returns the focusable state for the control.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   216
ContentPanel.prototype.isFocusable = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   217
    // a content panel is focusable if it's foldable and enabled
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   218
    return (this.foldable && this.enabled);
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   219
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   220
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   221
// Sets the focused state for the control.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   222
// Note: This may not always succeed.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   223
ContentPanel.prototype.setFocused = function(focused) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   224
    uiLogger.debug("ContentPanel.setFocused(" + focused + ")");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   225
    if (this.enabled && this.foldable) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   226
        if (focused) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   227
            this.captionLinkElement.focus();
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   228
        } else {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   229
            this.captionLinkElement.blur();
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   230
        }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   231
    }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   232
    // note that this.focused gets set as a result of focusStateChanged() being called
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   233
    // rather than setting it explicitly here
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   234
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   235
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   236
// Returns the expanded state.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   237
ContentPanel.prototype.isExpanded = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   238
    return this.expanded;
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   239
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   240
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   241
// Sets the expanded state.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   242
ContentPanel.prototype.setExpanded = function(expanded) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   243
    uiLogger.debug("ContentPanel.setExpanded(" + expanded + ")");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   244
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   245
    // make sure only foldable content panels are folded
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   246
    if (!this.foldable) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   247
        uiLogger.warn("Cannot fold a non-foldable content panel!");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   248
        return;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   249
    }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   250
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   251
    this.expanded = expanded;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   252
    if (this.expanded) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   253
        // expand
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   254
        this.contentElement.style.display = "block";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   255
        
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   256
        // find out control top and bottom
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   257
        var controlTop = this.getAbsoluteTop(this.rootElement);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   258
        var controlHeight = this.rootElement.clientHeight;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   259
        var controlBottom = controlTop + controlHeight;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   260
        
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   261
        // find out the viewport top and bottom
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   262
        var viewportTop = window.scrollY;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   263
        var viewportHeight = window.innerHeight;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   264
        var viewportBottom = viewportTop + viewportHeight;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   265
        
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   266
        // make sure the control is positioned so that it can be seen
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   267
        var overflow = controlBottom - viewportBottom;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   268
        if (overflow > 0) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   269
            // there's overflow so we need to scroll to get the control
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   270
            // into the viewport - however not so far that the control
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   271
            // goes past the viewport top.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   272
            var distanceToTop = controlTop - viewportTop;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   273
            var scrollAmount = Math.min(overflow, distanceToTop);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   274
            window.scrollBy(0, scrollAmount);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   275
        }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   276
    } else {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   277
        // collapse
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   278
        this.contentElement.style.display = "none";
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   279
    }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   280
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   281
    // notify event listeners
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   282
    this.fireEvent(this.createEvent("ExpandedStateChanged", this.expanded));
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   283
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   284
    // update the style
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   285
    this.updateStyleFromState();
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   286
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   287
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   288
// Returns the absolute position (y) of the given element.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   289
ContentPanel.prototype.getAbsoluteTop = function(element) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   290
    // traverse from element to root and add top-offset
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   291
    // for each element we find on the way
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   292
    var absTop = 0;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   293
    while (element != null) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   294
        absTop += element.offsetTop;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   295
        element = element.offsetParent;
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   296
    }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   297
    return absTop;
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   298
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   299
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   300
// Callback for when the caption is clicked.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   301
ContentPanel.prototype.captionClicked = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   302
    uiLogger.debug("ContentPanel.captionClicked()");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   303
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   304
    // if we're enabled then a click results toggling the expanded state
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   305
    if (this.enabled) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   306
        // focus when clicked
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   307
        if (!this.focused) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   308
            this.captionLinkElement.focus();
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   309
        }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   310
        
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   311
        // toggle the expanded state
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   312
        this.setExpanded(!this.expanded);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   313
    }
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   314
};
73
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   315
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   316
// Updates the style of the control to reflects the state of the control.
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   317
ContentPanel.prototype.updateStyleFromState = function() {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   318
    uiLogger.debug("ContentPanel.updateStyleFromState()");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   319
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   320
    // determine the state name
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   321
    var stateName = this.getStyleStateName();
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   322
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   323
    // set root element class name
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   324
    this.setClassName(this.rootElement, "Control");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   325
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   326
    // set the control assembly class names
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   327
    this.setClassName(this.assemblyElement, "ControlAssembly ControlAssembly" + stateName);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   328
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   329
    if (this.foldable) {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   330
        // foldable content panel
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   331
        this.setClassName(this.captionElement, "ContentPanelCaptionFoldable");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   332
        this.setClassName(this.foldToggleElement, "ContentPanelFoldToggle ContentPanelFoldToggle" + (this.expanded ? "Expanded" : "Collapsed"));
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   333
    } else {
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   334
        // non-folding
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   335
        this.setClassName(this.captionElement, "ContentPanelCaptionNonFoldable");
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   336
    }
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   337
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   338
    // set the content caption text class names
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   339
    this.setClassName(this.captionTextElement, "ContentPanelCaptionText ContentPanelCaptionText" + stateName);
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   340
    
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   341
    // set the content element class names
c56c874eef47 Added WRTKit
tasneems@symbian.org
parents:
diff changeset
   342
    this.setClassName(this.contentElement, "ContentPanelContent");
102
30e0796f3ebb Warnings in new projects were fixed
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 73
diff changeset
   343
};