Class JsBaseEngineHelper
JsEngineBaseClass
Abstract Base Class for All JsEngines to extend. Provides generic methods.
- AppHelper
- JsBaseEngineHelper
Direct Subclasses
Package: Cake\View\Helper
Copyright: Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
License: License (http://www.opensource.org/licenses/mit-license.php)
Location: Cake/View/Helper/JsBaseEngineHelper.php
Properties summary
-
$_callbackArguments
protectedarray
Contains a list of callback names -> default arguments. -
$_optionMap
protectedarray
Collection of option maps. Option maps allow other helpers to use generic names for engine callbacks and options. Allowing uniform code access for all engine types. Their use is optional for end user use though.
-
$bufferedMethods
publicarray
An array of lowercase method names in the Engine that are buffered unless otherwise disabled. This allows specific 'end point' methods to be automatically buffered by the JsHelper.
-
$selection
publicstring
The js snippet for the current selection.
Method Summary
-
_mapOptions() protected
Maps Abstract options to engine specific option names. If attributes are missing from the map, they are not changed.
-
_parseOptions() protected
Parse an options assoc array into an Javascript object literal. Similar to object() but treats any non-integer value as a string, does not include
{ }
-
_prepareCallbacks() protected
Prepare callbacks and wrap them with function ([args]) { } as defined in _callbackArgs array.
-
_processOptions() protected
Convenience wrapper method for all common option processing steps. Runs _mapOptions, _prepareCallbacks, and _parseOptions in order.
-
_toQuerystring() protected
Convert an array of data into a query string -
_utf8ToHex() protected
Encode a string into JSON. Converts and escapes necessary characters. -
alert() public
Create analert()
message in Javascript -
confirm() public
Create aconfirm()
message -
confirmReturn() public
Generate a confirm snippet that returns false from the current function scope.
-
domReady() abstract public
Create a domReady event. This is a special event in many libraries -
drag() abstract public
Create a draggable element. Works on the currently selected element. Additional options may be supported by the library implementation.
-
drop() abstract public
Create a droppable element. Allows for draggable elements to be dropped on it. Additional options may be supported by the library implementation.
-
each() abstract public
Create an iteration over the current selection result. -
effect() abstract public
Trigger an Effect. -
escape() public
Escape a string to be JSON friendly. -
event() abstract public
Add an event to the script cache. Operates on the currently selected elements. -
get() abstract public
Create javascript selector for a CSS rule -
object() public
Generates a JavaScript object in JavaScript Object Notation (JSON) from an array. Will use native JSON encode method if available, and $useNative == true
-
prompt() public
Create aprompt()
Javascript function -
redirect() public
Redirects to a URL. Creates a window.location modification snippet that can be used to trigger 'redirects' from Javascript.
-
request() abstract public
Make an XHR request -
serializeForm() abstract public
Serialize the form attached to $selector. Pass
true
for $isForm if the current selection is a form element. Converts the form or the form element attached to the current selection into a string/json object (depending on the library implementation) for use with XHR operations. -
slider() abstract public
Create a slider UI widget. Comprised of a track and knob. Additional options may be supported by the library implementation.
-
sortable() abstract public
Create a sortable element. Additional options may be supported by the library implementation.
-
value() public
Converts a PHP-native variable of any type to a JSON-equivalent representation
Method Detail
_mapOptions() protected ¶
_mapOptions( string $method , array $options )
Maps Abstract options to engine specific option names. If attributes are missing from the map, they are not changed.
Parameters
- string $method
- Name of method whose options are being worked with.
- array $options
- Array of options to map.
Returns
Array of mapped options.
_parseOptions() protected ¶
_parseOptions( array $options , array $safeKeys = array() )
Parse an options assoc array into an Javascript object literal.
Similar to object() but treats any non-integer value as a string,
does not include { }
Parameters
- array $options
- Options to be converted
- array $safeKeys optional array()
- Keys that should not be escaped.
Returns
Parsed JSON options without enclosing { }.
_prepareCallbacks() protected ¶
_prepareCallbacks( string $method , array $options , array $callbacks = array() )
Prepare callbacks and wrap them with function ([args]) { } as defined in _callbackArgs array.
Parameters
- string $method
- Name of the method you are preparing callbacks for.
- array $options
- Array of options being parsed
- array $callbacks optional array()
- Additional Keys that contain callbacks
Returns
Array of options with callbacks added.
_processOptions() protected ¶
_processOptions( string $method , array $options )
Convenience wrapper method for all common option processing steps. Runs _mapOptions, _prepareCallbacks, and _parseOptions in order.
Parameters
- string $method
- Name of method processing options for.
- array $options
- Array of options to process.
Returns
Parsed options string.
_toQuerystring() protected ¶
_toQuerystring( array $parameters )
Convert an array of data into a query string
Parameters
- array $parameters
- Array of parameters to convert to a query string
Returns
Querystring fragment
_utf8ToHex() protected ¶
_utf8ToHex( string $string )
Encode a string into JSON. Converts and escapes necessary characters.
Parameters
- string $string
- The string that needs to be utf8->hex encoded
alert() public ¶
alert( string $message )
Create an alert()
message in Javascript
Parameters
- string $message
- Message you want to alter.
Returns
completed alert()
confirm() public ¶
confirm( string $message )
Create a confirm()
message
Parameters
- string $message
- Message you want confirmed.
Returns
completed confirm()
confirmReturn() public ¶
confirmReturn( string $message )
Generate a confirm snippet that returns false from the current function scope.
Parameters
- string $message
- Message to use in the confirm dialog.
Returns
completed confirm with return script
domReady() abstract public ¶
domReady( string $functionBody )
Create a domReady event. This is a special event in many libraries
Parameters
- string $functionBody
- The code to run on domReady
Returns
completed domReady method
drag() abstract public ¶
drag( array $options = array() )
Create a draggable element. Works on the currently selected element. Additional options may be supported by the library implementation.
Options
handle
- selector to the handle element.snapGrid
- The pixel grid that movement snaps to, an array(x, y)container
- The element that acts as a bounding box for the draggable element.
Event Options
start
- Event fired when the drag startsdrag
- Event fired on every step of the dragstop
- Event fired when dragging stops (mouse release)
Parameters
- array $options optional array()
- Options array see above.
Returns
Completed drag script
drop() abstract public ¶
drop( array $options = array() )
Create a droppable element. Allows for draggable elements to be dropped on it. Additional options may be supported by the library implementation.
Options
accept
- Selector for elements this droppable will accept.hoverclass
- Class to add to droppable when a draggable is over.
Event Options
drop
- Event fired when an element is dropped into the drop zone.hover
- Event fired when a drag enters a drop zone.leave
- Event fired when a drag is removed from a drop zone without being dropped.
Parameters
- array $options optional array()
- Array of options for the drop. See above.
Returns
Completed drop script
each() abstract public ¶
each( string $callback )
Create an iteration over the current selection result.
Parameters
- string $callback
- The function body you wish to apply during the iteration.
Returns
completed iteration
effect() abstract public ¶
effect( string $name , array $options = array() )
Trigger an Effect.
Supported Effects
The following effects are supported by all core JsEngines
show
- reveal an element.hide
- hide an element.fadeIn
- Fade in an element.fadeOut
- Fade out an element.slideIn
- Slide an element in.slideOut
- Slide an element out.
Options
speed
- Speed at which the animation should occur. Accepted values are 'slow', 'fast'. Not all effects use the speed option.
Parameters
- string $name
- The name of the effect to trigger.
- array $options optional array()
- Array of options for the effect.
Returns
completed string with effect.
escape() public ¶
escape( string $string )
Escape a string to be JSON friendly.
List of escaped elements:
- "\r" => '\n'
- "\n" => '\n'
- '"' => '\"'
Parameters
- string $string
- String that needs to get escaped.
Returns
Escaped string.
event() abstract public ¶
event( string $type , string $callback , array $options = array() )
Add an event to the script cache. Operates on the currently selected elements.
Options
wrap
- Whether you want the callback wrapped in an anonymous function. (defaults to true)stop
- Whether you want the event to stopped. (defaults to true)
Parameters
- string $type
- Type of event to bind to the current dom id
- string $callback
- The Javascript function you wish to trigger or the function literal
- array $options optional array()
- Options for the event.
Returns
completed event handler
get() abstract public ¶
get( string $selector )
Create javascript selector for a CSS rule
Parameters
- string $selector
- The selector that is targeted
Returns
object() public ¶
object( array $data = array() , array $options = array() )
Generates a JavaScript object in JavaScript Object Notation (JSON) from an array. Will use native JSON encode method if available, and $useNative == true
Options:
prefix
- String prepended to the returned data.postfix
- String appended to the returned data.
Parameters
- array $data optional array()
- Data to be converted.
- array $options optional array()
- Set of options, see above.
Returns
A JSON code block
prompt() public ¶
prompt( string $message , string $default = '' )
Create a prompt()
Javascript function
Parameters
- string $message
- Message you want to prompt.
- string $default optional ''
- Default message
Returns
completed prompt()
redirect() public ¶
redirect( string|array $url = null , array $options ,… )
Redirects to a URL. Creates a window.location modification snippet that can be used to trigger 'redirects' from Javascript.
Parameters
- string|array $url optional null
- array $options ,…
Returns
completed redirect in javascript
request() abstract public ¶
request( string|array $url , array $options = array() )
Make an XHR request
Event Options
complete
- Callback to fire on complete.success
- Callback to fire on success.before
- Callback to fire on request initialization.error
- Callback to fire on request failure.
Options
method
- The method to make the request with defaults to GET in more librariesasync
- Whether or not you want an asynchronous request.data
- Additional data to send.update
- Dom id to update with the content of the request.type
- Data type for response. 'json' and 'html' are supported. Default is html for most libraries.evalScripts
- Whether or not