JavascriptHelper Class Info:

Class Declaration:
class JavascriptHelper extends AppHelper
File name:
cake/libs/view/helpers/javascript.php
Summary:
Javascript Helper class for easy use of JavaScript. JavascriptHelper encloses all methods needed while working with JavaScript.
Class Inheritance

AppHelper Helper Overloadable Object

package
cake
subpackage
cake.cake.libs.view.helpers

Properties:

Show/Hide parent properties
public action Current action.
public argSeparator URL argument separator character
public base Base URL
protected _blockOptions Holds options passed to codeBlock(), saved for when block is dumped to output
protected _cacheAll Indicates whether *all* generated JavaScript should be cached for later output
protected _cachedEvents Caches events written by event() for output at the end of page execution
protected _cacheEvents Indicates whether generated events should be cached for later output (can be written at the end of the page, in the <head />, or to an external file).
protected _cacheToFile Indicates whether cached events should be written to an external file
public data POST data for models
public enabled If true, automatically writes events to the end of a script or to an external JavaScript file at the end of page execution
public helpers List of helpers used by this helper
public here URL to current action.
protected _log Log object
public namedArgs List of named arguments
public params Parameter array.
public plugin Plugin path
protected _rules Contains event rules attached with CSS selectors. Used with the event:Selectors JavaScript library.
public safe Indicates whether <script /> blocks should be written 'safely,' i.e. wrapped in CDATA blocks
public tags HTML tags used by this helper.
public themeWeb Theme name
public useNative Determines whether native JSON extension is used for encoding. Set by object constructor.
public validationErrors Contains model validation errors of form post-backs
public webroot Webroot path

Method Summary:

Show/Hide parent methods
public addClass( $options = array ( ), $class = NULL, $key = 'class' )
public afterLayout( )
public afterRender( )
public beforeLayout( )
public beforeRender( )
public blockEnd( )
public cacheEvents( $file = false, $all = false )
public cakeError( $method, $messages = array ( ) )
public call__( $method, $params )
public clean( $output )
public codeBlock( $script = NULL, $options = array ( ) )
public __construct( $options = array ( ) )
public dispatchMethod( $method, $params = array ( ) )
public domId( $options = NULL, $id = 'id' )
public escapeScript( $script )
public escapeString( $string )
public event( $object, $event, $observer = NULL, $options = array ( ) )
public field( )
protected get__( $name )
public getCache( $clear = true )
public includeScript( $script = '', $options = array ( ) )
protected _initInputField( $field, $options = array ( ) )
public link( $url, $inline = true )
public loadConfig( $name = 'tags' )
public log( $msg, $type = 2 )
public model( )
public modelID( )
public __name( $options = array ( ), $field = NULL, $key = 'name' )
public object( $data = array ( ), $options = array ( ), $prefix = NULL, $postfix = NULL, $stringKeys = NULL, $quoteKeys = NULL, $q = NULL )
public output( $str )
public overload( )
public _parseAttributes( $options, $exclude = NULL, $insertBefore = ' ', $insertAfter = NULL )
protected _persist( $name, $return, $object, $type = NULL )
public requestAction( $url, $extra = array ( ) )
protected _savePersistent( $name, $object )
protected _set( $properties = array ( ) )
public set__( $name, $value )
public setEntity( $entity, $setScope = false )
public _stop( $status = 0 )
public tagIsInvalid( $model = NULL, $field = NULL, $modelID = NULL )
public toString( )
public url( $url = NULL, $full = false )
public _utf8ToHex( $string )
public value( $val, $quoteStrings = true )
public webroot( $file )
public writeEvents( $inline = true, $options = array ( ) )

addClass

top
Adds the given class to the element options
Parameters:
$options array optional array ( )
$class string optional NULL
$key string optional 'class'
Method defined in class:
Helper
Method defined in file:
cake/libs/view/helper.php on line 642
return
array

afterLayout

top
After layout callback. Overridden in subclasses.
Method defined in class:
Helper
Method defined in file:
cake/libs/view/helper.php on line 683

afterRender

top
AfterRender callback. Writes any cached events to the view, or to a temp file.
Method defined in class:
JavascriptHelper
Method defined in file:
cake/libs/view/helpers/javascript.php on line 703
return
null

beforeLayout

top
Before layout callback. Overridden in subclasses.
Method defined in class:
Helper
Method defined in file:
cake/libs/view/helper.php on line 677

beforeRender

