JavascriptHelper Class Reference

Inheritance diagram for JavascriptHelper:

AppHelper Helper Helper Overloadable Overloadable Object Object Object Object List of all members.

Public Member Functions

 __construct ($options=array())
 _utf8ToHex ($string)
 afterRender ()
 blockEnd ()
 cacheEvents ($file=false, $all=false)
 codeBlock ($script=null, $options=array())
 escapeScript ($script)
 escapeString ($string)
 event ($object, $event, $observer=null, $options=array())
 getCache ($clear=true)
 includeScript ($script="", $options=array())
 link ($url, $inline=true)
 object ($data=array(), $options=array(), $prefix=null, $postfix=null, $stringKeys=null, $quoteKeys=null, $q=null)
 value ($val, $quoteStrings=true)
 writeEvents ($inline=true, $options=array())

Public Attributes

 $__scriptBuffer = null
 $_blockOptions = array()
 $_cacheAll = false
 $_cachedEvents = array()
 $_cacheEvents = false
 $_cacheToFile = false
 $_rules = array()
 $enabled = true
 $safe = false
 $tags
 $useNative = false

Detailed Description

Definition at line 33 of file javascript.php.


Constructor & Destructor Documentation

JavascriptHelper::__construct ( options = array()  ) 

Constructor. Checks for presence of native PHP JSON extension to use for object encoding

public

Definition at line 132 of file javascript.php.

References __construct(), cache(), and safe().


Member Function Documentation

JavascriptHelper::_utf8ToHex ( string  ) 

Encode a string into JSON. Converts and escapes necessary characters.

Returns:
void

Definition at line 315 of file javascript.php.

References Multibyte::utf8().

JavascriptHelper::afterRender (  ) 

AfterRender callback. Writes any cached events to the view, or to a temp file.

Returns:
null

Reimplemented from Helper.

Definition at line 700 of file javascript.php.

JavascriptHelper::blockEnd (  ) 

Ends a block of cached JavaScript code

Returns:
mixed

Definition at line 205 of file javascript.php.

References codeBlock().

JavascriptHelper::cacheEvents ( file = false,
all = false 
)

Cache JavaScript events created with event()

Parameters:
boolean $file If true, code will be written to a file
boolean $all If true, all code written with JavascriptHelper will be sent to a file
Returns:
null

Definition at line 473 of file javascript.php.

JavascriptHelper::codeBlock ( script = null,
options = array() 
)

Returns a JavaScript script tag.

Options:

Parameters:
string $script The JavaScript to be wrapped in SCRIPT tags.
array $options Set of options:
Returns:
string The full SCRIPT element, with the JavaScript inside it, or null, if 'inline' is set to false.

Definition at line 169 of file javascript.php.

References ClassRegistry::getObject(), and safe().

Referenced by blockEnd().

JavascriptHelper::escapeScript ( script  ) 

Escape carriage returns and single and double quotes for JavaScript segments.

Parameters:
string $script string that might have javascript elements
Returns:
string escaped string

Definition at line 286 of file javascript.php.

JavascriptHelper::escapeString ( string  ) 

Escape a string to be JavaScript friendly.

List of escaped ellements: + "\r\n" => '
' + "\r" => '
' + "\n" => '
' + '"' => '\"' + "'" => "\\'"

Parameters:
string $script String that needs to get escaped.
Returns:
string Escaped string.

Definition at line 304 of file javascript.php.

References App::import().

JavascriptHelper::event ( object,
event,
observer = null,
options = array() 
)

Attach an event to an element. Used with the Prototype library.

Parameters:
string $object Object to be observed
string $event event to observe
string $observer function to call
array $options Set options: useCapture, allowCache, safe
Returns:
boolean true on success

Definition at line 413 of file javascript.php.

JavascriptHelper::getCache ( clear = true  ) 

Gets (and clears) the current JavaScript event cache

Parameters:
boolean $clear
Returns:
string

Definition at line 484 of file javascript.php.

References $out.

JavascriptHelper::includeScript ( script = "",
options = array() 
)

Includes the Prototype Javascript library (and anything else) inside a single script tag.

