summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts/TJavaScript.php
diff options
context:
space:
mode:
authorwei <>2006-04-27 08:39:55 +0000
committerwei <>2006-04-27 08:39:55 +0000
commit4aa1f46fcb508271b09cb5736d8bd0ef7206941d (patch)
tree09bc3e09d94e7cd768e904eaab14e523255af3a1 /framework/Web/Javascripts/TJavaScript.php
parentb387c4ae04ed2854dab5cd608468a95d3d49721c (diff)
Added client-side events to client-side validators. see tests/FunctionalTests/features/index.php?page=ValidatorEffects
Diffstat (limited to 'framework/Web/Javascripts/TJavaScript.php')
-rw-r--r--framework/Web/Javascripts/TJavaScript.php42
1 files changed, 30 insertions, 12 deletions
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 <tt>javascript:</tt>
+ */
+ 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'}
* </code>
- *
- * To pass raw javascript statements start strings with
- * <tt>javascript:</tt>. E.g.
- * <code>
- * $options['onLoading'] = "javascript:function(){ alert('hello'); }";
- * //outputs {'onLoading':function(){ alert('hello'); }}
- * </code>
*
- * 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 <tt>javascript:</tt> 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';