top
Before render callback. Overridden in subclasses.
Method defined in class:
Helper
Method defined in file:
cake/libs/view/helper.php on line 665

blockEnd

top
Ends a block of cached JavaScript code
Method defined in class:
JavascriptHelper
Method defined in file:
cake/libs/view/helpers/javascript.php on line 205
return
mixed

cacheEvents

top
Cache JavaScript events created with event()
Parameters:
$file boolean If true, code will be written to a file optional false
$all boolean If true, all code written with JavascriptHelper will be sent to a file optional false
Method defined in class:
JavascriptHelper
Method defined in file:
cake/libs/view/helpers/javascript.php on line 476
return
null

cakeError

top
Used to report user friendly errors. If there is a file app/error.php or app/app_error.php this file will be loaded error.php is the AppError class it should extend ErrorHandler class.
Parameters:
$method string Method to be called in the error class (AppError or ErrorHandler classes) required (no default)
$messages array Message that is to be displayed by the error class optional array ( )
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 189
return
error message
access
public

call__

top
Parameters:
$method required (no default)
$params required (no default)
Method defined in class:
Helper
Method defined in file:
cake/libs/view/helper.php on line 142

clean

top
Used to remove harmful tags from content
Parameters:
$output mixed required (no default)
Method defined in class:
Helper
Method defined in file:
cake/libs/view/helper.php on line 214
return
cleaned content for output
access
public

codeBlock

top
Returns a JavaScript script tag. Options: - allowCache: boolean, designates whether this block is cacheable using the current cache settings. - safe: boolean, whether this block should be wrapped in CDATA tags. Defaults to helper's object configuration. - inline: whether the block should be printed inline, or written to cached for later output (i.e. $scripts_for_layout).
Parameters:
$script string The JavaScript to be wrapped in SCRIPT tags. optional NULL
$options array Set of options: optional array ( )
Method defined in class:
JavascriptHelper
Method defined in file:
cake/libs/view/helpers/javascript.php on line 169
return
string The full SCRIPT element, with the JavaScript inside it, or null, if 'inline' is set to false.

__construct

top
Constructor. Checks for presence of native PHP JSON extension to use for object encoding
Parameters:
$options optional array ( )
Method defined in class:
JavascriptHelper
Method defined in file:
cake/libs/view/helpers/javascript.php on line 132
access
public

dispatchMethod

top
Calls a method on this object with the given parameters. Provides an OO wrapper for call_user_func_array, and improves performance by using straight method calls in most cases.
Parameters:
$method string Name of the method to call required (no default)
$params array Parameter list to use when calling $method optional array ( )
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 113
return
mixed Returns the result of the method call
access
public

domId

top
Generates a DOM ID for the selected element, if one is not set.
Parameters:
$options mixed optional NULL
$id string optional 'id'
Method defined in class:
Helper
Method defined in file:
cake/libs/view/helper.php on line 483
return
mixed

escapeScript

top
Escape carriage returns and single and double quotes for JavaScript segments.
Parameters:
$script string string that might have javascript elements required (no default)
Method defined in class:
JavascriptHelper
Method defined in file:
cake/libs/view/helpers/javascript.php on line 289
return
string escaped string

escapeString

top
Escape a string to be JavaScript friendly. List of escaped ellements: + "\r\n" => '\n' + "\r" => '\n' + "\n" => '\n' + '"' => '\"' + "'" => "\\'"
Parameters:
$string required (no default)
Method defined in class:
JavascriptHelper
Method defined in file:
cake/libs/view/helpers/javascript.php on line 307
return
string Escaped string.

event

top
Attach an event to an element. Used with the Prototype library.
Parameters:
$object string Object to be observed required (no default)
$event string event to observe required (no default)
$observer string function to call optional NULL
$options array Set options: useCapture, allowCache, safe optional array ( )
Method defined in class:
JavascriptHelper
Method defined in file:
cake/libs/view/helpers/javascript.php on line 416
return
boolean true on success

field

top
Gets the currently-used model field of the rendering context.
Method defined in class:
Helper
Method defined in file:
cake/libs/view/helper.php on line 445
return
string

get__

top
Default overload methods
Parameters:
$name required (no default)
Method defined in class:
Helper
Method defined in file:
cake/libs/view/helper.php on line 140
access
protected

getCache

top
Gets (and clears) the current JavaScript event cache
Parameters:
$clear boolean optional true
Method defined in class:
JavascriptHelper
Method defined in file:
cake/libs/view/helpers/javascript.php on line 487
return
string

