From 35c7ff28cbc311fba5e394b11fb756a4dc1edcb9 Mon Sep 17 00:00:00 2001 From: wei <> Date: Tue, 13 Dec 2005 07:08:30 +0000 Subject: Removed inline javascript from components. Adding TJavascriptLogger and logger.js --- framework/Web/UI/WebControls/TLinkButton.php | 63 +++++++++++++++------------- 1 file changed, 34 insertions(+), 29 deletions(-) (limited to 'framework/Web/UI/WebControls/TLinkButton.php') diff --git a/framework/Web/UI/WebControls/TLinkButton.php b/framework/Web/UI/WebControls/TLinkButton.php index dd2d8cb7..3ddb6f68 100644 --- a/framework/Web/UI/WebControls/TLinkButton.php +++ b/framework/Web/UI/WebControls/TLinkButton.php @@ -46,10 +46,6 @@ * You can change the postback target by setting the {@link setPostBackUrl PostBackUrl} * property. * - * To set the client-side javascript associated with the user's click action, - * use the {@link setOnClientClick OnClientClick} property. The value will be rendered - * as the onclick attribute of the link button. - * * TLinkButton will display the {@link setText Text} property value * as the hyperlink text. If {@link setText Text} is empty, the body content * of TLinkButton will be displayed. Therefore, you can use TLinkButton @@ -79,19 +75,41 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler { $page=$this->getPage(); $page->ensureRenderInForm($this); - $onclick=$this->removeAttribute('onclick'); - $onclick=THttpUtility::trimJavaScriptString($onclick).THttpUtility::trimJavaScriptString($this->getOnClientClick()); - if(!empty($onclick)) - $writer->addAttribute('onclick','javascript:'.$onclick); + + $writer->addAttribute('id',$this->getClientID()); // We call parent implementation here because some attributes // may be overwritten in the following parent::addAttributesToRender($writer); + + if($this->getEnabled()) + { + $url = $this->getPostBackUrl(); + //create unique no-op url references + $nop = "javascript:;//{$this->ClientID}"; + $writer->addAttribute('href', $url ? $url : $nop); + } + else// in this case, parent will not render 'disabled' + $writer->addAttribute('disabled','disabled'); + } + /** + * Registers the postback javascript code. + * If you override this method, be sure to call the parent implementation + * so that the event handlers can be invoked. + * @param TEventParameter event parameter to be passed to the event handlers + */ + protected function onPreRender($param) + { if($this->getEnabled(true)) - $writer->addAttribute('href',$page->getClientScript()->getPostBackEventReference($this,'',$this->getPostBackOptions(),true)); - else if($this->getEnabled()) // in this case, parent will not render 'disabled' - $writer->addAttribute('disabled','disabled'); + { + $scripts = $this->getPage()->getClientScript(); + $options = $this->getPostBackOptions(); + $postback = $scripts->getPostBackEventReference($this, '', $options, false); + $code = "{$postback}; Event.stop(e);"; + $scripts->registerClientEvent($this, "click", $code); + } + parent::onPreRender($param); } /** @@ -102,8 +120,11 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler protected function getPostBackOptions() { $flag=false; - $options=new TPostBackOptions(); - if($this->getCausesValidation() && $this->getPage()->getValidators($this->getValidationGroup())->getCount()>0) + + $option=new TPostBackOptions(); + $group = $this->getValidationGroup(); + $hasValidators = $this->getPage()->getValidators($group)->getCount()>0; + if($this->getCausesValidation() && $hasValidators) { $flag=true; $options->setPerformValidation(true); @@ -182,22 +203,6 @@ class TLinkButton extends TWebControl implements IPostBackEventHandler $this->setViewState('CommandParameter',$value,''); } - /** - * @return string the javascript to be executed when the button is clicked - */ - public function getOnClientClick() - { - return $this->getViewState('OnClientClick',''); - } - - /** - * @param string the javascript to be executed when the button is clicked. Do not prefix it with "javascript:". - */ - public function setOnClientClick($value) - { - $this->setViewState('OnClientClick',$value,''); - } - /** * @return string the URL of the page to post to when the button is clicked, default is empty meaning post to the current page itself */ -- cgit v1.2.3