From 4aa1f46fcb508271b09cb5736d8bd0ef7206941d Mon Sep 17 00:00:00 2001
From: wei <>
Date: Thu, 27 Apr 2006 08:39:55 +0000
Subject: Added client-side events to client-side validators. see
tests/FunctionalTests/features/index.php?page=ValidatorEffects
---
framework/Web/Javascripts/TJavaScript.php | 42 ++++++++++++++++++++++---------
1 file changed, 30 insertions(+), 12 deletions(-)
(limited to 'framework/Web/Javascripts/TJavaScript.php')
diff --git a/framework/Web/Javascripts/TJavaScript.php b/framework/Web/Javascripts/TJavaScript.php
index a3848201..75fc2438 100644
--- a/framework/Web/Javascripts/TJavaScript.php
+++ b/framework/Web/Javascripts/TJavaScript.php
@@ -84,6 +84,26 @@ class TJavaScript
else
return strtr($js,array("\t"=>'\t',"\n"=>'\n',"\r"=>'\r','"'=>'\"','\''=>'\\\'','\\'=>'\\\\'));
}
+
+ /**
+ * @return string considers the string as raw javascript function code
+ */
+ public static function quoteFunction($js)
+ {
+ if(self::isFunction($js))
+ return $js;
+ else
+ return 'javascript:'.$js;
+ }
+
+ /**
+ * @return boolean true if string is raw javascript function code, i.e., if
+ * the string begins with javascript:
+ */
+ public static function isFunction($js)
+ {
+ return preg_match('/^\s*javascript:/', $js);
+ }
/**
* Encodes a PHP variable into javascript representation.
@@ -96,16 +116,12 @@ class TJavaScript
* //expects the following javascript code
* // {'onLoading':'doit','onComplete':'more'}
*
- *
- * To pass raw javascript statements start strings with
- * javascript:. E.g.
- *
- * $options['onLoading'] = "javascript:function(){ alert('hello'); }";
- * //outputs {'onLoading':function(){ alert('hello'); }}
- *
*
- * For higher complexity data structures use {@link jsonEncode} and {@link
- * jsonDecode} to serialize and unserialize.
+ * For higher complexity data structures use {@link jsonEncode} and {@link jsonDecode}
+ * to serialize and unserialize.
+ *
+ * Note: strings begining with javascript: will be considered as
+ * raw javascript code and no encoding of that string will be enforced.
*
* @param mixed PHP variable to be encoded
* @param boolean whether the output is a map or a list.
@@ -122,9 +138,11 @@ class TJavaScript
if(($first==='[' && $last===']') || ($first==='{' && $last==='}'))
return $value;
}
- else if(strpos($value, 'javascript:')===0)
- return substr($value,11);
- return "'".self::quoteString($value)."'";
+ // if string begins with javascript: return the raw string minus the prefix
+ if(self::isFunction($value))
+ return preg_replace('/^\s*javascript:/', '', $value);
+ else
+ return "'".self::quoteString($value)."'";
}
else if(is_bool($value))
return $value?'true':'false';
--
cgit v1.2.3