includeScript

top
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 javascriptIncludeTag() to create remote script links.
Parameters:
$script string Script file to include optional ''
$options array Set options for codeBlock optional array ( )
Method defined in class:
JavascriptHelper
Method defined in file:
cake/libs/view/helpers/javascript.php on line 559
see
javascriptIncludeTag() to
return
string script with all javascript in/javascripts folder

_initInputField

top
Sets the defaults for an input tag
Parameters:
$field required (no default)
$options array optional array ( )
Method defined in class:
Helper
Method defined in file:
cake/libs/view/helper.php on line 621
return
array
access
protected

link

top
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:
$url mixed String URL to JavaScript file, or an array of URLs. required (no default)
$inline boolean If true, the <script /> tag will be printed inline, otherwise it will be printed in the <head />, using $scripts_for_layout optional true
Method defined in class:
JavascriptHelper
Method defined in file:
cake/libs/view/helpers/javascript.php on line 235
see
JS_URL
return
string

loadConfig

top
Parses tag templates into $this->tags.
Parameters:
$name optional 'tags'
Method defined in class:
Helper
Method defined in file:
cake/libs/view/helper.php on line 152
return
array merged tags from config/$name.php

log

top
API for logging events.
Parameters:
$msg string Log message required (no default)
$type integer Error type constant. Defined in app/config/core.php. optional 2
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 150
return
boolean Success of log write
access
public

model

top
Gets the currently-used model of the rendering context.
Method defined in class:
Helper
Method defined in file:
cake/libs/view/helper.php on line 423
return
string

modelID

top
Gets the ID of the currently-used model of the rendering context.
Method defined in class:
Helper
Method defined in file:
cake/libs/view/helper.php on line 436
return
mixed

__name

top
Gets the input field name for the current tag
Parameters:
$options array optional array ( )
$field optional NULL
$key string optional 'name'
Method defined in class:
Helper
Method defined in file:
cake/libs/view/helper.php on line 510
return
array

object

top
Generates a JavaScript object in JavaScript Object Notation (JSON) from an array ### Options - block - Wraps the return value in a script tag if true. Default is false - prefix - Prepends the string to the returned data. Default is '' - postfix - Appends the string to the returned data. Default is '' - stringKeys - A list of array keys to be treated as a string. - quoteKeys - If false treats $stringKeys as a list of keys **not** to be quoted. Default is true. - q - The type of quote to use. Default is "'"
Parameters:
$data array Data to be converted optional array ( )
$options array Set of options: block, prefix, postfix, stringKeys, quoteKeys, q optional array ( )
$prefix string DEPRECATED, use $options['prefix'] instead. Prepends the string to the returned data optional NULL
$postfix string DEPRECATED, use $options['postfix'] instead. Appends the string to the returned data optional NULL
$stringKeys array DEPRECATED, use $options['stringKeys'] instead. A list of array keys to be treated as a string optional NULL
$quoteKeys boolean DEPRECATED, use $options['quoteKeys'] instead. If false, treats $stringKey as a list of keys *not* to be quoted optional NULL
$q string DEPRECATED, use $options['q'] instead. The type of quote to use optional NULL
Method defined in class:
JavascriptHelper
Method defined in file:
cake/libs/view/helpers/javascript.php on line 596
return
string A JSON code block

output

top
Returns a string generated by a helper method This method can be overridden in subclasses to do generalized output post-processing
Parameters:
$str string String to be output. required (no default)
Method defined in class:
Helper
Method defined in file:
cake/libs/view/helper.php on line 658
return
string

overload

top
Overload implementation. No need for implementation in PHP5.
Method defined in class:
Overloadable
Method defined in file:
cake/libs/overloadable_php5.php on line 39
access
public

_parseAttributes

top
Returns a space-delimited string with items of the $options array. If a key of $options array happens to be one of: + 'compact' + 'checked' + 'declare' + 'readonly' + 'disabled' + 'selected' + 'defer' + 'ismap' + 'nohref' + 'noshade' + 'nowrap' + 'multiple' + 'noresize' And its value is one of: + 1 + true + 'true' Then the value will be reset to be identical with key's name. If the value is not one of these 3, the parameter is not output.
Parameters:
$options array Array of options. required (no default)
$exclude array Array of options to be excluded. optional NULL
$insertBefore string String to be inserted before options. optional ' '
$insertAfter string String to be inserted ater options. optional NULL
Method defined in class:
Helper
Method defined in file:
cake/libs/view/helper.php on line 260
return
string

