CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (GitHub)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • Slack
    • Paid Support
CakePHP

C CakePHP 1.3 API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 1.3
      • 4.2
      • 4.1
      • 4.0
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Classes

  • AclBase
  • AclBehavior
  • AclComponent
  • AclNode
  • AclShell
  • Aco
  • AcoAction
  • AjaxHelper
  • ApcEngine
  • ApiShell
  • App
  • AppController
  • AppHelper
  • AppModel
  • Aro
  • AuthComponent
  • BakeShell
  • BakeTask
  • BehaviorCollection
  • Cache
  • CacheEngine
  • CacheHelper
  • CakeErrorController
  • CakeLog
  • CakeRoute
  • CakeSchema
  • CakeSession
  • CakeSocket
  • ClassRegistry
  • Component
  • Configure
  • ConnectionManager
  • ConsoleShell
  • ContainableBehavior
  • Controller
  • ControllerTask
  • CookieComponent
  • DataSource
  • DbAcl
  • DbConfigTask
  • DboMssql
  • DboMysql
  • DboMysqlBase
  • DboMysqli
  • DboOracle
  • DboPostgres
  • DboSource
  • DboSqlite
  • Debugger
  • EmailComponent
  • ErrorHandler
  • ExtractTask
  • File
  • FileEngine
  • FileLog
  • FixtureTask
  • Folder
  • FormHelper
  • Helper
  • HtmlHelper
  • HttpSocket
  • I18n
  • I18nModel
  • I18nShell
  • Inflector
  • IniAcl
  • JavascriptHelper
  • JqueryEngineHelper
  • JsBaseEngineHelper
  • JsHelper
  • L10n
  • MagicDb
  • MagicFileResource
  • MediaView
  • MemcacheEngine
  • Model
  • ModelBehavior
  • ModelTask
  • MootoolsEngineHelper
  • Multibyte
  • NumberHelper
  • Object
  • Overloadable
  • Overloadable2
  • PagesController
  • PaginatorHelper
  • Permission
  • PluginShortRoute
  • PluginTask
  • ProjectTask
  • PrototypeEngineHelper
  • RequestHandlerComponent
  • Router
  • RssHelper
  • Sanitize
  • Scaffold
  • ScaffoldView
  • SchemaShell
  • Security
  • SecurityComponent
  • SessionComponent
  • SessionHelper
  • Set
  • Shell
  • String
  • TemplateTask
  • TestSuiteShell
  • TestTask
  • TextHelper
  • ThemeView
  • TimeHelper
  • TranslateBehavior
  • TreeBehavior
  • Validation
  • View
  • ViewTask
  • XcacheEngine
  • Xml
  • XmlElement
  • XmlHelper
  • XmlManager
  • XmlNode
  • XmlTextNode

