Wikipedia/WRTKit/UI/TextEntryControl.js
changeset 20 918767a9c8d3
equal deleted inserted replaced
19:f3521a11d878 20:918767a9c8d3
       
     1 /*
       
     2 © Copyright 2008 Nokia Corporation. All rights reserved.
       
     3 
       
     4 IMPORTANT:  The Nokia software ("WRTKit and Example Widget files") is supplied to you by Nokia
       
     5 Corporation (“Nokia”) in consideration of your agreement to the following terms. Your use, installation
       
     6 and/or redistribution of the WRTKit and Example Widget files constitutes acceptance of these terms. If
       
     7 you do not agree with these terms, please do not use, install, or redistribute the WRTKit and Example
       
     8 Widget files.
       
     9 
       
    10 In consideration of your agreement to abide by the following terms, and subject to these terms, Nokia
       
    11 grants you a personal, non-exclusive license, under Nokia’s copyrights in the WRTKit and Example
       
    12 Widget files, to use, reproduce, and redistribute the WRTKit and Example files, in text form (for HTML,
       
    13 CSS, or JavaScript files) or binary form (for associated images), for the sole purpose of creating S60
       
    14 Widgets.
       
    15 
       
    16 If you redistribute the WRTKit and Example files, you must retain this entire notice in all such
       
    17 redistributions of the WRTKit and Example files.
       
    18 
       
    19 You may not use the name, trademarks, service marks or logos of Nokia to endorse or promote products
       
    20 that include the WRTKit and Example files without the prior written explicit agreement with Nokia.
       
    21 Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by
       
    22 Nokia herein, including but not limited to any patent rights that may be infringed by your products that
       
    23 incorporate the WRTKit and Example files or by other works in which the WRTKit and Example files
       
    24 may be incorporated.
       
    25 
       
    26 The WRTKit and Example files are provided on an "AS IS" basis.  NOKIA MAKES NO
       
    27 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
       
    28 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A
       
    29 PARTICULAR PURPOSE, REGARDING THE EXAMPLES OR ITS USE AND OPERATION
       
    30 ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
       
    31 
       
    32 IN NO EVENT SHALL NOKIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
       
    33 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
       
    34 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
       
    35 INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, AND/OR
       
    36 DISTRIBUTION OF THE EXAMPLES, HOWEVER CAUSED AND WHETHER UNDER THEORY
       
    37 OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE,
       
    38 EVEN IF NOKIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    39 
       
    40 */
       
    41 
       
    42 ///////////////////////////////////////////////////////////////////////////////
       
    43 // The TextEntryControl class is an abstract base class for the single and multi-
       
    44 // line text entry controls TextField and TextArea. Don't use TextEntryControl
       
    45 // directly.
       
    46 
       
    47 // Constructor.
       
    48 function TextEntryControl(id, caption) {
       
    49     if (id != UI_NO_INIT_ID) {
       
    50         this.init(id, caption);
       
    51     }
       
    52 }
       
    53 
       
    54 // TextEntryControl inherits from Control.
       
    55 TextEntryControl.prototype = new Control(UI_NO_INIT_ID);
       
    56 
       
    57 // Reference to the peer HTML element.
       
    58 TextEntryControl.prototype.peerElement = null;
       
    59 
       
    60 // Initializer - called from constructor.
       
    61 TextEntryControl.prototype.init = function(id, caption) {
       
    62     uiLogger.debug("TextEntryControl.init(" + id + ", " + caption + ")");
       
    63     
       
    64     // call superclass initializer
       
    65     Control.prototype.init.call(this, id, caption);
       
    66 }
       
    67 
       
    68 // Common event listeners hookup function called from subclasses.
       
    69 TextEntryControl.prototype.bindTextEntryControlListeners = function() {
       
    70     var self = this;
       
    71     this.peerElement.addEventListener("focus", function() { self.focusStateChanged(true); }, false);
       
    72     this.peerElement.addEventListener("blur", function() { self.focusStateChanged(false); }, false);
       
    73     this.peerElement.addEventListener("mouseover", function() { self.hoverStateChanged(true); }, false);
       
    74     this.peerElement.addEventListener("mouseout", function() { self.hoverStateChanged(false); }, false);
       
    75     this.peerElement.addEventListener("change", function() { self.valueChanged(); }, false);
       
    76 }
       
    77 
       
    78 // Returns the enabled state.
       
    79 // Override this in subclasses as required to implement the state change.
       
    80 TextEntryControl.prototype.isEnabled = function() {
       
    81     return !this.peerElement.readOnly;
       
    82 }
       
    83 
       
    84 // Sets the enabled state.
       
    85 // Override this in subclasses as required to implement the state change.
       
    86 TextEntryControl.prototype.setEnabled = function(enabled) {
       
    87     uiLogger.debug("TextEntryControl.setEnabled(" + enabled + ")");
       
    88     this.peerElement.readOnly = !enabled;
       
    89     // update the style
       
    90     this.updateStyleFromState();
       
    91 }
       
    92 
       
    93 // Returns the control text.
       
    94 TextEntryControl.prototype.getText = function() {
       
    95     return this.peerElement.value;
       
    96 }
       
    97 
       
    98 // Sets the text for the control.
       
    99 TextEntryControl.prototype.setText = function(text) {
       
   100     this.peerElement.value = text;
       
   101 }
       
   102 
       
   103 // Returns the focusable state for the control.
       
   104 TextEntryControl.prototype.isFocusable = function() {
       
   105     // text entry controls are always focusable
       
   106     return true;
       
   107 }
       
   108 
       
   109 // Sets the focused state for the control.
       
   110 // Note: This may not always succeed.
       
   111 TextEntryControl.prototype.setFocused = function(focused) {
       
   112     uiLogger.debug("TextEntryControl.setFocused(" + focused + ")");
       
   113     if (focused) {
       
   114         this.peerElement.focus();
       
   115     } else {
       
   116         this.peerElement.blur();
       
   117     }
       
   118 }
       
   119 
       
   120 // Callback for value change events.
       
   121 TextEntryControl.prototype.valueChanged = function() {
       
   122     uiLogger.debug("TextEntryControl.valueChanged()");
       
   123     // notify event listeners
       
   124     this.fireEvent(this.createEvent("ValueChanged", this.peerElement.value));
       
   125 }