1 /**
  2  * @author Gillis Haasnoot <gillis.haasnoot@gmail.com>
  3  * @package Banana
  4  * @summary Link Component
  5  */
  6 
  7 goog.provide('Banana.Controls.Link');
  8 
  9 /** @namespace Banana.Controls.Link */
 10 namespace('Banana.Controls').Link = Banana.Controls.DataControl.extend(
 11 /** @lends Banana.Controls.Link.prototype */
 12 {
 13 	/**
 14 	 * Creates a link control. The equivalent of href
 15 	 * Use setHref to define a link and setText for the visible text.
 16 	 * By default the link control does not have a target.
 17 	 * 
 18 	 * example use:
 19 	 * var link = new Banana.Controls.Link();
 20 	 * link.setHref("http://foo.com");
 21 	 * link.setText("a link");
 22 	 * link.bind('click',function(){});
 23 	 *
 24 	 * @constructs
 25 	 * @extends Banana.Controls.DataControl
 26 	 */
 27 	init : function()
 28 	{
 29 		this._super(); 
 30 
 31 		this.addCssClass('BLink');
 32 	},
 33 	
 34 	/**
 35 	 * @override
 36 	 */
 37 	updateDisplay : function()
 38 	{
 39 		if (!this.text) return;
 40 		
 41 		Banana.Util.DomHelper.renderHtml(this.text,this);
 42 	},
 43 	
 44 	/**
 45 	 * Sets the target we want to direct the link to.
 46 	 * use "_blank" to direct to a new window.
 47 	 * @param {String} target
 48 	 */
 49 	setTarget : function(target)
 50 	{
 51 		this.setAttribute('target',target);
 52 	},
 53 	
 54 	/**
 55 	 * Sets the the target link
 56 	 * @param {String} href
 57 	 */
 58 	setHref : function(href)
 59 	{
 60 		this.setAttribute('href',href);
 61 		return this;
 62 	},
 63 	
 64 	/**
 65 	 * Sets the text we want to display 
 66 	 * @param {String} text
 67 	 */
 68 	setText : function(text)
 69 	{
 70 		this.text =text;
 71 		
 72 		if (this.isRendered)
 73 		{
 74 			Banana.Util.DomHelper.renderHtml(this.text,this,true);
 75 		}
 76 		return this;
 77 	},
 78 	
 79 	/**
 80 	 * @return {String} 
 81 	 */
 82 	getTagName : function()
 83 	{
 84 		return 'a';
 85 	}
 86 });