Functions

  • mb_encode_mimeheader
  • mb_stripos
  • mb_stristr
  • mb_strlen
  • mb_strpos
  • mb_strrchr
  • mb_strrichr
  • mb_strripos
  • mb_strrpos
  • mb_strstr
  • mb_strtolower
  • mb_strtoupper
  • mb_substr
  • mb_substr_count
  1: <?php
  2: /**
  3:  * MooTools Engine Helper for JsHelper
  4:  *
  5:  * Provides MooTools specific Javascript for JsHelper.
  6:  * Assumes that you have the following MooTools packages
  7:  *
  8:  * - Remote, Remote.HTML, Remote.JSON
  9:  * - Fx, Fx.Tween, Fx.Morph
 10:  * - Selectors, DomReady,
 11:  * - Drag, Drag.Move
 12:  *
 13:  * PHP versions 4 and 5
 14:  *
 15:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 16:  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 17:  *
 18:  * Licensed under The MIT License
 19:  * Redistributions of files must retain the above copyright notice.
 20:  *
 21:  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 22:  * @link          http://cakephp.org CakePHP(tm) Project
 23:  * @package       cake
 24:  * @subpackage    cake.cake.libs.view.helpers
 25:  * @since         CakePHP(tm) v 1.3
 26:  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 27:  */
 28: App::import('Helper', 'Js');
 29: 
 30: /**
 31:  * Mootools Engine Helper for JsHelper
 32:  *
 33:  * @package       cake
 34:  * @subpackage    cake.cake.libs.view.helpers
 35:  */
 36: class MootoolsEngineHelper extends JsBaseEngineHelper {
 37: /**
 38:  * Option mappings for MooTools
 39:  *
 40:  * @var array
 41:  */
 42:     var $_optionMap = array(
 43:         'request' => array(
 44:             'complete' => 'onComplete',
 45:             'success' => 'onSuccess',
 46:             'before' => 'onRequest',
 47:             'error' => 'onFailure'
 48:         ),
 49:         'sortable' => array(
 50:             'distance' => 'snap',
 51:             'containment' => 'constrain',
 52:             'sort' => 'onSort',
 53:             'complete' => 'onComplete',
 54:             'start' => 'onStart',
 55:         ),
 56:         'drag' => array(
 57:             'snapGrid' => 'snap',
 58:             'start' => 'onStart',
 59:             'drag' => 'onDrag',
 60:             'stop' => 'onComplete',
 61:         ),
 62:         'drop' => array(
 63:             'drop' => 'onDrop',
 64:             'hover' => 'onEnter',
 65:             'leave' => 'onLeave',
 66:         ),
 67:         'slider' => array(
 68:             'complete' => 'onComplete',
 69:             'change' => 'onChange',
 70:             'direction' => 'mode',
 71:             'step' => 'steps'
 72:         )
 73:     );
 74: 
 75: /**
 76:  * Contains a list of callback names -> default arguments.
 77:  *
 78:  * @var array
 79:  */
 80:     var $_callbackArguments = array(
 81:         'slider' => array(
 82:             'onTick' => 'position',
 83:             'onChange' => 'step',
 84:             'onComplete' => 'event'
 85:         ),
 86:         'request' => array(
 87:             'onRequest' => '',
 88:             'onComplete' => '',
 89:             'onCancel' => '',
 90:             'onSuccess' => 'responseText, responseXML',
 91:             'onFailure' => 'xhr',
 92:             'onException' => 'headerName, value',
 93:         ),
 94:         'drag' => array(
 95:             'onBeforeStart' => 'element',
 96:             'onStart' => 'element',
 97:             'onSnap' => 'element',
 98:             'onDrag' => 'element, event',
 99:             'onComplete' => 'element, event',
100:             'onCancel' => 'element',
101:         ),
102:         'drop' => array(
103:             'onBeforeStart' => 'element',
104:             'onStart' => 'element',
105:             'onSnap' => 'element',
106:             'onDrag' => 'element, event',
107:             'onComplete' => 'element, event',
108:             'onCancel' => 'element',
109:             'onDrop' => 'element, droppable, event',
110:             'onLeave' => 'element, droppable',
111:             'onEnter' => 'element, droppable',
112:         ),
113:         'sortable' => array(
114:             'onStart' => 'element, clone',
115:             'onSort' => 'element, clone',
116:             'onComplete' => 'element',
117:         )
118:     );
119: 
120: /**
121:  * Create javascript selector for a CSS rule
122:  *
123:  * @param string $selector The selector that is targeted
124:  * @return object instance of $this. Allows chained methods.
125:  */
126:     function get($selector) {
127:         $this->_multipleSelection = false;
128:         if ($selector == 'window' || $selector == 'document') {
129:             $this->selection = "$(" . $selector .")";
130:             return $this;
131:         }
132:         if (preg_match('/^#[^\s.]+$/', $selector)) {
133:             $this->selection = '$("' . substr($selector, 1) . '")';
134:             return $this;
135:         }
136:         $this->_multipleSelection = true;
137:         $this->selection = '$$("' . $selector . '")';
138:         return $this;
139:     }
140: 
141: /**
142:  * Add an event to the script cache. Operates on the currently selected elements.
143:  *
144:  * ### Options
145:  *
146:  * - 'wrap' - Whether you want the callback wrapped in an anonymous function. (defaults true)
147:  * - 'stop' - Whether you want the event to stopped. (defaults true)
148:  *
149:  * @param string $type Type of event to bind to the current dom id
150:  * @param string $callback The Javascript function you wish to trigger or the function literal
151:  * @param array $options Options for the event.
152:  * @return string completed event handler
153:  */
154:     function event($type, $callback, $options = array()) {
155:         $defaults = array('wrap' => true, 'stop' => true);
156:         $options = array_merge($defaults, $options);
157: 
158:         $function = 'function (event) {%s}';
159:         if ($options['wrap'] && $options['stop']) {
160:             $callback = "event.stop();\n" . $callback;
161:         }
162:         if ($options['wrap']) {
163:             $callback = sprintf($function, $callback);
164:         }
165:         $out = $this->selection . ".addEvent(\"{$type}\", $callback);";
166:         return $out;
167:     }
168: 
169: /**
170:  * Create a domReady event. This is a special event in many libraries
171:  *
172:  * @param string $functionBody The code to run on domReady
173:  * @return string completed domReady method
174:  */
175:     function domReady($functionBody) {
176:         $this->selection = 'window';
177:         return $this->event('domready', $functionBody, array('stop' => false));
178:     }
179: 
180: /**
181:  * Create an iteration over the current selection result.
182:  *
183:  * @param string $method The method you want to apply to the selection
184:  * @param string $callback The function body you wish to apply during the iteration.
185:  * @return string completed iteration
186:  */
187:     function each($callback) {
188:         return $this->selection . '.each(function (item, index) {' . $callback . '});';
189:     }
190: 
191: /**
192:  * Trigger an Effect.
193:  *
194:  * @param string $name The name of the effect to trigger.
195:  * @param array $options Array of options for the effect.
196:  * @return string completed string with effect.
197:  * @see JsBaseEngineHelper::effect()
198:  */
199:     function effect($name, $options = array()) {
200:         $speed = null;
201:         if (isset($options['speed']) && in_array($options['speed'], array('fast', 'slow'))) {
202:             if ($options['speed'] == 'fast') {
203:                 $speed = '"short"';
204:             } elseif ($options['speed'] == 'slow') {
205:                 $speed = '"long"';
206:             }
207:         }
208:         $effect = '';
209:         switch ($name) {
210:             case 'hide':
211:                 $effect = 'setStyle("display", "none")';
212:             break;
213:             case 'show':
214:                 $effect = 'setStyle("display", "")';
215:             break;
216:             case 'fadeIn':
217:             case 'fadeOut':
218:             case 'slideIn':
219:             case 'slideOut':
220:                 list($effectName, $direction) = preg_split('/([A-Z][a-z]+)/', $name, -1, PREG_SPLIT_DELIM_CAPTURE);
221:                 $direction = strtolower($direction);
222:                 if ($speed) {
223:                     $effect .= "set(\"$effectName\", {duration:$speed}).";
224:                 }
225:                 $effect .= "$effectName(\"$direction\")";
226:             break;
227:         }
228:         return $this->selection . '.' . $effect . ';';
229:     }
230: 
231: /**
232:  * Create an new Request.
233:  *
234:  * Requires `Request`.  If you wish to use 'update' key you must have ```Request.HTML```
235:  * if you wish to do Json requests you will need ```JSON``` and ```Request.JSON```.
236:  *
237:  * @param mixed $url
238:  * @param array $options
239:  * @return string The completed ajax call.
240:  */
241:     function request($url, $options = array()) {
242:         $url = $this->url($url);
243:         $options = $this->_mapOptions('request', $options);
244:         $type = $data = null;
245:         if (isset($options['type']) || isset($options['update'])) {
246:             if (isset($options['type']) && strtolower($options['type']) == 'json') {
247:                 $type = '.JSON';
248:             }
249:             if (isset($options['update'])) {
250:                 $options['update'] = str_replace('#', '', $options['update']);
251:                 $type = '.HTML';
252:             }
253:             unset($options['type']);
254:         }
255:         if (!empty($options['data'])) {
256:             $data = $options['data'];
257:             unset($options['data']);
258:         }
259:         $options['url'] = $url;
260:         $options = $this->_prepareCallbacks('request', $options);
261:         if (!empty($options['dataExpression'])) {
262:             $callbacks[] = 'data';
263:             unset($options['dataExpression']);
264:         } elseif (!empty($data)) {
265:             $data = $this->object($data);
266:         }
267:         $options = $this->_parseOptions($options, array_keys($this->_callbackArguments['request']));
268:         return "var jsRequest = new Request$type({{$options}}).send($data);";
269:     }
270: 
271: /**
272:  * Create a sortable element.
273:  *
274:  * Requires the `Sortables` plugin from MootoolsMore
275:  *
276:  * @param array $options Array of options for the sortable.
277:  * @return string Completed sortable script.
278:  * @see JsBaseEngineHelper::sortable() for options list.
279:  */
280:     function sortable($options = array()) {
281:         $options = $this->_processOptions('sortable', $options);
282:         return 'var jsSortable = new Sortables(' . $this->selection . ', {' . $options . '});';
283:     }
284: 
285: /**
286:  * Create a Draggable element.
287:  *
288:  * Requires the `Drag` plugin from MootoolsMore
289:  *
290:  * @param array $options Array of options for the draggable.
291:  * @return string Completed draggable script.
292:  * @see JsHelper::drag() for options list.
293:  */
294:     function drag($options = array()) {
295:         $options = $this->_processOptions('drag', $options);
296:         return $this->selection . '.makeDraggable({' . $options . '});';
297:     }
298: 
299: /**
300:  * Create a Droppable element.
301:  *
302:  * Requires the `Drag` and `Drag.Move` plugins from MootoolsMore
303:  *
304:  * Droppables in Mootools function differently from other libraries.  Droppables
305:  * are implemented as an extension of Drag.  So in addtion to making a get() selection for
306:  * the droppable element. You must also provide a selector rule to the draggable element. Furthermore,
307:  * Mootools droppables inherit all options from Drag.
308:  *
309:  * @param array $options Array of options for the droppable.
310:  * @return string Completed droppable script.
311:  * @see JsBaseEngineHelper::drop() for options list.
312:  */
313:     function drop($options = array()) {
314:         if (empty($options['drag'])) {
315:             trigger_error(
316:                 __('MootoolsEngine::drop() requires a "drag" option to properly function', true), E_USER_WARNING
317:             );
318:             return false;
319:         }
320:         $options['droppables'] = $this->selection;
321: 
322:         $this->get($options['drag']);
323:         unset($options['drag']);
324: 
325:         $options = $this->_mapOptions('drag', $this->_mapOptions('drop', $options));
326:         $options = $this->_prepareCallbacks('drop', $options);
327:         $safe = array_merge(array_keys($this->_callbackArguments['drop']), array('droppables'));
328:         $optionString = $this->_parseOptions($options, $safe);
329:         $out = $this->selection . '.makeDraggable({' . $optionString . '});';
330:         $this->selection = $options['droppables'];
331:         return $out;
332:     }
333: 
334: /**
335:  * Create a slider control
336:  *
337:  * Requires `Slider` from MootoolsMore
338:  *
339:  * @param array $options Array of options for the slider.
340:  * @return string Completed slider script.
341:  * @see JsBaseEngineHelper::slider() for options list.
342:  */
343:     function slider($options = array()) {
344:         $slider = $this->selection;
345:         $this->get($options['handle']);
346:         unset($options['handle']);
347: 
348:         if (isset($options['min']) && isset($options['max'])) {
349:             $options['range'] = array($options['min'], $options['max']);
350:             unset($options['min'], $options['max']);
351:         }
352:         $optionString = $this->_processOptions('slider', $options);
353:         if (!empty($optionString)) {
354:             $optionString = ', {' . $optionString . '}';
355:         }
356:         $out = 'var jsSlider = new Slider(' . $slider . ', ' . $this->selection . $optionString . ');';
357:         $this->selection = $slider;
358:         return $out;
359:     }
360: 
361: /**
362:  * Serialize the form attached to $selector.
363:  *
364:  * @param array $options Array of options.
365:  * @return string Completed serializeForm() snippet
366:  * @see JsBaseEngineHelper::serializeForm()
367:  */
368:     function serializeForm($options = array()) {
369:         $options = array_merge(array('isForm' => false, 'inline' => false), $options);
370:         $selection = $this->selection;
371:         if (!$options['isForm']) {
372:             $selection = '$(' . $this->selection . '.form)';
373:         }
374:         $method = '.toQueryString()';
375:         if (!$options['inline']) {
376:             $method .= ';';
377:         }
378:         return $selection . $method;
379:     }
380: }
381: 
OpenHub
Rackspace
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (GitHub)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • Slack
  • Paid Support

Generated using CakePHP API Docs