JavascriptHelper Class Reference

Inheritance diagram for JavascriptHelper:

Helper Object

List of all members.


Public Member Functions

 afterRender ()
 cacheEvents ($file=false, $all=false)
 codeBlock ($script, $allowCache=true)
 escapeScript ($script)
 escapeString ($string)
 event ($object, $event, $observer=null, $useCapture=false)
 includeScript ($script="")
 link ($url)
 linkOut ($url)
 object ($data=array(), $block=false, $prefix= '', $postfix= '', $stringKeys=array(), $quoteKeys=true, $q="\"")
 writeEvents ()

Public Attributes

 $_cacheAll = false
 $_cachedEvents = array()
 $_cacheEvents = false
 $_cacheToFile = false
 $_rules = array()

Detailed Description

Definition at line 35 of file javascript.php.


Member Function Documentation

JavascriptHelper::afterRender (  ) 

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

Returns:
void public

Reimplemented from Helper.

Definition at line 313 of file javascript.php.

References writeEvents().

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:
void public

Definition at line 165 of file javascript.php.

References $file.

JavascriptHelper::codeBlock ( script,
allowCache = true 
)

Returns a JavaScript script tag.

Parameters:
string $script The JavaScript to be wrapped in SCRIPT tags.
boolean $allowCache Allows the script to be cached if non-event caching is active
Returns:
string The full SCRIPT element, with the JavaScript inside it. public

Definition at line 49 of file javascript.php.

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 public

Definition at line 89 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. public

Definition at line 108 of file javascript.php.

Referenced by object().

JavascriptHelper::event ( object,
event,
observer = null,
useCapture = false 
)

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
boolean $useCapture default true
Returns:
boolean true on success public

Definition at line 122 of file javascript.php.

References codeBlock().

JavascriptHelper::includeScript ( script = ""  ) 

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 name of script to include
Returns:
string script with all javascript in/javascripts folder public

Definition at line 223 of file javascript.php.

References $file, $filename, and codeBlock().

JavascriptHelper::link ( url  ) 

Returns a JavaScript include tag (SCRIPT element)

Parameters:
string $url URL to JavaScript file.
Returns:
string public

Definition at line 63 of file javascript.php.

Referenced by writeEvents().

JavascriptHelper::linkOut ( url  ) 

Returns a JavaScript include tag for an externally-hosted script

Parameters:
string $url URL to JavaScript file.
Returns:
string public

Definition at line 76 of file javascript.php.

JavascriptHelper::object ( data = array(),
block = false,
prefix = '',
postfix = '',
stringKeys = array(),
quoteKeys = true,
q = "\"" 
)

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

Parameters:
array $data Data to be converted
boolean $block Wraps return value in a <script> block if true
string $prefix Prepends the string to the returned data
string $postfix Appends the string to the returned data
array $stringKeys A list of array keys to be treated as a string
boolean $quoteKeys If false, treats $stringKey as a list of keys *not* to be quoted
string $q The type of quote to use
Returns:
string A JSON code block public

Definition at line 255 of file javascript.php.

References $data, codeBlock(), and escapeString().

JavascriptHelper::writeEvents (  ) 

Write cached JavaScript events

Returns:
string public

Definition at line 176 of file javascript.php.

References $data, $filename, codeBlock(), and link().

Referenced by afterRender().


Member Data Documentation

JavascriptHelper::$_cacheAll = false

Definition at line 39 of file javascript.php.

JavascriptHelper::$_cachedEvents = array()

Definition at line 36 of file javascript.php.

JavascriptHelper::$_cacheEvents = false

Definition at line 37 of file javascript.php.

JavascriptHelper::$_cacheToFile = false

Definition at line 38 of file javascript.php.

JavascriptHelper::$_rules = array()

Definition at line 40 of file javascript.php.


The documentation for this class was generated from the following file: