Source for file Prototype.php
Documentation is available at Prototype.php
* An open source set of php helper classes for prototype and script.aculo.us.
* @copyright Copyright (c) 2006, ngcoders.
* @license http://www.gnu.org/copyleft/gpl.html
* @link http://www.ngcoders.com
return 'eval(request.responseText)';
return '<form action="'. $options['url']. '" onsubmit="'. $this->remote_function($options). '; return false;" method="'. (isset ($options['method'])? $options['method']: 'post'). '" >';
if (isset ($options['frequency']) && $options['frequency']> 0 ) {
return $this->_build_observer('Form.Element.EventObserver',$field_id,$options);
if (isset ($options['frequency'])) {
$frequency= (isset ($options['frequency']))? $options['frequency']: 10;
$code = 'new PeriodicalExecuter(function() {'. $this->remote_function($options). '},'. $frequency. ')';
if( isset ($options['update']) && is_array($options['update']) )
$update= (isset ($options['update']['success']))? 'success: '. $options['update']['success']: '';
$update.= (empty($update))? '': ",";
$update.= (isset ($options['update']['failure']))? 'failure: '. $options['update']['failure']: '';
$update.= (isset ($options['update']))? $options['update']: '';
$ajax_function= (empty($update))? 'new Ajax.Request(': 'new Ajax.Updater(\''. $update. '\',';
$ajax_function.= "'". $options['url']. "'";
$ajax_function.= ",". $javascript_options. ')';
$ajax_function= (isset ($options['before']))? $options['before']. ';'. $ajax_function : $ajax_function;
$ajax_function= (isset ($options['after']))? $ajax_function. ';'. $options['after'] : $ajax_function;
$ajax_function= (isset ($options['condition']))? 'if ('. $options['condition']. ') {'. $ajax_function. '}' : $ajax_function;
$ajax_function= (isset ($options['confirm'])) ? 'if ( confirm(\''. $options['confirm']. '\' ) ) { '. $ajax_function. ' } ': $ajax_function;
if(isset ($options['with'])){
$options['with'] = "Form.serialize(this.form)";
return '<input type="button" onclick="'. $this->remote_function($options). '" name="'. $name. '" value ="'. $value. '" />';
$content= (isset ($options['content']))? $options['content']: '';
$content= $this->escape($content);
return $this->tag($block);
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
foreach ($options as $callback=> $code) {
$callbacks[$name]= 'function(request){'. $code. '}';
if (isset ($options['with']) && !strstr($options['with'],'=') ) {
$options['with'] = '\''. $options['with']. '=\' + value';
}else if (isset ($options['with']) && isset ($options['update'])) {
$options['with'] = 'value';
$callback = $options['function'] ? $options['function'] : $this->remote_function($options);
$javascript = "new $klass('$name', ";
$javascript.= (isset ($options['frequency']))? $options['frequency']. ', ': '';
$javascript.= 'function (element,value) { ';
$javascript.= (isset ($options['on']))? ', '. $options['on']: '';
return (strstr($method,"'"))? $method: "'$method'";
if (isset ($options['type']) && $option['type']== 'synchronous') $js_options['asynchronous'] = 'false';
if (isset ($options['method'])) $js_options['method'] = $this->_method_option_to_s($options['method']);
if (isset ($options['position'])) $js_options['insertion'] = 'Insertion.'. ucfirst($options['position']);
$js_options['evalScripts'] = isset ($options['script'])? $options['script']: 'true';
if (isset ($options['form'])) {
$js_options['parameters']= 'Form.serialize(this)';
}elseif (isset ($options['parameters'])){
$js_options['parameters']= 'Form.serialize(\''. $options['submit']. '\')';
}elseif (isset ($options['with'])) {
$js_options['parameters']= $options['with'];
/////////////////////////////////////////////////////////////////////////////////////
// Mergerd Javascript Generator helpers
/////////////////////////////////////////////////////////////////////////////////////
function dump($javascript)
function ID($id,$extend= null)
return "$('$id')". (!empty($extend))? '.'. $extend. '()': '';
return $this->call('alert',$message);
function assign($variable,$value)
return "$variable = $value;";
function call($function , $args = null)
if(!empty($arg_str))$arg_str.= ', ';
return "$function($arg_str)";
function delay($seconds= 1,$script= '')
return "setTimeout( function() { $script } , ". ($seconds* 1000). " )";
return $this->call('Element.hide',$id);
function insert_html($position,$id,$options_for_render= null)
$args= array_merge(array($id),(is_array($options_for_render)? $options_for_render: array($options_for_render)));
return $this->call('new Insertion.'. ucfirst($position),$args);
return $this->assign('window.location.href',$location);
if(!empty($arg_str))$arg_str.= ', ';
return "$A[$arg_str].each(Element.remove)";
return "Element.remove('$id')";
function replace($id,$options_for_render)
$args= array_merge(array($id),(is_array($options_for_render)? $options_for_render: array($options_for_render)));
return $this->call('Element.replace',$args);
$args= array_merge(array($id),(is_array($options_for_render)? $options_for_render: array($options_for_render)));
return $this->call('Element.update',$args);
function select($pattern,$extend= null)
return "$$('$pattern')". (!empty($extend))? '.'. $extend: '';
return $this->call('Element.show',$id);
return $this->call('Element.toggle',$id);
|