Wikipedia/WRTKit/UI/NavigationButton.js
author ivanl
Tue, 09 Mar 2010 10:34:58 +0000
changeset 20 918767a9c8d3
permissions -rw-r--r--
Adding Wikipedia Widget 1.0rc5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
     1
/*
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
     2
� Copyright 2008 Nokia Corporation. All rights reserved.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
     3
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
     4
IMPORTANT:  The Nokia software ("WRTKit and Example Widget files") is supplied to you by Nokia
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
     5
Corporation (�Nokia�) in consideration of your agreement to the following terms. Your use, installation
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
     6
and/or redistribution of the WRTKit and Example Widget files constitutes acceptance of these terms. If
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
     7
you do not agree with these terms, please do not use, install, or redistribute the WRTKit and Example
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
     8
Widget files.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
     9
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    10
In consideration of your agreement to abide by the following terms, and subject to these terms, Nokia
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    11
grants you a personal, non-exclusive license, under Nokia�s copyrights in the WRTKit and Example
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    12
Widget files, to use, reproduce, and redistribute the WRTKit and Example files, in text form (for HTML,
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    13
CSS, or JavaScript files) or binary form (for associated images), for the sole purpose of creating S60
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    14
Widgets.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    15
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    16
If you redistribute the WRTKit and Example files, you must retain this entire notice in all such
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    17
redistributions of the WRTKit and Example files.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    18
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    19
You may not use the name, trademarks, service marks or logos of Nokia to endorse or promote products
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    20
that include the WRTKit and Example files without the prior written explicit agreement with Nokia.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    21
Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    22
Nokia herein, including but not limited to any patent rights that may be infringed by your products that
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    23
incorporate the WRTKit and Example files or by other works in which the WRTKit and Example files
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    24
may be incorporated.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    25
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    26
The WRTKit and Example files are provided on an "AS IS" basis.  NOKIA MAKES NO
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    27
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    28
WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    29
PARTICULAR PURPOSE, REGARDING THE EXAMPLES OR ITS USE AND OPERATION
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    30
ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    31
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    32
IN NO EVENT SHALL NOKIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    33
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    34
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    35
INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, AND/OR
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    36
DISTRIBUTION OF THE EXAMPLES, HOWEVER CAUSED AND WHETHER UNDER THEORY
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    37
OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE,
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    38
EVEN IF NOKIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    39
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    40
*/
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    41
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    42
///////////////////////////////////////////////////////////////////////////////
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    43
// The NavigationButton class implements a button control for use in
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    44
// navigational contexts in menu-style UIs.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    45
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    46
// Constructor.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    47
function NavigationButton(id, image, text, titleBar) {
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    48
    if (id != UI_NO_INIT_ID) {
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    49
        this.init(id, image, text, titleBar);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    50
    }
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    51
}
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    52
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    53
// NavigationButton inherits from ActionControl.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    54
NavigationButton.prototype = new ActionControl(UI_NO_INIT_ID);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    55
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    56
// Button table element.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    57
NavigationButton.prototype.tableElement = null;
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    58
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    59
// Button table row element.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    60
NavigationButton.prototype.tableRowElement = null;
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    61
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    62
// Button table left cell element.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    63
NavigationButton.prototype.tableLeftCellElement = null;
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    64
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    65
// Button table right cell element.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    66
NavigationButton.prototype.tableRightCellElement = null;
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    67
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    68
// Button image element.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    69
NavigationButton.prototype.imageElement = null;
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    70
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    71
// Button link element.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    72
NavigationButton.prototype.linkElement = null;
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    73
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    74
// Button text element.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    75
NavigationButton.prototype.textElement = null;
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    76
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    77
// Button table element.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    78
NavigationButton.prototype.titleBar = false;
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    79
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    80
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    81
// Initializer - called from constructor.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    82
NavigationButton.prototype.init = function(id, image, text, titleBar) {
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    83
    uiLogger.debug("NavigationButton.init(" + id + ", " + image + ", " + text + ")");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    84
    
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    85
    // call superclass initializer
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    86
    ActionControl.prototype.init.call(this, id, null);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    87
    
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    88
	if ( titleBar != undefined ) {
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    89
		this.titleBar = titleBar;
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    90
	}
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    91
    // remove caption element
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    92
    this.assemblyElement.removeChild(this.captionElement);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    93
    
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    94
    // construct the button
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    95
    this.buttonElement = document.createElement("div");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    96
    this.tableElement = document.createElement("table");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    97
    this.tableRowElement = document.createElement("tr");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    98
    this.tableLeftCellElement = document.createElement("td");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
    99
    this.tableRightCellElement = document.createElement("td");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   100
    this.imageElement = null;
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   101
    this.linkElement = document.createElement("a");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   102
    this.linkElement.href = "JavaScript:void(0)";
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   103
    this.textElement = document.createElement("span");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   104
    this.tableElement.appendChild(this.tableRowElement);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   105
    this.tableRowElement.appendChild(this.tableLeftCellElement);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   106
    this.tableRowElement.appendChild(this.tableRightCellElement);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   107
    this.tableRightCellElement.appendChild(this.linkElement);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   108
    this.linkElement.appendChild(this.textElement);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   109
    this.buttonElement.appendChild(this.tableElement);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   110
	this.controlElement.appendChild(this.buttonElement);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   111
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   112
    // set the image and text
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   113
    this.setImage(image);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   114
    this.setText(text);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   115
    
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   116
    // bind event listeners
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   117
    this.bindActionControlListeners();
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   118
    
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   119
    // update the style
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   120
    this.updateStyleFromState();
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   121
}
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   122
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   123
// Sets the enabled state.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   124
NavigationButton.prototype.setEnabled = function(enabled) {
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   125
    uiLogger.debug("NavigationButton.setEnabled(" + enabled + ")");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   126
    
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   127
    // bail out early if there is no change in state
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   128
    if (this.enabled == enabled) {
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   129
        return;
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   130
    }
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   131
    
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   132
    // set the enabled state
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   133
    this.enabled = enabled;
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   134
    
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   135
    if (this.enabled) {
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   136
        // diabled -> enabled
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   137
        this.tableRightCellElement.removeChild(this.textElement);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   138
        this.tableRightCellElement.appendChild(this.linkElement);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   139
        this.linkElement.appendChild(this.textElement);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   140
    } else {
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   141
        // enabled -> diabled
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   142
        this.linkElement.removeChild(this.textElement);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   143
        this.tableRightCellElement.removeChild(this.linkElement);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   144
        this.tableRightCellElement.appendChild(this.textElement);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   145
    }
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   146
    
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   147
    // update the style
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   148
    this.updateStyleFromState();
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   149
}
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   150
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   151
// Returns the button image (URL); null if none.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   152
NavigationButton.prototype.getImage = function() {
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   153
    return (this.imageElement != null) ? this.imageElement.src : null;
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   154
}
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   155
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   156
// Sets the button image (URL); null if none.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   157
NavigationButton.prototype.setImage = function(image) {
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   158
    uiLogger.debug("NavigationButton.setImage(" + image + ")");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   159
    
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   160
    if (image == null) {
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   161
        // remove image - if any
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   162
        if (this.imageElement != null) {
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   163
            this.tableLeftCellElement.removeChild(this.imageElement);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   164
        }
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   165
    } else {
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   166
        // default to not append image element
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   167
        var append = false;
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   168
        
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   169
        // create image element if one doesn't exist
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   170
        if (this.imageElement == null) {
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   171
            this.imageElement = document.createElement("img");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   172
            this.imageElement.setAttribute("id", "wrtnavimg");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   173
            this.imageElement.style.width = "auto";
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   174
            append = true;
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   175
        }
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   176
        
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   177
        this.imageElement.src = image;
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   178
        
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   179
        // append the image element to the left cell?
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   180
        if (append) {
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   181
            this.tableLeftCellElement.appendChild(this.imageElement);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   182
        }
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   183
    }
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   184
}
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   185
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   186
// Returns the button text.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   187
NavigationButton.prototype.getText = function() {
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   188
    return this.textElement.innerHTML;
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   189
}
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   190
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   191
// Sets the button text.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   192
NavigationButton.prototype.setText = function(text) {
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   193
    uiLogger.debug("NavigationButton.setText(" + text + ")");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   194
    this.textElement.innerHTML = (text == null) ? "" : text;;
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   195
}
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   196
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   197
// Updates the style of the control to reflects the state of the control.
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   198
NavigationButton.prototype.updateStyleFromState = function() {
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   199
    uiLogger.debug("NavigationButton.updateStyleFromState()");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   200
    
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   201
    // determine the state name
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   202
    var stateName = this.getStyleStateName();
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   203
    
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   204
	if (this.titleBar) {
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   205
		// set root element class name
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   206
		this.setClassName(this.rootElement, "TitleBarControl");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   207
	}
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   208
	else {
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   209
		// set root element class name
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   210
		this.setClassName(this.rootElement, "Control");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   211
	}
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   212
    // set the control assembly class names
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   213
    this.setClassName(this.assemblyElement, "ControlAssembly ControlAssembly" + stateName);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   214
    
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   215
    // control element
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   216
    this.setClassName(this.controlElement, "ControlElement NavigationButtonControlElement");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   217
    
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   218
    // set the button table class names
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   219
    this.setClassName(this.buttonElement, "NavigationButton");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   220
    this.setClassName(this.tableElement, "NavigationButtonTable");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   221
    this.setClassName(this.tableRowElement, "NavigationButtonRow");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   222
    this.setClassName(this.tableLeftCellElement, "NavigationButtonImageCell");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   223
    this.setClassName(this.tableRightCellElement, "NavigationButtonTextCell");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   224
    
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   225
    // set image class names
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   226
    if (this.imageElement) {
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   227
        this.setClassName(this.imageElement, "NavigationButtonImage");
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   228
    }
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   229
    
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   230
    // set the button text class name
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   231
    this.setClassName(this.textElement, "NavigationButtonText NavigationButtonText" + stateName);
918767a9c8d3 Adding Wikipedia Widget 1.0rc5
ivanl
parents:
diff changeset
   232
}