\Jquery\View\HelperJqueryHelper

jQuery Helper.

Add your application-wide methods in the class below, your helpers will inherit them.

Summary

Methods
Properties
Constants
load()
ui()
theme()
trigger()
eventDispatcher()
triggered()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

load()

load(array $options) : mixed

Loads jQuery's core library.

Options

  • block Set to true to append output to view block "script" or provide custom block name.

  • once Whether or not the script should be checked for uniqueness. If true scripts will only be included once, use false to allow the same script to be included more than once per request.

  • plugin False value will prevent parsing path as a plugin.

  • fullBase If true the url will get a full address for the script file.

Parameters

array $options

Array of options, and html attributes see above.

Returns

mixed —

String of <script /> tags or null if block is specified in options or if $once is true and the file has been included before.

ui()

ui() : mixed

Loads the given jQuery UI components JS files.

You can indicate the name of the JS files to include as follow:

$this->jQuery->ui('mouse', 'droppable', 'widget', ...);

You can provide an array of options for HtmlHelper::script() as follow:

$this->jQuery->ui('mouse', 'droppable', ['block' => 'true'], 'widget', ...);

If no component is given, all components (concatenated as a single JS file) will be loaded at once.

Returns

mixed —

String of <script /> tags or null if block is specified in options or if $once is true and the file has been included before

theme()

theme(string|array|null $themeName, array $options) : string

Loads all CSS and JS files for the given UI theme.

Usage

You can indicate UI themes provided by an specific plugin:

// Theme's assets should be located at `MyPlugin/webroot/css/ui/flick/`
$this->jQuery->theme('MyPlugin.flick');

If no plugin syntax is given, Jquery plugin will be used by default:

// Theme's assets are located at `Jquery/webroot/css/ui/flick/`
$this->jQuery->theme('flick');

If you want to use default theme ($themeName = null) and provide some options (second argument), you can do as follow:

$this->jQuery->theme(['block' => true]);

Theme auto-detect

If no theme is given ($themeName = null) this method will try to:

  • Use global parameter jQueryUI.defaultTheme.
  • Use Jquery.ui-lightness otherwise.

Default theme

You can define the global parameter jQueryUI.defaultTheme in your site's bootstrap.php to indicate the theme to use by default. For instance:

Configure::write('jQueryUI.defaultTheme', 'MyPlugin.ui-darkness');

The MyPlugin.ui-darkness theme will be used by default every time this method is used with no arguments:

$this->jQuery->theme();

Theme's assets should be located at MyPlugin/webroot/css/ui/ui-darkness/

Options

  • block Set to true to append output to view block "css" or provide custom block name.

  • once Whether or not the css file should be checked for uniqueness. If true css files will only be included once, use false to allow the same css to be included more than once per request.

  • plugin False value will prevent parsing path as a plugin.

  • rel Defaults to 'stylesheet'. If equal to 'import' the stylesheet will be imported.

  • fullBase If true the URL will get a full address for the css file.

Parameters

string|array|null $themeName

Name of the theme to load, or array of options (will replace $options) to use default theme with options

array $options

Array of options and HTML arguments

Returns

string —

CSS or