Permalink
Browse files

Adding Access tags, adding _parseOptions

  • Loading branch information...
1 parent 6213b83 commit efbef5f8c68281cf36669799a0d3eedb74c5f661 @markstory markstory committed Mar 8, 2009
Showing with 29 additions and 8 deletions.
  1. +29 −8 cake/libs/view/helpers/js.php
@@ -376,16 +376,17 @@ function prompt($message, $default = '') {
* from an array. Will use native JSON encode method if available, and $useNative == true
*
* Options:
- *
- * - prefix - String prepended to the returned data.
- * - postfix - String appended to the returned data.
- * - stringKeys - A list of array keys to be treated as a string
- * - quoteKeys - If false treats $options['stringKeys'] as a list of keys **not** to be quoted.
- * - q - Type of quote to use.
- *
+ *
+ * - 'prefix' - String prepended to the returned data.
+ * - 'postfix' - String appended to the returned data.
+ * - 'stringKeys' - A list of array keys to be treated as a string
+ * - 'quoteKeys' - If false treats $options['stringKeys'] as a list of keys **not** to be quoted.
+ * - 'q' - Type of quote to use.
+ *
* @param array $data Data to be converted.
* @param array $options Set of options, see above.
* @return string A JSON code block
+ * @access public
*/
function object($data = array(), $options = array()) {
$defaultOptions = array(
@@ -448,6 +449,7 @@ function object($data = array(), $options = array()) {
* @param mixed $val A PHP variable to be converted to JSON
* @param boolean $quoteStrings If false, leaves string values unquoted
* @return string a JavaScript-safe/JSON representation of $val
+ * @access public
*/
function value($val, $quoteStrings = true) {
switch (true) {
@@ -487,12 +489,31 @@ function value($val, $quoteStrings = true) {
*
* @param string $script String that needs to get escaped.
* @return string Escaped string.
+ * @access public
*/
function escape($string) {
$escape = array("\r\n" => '\n', "\r" => '\n', "\n" => '\n', '"' => '\"', "'" => "\\'");
return str_replace(array_keys($escape), array_values($escape), $string);
}
-
+/**
+ * Parse an options assoc array into an Javascript object literal.
+ * Similar to object() but treats any non-integer value as a string,
+ * does not include { }
+ *
+ * @param array $options Options to be converted
+ * @return string
+ * @access protected
+ **/
+ function _parseOptions($options) {
+ $out = array();
+ foreach ($options as $key => $value) {
+ if (!is_int($val)) {
+ $val = '"' . $val . '"';
+ }
+ $out[] = $key . ':' . $val;
+ }
+ return join(', ', $out);;
+ }
}

0 comments on commit efbef5f

Please sign in to comment.