Class JsBaseEngineHelper
JsEngineBaseClass
Abstract Base Class for All JsEngines to extend. Provides generic methods.
- Object
- Overloadable
- Helper
- AppHelper
- JsBaseEngineHelper
Direct Subclasses
Copyright: Copyright 2005-2012, Cake Software Foundation, Inc.
License: License (http://www.opensource.org/licenses/mit-license.php)
Location: view/helpers/js.php
Properties summary
-
$_callbackArguments
publicarray
Contains a list of callback names -> default arguments. -
$_optionMap
publicarray
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. -
$useNative
publicboolean
Determines whether native JSON extension is used for encoding. Set by object constructor.
Inherited Properties
Method Summary
-
__construct() public
Constructor. -
_mapOptions() public
Maps Abstract options to engine specific option names. If attributes are missing from the map, they are not changed.
-
_parseOptions() public
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() public
Prepare callbacks and wrap them with function ([args]) { } as defined in _callbackArgs array.
-
_processOptions() public
Conveinence wrapper method for all common option processing steps. Runs _mapOptions, _prepareCallbacks, and _parseOptions in order.
-
_toQuerystring() public
Convert an array of data into a query string -
_utf8ToHex() public
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() public
Create a domReady event. This is a special event in many libraries -
drag() public
Create a draggable element. Works on the currently selected element. Additional options may be supported by the library implementation.
-
drop() public
Create a droppable element. Allows for draggable elements to be dropped on it. Additional options may be supported by the library implementation.
-
each() public
Create an iteration over the current selection result. -
effect() public
Trigger an Effect. -
escape() public
Escape a string to be JSON friendly. -
event() public
Add an event to the script cache. Operates on the currently selected elements. -
get() 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() public
Make an XHR request -
serializeForm() 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() public
Create a slider UI widget. Comprised of a track and knob. Additional options may be supported by the library implementation.
-
sortable() 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() public ¶
_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() public ¶
_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() public ¶
_prepareCallbacks( string $method , array $options , string $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
- string $callbacks optional array()
- Additional Keys that contain callbacks
Returns
Array of options with callbacks added.
_processOptions() public ¶
_processOptions( string $method , array $options )
Conveinence 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() public ¶
_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() public ¶
_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() 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() 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() public ¶
drop( $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.
Returns
Completed drop script
each() 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() public ¶
effect( string $name , array $options )
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
- 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
- $script String that needs to get escaped.
Returns
Escaped string.
event() 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() public ¶
get( string $selector )
Create javascript selector for a CSS rule
Parameters
- string $selector
- The selector that is targeted
Returns
instance of $this. Allows chained methods.
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( mixed $url = null , array $options ,… )
Redirects to a URL. Creates a window.location modification snippet that can be used to trigger 'redirects' from Javascript.
Parameters
- mixed $url optional null
- array $options ,…
Returns
completed redirect in javascript
request() public ¶
request( mixed $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