📄 ajax.php.svn-base
字号:
$divOptions = array('id' => $options['id'] . "_autoComplete", 'class' => isset($options['class']) ? $options['class'] : 'auto_complete'); if (isset($options['div_id'])) { $divOptions['id'] = $options['div_id']; unset($options['div_id']); } $htmlOptions = $this->__getHtmlOptions($options); $htmlOptions['autocomplete'] = "off"; foreach ($this->autoCompleteOptions as $opt) { unset($htmlOptions[$opt]); } if (isset($options['tokens'])) { if (is_array($options['tokens'])) { $options['tokens'] = $this->Javascript->object($options['tokens']); } else { $options['tokens'] = '"' . $options['tokens'] . '"'; } } $options = $this->_optionsToString($options, array('paramName', 'indicator')); $options = $this->_buildOptions($options, $this->autoCompleteOptions); return $this->Html->input($field, $htmlOptions) . "\n" . $this->Html->tag('div', $divOptions, true) . "</div>\n" . $this->Javascript->codeBlock("{$var}new Ajax.Autocompleter('" . $htmlOptions['id'] . "', '" . $divOptions['id'] . "', '" . $this->Html->url($url) . "', " . $options . ");"); }/** * Setup a Draggable Element. * For a reference on the options for this function, check out * * @link http://wiki.script.aculo.us/scriptaculous/show/Draggable * @param sting $id the DOM id to enable * @param array $options a set of options * @return string Javascript::codeBlock(); * @access public */ function drag($id, $options = array()) { return $this->Javascript->codeBlock("new Draggable('$id', " . $this->_optionsForDraggable($options) . ");"); }/** * Creates an Ajax-updateable DIV element * * @param string $id options for javascript * @param array $options a set of options * @return string HTML code * @access public */ function div($id, $options = array()) { if (env('HTTP_X_UPDATE') != null) { $divs = explode(' ', env('HTTP_X_UPDATE')); if (in_array($id, $divs)) { @ob_end_clean(); ob_start(); return ''; } } $attr = $this->Html->_parseAttributes(am($options, array('id' => $id))); return $this->output(sprintf($this->tags['blockstart'], $attr)); }/** * Closes an Ajax-updateable DIV element * * @param string $id The DOM ID of the element * @return string HTML code * @access public */ function divEnd($id) { if (env('HTTP_X_UPDATE') != null) { $divs = explode(' ', env('HTTP_X_UPDATE')); if (in_array($id, $divs)) { $this->__ajaxBuffer[$id] = ob_get_contents(); ob_end_clean(); return ''; } } return $this->output($this->tags['blockend']); }/** * Protectd helper method to return an array of options for draggable. * * @param array $options * @return array * @access protected */ function _optionsForDraggable($options) { $options = $this->_optionsToString($options, array('handle', 'constraint')); return $this->_buildOptions($options, $this->dragOptions); }/** * Setup a droppable element * For a reference on the options for this function, check out * * @link http://wiki.script.aculo.us/scriptaculous/show/Droppables.add * @param string $id * @param array $options * @return array * @access public */ function drop($id, $options = array()) { $options = $this->_optionsForDroppable($options); return $this->Javascript->codeBlock("Droppables.add('$id', $options);"); }/** * Protected helper method to return an array of options for droppable. * * @param string $options * @return string String of Javascript array definition * @access protected */ function _optionsForDroppable($options) { $options = $this->_optionsToString($options, array('accept', 'overlap', 'hoverclass')); return $this->_buildOptions($options, $this->dropOptions); }/** * Setup a remote droppable element. * * @link http://wiki.script.aculo.us/scriptaculous/show/Droppables.add * @see link() and remoteFunction() * @param string $id DOM id of droppable * @param array $options ame as drop() * @param array $ajaxOptions same as remoteFunction() * @return string Javascript::codeBlock() * @access public */ function dropRemote($id, $options = array(), $ajaxOptions = array()) { $options['onDrop'] = "function(element){" . $this->remoteFunction($ajaxOptions) . "}"; $options = $this->_optionsForDroppable($options); return $this->Javascript->codeBlock("Droppables.add('$id', $options);"); }/** * Makes a slider control. * * @link http://wiki.script.aculo.us/scriptaculous/show/Slider * @param string $id DOM ID of slider handle * @param string $track_id DOM ID of slider track * @param array $options Array of options to control the slider * @return string Javascript::codeBlock() * @access public */ function slider($id, $track_id, $options = array()) { $options = $this->_optionsToString($options, array('axis', 'handleImage', 'handleDisabled')); if (isset($options['change'])) { $options['onChange'] = $options['change']; unset($options['change']); } if (isset($options['slide'])) { $options['onSlide'] = $options['slide']; unset($options['slide']); } $options = $this->_buildOptions($options, $this->sliderOptions); return $this->Javascript->codeBlock("var $id = new Control.Slider('$id', '$track_id', $options);"); }/** * Makes an Ajax In Place editor control. * * @link http://wiki.script.aculo.us/scriptaculous/show/Ajax.InPlaceEditor * @param string $id DOM ID of input element * @param string $url Postback URL of saved data * @param array $options Array of options to control the editor, including ajaxOptions (see link). * @return string Javascript::codeBlock() * @access public */ function editor($id, $url, $options = array()) { $url = $this->Html->url($url); $options['ajaxOptions'] = $this->__optionsForAjax($options); foreach($this->ajaxOptions as $opt) { if (isset($options[$opt])) { unset($options[$opt]); } } if (isset($options['callback'])) { $options['callback'] = 'function(form, value) {' . $options['callback'] . '}'; } $options = $this->_optionsToString($options, array('okText', 'cancelText', 'savingText', 'formId', 'externalControl', 'highlightcolor', 'highlightendcolor', 'savingClassName', 'formClassName', 'loadTextURL', 'loadingText', 'clickToEditText')); $options = $this->_buildOptions($options, $this->editorOptions); return $this->Javascript->codeBlock("new Ajax.InPlaceEditor('{$id}', '{$url}', {$options});"); }/** * Makes a list or group of floated objects sortable. * * @link http://wiki.script.aculo.us/scriptaculous/show/Sortable.create * @param string $id DOM ID of parent * @param array $options Array of options to control sort * @return string Javascript::codeBlock() * @access public */ function sortable($id, $options = array()) { if (!empty($options['url'])) { $options['with'] = "Sortable.serialize('$id')"; $options['onUpdate'] = 'function(sortable){' . $this->remoteFunction($options) . '}'; } $options = $this->__optionsForSortable($options); return $this->Javascript->codeBlock("Sortable.create('$id', $options);"); }/** * Private method; generates sortables code from array options * * @param array $options * @return string String of Javascript array definition * @access private */ function __optionsForSortable($options) { $options = $this->_optionsToString($options, array('handle', 'tag', 'constraint', 'ghosting', 'only')); return $this->_buildOptions($options, $this->sortOptions); }/** * Private helper function for Ajax. * * @param array $options * @return string String of Javascript array definition * @access private */ function __optionsForAjax($options = array()) { $js_options = $this->_buildCallbacks($options); if (!isset($js_options['asynchronous'])) { $js_options['asynchronous'] = 'true'; } if (!isset($js_options['evalScripts'])) { $js_options['evalScripts'] = 'true'; } $options = $this->_optionsToString($options, array('method')); foreach($options as $key => $value) { switch($key) { case 'type': $js_options['asynchronous'] = ($value == 'synchronous') ? 'false' : 'true'; break; case 'position': $js_options['insertion'] = "Insertion." . Inflector::camelize($options['position']); break; case 'with': $js_options['parameters'] = $options['with']; break; case 'form': $js_options['parameters'] = 'Form.serialize(this)'; break; case 'requestHeaders': $keys = array(); foreach ($value as $key => $val) { $keys[] = "'" . $key . "'"; $keys[] = "'" . $val . "'"; } $js_options['requestHeaders'] = '[' . join(', ', $keys) . ']'; break; } } return $this->_buildOptions($js_options, $this->ajaxOptions); }/** * Private Method to return a string of html options * option data as a JavaScript options hash. * * @param array $options Options in the shape of keys and values * @param array $extra Array of legal keys in this options context * @return array Array of html options * @access private */ function __getHtmlOptions($options, $extra = array()) { foreach($this->ajaxOptions as $key) { if (isset($options[$key])) { unset($options[$key]); } } foreach($extra as $key) { if (isset($options[$key])) { unset($options[$key]); } } return $options; }/** * Protected Method to return a string of JavaScript with the given * option data as a JavaScript options hash. * * @param array $options Options in the shape of keys and values * @param array $acceptable Array of legal keys in this options context * @return string String of Javascript array definition * @access protected */ function _buildOptions($options, $acceptable) { if (is_array($options)) { $out = array(); foreach($options as $k => $v) { if (in_array($k, $acceptable)) { $out[] = "$k:$v"; } } $out = join(', ', $out); $out = '{' . $out . '}'; return $out; } else { return false; } }/** * Protected Method to return JavaScript text for an observer... * * @param string $klass Name of JavaScript class * @param string $name * @param array $options Ajax options * @return string Formatted JavaScript * @access protected */ function _buildObserver($klass, $name, $options = null) { if (!isset($options['with']) && isset($options['update'])) { $options['with'] = 'value'; } $callback = $this->remoteFunction($options); $javascript = "new $klass('$name', "; $javascript .= (isset($options['frequency']) ? $options['frequency'] : 2) . ", function(element, value) {"; $javascript .= "$callback})"; return $javascript; }/** * Protected Method to return JavaScript text for all callbacks... * * @param array $options * @return array * @access protected */ function _buildCallbacks($options) { $callbacks = array(); foreach($this->callbacks as $callback) { if (isset($options[$callback])) { $name = 'on' . ucfirst($callback); $code = $options[$callback]; $callbacks[$name] = "function(request){" . $code . "}"; } } return $callbacks; }/** * Protected Method to return a string of JavaScript with a string representation * of given options array. * * @param array $options Ajax options array * @param array $stringOpts Options as strings in an array * @access private * @return array * @access protected */ function _optionsToString($options, $stringOpts = array()) { foreach($stringOpts as $option) { if (isset($options[$option]) && !$options[$option][0] != "'") { if ($options[$option] === true || $options[$option] === 'true') { $options[$option] = 'true'; } elseif ($options[$option] === false || $options[$option] === 'false') { $options[$option] = 'false'; } else { $options[$option] = "'{$options[$option]}'"; } } } return $options; }/** * afterRender callback * * @return array * @access public */ function afterRender() { if (env('HTTP_X_UPDATE') != null && count($this->__ajaxBuffer) > 0) { $data = array(); $divs = explode(' ', env('HTTP_X_UPDATE')); foreach ($this->__ajaxBuffer as $key => $val) { if (in_array($key, $divs)) { $data[] = $key . ':"' . rawurlencode($val) . '"'; } } $out = 'var __ajaxUpdater__ = {' . join(', ', $data) . '};' . "\n"; $out .= 'for (n in __ajaxUpdater__) { if (typeof __ajaxUpdater__[n] == "string" && $(n)) Element.update($(n), unescape(__ajaxUpdater__[n])); }'; @ob_end_clean(); e($this->Javascript->codeBlock($out)); exit(); } }}/** * Replaced by AjaxHelper::link() * * @deprecated will not be avialable after 1.1.x.x*/ function linkToRemote($title, $options = array(), $html_options = array()) { //trigger_error('Deprecated function: use AjaxHelper::link', E_USER_WARNING); $href = '#'; if (!empty($options['fallback']) && isset($options['fallback'])) { $href = $options['fallback']; } if (isset($html_options['id'])) { return $this->Html->link($title, $href, $html_options) . $this->Javascript->event("$('{$html_options['id']}')", "click", $this->remoteFunction($options)); } else { $html_options['onclick'] = $this->remoteFunction($options) . "; return false;"; return $this->Html->link($title, $href, $html_options); } }?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -