1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013, 2014, 2015, 2016 Synacor, Inc. 5 * 6 * The contents of this file are subject to the Common Public Attribution License Version 1.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: https://www.zimbra.com/license 9 * The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15 10 * have been added to cover use of software over a computer network and provide for limited attribution 11 * for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B. 12 * 13 * Software distributed under the License is distributed on an "AS IS" basis, 14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. 15 * See the License for the specific language governing rights and limitations under the License. 16 * The Original Code is Zimbra Open Source Web Client. 17 * The Initial Developer of the Original Code is Zimbra, Inc. All rights to the Original Code were 18 * transferred by Zimbra, Inc. to Synacor, Inc. on September 14, 2015. 19 * 20 * All portions of the code are Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013, 2014, 2015, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 25 /** 26 * Creates a text control. 27 * @constructor 28 * @class 29 * This class represents a container for a piece of text. 30 * 31 * @author Ross Dargahi 32 * 33 * @param {hash} params a hash of parameters 34 * @param {DwtComposite} parent the parent widget 35 * @param {string} className CSS class 36 * @param {constant} posStyle the positioning style (see {@link DwtControl}) 37 * @param {string} id an explicit ID to use for the control's HTML element 38 * 39 * @extends DwtControl 40 */ 41 DwtText = function(params) { 42 if (arguments.length == 0) return; 43 params = Dwt.getParams(arguments, DwtText.PARAMS); 44 params.className = params.className || "DwtText"; 45 46 if (Dwt.hasClass(params, 'FakeAnchor')) { 47 this.role = 'link'; 48 } 49 50 DwtControl.call(this, params); 51 52 // we start out empty, so suppress focus 53 this.noTab = true; 54 }; 55 56 DwtText.PARAMS = ["parent", "className", "posStyle"]; 57 58 DwtText.prototype = new DwtControl; 59 DwtText.prototype.constructor = DwtText; 60 61 DwtText.prototype.isDwtText = true; 62 DwtText.prototype.toString = function() { return "DwtText"; }; 63 64 65 /** 66 * Sets the text. 67 * 68 * @param {string} text the text 69 */ 70 DwtText.prototype.setText = 71 function(text) { 72 // only appear in tab order when we have text 73 this.noTab = !text; 74 75 if (!this._textNode) { 76 this._textNode = document.createTextNode(text); 77 this.getHtmlElement().appendChild(this._textNode); 78 } else { 79 try { // IE mysteriously throws an error sometimes, but still does the right thing 80 this._textNode.data = text; 81 } catch (e) {} 82 } 83 84 // this is largely redundant, but helps ensure screen readers read aloud 85 // text in toolbars 86 this.setAttribute('aria-label', text); 87 }; 88 89 /** 90 * Gets the text. 91 * 92 * @return {string} the text 93 */ 94 DwtText.prototype.getText = 95 function() { 96 return this._textNode ? this._textNode.data : ""; 97 }; 98 99 /** 100 * Gets the text node. 101 * 102 * @return {Object} the node 103 */ 104 DwtText.prototype.getTextNode = 105 function() { 106 return this._textNode; 107 }; 108 109 DwtText.prototype._focus = function() { 110 this.setDisplayState(DwtControl.FOCUSED); 111 }; 112 113 DwtText.prototype._blur = function() { 114 this.setDisplayState(DwtControl.NORMAL); 115 }; 116