JavascriptHelper Class Reference

Public Member Functions | |
| afterRender () | |
| blockEnd () | |
| cacheEvents ($file=false, $all=false) | |
| codeBlock ($script=null, $options=array(), $safe=true) | |
| 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 | |
| $_blockOptions = array() | |
| $_cacheAll = false | |
| $_cachedEvents = array() | |
| $_cacheEvents = false | |
| $_cacheToFile = false | |
| $_rules = array() | |
| $enabled = true | |
| $safe = false | |
| $tags | |
| $useNative = false | |
Detailed Description
Definition at line 38 of file javascript.php.
Member Function Documentation
| JavascriptHelper::afterRender | ( | ) |
AfterRender callback. Writes any cached events to the view, or to a temp file.
- Returns:
- null
Reimplemented from Helper.
Definition at line 573 of file javascript.php.
References writeEvents().
| JavascriptHelper::blockEnd | ( | ) |
Ends a block of cached JavaScript code
- Returns:
- mixed
Definition at line 213 of file javascript.php.
References $safe, ClassRegistry::getObject(), and ife().
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 374 of file javascript.php.
References $file.
| JavascriptHelper::codeBlock | ( | $ | script = null, |
|
| $ | options = array(), |
|||
| $ | safe = true | |||
| ) |
Returns a JavaScript script tag.
- Parameters:
-
string $script The JavaScript to be wrapped in SCRIPT tags. array $options Set of options: allowCache, safe boolean $safe DEPRECATED. Use $options['safe'] instead
- Returns:
- string The full SCRIPT element, with the JavaScript inside it.
Definition at line 164 of file javascript.php.
References $safe, and ClassRegistry::getObject().
Referenced by event(), includeScript(), object(), and writeEvents().
| 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 291 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 309 of file javascript.php.
Referenced by value().
| 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 322 of file javascript.php.
References codeBlock().
| JavascriptHelper::getCache | ( | $ | clear = true |
) |
Gets (and clears) the current JavaScript event cache
- Parameters:
-
boolean $clear
- Returns:
- string
Definition at line 385 of file javascript.php.
References Helper::$data, and $out.
Referenced by writeEvents().
| 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 453 of file javascript.php.
References $file, and codeBlock().
| 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 246 of file javascript.php.
References $out, $url, and Configure::read().
Referenced by writeEvents().
| 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
- 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 481 of file javascript.php.
References Helper::$data, $out, am(), codeBlock(), and value().
Referenced by value().
| 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 542 of file javascript.php.
References escapeString(), ife(), and object().
Referenced by object().
| 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 415 of file javascript.php.
References Helper::$data, $filename, $out, cache(), codeBlock(), getCache(), ClassRegistry::getObject(), and link().
Referenced by afterRender().
Member Data Documentation
| JavascriptHelper::$_blockOptions = array() |
Definition at line 80 of file javascript.php.
| JavascriptHelper::$_cacheAll = false |
Definition at line 116 of file javascript.php.
| JavascriptHelper::$_cachedEvents = array() |
Definition at line 88 of file javascript.php.
| JavascriptHelper::$_cacheEvents = false |
Definition at line 98 of file javascript.php.
| JavascriptHelper::$_cacheToFile = false |
Definition at line 107 of file javascript.php.
| JavascriptHelper::$_rules = array() |
Definition at line 125 of file javascript.php.
| JavascriptHelper::$enabled = true |
Definition at line 53 of file javascript.php.
| JavascriptHelper::$safe = false |
| JavascriptHelper::$tags |
Initial value:
array(
'javascriptblock' => '<script type="text/javascript">%s</script>',
'javascriptstart' => '<script type="text/javascript">',
'javascriptlink' => '<script type="text/javascript" src="%s"></script>',
'javascriptend' => '</script>'
)
Reimplemented from Helper.
Definition at line 67 of file javascript.php.
| JavascriptHelper::$useNative = false |
Definition at line 45 of file javascript.php.
The documentation for this class was generated from the following file:
- 1.2.x.x/cake/libs/view/helpers/javascript.php