1 /** 2 * @author Gillis Haasnoot <gillis.haasnoot@gmail.com> 3 * @package Banana.Controls 4 * @summary Label control with character limit support 5 */ 6 7 goog.provide('Banana.Controls.DataControls.LimitCharLabel'); 8 9 goog.require('Banana.Controls.DataControls.Label'); 10 11 /** @namespace Banana.Controls.LimitCharLabel */ 12 namespace('Banana.Controls').LimitCharLabel = Banana.Controls.Label.extend( 13 /** @lends Banana.Controls.LimitCharLabel.prototype */ 14 { 15 16 /** 17 * Creates a label with character limit support. 18 * if the supplied data exceeds the character limit we show only the character limit part of the data. 19 * @constructs 20 * @extends Banana.Controls.Label 21 */ 22 init : function() 23 { 24 this._super(); 25 }, 26 27 /** 28 * Sets character limit 29 * @param {int} limit 30 * @return {this} 31 */ 32 setCharLimit : function(limit) 33 { 34 this.charLimit = limit; 35 return this; 36 }, 37 38 /** 39 * @override 40 * 41 * @param {mixed} data for the label 42 * @param {boolean} ignoreEvent when true no datachanged is triggered. This is useful when you are running in a circle or performance issues 43 * @param {boolean} ignoreDom when true setDomData function is not called. Useful in cases of optimizing performance 44 * @return {this} 45 */ 46 setData : function(data,ignoreEvent,ignoreDom) 47 { 48 if (this.charLimit && data && data.length > this.charLimit) 49 { 50 this.setAttribute('title',data); 51 data = data.substr(0,this.charLimit) + '...'; 52 } 53 54 return this._super(data,ignoreEvent,ignoreDom); 55 } 56 });