3 * TActiveHyperLink class file.
5 * @author Wei Zhuo <weizhuo[at]gamil[dot]com>
6 * @link https://github.com/pradosoft/prado
7 * @copyright Copyright © 2005-2016 The PRADO Group
8 * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9 * @package System.Web.UI.ActiveControls
13 * TActiveHyperLink class.
15 * The active control counterpart of THyperLink component. When
16 * {@link TBaseActiveControl::setEnableUpdate ActiveControl.EnableUpdate}
17 * property is true the during a callback request, setting {@link setText Text}
18 * property will also set the text of the label on the client upon callback
19 * completion. Similarly, for other properties such as {@link setImageUrl ImageUrl},
20 * {@link setNavigateUrl NavigateUrl} and {@link setTarget Target}.
22 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
23 * @package System.Web.UI.ActiveControls
26 class TActiveHyperLink extends THyperLink implements IActiveControl
29 * Creates a new callback control, sets the adapter to
30 * TActiveControlAdapter. If you override this class, be sure to set the
31 * adapter appropriately by, for example, by calling this constructor.
33 public function __construct()
35 parent::__construct();
36 $this->setAdapter(new TActiveControlAdapter($this));
40 * @return TBaseActiveControl basic active control options.
42 public function getActiveControl()
44 return $this->getAdapter()->getBaseActiveControl();
48 * On callback response, the inner HTMl of the label is updated.
49 * @param string the text value of the label
51 public function setText($value)
53 if(parent::getText() === $value)
56 parent::setText($value);
57 if($this->getActiveControl()->canUpdateClientSide())
58 $this->getPage()->getCallbackClient()->update($this, $value);
62 * Sets the location of image file of the THyperLink.
63 * @param string the image file location
65 public function setImageUrl($value)
67 if(parent::getImageUrl() === $value)
70 parent::setImageUrl($value);
71 if($this->getActiveControl()->canUpdateClientSide() && $value !== '')
73 $textWriter = new TTextWriter;
74 $renderer = Prado::createComponent($this->GetResponse()->getHtmlWriterType(), $textWriter);
75 $this->createImage($value)->renderControl($renderer);
76 $this->getPage()->getCallbackClient()->update($this, $textWriter->flush());
81 * Sets the URL to link to when the THyperLink component is clicked.
82 * @param string the URL
84 public function setNavigateUrl($value)
86 if(parent::getNavigateUrl() === $value)
89 parent::setNavigateUrl($value);
90 if($this->getActiveControl()->canUpdateClientSide())
92 //replace & with & and urldecode the url (setting the href using javascript is literal)
93 $url = urldecode(str_replace('&', '&', $value));
94 $this->getPage()->getCallbackClient()->setAttribute($this, 'href', $url);
99 * Sets the target window or frame to display the Web page content linked to when the THyperLink component is clicked.
100 * @param string the target window, valid values include '_blank', '_parent', '_self', '_top' and empty string.
102 public function setTarget($value)
104 if(parent::getTarget() === $value)
107 parent::setTarget($value);
108 if($this->getActiveControl()->canUpdateClientSide())
109 $this->getPage()->getCallbackClient()->setAttribute($this, 'target', $value);