PHP Class Prado\Web\Javascripts\TJavaScript

TJavaScript is a utility class containing commonly-used javascript-related functions.
Since: 3.0
ファイルを表示 Open project: pradosoft/prado Class Usage Examples

Public Methods

Method Description
JSMin ( $code ) : minimized Minimize the size of a javascript script.
encode ( $value, $toMap = true, $encodeEmptyStrings = false ) : string Encodes a PHP variable into javascript representation.
isFunction ( $js ) Deprecated, use {@link isJsLiteral} instead
isJsLiteral ( $js ) : boolean
jsonDecode ( $value, $assoc = false, $depth = 512 ) : mixed Decodes a javascript string into PHP variable.
jsonEncode ( $value, $options ) : string Encodes a PHP variable into javascript string.
quoteFunction ( $js ) Deprecated, use {@link quoteJsLiteral} instead
quoteJsLiteral ( $js ) : Marks
quoteString ( $js ) : string Quotes a javascript string.
renderScriptBlock ( $script ) : string Renders javascript block
renderScriptBlocks ( $scripts ) : string Renders a list of javascript blocks
renderScriptBlocksCallback ( $scripts ) : string Renders a list of javascript code
renderScriptFile ( $file ) : string Renders a javascript file
renderScriptFiles ( $files ) : string Renders a list of javascript files

Private Methods

Method Description
checkJsonError ( )
convertToUtf8 ( string | array | mixed &$value, string $sourceEncoding ) Encodes an string or the content of an array to UTF8

Method Details

JSMin() public static method

This method is based on Douglas Crockford's JSMin.
public static JSMin ( $code ) : minimized
return minimized version of the code

encode() public static method

Example: $options['onLoading'] = "doit"; $options['onComplete'] = "more"; echo TJavaScript::encode($options); expects the following javascript code {'onLoading':'doit','onComplete':'more'} For higher complexity data structures use {@link jsonEncode} and {@link jsonDecode} to serialize and unserialize.
Since: 3.1.5
public static encode ( $value, $toMap = true, $encodeEmptyStrings = false ) : string
return string the encoded string

isFunction() public static method

Deprecated, use {@link isJsLiteral} instead
public static isFunction ( $js )

isJsLiteral() public static method

public static isJsLiteral ( $js ) : boolean
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}

jsonDecode() public static method

This method invokes json_decode to perform the decoding.
public static jsonDecode ( $value, $assoc = false, $depth = 512 ) : mixed
return mixed decoded variable

jsonEncode() public static method

This method invokes json_encode to perform the encoding.
public static jsonEncode ( $value, $options ) : string
return string encoded string

quoteFunction() public static method

Deprecated, use {@link quoteJsLiteral} instead
public static quoteFunction ( $js )

quoteJsLiteral() public static method

public static quoteJsLiteral ( $js ) : Marks
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}

quoteString() public static method

After processing, the string is safely enclosed within a pair of quotation marks and can serve as a javascript string.
public static quoteString ( $js ) : string
return string the quoted string

renderScriptBlock() public static method

Renders javascript block
public static renderScriptBlock ( $script ) : string
return string rendering result

renderScriptBlocks() public static method

Renders a list of javascript blocks
public static renderScriptBlocks ( $scripts ) : string
return string rendering result

renderScriptBlocksCallback() public static method

Renders a list of javascript code
public static renderScriptBlocksCallback ( $scripts ) : string
return string rendering result

renderScriptFile() public static method

Renders a javascript file
public static renderScriptFile ( $file ) : string
return string rendering result

renderScriptFiles() public static method

Renders a list of javascript files
public static renderScriptFiles ( $files ) : string
return string rendering result