From d830818a513a255e2ae047e7d0057238aa462f3d Mon Sep 17 00:00:00 2001 From: xue <> Date: Mon, 20 Feb 2006 05:16:06 +0000 Subject: TPage::setFocus is working. --- framework/Web/Javascripts/TJavaScript.php | 68 ++++++++++++++++--------------- 1 file changed, 35 insertions(+), 33 deletions(-) (limited to 'framework/Web/Javascripts') diff --git a/framework/Web/Javascripts/TJavaScript.php b/framework/Web/Javascripts/TJavaScript.php index 02dfdd6a..47d506fb 100644 --- a/framework/Web/Javascripts/TJavaScript.php +++ b/framework/Web/Javascripts/TJavaScript.php @@ -1,26 +1,25 @@ - * $options['onLoading'] = "doit"; - * $options['onComplete'] = "more"; - * $js = new TJavascriptSerializer($options); - * echo $js->toMap(); - * //expects the following javascript code - * // {'onLoading':'doit','onComplete':'more'} - * + * TJavaScript class file * - * For higher complexity data structures use TJSON to serialize and unserialize. + * @author Wei Zhuo + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Revision: $ $Date: $ + * @package System.Web.Javascripts + */ + +/** + * TJavaScript class. * - * Namespace: System.Web.UI + * TJavaScript is a utility class containing commonly used javascript-related + * functions. * * @author Wei Zhuo - * @version $Revision: 1.3 $ $Date: 2005/11/10 23:43:26 $ - * @package System.Web.UI + * @version $Revision: $ $Date: $ + * @package System.Web.Javascripts + * @since 3.0 */ class TJavaScript { @@ -72,7 +71,7 @@ class TJavaScript return $str; } - public static function quoteJavaScriptString($js,$forUrl=false) + public static function quoteString($js,$forUrl=false) { if($forUrl) return strtr($js,array('%'=>'%25',"\t"=>'\t',"\n"=>'\n',"\r"=>'\r','"'=>'\"','\''=>'\\\'','\\'=>'\\\\')); @@ -80,18 +79,21 @@ class TJavaScript return strtr($js,array("\t"=>'\t',"\n"=>'\n',"\r"=>'\r','"'=>'\"','\''=>'\\\'','\\'=>'\\\\')); } - public static function trimJavaScriptString($js) - { - if($js!=='' && $js!==null) - { - $js=trim($js); - if(($pos=strpos($js,'javascript:'))===0) - $js=substr($js,11); - $js=rtrim($js,';').';'; - } - return $js; - } - + /** + * Encodes a PHP variable into javascript representation. + * + * Example: + * + * $options['onLoading'] = "doit"; + * $options['onComplete'] = "more"; + * $js = new TJavascriptSerializer($options); + * echo $js->toMap(); + * //expects the following javascript code + * // {'onLoading':'doit','onComplete':'more'} + * + * + * For higher complexity data structures use TJSON to serialize and unserialize. + */ public static function encode($value,$toMap=true) { if(is_string($value)) @@ -103,7 +105,7 @@ class TJavaScript if(($first==='[' && $last===']') || ($first==='{' && $last==='}')) return $value; } - return "'".self::quoteJavaScriptString($value)."'"; + return "'".self::quoteString($value)."'"; } else if(is_bool($value)) return $value?'true':'false'; @@ -142,13 +144,13 @@ class TJavaScript return ''; } - public static function encodeJSON($value) + public static function jsonEncode($value) { Prado::using('System.Web.Javascripts.TJSON'); return TJSON::encode($value); } - public static function decodeJSON($value) + public static function jsonDecode($value) { Prado::using('System.Web.Javascripts.TJSON'); return TJSON::decode($value); -- cgit v1.2.3