Class TJavaScript

Description

TJavaScript class.

TJavaScript is a utility class containing commonly-used javascript-related functions.

  • author: Wei Zhuo<weizhuo[at]gmail[dot]com>
  • version: $Id: TJavaScript.php 3121 2012-03-25 20:51:49Z ctrlaltca@gmail.com $
  • since: 3.0

Located in /Web/Javascripts/TJavaScript.php (line 24)


	
			
Method Summary
static string encode (mixed $value, [boolean $toMap = true], [boolean $encodeEmptyStrings = false])
static void isFunction ( $js)
static boolean isJsLiteral ( $js)
static minimized JSMin (string $code)
static mixed jsonDecode (string $value, [bool $assoc = false], [int $depth = 512])
static string jsonEncode (mixed $value, [ $options = 0])
static void quoteFunction ( $js)
static Marks quoteJsLiteral ( $js)
static string quoteString (string $js)
static string renderScriptBlock (string $script)
static string renderScriptBlocks (array $scripts)
static string renderScriptFile (string $file)
static string renderScriptFiles (array $files)
Methods
static method encode (line 142)

Encodes a PHP variable into javascript representation.

Example:

  1.  $options['onLoading'"doit";
  2.  $options['onComplete'"more";
  3.  echo TJavaScript::encode($options);
  4.  //expects the following javascript code
  5.  // {'onLoading':'doit','onComplete':'more'}

For higher complexity data structures use jsonEncode and jsonDecode to serialize and unserialize.

  • return: the encoded string
  • since: 3.1.5
  • access: public
static string encode (mixed $value, [boolean $toMap = true], [boolean $encodeEmptyStrings = false])
  • mixed $value: PHP variable to be encoded
  • boolean $toMap: whether the output is a map or a list.
  • boolean $encodeEmptyStrings: wether to encode empty strings too. Default to false for BC.
static method isFunction (line 116)

Deprecated, use isJsLiteral instead

  • access: public
static void isFunction ( $js)
  • $js
static method isJsLiteral (line 108)
  • return: 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 encode
  • access: public
static boolean isJsLiteral ( $js)
  • $js
static method JSMin (line 277)

Minimize the size of a javascript script.

This method is based on Douglas Crockford's JSMin.

  • return: version of the code
  • access: public
static minimized JSMin (string $code)
  • string $code: code that you want to minimzie
static method jsonDecode (line 235)

Decodes a javascript string into PHP variable.

This method invokes json_decode to perform the decoding.

  • return: decoded variable
  • access: public
static mixed jsonDecode (string $value, [bool $assoc = false], [int $depth = 512])
  • string $value: string to be decoded
  • bool $assoc: whether to convert returned objects to associative arrays
  • int $depth: recursion depth
static method jsonEncode (line 216)

Encodes a PHP variable into javascript string.

This method invokes json_encode to perform the encoding.

  • return: encoded string
  • access: public
static string jsonEncode (mixed $value, [ $options = 0])
  • mixed $value: variable to be encoded
  • $options
static method quoteFunction (line 99)

Deprecated, use quoteJsLiteral instead

  • access: public
static void quoteFunction ( $js)
  • $js
static method quoteJsLiteral (line 88)
  • return: 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 encode
  • access: public
static Marks quoteJsLiteral ( $js)
  • $js
static method quoteString (line 79)

Quotes a javascript string.

After processing, the string is safely enclosed within a pair of quotation marks and can serve as a javascript string.

  • return: the quoted string
  • access: public
static string quoteString (string $js)
  • string $js: string to be quoted
static method renderScriptBlock (line 67)

Renders javascript block

  • return: rendering result
  • access: public
static string renderScriptBlock (string $script)
  • string $script: javascript block
static method renderScriptBlocks (line 54)

Renders a list of javascript blocks

  • return: rendering result
  • access: public
static string renderScriptBlocks (array $scripts)
  • array $scripts: javascript blocks
static method renderScriptFile (line 44)

Renders a javascript file

  • return: rendering result
  • access: public
static string renderScriptFile (string $file)
  • string $file: URL to the javascript file
static method renderScriptFiles (line 31)

Renders a list of javascript files

  • return: rendering result
  • access: public
static string renderScriptFiles (array $files)
  • array $files: URLs to the javascript files

Documentation generated on Mon, 25 Jun 2012 14:38:32 +0200 by phpDocumentor 1.4.3