diff options
author | ctrlaltca@gmail.com <> | 2012-03-23 18:15:03 +0000 |
---|---|---|
committer | ctrlaltca@gmail.com <> | 2012-03-23 18:15:03 +0000 |
commit | e0de4ef01a644bccae872f60b3584a1755dcbc1f (patch) | |
tree | ec7aef2e1ea355f7dd9a89b2090beb54024502ee /framework/Web/Javascripts | |
parent | 942bee46430fe06e17200a9f5a649768081d6eae (diff) |
Fixed #390 and #391
Diffstat (limited to 'framework/Web/Javascripts')
-rw-r--r-- | framework/Web/Javascripts/TJavaScript.php | 66 |
1 files changed, 48 insertions, 18 deletions
diff --git a/framework/Web/Javascripts/TJavaScript.php b/framework/Web/Javascripts/TJavaScript.php index 4f12eb94..ad120771 100644 --- a/framework/Web/Javascripts/TJavaScript.php +++ b/framework/Web/Javascripts/TJavaScript.php @@ -82,23 +82,24 @@ class TJavaScript }
/**
- * @return string considers the string as raw javascript function code
+ * @return Marks a string as a javascript function. Once marke, the string is considered as a
+ * raw javascript function that is not supposed to be encoded by {@link encode}
*/
public static function quoteFunction($js)
{
- if(self::isFunction($js))
+ if($js instanceof TJavaScriptFunction)
return $js;
else
- return 'javascript:'.$js;
+ return new TJavaScriptFunction($js);
}
/**
- * @return boolean true if string is raw javascript function code, i.e., if
- * the string begins with <tt>javascript:</tt>
+ * @return boolean true if the parameter is marked as a javascript function, i.e. if it's considered as a
+ * raw javascript function that is not supposed to be encoded by {@link encode}
*/
public static function isFunction($js)
{
- return preg_match('/^\s*javascript:/i', $js);
+ return ($js instanceof TJavaScriptFunction);
}
/**
@@ -136,11 +137,7 @@ class TJavaScript if(($first==='[' && $last===']') || ($first==='{' && $last==='}'))
return $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);
+ return self::quoteString($value);
}
else if(is_bool($value))
return $value?'true':'false';
@@ -178,15 +175,28 @@ class TJavaScript return "$value";
else if(is_float($value))
{
- if($value===-INF)
- return 'Number.NEGATIVE_INFINITY';
- else if($value===INF)
- return 'Number.POSITIVE_INFINITY';
- else
- return "$value";
+ switch($value)
+ {
+ case -INF:
+ return 'Number.NEGATIVE_INFINITY';
+ break;
+ case INF:
+ return 'Number.POSITIVE_INFINITY';
+ break;
+ default:
+ $locale=localeConv();
+ if($locale['decimal_point']=='.')
+ return "$value";
+ else
+ return str_replace($locale['decimal_point'], '.', "$value");
+ break;
+ }
}
else if(is_object($value))
- return self::encode(get_object_vars($value),$toMap);
+ if ($value instanceof TJavaScriptFunction)
+ return preg_replace('/^\s*javascript:/', '', $value);
+ else
+ return self::encode(get_object_vars($value),$toMap);
else if($value===null)
return 'null';
else
@@ -265,3 +275,23 @@ class TJavaScript }
}
+/**
+ * TJavaScriptFunction class that encloses string literals that are not
+ * supposed to be escaped by TJavaScript::encode()
+ *
+ */
+class TJavaScriptFunction
+{
+ private $_s;
+
+ public function __construct($s)
+ {
+ $this->_s = $s;
+ }
+
+ public function __toString()
+ {
+ return $this->_s;
+ }
+}
+
|