Skip to content
Permalink
Browse files

Adding newlines

  • Loading branch information...
markstory committed Jul 27, 2009
1 parent d4d9db4 commit 7246563bae0256bed6c7902183a62496bc75f0c1
Showing with 56 additions and 20 deletions.
  1. +56 −20 cake/libs/view/helpers/js.php
@@ -35,38 +35,44 @@ class JsHelper extends AppHelper {
* @var boolean
**/
var $bufferScripts = true;
/**
* helpers
*
* @var array
**/
var $helpers = array('Html', 'Form');
/**
* Scripts that are queued for output
*
* @var array
**/
var $__bufferedScripts = array();
/**
* Current Javascript Engine that is being used
*
* @var string
* @access private
**/
var $__engineName;
/**
* __objects
*
* @var array
* @access private
**/
var $__objects = array();
/**
* output
*
* @var string
**/
var $output = false;
/**
* Constructor - determines engine helper
*
@@ -90,12 +96,13 @@ function __construct($settings = array()) {
$this->helpers[] = $engineClass;
parent::__construct();
}
/**
* call__ Allows for dispatching of methods to the Engine Helper.
* methods in the Engines bufferedMethods list will be automatically buffered.
* You can control buffering with the buffer param as well. By setting the last parameter to
* You can control buffering with the buffer param as well. By setting the last parameter to
* any engine method to a boolean you can force or disable buffering.
*
*
* e.g. `$js->get('#foo')->effect('fadeIn', array('speed' => 'slow'), true);`
*
* Will force buffering for the effect method. If the method takes an options array you may also add
@@ -142,6 +149,7 @@ function call__($method, $params) {
}
trigger_error(sprintf(__('JsHelper:: Missing Method %s is undefined', true), $method), E_USER_WARNING);
}
/**
* Writes all Javascript generated so far to a code block or
* caches them to a file and returns a linked script.
@@ -162,7 +170,7 @@ function writeBuffer($options = array()) {
$defaults = array('onDomReady' => true, 'inline' => true, 'cache' => false, 'clear' => true, 'safe' => true);
$options = array_merge($defaults, $options);
$script = implode("\n", $this->getBuffer($options['clear']));
if ($options['onDomReady']) {
$script = $this->{$this->__engineName}->domReady($script);
}
@@ -180,6 +188,7 @@ function writeBuffer($options = array()) {
$view->addScript($script);
return null;
}
/**
* Write a script to the cached scripts.
*
@@ -188,6 +197,7 @@ function writeBuffer($options = array()) {
function buffer($script) {
$this->__bufferedScripts[] = $script;
}
/**
* Get all the cached scripts
*
@@ -201,19 +211,20 @@ function getBuffer($clear = true) {
}
return $scripts;
}
/**
* Generate an 'Ajax' link. Uses the selected JS engine to create a link
* element that is enhanced with Javascript. Options can include
* both those for HtmlHelper::link() and JsBaseEngine::request(), JsBaseEngine::event();
* both those for HtmlHelper::link() and JsBaseEngine::request(), JsBaseEngine::event();
*
* ### Options
*
*
* - `confirm` - Generate a confirm() dialog before sending the event.
* - `id` - use a custom id.
* - `htmlAttributes` - additional non-standard htmlAttributes. Standard attributes are class, id,
* rel, title, escape, onblur and onfocus.
* - `buffer` - Disable the buffering and return a script tag in addition to the link.
*
*
* @param string $title Title for the link.
* @param mixed $url Mixed either a string URL or an cake url array.
* @param array $options Options for both the HTML element and Js::request()
@@ -248,7 +259,7 @@ function link($title, $url = null, $options = array()) {
*
* Forms submitting with this method, cannot send files. Files do not transfer over XmlHttpRequest
* and require an iframe.
*
*
* @param string $title The display text of the submit button.
* @param array $options Array of options to use.
* @return string Completed submit button.
@@ -327,13 +338,15 @@ class JsBaseEngineHelper extends AppHelper {
* @access public
**/
var $useNative = false;
/**
* The js snippet for the current selection.
*
* @var string
* @access public
**/
var $selection;
/**
* 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
@@ -342,13 +355,15 @@ class JsBaseEngineHelper extends AppHelper {
* @var array
**/
var $_optionMap = array();
/**
* An array of lowercase method names in the Engine that are buffered unless otherwise disabled.
* 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.
*
* @var array
**/
var $bufferedMethods = array('event', 'sortable', 'drag', 'drop', 'slider');
/**
* Constructor.
*
@@ -357,6 +372,7 @@ class JsBaseEngineHelper extends AppHelper {
function __construct() {
$this->useNative = function_exists('json_encode');
}
/**
* Create an alert message in Javascript
*
@@ -367,6 +383,7 @@ function __construct() {
function alert($message) {
return 'alert("' . $this->escape($message) . '");';
}
/**
* Redirects to a URL
*
@@ -388,10 +405,11 @@ function redirect($url = null) {
function confirm($message) {
return 'confirm("' . $this->escape($message) . '");';
}
/**
* Generate a confirm snippet that returns false from the current
* function scope.
*
*
* @param string $message Message to use in the confirm dialog.
* @access public
* @return string
@@ -401,6 +419,7 @@ function confirmReturn($message) {
$out .= "if (!_confirm) {\n\treturn false;\n}";
return $out;
}
/**
* Create a prompt() Javascript function
*
@@ -412,6 +431,7 @@ function confirmReturn($message) {
function prompt($message, $default = '') {
return 'prompt("' . $this->escape($message) . '", "' . $this->escape($default) . '");';
}
/**
* Generates a JavaScript object in JavaScript Object Notation (JSON)
* from an array. Will use native JSON encode method if available, and $useNative == true
@@ -477,6 +497,7 @@ function object($data = array(), $options = array()) {
$rt = $options['prefix'] . $rt . $options['postfix'];
return $rt;
}
/**
* Converts a PHP-native variable of any type to a JSON-equivalent representation
*
@@ -511,6 +532,7 @@ function value($val, $quoteString = true) {
}
return $val;
}
/**
* Escape a string to be JSON friendly.
*
@@ -528,6 +550,7 @@ function escape($string) {
App::import('Core', 'Multibyte');
return $this->_utf8ToHex($string);
}
/**
* Encode a string into JSON. Converts and escapes necessary characters.
*
@@ -621,6 +644,7 @@ function _utf8ToHex($string) {
}
return $return;
}
/**
* Create javascript selector for a CSS rule
*
@@ -631,6 +655,7 @@ function get($selector) {
trigger_error(sprintf(__('%s does not have get() implemented', true), get_class($this)), E_USER_WARNING);
return $this;
}
/**
* Add an event to the script cache. Operates on the currently selected elements.
*
@@ -647,6 +672,7 @@ function get($selector) {
function event($type, $callback, $options = array()) {
trigger_error(sprintf(__('%s does not have event() implemented', true), get_class($this)), E_USER_WARNING);
}
/**
* Create a domReady event. This is a special event in many libraries
*
@@ -656,6 +682,7 @@ function event($type, $callback, $options = array()) {
function domReady($functionBody) {
trigger_error(sprintf(__('%s does not have domReady() implemented', true), get_class($this)), E_USER_WARNING);
}
/**
* Create an iteration over the current selection result.
*
@@ -665,6 +692,7 @@ function domReady($functionBody) {
function each($callback) {
trigger_error(sprintf(__('%s does not have each() implemented', true), get_class($this)), E_USER_WARNING);
}
/**
* Trigger an Effect.
*
@@ -691,6 +719,7 @@ function each($callback) {
function effect($name, $options) {
trigger_error(sprintf(__('%s does not have effect() implemented', true), get_class($this)), E_USER_WARNING);
}
/**
* Make an XHR request
*
@@ -703,22 +732,23 @@ function effect($name, $options) {
*
* ### Options
*
* - `method` - The method to make the request with defaults to GET in more libraries
* - `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 <script> tags should be eval'ed.
* - `dataExpression` - Should the `data` key be treated as a callback. Useful for supplying `$options['data']` as
* - `dataExpression` - Should the `data` key be treated as a callback. Useful for supplying `$options['data']` as
* another Javascript expression.
*
* @param mixed $url Array or String URL to target with the request.
* @param array $options Array of options. See above for cross library supported options
* @return string XHR request.
**/
function request($url, $options = array()) {
trigger_error(sprintf(__('%s does not have request() implemented', true), get_class($this)), E_USER_WARNING);
trigger_error(sprintf(__('%s does not have request() implemented', true), get_class($this)), E_USER_WARNING);
}
/**
* Create a draggable element. Works on the currently selected element.
* Additional options may be supported by your library.
@@ -739,8 +769,9 @@ function request($url, $options = array()) {
* @return string Completed drag script
**/
function drag($options = array()) {
trigger_error(sprintf(__('%s does not have drag() implemented', true), get_class($this)), E_USER_WARNING);
trigger_error(sprintf(__('%s does not have drag() implemented', true), get_class($this)), E_USER_WARNING);
}
/**
* Create a droppable element. Allows for draggable elements to be dropped on it.
* Additional options may be supported by your library.
@@ -759,8 +790,9 @@ function drag($options = array()) {
* @return string Completed drop script
**/
function drop($options = array()) {
trigger_error(sprintf(__('%s does not have drop() implemented', true), get_class($this)), E_USER_WARNING);
trigger_error(sprintf(__('%s does not have drop() implemented', true), get_class($this)), E_USER_WARNING);
}
/**
* Create a sortable element.
*
@@ -778,16 +810,16 @@ function drop($options = array()) {
* - `sort` - Event fired during sorting
* - `complete` - Event fired when sorting completes.
*
*
* @param array $options Array of options for the sortable. See above.
* @return string Completed sortable script.
**/
function sortable() {
trigger_error(sprintf(__('%s does not have sortable() implemented', true), get_class($this)), E_USER_WARNING);
trigger_error(sprintf(__('%s does not have sortable() implemented', true), get_class($this)), E_USER_WARNING);
}
/**
* Create a slider UI widget. Comprised of a track and knob
*
*
* ### Options
*
* - `handle` - The id of the element used in sliding.
@@ -805,16 +837,17 @@ function sortable() {
* @return string Completed slider script
**/
function slider() {
trigger_error(sprintf(__('%s does not have slider() implemented', true), get_class($this)), E_USER_WARNING);
trigger_error(sprintf(__('%s does not have slider() implemented', true), get_class($this)), E_USER_WARNING);
}
/**
* 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.
*
*
* ### Options
*
*
* - `isForm` - is the current selection a form, or an input? (defaults to false)
* - `inline` - is the rendered statement going to be used inside another JS statement? (defaults to false)
*
@@ -826,6 +859,7 @@ function serializeForm() {
sprintf(__('%s does not have serializeForm() implemented', true), get_class($this)), E_USER_WARNING
);
}
/**
* Parse an options assoc array into an Javascript object literal.
* Similar to object() but treats any non-integer value as a string,
@@ -847,6 +881,7 @@ function _parseOptions($options, $safeKeys = array()) {
sort($out);
return join(', ', $out);
}
/**
* Maps Abstract options to engine specific option names.
* If attributes are missing from the map, they are not changed.
@@ -868,6 +903,7 @@ function _mapOptions($method, $options) {
}
return $options;
}
/**
* Convert an array of data into a query string
*

0 comments on commit 7246563

Please sign in to comment.
You can’t perform that action at this time.