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:  * Prototype Engine Helper for JsHelper
  4:  *
  5:  * Provides Prototype specific Javascript for JsHelper. Requires at least
  6:  * Prototype 1.6
  7:  *
  8:  * PHP versions 4 and 5
  9:  *
 10:  * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 11:  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 12:  *
 13:  * Licensed under The MIT License
 14:  * Redistributions of files must retain the above copyright notice.
 15:  *
 16:  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
 17:  * @link          http://cakephp.org CakePHP(tm) Project
 18:  * @package       cake
 19:  * @subpackage    cake.cake.libs.view.helpers
 20:  * @since         CakePHP(tm) v 1.3
 21:  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 22:  */
 23: App::import('Helper', 'Js');
 24: 
 25: /**
 26:  * Prototype Engine Helper for JsHelper
 27:  *
 28:  * @package       cake
 29:  * @subpackage    cake.cake.libs.view.helpers
 30:  */
 31: class PrototypeEngineHelper extends JsBaseEngineHelper {
 32: /**
 33:  * Is the current selection a multiple selection? or is it just a single element.
 34:  *
 35:  * @var boolean
 36:  */
 37:     var $_multiple = false;
 38: 
 39: /**
 40:  * Option mappings for Prototype
 41:  *
 42:  * @var array
 43:  */
 44:     var $_optionMap = array(
 45:         'request' => array(
 46:             'async' => 'asynchronous',
 47:             'data' => 'parameters',
 48:             'before' => 'onCreate',
 49:             'success' => 'onSuccess',
 50:             'complete' => 'onComplete',
 51:             'error' => 'onFailure'
 52:         ),
 53:         'sortable' => array(
 54:             'sort' => 'onChange',
 55:             'complete' => 'onUpdate',
 56:         ),
 57:         'drag' => array(
 58:             'snapGrid' => 'snap',
 59:             'container' => 'constraint',
 60:             'stop' => 'onEnd',
 61:             'start' => 'onStart',
 62:             'drag' => 'onDrag',
 63:         ),
 64:         'drop' => array(
 65:             'hover' => 'onHover',
 66:             'drop' => 'onDrop',
 67:             'hoverClass' => 'hoverclass',
 68:         ),
 69:         'slider' => array(
 70:             'direction' => 'axis',
 71:             'change' => 'onSlide',
 72:             'complete' => 'onChange',
 73:             'value' => 'sliderValue',
 74:         )
 75:     );
 76: 
 77: /**
 78:  * Contains a list of callback names -> default arguments.
 79:  *
 80:  * @var array
 81:  */
 82:     var $_callbackArguments = array(
 83:         'slider' => array(
 84:             'onSlide' => 'value',
 85:             'onChange' => 'value',
 86:         ),
 87:         'drag' => array(
 88:             'onStart' => 'event',
 89:             'onDrag' => 'event',
 90:             'change' => 'draggable',
 91:             'onEnd' => 'event',
 92:         ),
 93:         'drop' => array(
 94:             'onHover' => 'draggable, droppable, event',
 95:             'onDrop' => 'draggable, droppable, event',
 96:         ),
 97:         'request' => array(
 98:             'onCreate' => 'transport',
 99:             'onComplete' => 'transport',
100:             'onFailure' => 'response, jsonHeader',
101:             'onRequest' => 'transport',
102:             'onSuccess' => 'response, jsonHeader'
103:         ),
104:         'sortable' => array(
105:             'onStart' => 'element',
106:             'onChange' => 'element',
107:             'onUpdate' => 'element',
108:         ),
109:     );
110: 
111: /**
112:  * Create javascript selector for a CSS rule
113:  *
114:  * @param string $selector The selector that is targeted
115:  * @return object instance of $this. Allows chained methods.
116:  */
117:     function get($selector) {
118:         $this->_multiple = false;
119:         if ($selector == 'window' || $selector == 'document') {
120:             $this->selection = "$(" . $selector .")";
121:             return $this;
122:         }
123:         if (preg_match('/^#[^\s.]+$/', $selector)) {
124:             $this->selection = '$("' . substr($selector, 1) . '")';
125:             return $this;
126:         }
127:         $this->_multiple = true;
128:         $this->selection = '$$("' . $selector . '")';
129:         return $this;
130:     }
131: 
132: /**
133:  * Add an event to the script cache. Operates on the currently selected elements.
134:  *
135:  * ### Options
136:  *
137:  * - `wrap` - Whether you want the callback wrapped in an anonymous function. (defaults true)
138:  * - `stop` - Whether you want the event to stopped. (defaults true)
139:  *
140:  * @param string $type Type of event to bind to the current 946 id
141:  * @param string $callback The Javascript function you wish to trigger or the function literal
142:  * @param array $options Options for the event.
143:  * @return string completed event handler
144:  */
145:     function event($type, $callback, $options = array()) {
146:         $defaults = array('wrap' => true, 'stop' => true);
147:         $options = array_merge($defaults, $options);
148: 
149:         $function = 'function (event) {%s}';
150:         if ($options['wrap'] && $options['stop']) {
151:             $callback = "event.stop();\n" . $callback;
152:         }
153:         if ($options['wrap']) {
154:             $callback = sprintf($function, $callback);
155:         }
156:         $out = $this->selection . ".observe(\"{$type}\", $callback);";
157:         return $out;
158:     }
159: 
160: /**
161:  * Create a domReady event. This is a special event in many libraries
162:  *
163:  * @param string $functionBody The code to run on domReady
164:  * @return string completed domReady method
165:  * @access public
166:  */
167:     function domReady($functionBody) {
168:         $this->selection = 'document';
169:         return $this->event('dom:loaded', $functionBody, array('stop' => false));
170:     }
171: 
172: /**
173:  * Create an iteration over the current selection result.
174:  *
175:  * @param string $method The method you want to apply to the selection
176:  * @param string $callback The function body you wish to apply during the iteration.
177:  * @return string completed iteration
178:  * @access public
179:  */
180:     function each($callback) {
181:         return $this->selection . '.each(function (item, index) {' . $callback . '});';
182:     }
183: 
184: /**
185:  * Trigger an Effect.
186:  *
187:  * ### Note: Effects require Scriptaculous to be loaded.
188:  *
189:  * @param string $name The name of the effect to trigger.
190:  * @param array $options Array of options for the effect.
191:  * @return string completed string with effect.
192:  * @access public
193:  * @see JsBaseEngineHelper::effect()
194:  */
195:     function effect($name, $options = array()) {
196:         $effect = '';
197:         $optionString = null;
198:         if (isset($options['speed'])) {
199:             if ($options['speed'] == 'fast') {
200:                 $options['duration'] = 0.5;
201:             } elseif ($options['speed'] == 'slow') {
202:                 $options['duration'] = 2;
203:             } else {
204:                 $options['duration'] = 1;
205:             }
206:             unset($options['speed']);
207:         }
208:         if (!empty($options)) {
209:             $optionString = ', {' . $this->_parseOptions($options) . '}';
210:         }
211:         switch ($name) {
212:             case 'hide':
213:             case 'show':
214:                 $effect = $this->selection . '.' . $name . '();';
215:             break;
216:             case 'slideIn':
217:             case 'slideOut':
218:                 $name = ($name == 'slideIn') ? 'slideDown' : 'slideUp';
219:                 $effect = 'Effect.' . $name . '(' . $this->selection . $optionString . ');';
220:             break;
221:             case 'fadeIn':
222:             case 'fadeOut':
223:                 $name = ($name == 'fadeIn') ? 'appear' : 'fade';
224:                 $effect = $this->selection . '.' . $name .'(' . substr($optionString, 2) . ');';
225:             break;
226:         }
227:         return $effect;
228:     }
229: 
230: /**
231:  * Create an Ajax or Ajax.Updater call.
232:  *
233:  * @param mixed $url
234:  * @param array $options
235:  * @return string The completed ajax call.
236:  * @access public
237:  */
238:     function request($url, $options = array()) {
239:         $url = '"'. $this->url($url) . '"';
240:         $options = $this->_mapOptions('request', $options);
241:         $type = '.Request';
242:         $data = null;
243:         if (isset($options['type']) && strtolower($options['type']) == 'json') {
244:             unset($options['type']);
245:         }
246:         if (isset($options['update'])) {
247:             $url = '"' . str_replace('#', '', $options['update']) . '", ' . $url;
248:             $type = '.Updater';
249:             unset($options['update'], $options['type']);
250:         }
251:         $safe = array_keys($this->_callbackArguments['request']);
252:         $options = $this->_prepareCallbacks('request', $options, $safe);
253:         if (!empty($options['dataExpression'])) {
254:             $safe[] = 'parameters';
255:             unset($options['dataExpression']);
256:         }
257:         $options = $this->_parseOptions($options, $safe);
258:         if (!empty($options)) {
259:             $options = ', {' . $options . '}';
260:         }
261:         return "var jsRequest = new Ajax$type($url$options);";
262:     }
263: 
264: /**
265:  * Create a sortable element.
266:  *
267:  * #### Note: Requires scriptaculous to be loaded.
268:  *
269:  * The scriptaculous implementation of sortables does not suppot the 'start'
270:  * and 'distance' options.
271:  *
272:  * @param array $options Array of options for the sortable.
273:  * @return string Completed sortable script.
274:  * @access public
275:  * @see JsBaseEngineHelper::sortable() for options list.
276:  */
277:     function sortable($options = array()) {
278:         $options = $this->_processOptions('sortable', $options);
279:         if (!empty($options)) {
280:             $options = ', {' . $options . '}';
281:         }
282:         return 'var jsSortable = Sortable.create(' . $this->selection . $options . ');';
283:     }
284: 
285: /**
286:  * Create a Draggable element.
287:  *
288:  * #### Note: Requires scriptaculous to be loaded.
289:  *
290:  * @param array $options Array of options for the draggable.
291:  * @return string Completed draggable script.
292:  * @access public
293:  * @see JsBaseEngineHelper::draggable() for options list.
294:  */
295:     function drag($options = array()) {
296:         $options = $this->_processOptions('drag', $options);
297:         if (!empty($options)) {
298:             $options = ', {' . $options . '}';
299:         }
300:         if ($this->_multiple) {
301:             return $this->each('new Draggable(item' . $options . ');');
302:         }
303:         return 'var jsDrag = new Draggable(' . $this->selection . $options . ');';
304:     }
305: 
306: /**
307:  * Create a Droppable element.
308:  *
309:  * #### Note: Requires scriptaculous to be loaded.
310:  *
311:  * @param array $options Array of options for the droppable.
312:  * @return string Completed droppable script.
313:  * @access public
314:  * @see JsBaseEngineHelper::droppable() for options list.
315:  */
316:     function drop($options = array()) {
317:         $options = $this->_processOptions('drop', $options);
318:         if (!empty($options)) {
319:             $options = ', {' . $options . '}';
320:         }
321:         return 'Droppables.add(' . $this->selection . $options . ');';
322:     }
323: 
324: /**
325:  * Creates a slider control widget.
326:  *
327:  * ### Note: Requires scriptaculous to be loaded.
328:  *
329:  * @param array $options Array of options for the slider.
330:  * @return string Completed slider script.
331:  * @access public
332:  * @see JsBaseEngineHelper::slider() for options list.
333:  */
334:     function slider($options = array()) {
335:         $slider = $this->selection;
336:         $this->get($options['handle']);
337:         unset($options['handle']);
338: 
339:         if (isset($options['min']) && isset($options['max'])) {
340:             $options['range'] = sprintf('$R(%s,%s)', $options['min'], $options['max']);
341:             unset($options['min'], $options['max']);
342:         }
343:         $options = $this->_mapOptions('slider', $options);
344:         $options = $this->_prepareCallbacks('slider', $options);
345:         $optionString = $this->_parseOptions(
346:             $options, array_merge(array_keys($this->_callbackArguments['slider']), array('range'))
347:         );
348:         if (!empty($optionString)) {
349:             $optionString = ', {' . $optionString . '}';
350:         }
351:         $out = 'var jsSlider = new Control.Slider(' . $this->selection . ', ' . $slider . $optionString . ');';
352:         $this->selection = $slider;
353:         return $out;
354:     }
355: 
356: /**
357:  * Serialize the form attached to $selector.
358:  *
359:  * @param array $options Array of options.
360:  * @return string Completed serializeForm() snippet
361:  * @access public
362:  * @see JsBaseEngineHelper::serializeForm()
363:  */
364:     function serializeForm($options = array()) {
365:         $options = array_merge(array('isForm' => false, 'inline' => false), $options);
366:         $selection = $this->selection;
367:         if (!$options['isForm']) {
368:             $selection = '$(' . $this->selection . '.form)';
369:         }
370:         $method = '.serialize()';
371:         if (!$options['inline']) {
372:             $method .= ';';
373:         }
374:         return $selection . $method;
375:     }
376: }
377: 
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