Class JsBaseEngineHelper
JsEngineBaseClass
Abstract Base Class for All JsEngines to extend. Provides generic methods.
- AppHelper
- JsBaseEngineHelper
Direct Subclasses
Package: Cake\View\Helper
Copyright: Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
License: MIT License
Location: Cake/View/Helper/JsBaseEngineHelper.php
Properties summary
-
$_callbackArguments
protectedContains a list of callback names -> default arguments.array
-
$_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
publicThe js snippet for the current selection.string
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 a 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() protectedConvert an array of data into a query string
- _utf8ToHex() protectedEncode a string into JSON. Converts and escapes necessary characters.
- alert() publicCreate an
alert()
message in JavaScript - confirm() publicCreate a
confirm()
message - confirmReturn() public
Generate a confirm snippet that returns false from the current function scope.
- Create a domReady event. This is a special event in many libraries
-
Create a draggable element. Works on the currently selected element. Additional options may be supported by the library implementation.
-
Create a droppable element. Allows for draggable elements to be dropped on it. Additional options may be supported by the library implementation.
- Create an iteration over the current selection result.
- Trigger an Effect.
- escape() publicEscape a string to be JSON friendly.
- Add an event to the script cache. Operates on the currently selected elements.
- 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() publicCreate a
prompt()
JavaScript function - redirect() public
Redirects to a URL. Creates a window.location modification snippet that can be used to trigger 'redirects' from JavaScript.
- Make an XHR request
-
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. -
Create a slider UI widget. Comprised of a track and knob. Additional options may be supported by the library implementation.
-
Create a sortable element. Additional options may be supported by the library implementation.
- value() publicConverts a PHP-native variable of any type to a JSON-equivalent representation
Method Detail
_mapOptions()source 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
arrayArray of mapped options.
_parseOptions()source protected
_parseOptions( array $options , array $safeKeys array() )
Parse an options assoc array into a 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
stringParsed JSON options without enclosing { }.
_prepareCallbacks()source 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
arrayArray of options with callbacks added.
_processOptions()source 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
stringParsed options string.
_toQuerystring()source 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
stringQuerystring fragment
_utf8ToHex()source 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()source public
alert( string $message )
Create an alert()
message in JavaScript
Parameters
- string
$message
- Message you want to alter.
Returns
stringcompleted alert()
confirm()source public
confirm( string $message )
Create a confirm()
message
Parameters
- string
$message
- Message you want confirmed.
Returns
stringcompleted confirm()
confirmReturn()source 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
stringcompleted confirm with return script
domReady()source 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
stringcompleted domReady method
drag()source 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 starts -
drag
- Event fired on every step of the drag -
stop
- Event fired when dragging stops (mouse release)
Parameters
- array
$options
optional array() - Options array see above.
Returns
stringCompleted drag script
drop()source 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
stringCompleted drop script
each()source 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
stringcompleted iteration
effect()source 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
stringcompleted string with effect.
escape()source 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
stringEscaped string.
event()source 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
stringcompleted event handler
get()source abstract public
get( string $selector )
Create javascript selector for a CSS rule
Parameters
- string
$selector
- The selector that is targeted
Returns
JsBaseEngineHelper
instance of $this. Allows chained methods.
object()source 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
stringA JSON code block
prompt()source 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
stringcompleted prompt()
redirect()source public
redirect( string|array $url null )
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 - URL
Returns
stringcompleted redirect in javascript
request()source 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 libraries -
async
- 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
© 2005–2017 The Cake Software Foundation, Inc.
Licensed under the MIT License.
CakePHP is a registered trademark of Cake Software Foundation, Inc.
We are not endorsed by or affiliated with CakePHP.
https://api.cakephp.org/2.10/class-JsBaseEngineHelper.html