1 | <?php |
||
21 | class JqueryHelper extends Helper |
||
22 | { |
||
23 | |||
24 | /** |
||
25 | * Loads jQuery's core library. |
||
26 | * |
||
27 | * ### Options |
||
28 | * |
||
29 | * - `block` Set to true to append output to view block "script" or provide |
||
30 | * custom block name. |
||
31 | * |
||
32 | * - `once` Whether or not the script should be checked for uniqueness. If true |
||
33 | * scripts will only be included once, use false to allow the same script to |
||
34 | * be included more than once per request. |
||
35 | * |
||
36 | * - `plugin` False value will prevent parsing path as a plugin. |
||
37 | * |
||
38 | * - `fullBase` If true the url will get a full address for the script file. |
||
39 | * |
||
40 | * @param array $options Array of options, and html attributes see above. |
||
41 | * @return mixed String of `<script />` tags or null if block is specified in options |
||
42 | * or if $once is true and the file has been included before. |
||
43 | */ |
||
44 | public function load($options = []) |
||
45 | { |
||
46 | if (Configure::read('debug')) { |
||
47 | return $this->_View->Html->script('Jquery.jquery-1.11.2.js', $options); |
||
48 | } |
||
49 | |||
50 | return $this->_View->Html->script('Jquery.jquery-1.11.2.min.js', $options); |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Loads the given jQuery UI components JS files. |
||
55 | * |
||
56 | * You can indicate the name of the JS files to include as follow: |
||
57 | * |
||
58 | * ```php |
||
59 | * $this->jQuery->ui('mouse', 'droppable', 'widget', ...); |
||
60 | * ``` |
||
61 | * |
||
62 | * You can provide an array of options for HtmlHelper::script() as follow: |
||
63 | * |
||
64 | * ```php |
||
65 | * $this->jQuery->ui('mouse', 'droppable', ['block' => 'true'], 'widget', ...); |
||
66 | * ``` |
||
67 | * |
||
68 | * If no component is given, all components (concatenated as a single JS file) |
||
69 | * will be loaded at once. |
||
70 | * |
||
71 | * @return mixed String of `<script />` tags or null if block is specified in |
||
72 | * options or if $once is true and the file has been included before |
||
73 | */ |
||
74 | public function ui() |
||
113 | |||
114 | /** |
||
115 | * Loads all CSS and JS files for the given UI theme. |
||
116 | * |
||
117 | * ### Usage |
||
118 | * |
||
119 | * You can indicate UI themes provided by an specific plugin: |
||
120 | * |
||
121 | * ```php |
||
122 | * // Theme's assets should be located at `MyPlugin/webroot/css/ui/flick/` |
||
123 | * $this->jQuery->theme('MyPlugin.flick'); |
||
124 | * ``` |
||
125 | * |
||
126 | * If no plugin syntax is given, **Jquery** plugin will be used by default: |
||
127 | * |
||
128 | * ```php |
||
129 | * // Theme's assets are located at `Jquery/webroot/css/ui/flick/` |
||
130 | * $this->jQuery->theme('flick'); |
||
131 | * ``` |
||
132 | * |
||
133 | * If you want to use default theme ($themeName = null) and provide some options |
||
134 | * (second argument), you can do as follow: |
||
135 | * |
||
136 | * ```php |
||
137 | * $this->jQuery->theme(['block' => true]); |
||
138 | * ``` |
||
139 | * |
||
140 | * ### Theme auto-detect |
||
141 | * |
||
142 | * If no theme is given ($themeName = null) this method will try to: |
||
143 | * |
||
144 | * - Use global parameter `jQueryUI.defaultTheme`. |
||
145 | * - Use `Jquery.ui-lightness` otherwise. |
||
146 | * |
||
147 | * ### Default theme |
||
148 | * |
||
149 | * You can define the global parameter `jQueryUI.defaultTheme` in your site's |
||
150 | * `bootstrap.php` to indicate the theme to use by default. For instance: |
||
151 | * |
||
152 | * ```php |
||
153 | * Configure::write('jQueryUI.defaultTheme', 'MyPlugin.ui-darkness'); |
||
154 | * ``` |
||
155 | * |
||
156 | * The `MyPlugin.ui-darkness` theme will be used by default every time this |
||
157 | * method is used with no arguments: |
||
158 | * |
||
159 | * ```php |
||
160 | * $this->jQuery->theme(); |
||
161 | * ``` |
||
162 | * |
||
163 | * Theme's assets should be located at `MyPlugin/webroot/css/ui/ui-darkness/` |
||
164 | * |
||
165 | * ### Options |
||
166 | * |
||
167 | * - `block` Set to true to append output to view block "css" or provide |
||
168 | * custom block name. |
||
169 | * |
||
170 | * - `once` Whether or not the css file should be checked for uniqueness. If |
||
171 | * true css files will only be included once, use false to allow the same |
||
172 | * css to be included more than once per request. |
||
173 | * |
||
174 | * - `plugin` False value will prevent parsing path as a plugin. |
||
175 | * |
||
176 | * - `rel` Defaults to 'stylesheet'. If equal to 'import' the stylesheet will be |
||
177 | * imported. |
||
178 | * |
||
179 | * - `fullBase` If true the URL will get a full address for the css file. |
||
180 | * |
||
181 | * @param string|array|null $themeName Name of the theme to load, or array |
||
182 | * of options (will replace $options) to use default theme with options |
||
183 | * @param array $options Array of options and HTML arguments |
||
184 | * @return string CSS <link /> or <style /> tag, depending on the type of link. |
||
185 | */ |
||
186 | public function theme($themeName = null, array $options = []) |
||
213 | } |
||
214 |