本文整理汇总了PHP中JavaScriptHelper::codeBlock方法的典型用法代码示例。如果您正苦于以下问题:PHP JavaScriptHelper::codeBlock方法的具体用法?PHP JavaScriptHelper::codeBlock怎么用?PHP JavaScriptHelper::codeBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JavaScriptHelper
的用法示例。
在下文中一共展示了JavaScriptHelper::codeBlock方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: afterRender
/**
* Executed after a view has rendered, used to include bufferred code
* blocks.
*
* @access public
*/
function afterRender()
{
if (env('HTTP_X_UPDATE') != null && !empty($this->__ajaxBuffer)) {
@ob_end_clean();
$data = array();
$divs = explode(' ', env('HTTP_X_UPDATE'));
$keys = array_keys($this->__ajaxBuffer);
if (count($divs) == 1 && in_array($divs[0], $keys)) {
echo $this->__ajaxBuffer[$divs[0]];
} else {
foreach ($this->__ajaxBuffer as $key => $val) {
if (in_array($key, $divs)) {
$data[] = $key . ':"' . rawurlencode($val) . '"';
}
}
$out = 'var __ajaxUpdater__ = {' . implode(", \n", $data) . '};' . "\n";
$out .= 'for (n in __ajaxUpdater__) { if (typeof __ajaxUpdater__[n] == "string"';
$out .= ' && $(n)) Element.update($(n), unescape(decodeURIComponent(';
$out .= '__ajaxUpdater__[n]))); }';
echo $this->Javascript->codeBlock($out, false);
}
$scripts = $this->Javascript->getCache();
if (!empty($scripts)) {
echo $this->Javascript->codeBlock($scripts, false);
}
$this->_stop();
}
}
示例2: autoComplete
/**
* Create a text field with Jquery UI Autocomplete.
*
* Creates an autocomplete field with the given ID and options.
* needs include jQuery UI Autocomplete file
*
* @param string $field DOM ID of field to observe
* @param array $options Ajax options
* @return string Ajax script
* check out http://jqueryui.com/demos/autocomplete/
*/
function autoComplete($field, $options = array())
{
$var = '';
if (isset($options['var'])) {
$var = 'var ' . $options['var'] . ' = ';
unset($options['var']);
}
if (isset($options['source'])) {
$options['source'] = "'" . Router::url($options['source']) . "'";
}
if (!isset($options['id'])) {
$options['id'] = Inflector::camelize(str_replace(".", "_", $field));
}
$htmlOptions = $this->__getHtmlOptions($options);
$htmlOptions['autocomplete'] = "off";
foreach ($this->autoCompleteOptions as $opt) {
unset($htmlOptions[$opt]);
}
$options = $this->_optionsToString($options, array('multipleSeparator'));
$callbacks = array('formatItem', 'formatMatch', 'formatResult', 'highlight');
foreach ($callbacks as $callback) {
if (isset($options[$callback])) {
$name = $callback;
$code = $options[$callback];
switch ($name) {
case 'formatResult':
$options[$name] = "function(data, i, max) {" . $code . "}";
break;
case 'highlight':
$options[$name] = "function(data, search) {" . $code . "}";
break;
default:
$options[$name] = "function(row, i, max, term) {" . $code . "}";
break;
}
}
}
$options = $this->_buildOptions($options, $this->autoCompleteOptions);
$text = $this->Form->text($field, $htmlOptions);
$script = "{$var} \$('#{$htmlOptions['id']}').autocomplete(";
$script .= "{$options});";
return "{$text}\n" . $this->Javascript->codeBlock($script);
}