Note: The recommended approach is to copy the contents of javascripts into your application's public/javascripts/ directory, and use

See also:
javascriptIncludeTag() to create remote script links.
Parameters:
string $script Script file to include
array $options Set options for codeBlock
Returns:
string script with all javascript in/javascripts folder

Definition at line 556 of file javascript.php.

JavascriptHelper::link ( url,
inline = true 
)

Returns a JavaScript include tag (SCRIPT element). If the filename is prefixed with "/", the path will be relative to the base path of your application. Otherwise, the path will be relative to your JavaScript path, usually webroot/js.

Parameters:
mixed $url String URL to JavaScript file, or an array of URLs.
boolean $inline If true, the <script> tag will be printed inline, otherwise it will be printed in the <head>, using $scripts_for_layout
See also:
JS_URL
Returns:
string

Definition at line 235 of file javascript.php.

References $out, $url, Configure::read(), and Helper::webroot().

JavascriptHelper::object ( data = array(),
options = array(),
prefix = null,
postfix = null,
stringKeys = null,
quoteKeys = null,
q = null 
)

Generates a JavaScript object in JavaScript Object Notation (JSON) from an array

### Options

Parameters:
array $data Data to be converted
array $options Set of options: block, prefix, postfix, stringKeys, quoteKeys, q
string $prefix DEPRECATED, use $options['prefix'] instead. Prepends the string to the returned data
string $postfix DEPRECATED, use $options['postfix'] instead. Appends the string to the returned data
array $stringKeys DEPRECATED, use $options['stringKeys'] instead. A list of array keys to be treated as a string
boolean $quoteKeys DEPRECATED, use $options['quoteKeys'] instead. If false, treats $stringKey as a list of keys *not* to be quoted
string $q DEPRECATED, use $options['q'] instead. The type of quote to use
Returns:
string A JSON code block

Definition at line 593 of file javascript.php.

References $out.

JavascriptHelper::value ( val,
quoteStrings = true 
)

Converts a PHP-native variable of any type to a JSON-equivalent representation

Parameters:
mixed $val A PHP variable to be converted to JSON
boolean $quoteStrings If false, leaves string values unquoted
Returns:
string a JavaScript-safe/JSON representation of $val

Definition at line 669 of file javascript.php.

References ife().

JavascriptHelper::writeEvents ( inline = true,
options = array() 
)

Write cached JavaScript events

Parameters:
boolean $inline If true, returns JavaScript event code. Otherwise it is added to the output of $scripts_for_layout in the layout.
array $options Set options for codeBlock
Returns:
string

Definition at line 514 of file javascript.php.

References $filename, $out, cache(), ClassRegistry::getObject(), and md5().


Member Data Documentation

JavascriptHelper::$__scriptBuffer = null

Definition at line 126 of file javascript.php.

JavascriptHelper::$_blockOptions = array()

Definition at line 75 of file javascript.php.

JavascriptHelper::$_cacheAll = false

Definition at line 111 of file javascript.php.

JavascriptHelper::$_cachedEvents = array()

Definition at line 83 of file javascript.php.

JavascriptHelper::$_cacheEvents = false

Definition at line 93 of file javascript.php.

JavascriptHelper::$_cacheToFile = false

Definition at line 102 of file javascript.php.

JavascriptHelper::$_rules = array()

Definition at line 121 of file javascript.php.

JavascriptHelper::$enabled = true

Definition at line 48 of file javascript.php.

JavascriptHelper::$safe = false

Definition at line 55 of file javascript.php.

JavascriptHelper::$tags

Initial value:

 array(
        'javascriptstart' => '<script type="text/javascript">',
        'javascriptend' => '</script>',
        'javascriptblock' => '<script type="text/javascript">%s</script>',
        'javascriptlink' => '<script type="text/javascript" src="%s"></script>'
    )

Reimplemented from Helper.

Definition at line 62 of file javascript.php.

JavascriptHelper::$useNative = false

Definition at line 40 of file javascript.php.


The documentation for this class was generated from the following file:
Generated on Sun Nov 22 00:30:56 2009 for CakePHP 1.2.x.x (v1.2.4.8284) by doxygen 1.4.7