_persist

top
Checks for a persistent class file, if found file is opened and true returned If file is not found a file is created and false returned If used in other locations of the model you should choose a unique name for the persistent file There are many uses for this method, see manual for examples
Parameters:
$name string name of the class to persist required (no default)
$return required (no default)
$object string the object to persist required (no default)
$type optional NULL
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 219
return
boolean Success
access
protected
todo
add examples to manual

requestAction

top
Calls a controller's method from any location.
Parameters:
$url mixed String or array-based url. required (no default)
$extra array if array includes the key "return" it sets the AutoRender to true. optional array ( )
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 86
return
mixed Boolean true or false on success/failure, or contents of rendered action if 'return' is set in $extra.
access
public

_savePersistent

top
You should choose a unique name for the persistent file There are many uses for this method, see manual for examples
Parameters:
$name string name used for object to cache required (no default)
$object object the object to persist required (no default)
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 247
return
boolean true on save, throws error if file can not be created
access
protected

_set

top
Allows setting of multiple properties of the object in a single line of code.
Parameters:
$properties array An associative array containing properties and corresponding values. optional array ( )
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 169
return
void
access
protected

set__

top
Parameters:
$name required (no default)
$value required (no default)
Method defined in class:
Helper
Method defined in file:
cake/libs/view/helper.php on line 141

setEntity

top
Sets this helper's model and field properties to the dot-separated value-pair in $entity.
Parameters:
$entity mixed A field name, like "ModelName.fieldName" or "ModelName.ID.fieldName" required (no default)
$setScope boolean Sets the view scope to the model specified in $tagValue optional false
Method defined in class:
Helper
Method defined in file:
cake/libs/view/helper.php on line 311
return
void

_stop

top
Stop execution of the current script
Parameters:
$status optional 0
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 139
return
void
access
public

tagIsInvalid

top
Returns false if given FORM field has no errors. Otherwise it returns the constant set in the array Model->validationErrors.
Parameters:
$model string Model name as string optional NULL
$field string Fieldname as string optional NULL
$modelID integer Unique index identifying this record within the form optional NULL
Method defined in class:
Helper
Method defined in file:
cake/libs/view/helper.php on line 457
return
boolean True on errors.

toString

top
Object-to-string conversion. Each class can override this method as necessary.
Method defined in class:
Object
Method defined in file:
cake/libs/object.php on line 73
return
string The name of this class
access
public

url

top
Finds URL for specified action. Returns an URL pointing to a combination of controller and action. Param $url can be: + Empty - the method will find adress to actuall controller/action. + '/' - the method will find base URL of application. + A combination of controller/action - the method will find url for it.
Parameters:
$url mixed Cake-relative URL, like "/products/edit/92" or "/presidents/elect/4" or an array specifying any of the following: 'controller', 'action', and/or 'plugin', in addition to named arguments (keyed array elements), and standard URL arguments (indexed array elements) optional NULL
$full boolean If true, the full base URL will be prepended to the result optional false
Method defined in class:
Helper
Method defined in file:
cake/libs/view/helper.php on line 177
return
string Full translated URL with base path.

_utf8ToHex

top
Encode a string into JSON. Converts and escapes necessary characters.
Parameters:
$string required (no default)
Method defined in class:
JavascriptHelper
Method defined in file:
cake/libs/view/helpers/javascript.php on line 318
return
void

value

top
Converts a PHP-native variable of any type to a JSON-equivalent representation
Parameters:
$val mixed A PHP variable to be converted to JSON required (no default)
$quoteStrings boolean If false, leaves string values unquoted optional true
Method defined in class:
JavascriptHelper
Method defined in file:
cake/libs/view/helpers/javascript.php on line 672
return
string a JavaScript-safe/JSON representation of $val

webroot

top
Checks if a file exists when theme is used, if no file is found default location is returned
Parameters:
$file string required (no default)
Method defined in class:
Helper
Method defined in file:
cake/libs/view/helper.php on line 186
return
string $webPath web path to file.

writeEvents

top
Write cached JavaScript events
Parameters:
$inline boolean If true, returns JavaScript event code. Otherwise it is added to the output of $scripts_for_layout in the layout. optional true
$options array Set options for codeBlock optional array ( )
Method defined in class:
JavascriptHelper
Method defined in file:
cake/libs/view/helpers/javascript.php on line 517
return
string