cvs: pear /HTML_AJAX AJAX.php package.php package.xml /HTML_AJAX/AJAX JSON.php Server.php /HTML_AJAX/AJAX/Serializer JSON.php Null.php
/HTML_AJAX/js Dispatcher.js HTML_AJAX.js HTML_AJAX_lite.js HttpClient.js Main.js Request.js build.php util.js

From: Date: Tue, 25 Oct 2005 03:26:14 +0000
Subject: cvs: pear /HTML_AJAX AJAX.php package.php package.xml /HTML_AJAX/AJAX JSON.php Server.php /HTML_AJAX/AJAX/Serializer JSON.php Null.php
/HTML_AJAX/js Dispatcher.js HTML_AJAX.js HTML_AJAX_lite.js HttpClient.js Main.js Request.js build.php util.js
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-35831@lists.php.net to get a copy of this message
jeichorn Mon Oct 24 23:26:14 2005 EDT Modified files: /pear/HTML_AJAX AJAX.php package.php package.xml /pear/HTML_AJAX/AJAX JSON.php Server.php /pear/HTML_AJAX/AJAX/Serializer JSON.php Null.php /pear/HTML_AJAX/js Dispatcher.js HTML_AJAX.js HTML_AJAX_lite.js HttpClient.js Main.js Request.js build.php util.js Log: Merge with local development getting ready for a release I should do this more often

http://cvs.php.net/diff.php/pear/HTML_AJAX/AJAX.php?r1=1.8&r2=1.9&ty=u Index: pear/HTML_AJAX/AJAX.php diff -u pear/HTML_AJAX/AJAX.php:1.8 pear/HTML_AJAX/AJAX.php:1.9 --- pear/HTML_AJAX/AJAX.php:1.8 Tue Sep 27 11:14:27 2005 +++ pear/HTML_AJAX/AJAX.php Mon Oct 24 23:26:12 2005 @@ -1,14 +1,8 @@ <?php -// $Id: AJAX.php,v 1.8 2005/09/27 15:14:27 jeichorn Exp $ +// $Id: AJAX.php,v 1.9 2005/10/25 03:26:12 jeichorn Exp $ /** * OO AJAX Implementation for PHP * - * LICENSE: This source file is subject to version 3.0 of the PHP license - * that is available through the world-wide-web at the following URI: - * http://www.php.net/license/3_0.txt. If you did not receive a copy of - * the PHP License and are unable to obtain it through the web, please - * send a note to license@php.net so we can mail you a copy immediately. - * * @category HTML * @package AJAX * @author Joshua Eichorn <josh@bluga.net> @@ -23,6 +17,7 @@ require_once "HTML/AJAX/Serializer/JSON.php"; require_once "HTML/AJAX/Serializer/Null.php"; require_once "HTML/AJAX/Serializer/Error.php"; +require_once 'HTML/AJAX/Debug.php'; /** * OO AJAX Implementation for PHP @@ -31,7 +26,7 @@ * @package AJAX * @author Joshua Eichorn <josh@bluga.net> * @copyright 2005 Joshua Eichorn - * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @version Release: @package_version@ * @link http://pear.php.net/package/PackageName * @todo Decide if its good thing to support get @@ -56,9 +51,9 @@ * and clean/retrieve get vars */ var $_callbacks = array( - 'headers' => array('HTML_AJAX', '_sendHeaders'), - 'get' => array('HTML_AJAX', '_getVar'), - 'server' => array('HTML_AJAX', '_getVar'), + 'headers' => array('HTML_AJAX', '_sendHeaders'), + 'get' => array('HTML_AJAX', '_getVar'), + 'server' => array('HTML_AJAX', '_getVar'), ); /** @@ -90,8 +85,30 @@ 'Null' => 'text/plain', 'Error' => 'application/error', ); + + /** + * This is the debug variable that we will be passing the + * HTML_AJAX_Debug instance to. + * + * @param object HTML_AJAX_Debug + */ + var $debug; /** + * This is to tell if debug is enabled or not. If so, then + * debug is called, instantiated then saves the file and such. + */ + var $debugEnabled = false; + + /** + * This puts the error into a session variable is set to true. + * set to false by default. + * + * @access public + */ + var $debugSession = false; + + /** * Set a class to handle requests * * @param object $instance @@ -163,25 +180,17 @@ */ function registerCallback($callback, $type = 'headers') { - if(is_callable($callback)) - { - if($type == 'headers') - { + if(is_callable($callback)) { + if($type == 'headers') { $this->_callbacks['headers'] = $callback; return true; - } - elseif($type == 'get') - { + } elseif($type == 'get') { $this->_callbacks['get'] = $callback; return true; - } - elseif($type == 'server') - { + } elseif($type == 'server') { $this->_callbacks['server'] = $callback; return true; - } - else - { + } else { return false; } } @@ -248,6 +257,9 @@ $method = call_user_func($this->_callbacks['get'], 'm'); if (!empty($class) && !empty($method)) { set_error_handler(array(&$this,'_errorHandler')); + if (function_exists('set_exception_handler')) { + set_exception_handler(array(&$this,'_exceptionHandler')); + } if (!isset($this->_exportedInstances[$class])) { // handle error @@ -273,7 +285,6 @@ $ret = call_user_func_array(array(&$this->_exportedInstances[$class]['instance'],$method),$args); - restore_error_handler(); $this->_sendResponse($ret); @@ -283,13 +294,15 @@ } function _getClientPayloadContentType() { - $type = call_user_func($this->_callbacks['server'], 'CONTENT_TYPE'); - if(!empty($type)) { + if (isset($_SERVER['CONTENT_TYPE'])) { + $type = $_SERVER['CONTENT_TYPE']; if (strstr($type,';')) { - $type = array_shift(explode(';',$type)); + $types = explode(';',$type); + $type = array_shift($types); } return strtolower($type); } + return 'text/plain'; } /** @@ -330,8 +343,7 @@ */ function _sendHeaders($array) { - foreach($array as $header => $value) - { + foreach($array as $header => $value) { header($header .': '.$value); } } @@ -365,30 +377,37 @@ } /** - * stub for getting get/server vars - applies strip tags + * stub for getting get/server vars - applies strip_tags * * @access private * @return string filtered _GET value */ function _getVar($var) { - if(!isset($_GET[$var])) - { + if (!isset($_GET[$var])) { return NULL; - } - else - { + } else { return strip_tags($_GET[$var]); } } /** + * Exception handler, passes them to _errorHandler to do the actual work + * + * @access private + */ + function _exceptionHandler($ex) { + $this->_errorHandler($ex->getCode(),$ex->getMessage(),$ex->getFile(),$ex->getLine()); + } + + + /** * Error handler that sends it errors to the client side * * @access private */ function _errorHandler($errno, $errstr, $errfile, $errline) { - if (error_reporting()) { + if ($errno < error_reporting()) { $e = new stdClass(); $e->errNo = $errno; $e->errStr = $errstr; @@ -396,7 +415,13 @@ $e->errLine = $errline; $this->serializer = 'Error'; $this->_sendResponse($e); - + if ($this->debugEnabled) { + $this->debug =& new HTML_AJAX_Debug($errstr, $errline, $errno, $errfile); + if ($this->debugSession) { + $this->debug->sessionError(); + } + $this->debug->_saveError(); + } die(); } } http://cvs.php.net/diff.php/pear/HTML_AJAX/package.php?r1=1.6&r2=1.7&ty=u Index: pear/HTML_AJAX/package.php diff -u pear/HTML_AJAX/package.php:1.6 pear/HTML_AJAX/package.php:1.7 --- pear/HTML_AJAX/package.php:1.6 Tue Sep 27 11:14:27 2005 +++ pear/HTML_AJAX/package.php Mon Oct 24 23:26:12 2005 @@ -13,30 +13,20 @@ * @author Greg Beaver <cellog@php.net> * @copyright 2005 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 - * @version CVS: $Id: package.php,v 1.6 2005/09/27 15:14:27 jeichorn Exp $ + * @version CVS: $Id: package.php,v 1.7 2005/10/25 03:26:12 jeichorn Exp $ * @link http://pear.php.net/package/PEAR_PackageFileManager * @since File available since Release 0.1.0 */ require_once 'PEAR/PackageFileManager.php'; -$version = '0.2.0'; +$version = '0.2.3'; $notes = <<<EOT -Reliense under the LGPL fixing concerns about GPL compability - -Full rewrite of all JavaScript code pulled in from JPSpan, this allows for relicence, as well as shrinking the code size while adding new features - Big new Features are: - Request object non contains all information needed to make a request, HTML_AJAX.makeRequest added service a request object - HTML_AJAX_HttpClient instances now created as needed by a factory HTML_AJAX.httpClient(), this functionality will be replaced at some future point - - These changes will allow for various queue and pool structures to be created in the future, but for now client in progress errors should not be possible - when using proxy objects - -Serializer that mimics post added, filling _POST on an ajax request, helper code for AJAX forms still in progress - -Bugs Fixed: -5087, 5284 - jsClient Location fixes, allows it to be set manually -5908 - PHP 5 bug fix, auto loading of classes not working in php5 for an unknown reason, just load serializer as a normal include -5029 - init bug in auto_server + Initial Helper API see examples/usage_helper.php for details + HTML_AJAX.append + BC Change, default loading implementation moved to its own file + client param takes a comma seperated list of args now ex: server.php?client=main,httpclient + ajax server has support for delivering custom libraries HTML_AJAX_Server::registerJSLibrary + Bug #5675 Reference bug in php 4.4 5.1 etc EOT; $description =<<<EOT @@ -52,7 +42,7 @@ 'version' => $version, 'state' => 'alpha', 'license' => 'lgpl', - 'ignore' => array('package.php', 'package.xml', '*.bak', '*src*', '*.tgz','test.bat','build.php'), + 'ignore' => array('package.php', 'package.xml', '*.bak', '*src*', '*.tgz','test.bat','build.php','DeveloperNotes.txt'), 'filelistgenerator' => 'file', // other option is 'file' 'notes' => $notes, 'changelogoldtonew' => false, @@ -74,7 +64,7 @@ // dependencies can be added at will here $package->addDependency('PEAR', '1.3.5', 'ge', 'pkg', false); -$package->addDependency('php', '4.3.0', 'ge', 'php', false); +$package->addDependency('php', '4.1.0', 'ge', 'php', false); if (isset($_SERVER['argv'][1]) && $_SERVER['argv'][1] == 'commit') { $result = $package->writePackageFile(); http://cvs.php.net/diff.php/pear/HTML_AJAX/package.xml?r1=1.5&r2=1.6&ty=u Index: pear/HTML_AJAX/package.xml diff -u pear/HTML_AJAX/package.xml:1.5 pear/HTML_AJAX/package.xml:1.6 --- pear/HTML_AJAX/package.xml:1.5 Tue Sep 27 11:23:52 2005 +++ pear/HTML_AJAX/package.xml Mon Oct 24 23:26:12 2005 @@ -20,30 +20,20 @@ </maintainer> </maintainers> <release> - <version>0.2.0</version> - <date>2005-09-27</date> + <version>0.2.3</version> + <date>2005-10-24</date> <license>lgpl</license> <state>alpha</state> - <notes>Reliense under the LGPL fixing concerns about GPL compability - -Full rewrite of all JavaScript code pulled in from JPSpan, this allows for relicence, as well as shrinking the code size while adding new features - Big new Features are: - Request object non contains all information needed to make a request, HTML_AJAX.makeRequest added service a request object - HTML_AJAX_HttpClient instances now created as needed by a factory HTML_AJAX.httpClient(), this functionality will be replaced at some future point - - These changes will allow for various queue and pool structures to be created in the future, but for now client in progress errors should not be possible - when using proxy objects - -Serializer that mimics post added, filling _POST on an ajax request, helper code for AJAX forms still in progress - -Bugs Fixed: -5087, 5284 - jsClient Location fixes, allows it to be set manually -5908 - PHP 5 bug fix, auto loading of classes not working in php5 for an unknown reason, just load serializer as a normal include -5029 - init bug in auto_server + <notes>Initial Helper API see examples/usage_helper.php for details + HTML_AJAX.append + BC Change, default loading implementation moved to its own file + client param takes a comma seperated list of args now ex: server.php?client=main,httpclient + ajax server has support for delivering custom libraries HTML_AJAX_Server::registerJSLibrary + Bug #5675 Reference bug in php 4.4 5.1 etc </notes> <deps> <dep type="pkg" rel="ge" version="1.3.5" optional="no">PEAR</dep> - <dep type="php" rel="ge" version="4.3.0" optional="no"/> + <dep type="php" rel="ge" version="4.1.0" optional="no"/> </deps> <filelist> <dir name="/" baseinstalldir="HTML"> @@ -59,6 +49,12 @@ <replace type="package-info" from="@package_version@" to="version"/> </file> </dir> <!-- /AJAX/Serializer --> + <file role="php" name="Debug.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="php" name="Helper.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> <file role="php" name="JSON.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> @@ -68,6 +64,11 @@ </file> </dir> <!-- /AJAX --> <dir name="docs"> + <dir name="examples"> + <file role="doc" name="error_usage.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + </dir> <!-- /docs/examples --> <file role="doc" name="todo"> <replace type="package-info" from="@package_version@" to="version"/> </file> @@ -76,6 +77,21 @@ <file role="doc" name="auto_server.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> + <file role="doc" name="customLib.js"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="doc" name="error_usage.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="doc" name="helper_usage.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="doc" name="index.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="doc" name="livesearch.class.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> <file role="doc" name="proxyless_usage.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> @@ -85,6 +101,9 @@ <file role="doc" name="proxy_usage_server.php"> <replace type="package-info" from="@package_version@" to="version"/> </file> + <file role="doc" name="queue_usage.php"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> <file role="doc" name="README"> <replace type="package-info" from="@package_version@" to="version"/> </file> @@ -126,12 +145,21 @@ <file role="data" name="JSON.js"> <replace type="package-info" from="@package_version@" to="version"/> </file> + <file role="data" name="Loading.js"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> <file role="data" name="Main.js"> <replace type="package-info" from="@package_version@" to="version"/> </file> <file role="data" name="Request.js"> <replace type="package-info" from="@package_version@" to="version"/> </file> + <file role="data" name="serialize.js"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> + <file role="data" name="util.js"> + <replace type="package-info" from="@package_version@" to="version"/> + </file> </dir> <!-- /js --> <file role="php" name="AJAX.php"> <replace type="package-info" from="@package_version@" to="version"/> @@ -141,25 +169,63 @@ </release> <changelog> <release> + <version>0.2.3</version> + <date>2005-10-24</date> + <license>lgpl</license> + <state>alpha</state> + <notes>Initial Helper API see examples/usage_helper.php for details + HTML_AJAX.append + BC Change, default loading implementation moved to its own file + client param takes a comma seperated list of args now ex: server.php?client=main,httpclient + ajax server has support for delivering custom libraries HTML_AJAX_Server::registerJSLibrary + Bug #5675 Reference bug in php 4.4 5.1 etc + </notes> + </release> + <release> + <version>0.2.2</version> + <date>2005-09-30</date> + <license>lgpl</license> + <state>alpha</state> + <notes>AJAX request queues, see examples/queue_usage.php for usage + </notes> + </release> + <release> + <version>0.2.1</version> + <date>2005-09-30</date> + <license>lgpl</license> + <state>alpha</state> + <notes>This release is mainly bug fixes. + Remove debug message when throwing an exception + Fix problems with async calls + Fix broken content-type detection + Stop trying to run an init method when the init flag isn&apos;t set + PHP required version moved to 4.1.0 which is what it should need + +There is also a couple small features added + A basic debug class has been added, allowing you to write PHP errors to a file + HTML_AJAX.replace now works async + </notes> + </release> + <release> <version>0.2.0</version> <date>2005-09-26</date> <license>lgpl</license> <state>alpha</state> - <notes>Reliense under the LGPL fixing concerns about GPL compability - -Full rewrite of all JavaScript code pulled in from JPSpan, this allows for relicence, as well as shrinking the code size while adding new features - Big new Features are: - Request object non contains all information needed to make a request, HTML_AJAX.makeRequest added service a request object - HTML_AJAX_HttpClient instances now created as needed by a factory HTML_AJAX.httpClient(), this functionality will be replaced at some future point - - These changes will allow for various queue and pool structures to be created in the future, but for now client in progress errors should not be possible - when using proxy objects - -Serializer that mimics post added, filling _POST on an ajax request, helper code for AJAX forms still in progress - -Bugs Fixed: -5087, 5284 - jsClient Location fixes, allows it to be set manually -5908 - PHP 5 bug fix, auto loading of classes not working in php5 for an unknown reason, just load serializer as a normal include + <notes>Reliense under the LGPL fixing concerns about GPL compability + +Full rewrite of all JavaScript code pulled in from JPSpan, this allows for relicence, as well as shrinking the code size while adding new features + Big new Features are: + Request object non contains all information needed to make a request, HTML_AJAX.makeRequest added service a request object + HTML_AJAX_HttpClient instances now created as needed by a factory HTML_AJAX.httpClient(), this functionality will be replaced at some future point + + These changes will allow for various queue and pool structures to be created in the future, but for now client in progress errors should not be possible + when using proxy objects + +Serializer that mimics post added, filling _POST on an ajax request, helper code for AJAX forms still in progress + +Bugs Fixed: +5087, 5284 - jsClient Location fixes, allows it to be set manually +5908 - PHP 5 bug fix, auto loading of classes not working in php5 for an unknown reason, just load serializer as a normal include 5029 - init bug in auto_server </notes> </release> http://cvs.php.net/diff.php/pear/HTML_AJAX/AJAX/JSON.php?r1=1.7&r2=1.8&ty=u Index: pear/HTML_AJAX/AJAX/JSON.php diff -u pear/HTML_AJAX/AJAX/JSON.php:1.7 pear/HTML_AJAX/AJAX/JSON.php:1.8 --- pear/HTML_AJAX/AJAX/JSON.php:1.7 Tue Sep 27 11:14:27 2005 +++ pear/HTML_AJAX/AJAX/JSON.php Mon Oct 24 23:26:13 2005 @@ -18,7 +18,7 @@ // | Brett Stimmerman, brettstimmerman[at]gmail[dot]com | // +----------------------------------------------------------------------+ // - // $Id: JSON.php,v 1.7 2005/09/27 15:14:27 jeichorn Exp $ + // $Id: JSON.php,v 1.8 2005/10/25 03:26:13 jeichorn Exp $ /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ define('HTML_AJAX_JSON_SLICE', 1); http://cvs.php.net/diff.php/pear/HTML_AJAX/AJAX/Server.php?r1=1.6&r2=1.7&ty=u Index: pear/HTML_AJAX/AJAX/Server.php diff -u pear/HTML_AJAX/AJAX/Server.php:1.6 pear/HTML_AJAX/AJAX/Server.php:1.7 --- pear/HTML_AJAX/AJAX/Server.php:1.6 Tue Sep 27 11:14:27 2005 +++ pear/HTML_AJAX/AJAX/Server.php Mon Oct 24 23:26:13 2005 @@ -2,12 +2,6 @@ /** * OO AJAX Implementation for PHP * - * LICENSE: This source file is subject to version 3.0 of the PHP license - * that is available through the world-wide-web at the following URI: - * http://www.php.net/license/3_0.txt. If you did not receive a copy of - * the PHP License and are unable to obtain it through the web, please - * send a note to license@php.net so we can mail you a copy immediately. - * * @category HTML * @package AJAX * @author Joshua Eichorn <josh@bluga.net> @@ -37,10 +31,9 @@ * @package AJAX * @author Joshua Eichorn <josh@bluga.net> * @copyright 2005 Joshua Eichorn - * @license http://www.php.net/license/3_0.txt PHP License 3.0 + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @version Release: @package_version@ * @link http://pear.php.net/package/PackageName - * @todo extend options and generateClient fileList building to support , seperated lists of libs */ class HTML_AJAX_Server { @@ -102,23 +95,44 @@ /** * Javascript library names and there path * - * the return of $this->clientJsLocation(), is appended before running readfile on them + * the return of $this->clientJsLocation(), is prepended before running readfile on them * * @access public * @var array */ var $javascriptLibraries = array( - 'all' => 'HTML_AJAX.js', - 'html_ajax' => 'HTML_AJAX.js', + 'all' => 'HTML_AJAX.js', + 'html_ajax' => 'HTML_AJAX.js', 'html_ajax_lite'=> 'HTML_AJAX_lite.js', - 'json' => 'JSON.js', - 'request' => 'Request.js', - 'main' => 'Main.js', - 'httpclient'=> 'HttpClient.js', - 'dispatcher'=> 'Dispatcher.js' + 'json' => 'JSON.js', + 'request' => 'Request.js', + 'main' => 'Main.js', + 'httpclient' => 'HttpClient.js', + 'dispatcher' => 'Dispatcher.js', + 'util' => 'util.js', + 'loading' => 'Loading.js', + 'phpserializer' => 'serialize.js', + 'behavior' => array('behavior.js','cssQuery-p.js') ); /** + * Custom paths to use for javascript libraries, if not set {@link clientJsLocation} is used to find the system path + * + * @access public + * @var array + * @see registerJsLibrary + */ + var $javascriptLibraryPaths = array(); + + /** + * Array of className => init methods to call, generated from constructor from initClassName methods + * + * @access protected + */ + var $_initLookup = array(); + + + /** * Constructor creates the HTML_AJAX instance * * @todo: verify that PHP_SELF always does what we want @@ -127,6 +141,13 @@ { $this->ajax =& new HTML_AJAX(); $this->ajax->serverUrl = $_SERVER['PHP_SELF']; + + $methods = get_class_methods($this); + foreach($methods as $method) { + if (preg_match('/^init([a-zA-Z0-0]+)$/',$method,$match)) { + $this->_initLookup[$match[1]] = $method; + } + } } /** @@ -158,26 +179,64 @@ } /** + * Register a new js client library + * + * @param string $libraryName name you'll reference the library as + * @param string|array $fileName actual filename with no path, for example customLib.js + * @param string|false $path Optional, if not set the result from jsClientLocation is used + */ + function registerJSLibrary($libraryName,$fileName,$path = false) { + $libraryName = strtolower($libraryName); + $this->javascriptLibraries[$libraryName] = $fileName; + + if ($path !== false) { + $this->javascriptLibraryPaths[$libraryName] = $path; + } + } + + /** + * Register init methods from an external class + * + * @param object $instance an external class with initClassName methods + */ + function registerInitObject(&$instance) { + $methods = get_class_methods($instance); + foreach($methods as $method) { + if (preg_match('/^init([a-zA-Z0-9_]+)$/',$method,$match)) { + $this->_initLookup[$match[1]] = array(&$instance,$method); + } + } + } + + /** * Generate client js * * @todo this is going to need tests to cover all the options */ function generateClient() { - header('Content-Type: text/javascript'); + $headers = array(); ob_start(); // create a list list of js files were going to need to output $fileList = array(); - $library = strtolower($this->options['client']); - if (isset($this->javascriptLibraries[$library])) { - $fileList[] = $this->clientJsLocation().$this->javascriptLibraries[$library]; + foreach($this->options['client'] as $library) { + if (isset($this->javascriptLibraries[$library])) { + $lib = (array)$this->javascriptLibraries[$library]; + foreach($lib as $file) { + if (isset($this->javascriptLibraryPaths[$library])) { + $fileList[] = $this->javascriptLibraryPaths[$library].$file; + } + else { + $fileList[] = $this->clientJsLocation().$file; + } + } + } } // do needed class init if were running an init server - if(!is_array($this->options['stub'])) - { + if(!is_array($this->options['stub'])) { $this->options['stub'] = array(); } $classList = $this->options['stub']; @@ -204,7 +263,9 @@ if ($classList != false && count($classList) > 0) { // were setup enough to make a stubETag if the input it wants is a class list - if ($this->cacheOptions['httpCacheStub'] && $this->cacheOptions['StubCacheExpects'] == 'classes') { + if ($this->cacheOptions['httpCacheStub'] && + $this->cacheOptions['StubCacheExpects'] == 'classes') + { $stubETag = $this->_callCacheRule('Stub',$classList); } @@ -222,7 +283,9 @@ } // if were cacheing and the rule expects content make a tag and check it, if the check is true were done - if ($this->cacheOptions['httpCacheStub'] && $this->cacheOptions['StubCacheExpects'] == 'content') { + if ($this->cacheOptions['httpCacheStub'] && + $this->cacheOptions['StubCacheExpects'] == 'content') + { $stubETag = $this->_callCacheRule('Stub',ob_get_contents()); } @@ -237,7 +300,9 @@ if (count($fileList) > 0) { // if were caching and need a file list build our jsETag - if ($this->cacheOptions['httpCacheClient'] && $this->cacheOptions['ClientCacheExpects'] === 'files') { + if ($this->cacheOptions['httpCacheClient'] && + $this->cacheOptions['ClientCacheExpects'] === 'files') + { $jsETag = $this->_callCacheRule('Client',$fileList); } @@ -256,7 +321,9 @@ } // if were caching and need content build the etag - if ($this->cacheOptions['httpCacheClient'] && $this->cacheOptions['ClientCacheExpects'] === 'content') { + if ($this->cacheOptions['httpCacheClient'] && + $this->cacheOptions['ClientCacheExpects'] === 'content') + { $jsETag = $this->_callCacheRule('Client',ob_get_contents()); } @@ -280,8 +347,10 @@ // were outputting content, add our length header and send the output $length = ob_get_length(); if ($length > 0) { - header('Content-Length: '.$length); + $headers['Content-Length'] = $length; } + $headers['Content-Type'] = 'text/javascript; charset=utf-8'; + call_user_func($this->ajax->_callbacks['headers'],$headers); ob_end_flush(); } @@ -326,7 +395,26 @@ { $this->options = array('client'=>false,'stub'=>false); if (isset($_GET['client'])) { - $this->options['client'] = $this->_cleanIdentifier($_GET['client']); + $this->options['client'] = array(); + if (strstr($_GET['client'],',')) { + $clients = explode(',',$_GET['client']); + } else { + $clients = array($_GET['client']); + } + + $client = array(); + foreach($clients as $val) { + $cleanVal = $this->_cleanIdentifier($val); + if (!empty($cleanVal)) { + $client[] = strtolower($cleanVal); + } + } + + if (count($client) > 0) { + $this->options['client'] = $client; + } else { + $this->options['client'] = false; + } } if (isset($_GET['stub'])) { if (strstr($_GET['stub'],',')) { @@ -368,11 +456,9 @@ */ function _initAll() { - $methods = get_class_methods(get_class($this)); - - foreach($methods as $method) { - if (substr($method,0,4) == 'init') { - $this->$method(); + if ($this->initMethods) { + foreach($this->_initLookup as $class => $method) { + $this->_init($class); } } } @@ -382,13 +468,21 @@ * * @param string $className * @access private - * @todo error handling if the method doesn't exist */ function _init($className) { - $m = "init$className"; - if (is_callable(array(&$this,$m))) { - $this->$m(); + if ($this->initMethods) { + if (isset($this->_initLookup[$className])) { + $method =& $this->_initLookup[$className]; + if (is_array($method)) { + call_user_func($method); + } + else { + $this->$method(); + } + } else { + trigger_error("Could find an init method for class: " . $className); + } } } @@ -445,7 +539,7 @@ header('Cache-Control: must-revalidate'); header('ETag: '.$etag); if ($notModified) { - header('HTTP/1.0 304 Not Modified'); + header('HTTP/1.0 304 Not Modified',false,304); } } http://cvs.php.net/diff.php/pear/HTML_AJAX/AJAX/Serializer/JSON.php?r1=1.7&r2=1.8&ty=u Index: pear/HTML_AJAX/AJAX/Serializer/JSON.php diff -u pear/HTML_AJAX/AJAX/Serializer/JSON.php:1.7 pear/HTML_AJAX/AJAX/Serializer/JSON.php:1.8 --- pear/HTML_AJAX/AJAX/Serializer/JSON.php:1.7 Tue Sep 27 11:14:28 2005 +++ pear/HTML_AJAX/AJAX/Serializer/JSON.php Mon Oct 24 23:26:13 2005 @@ -1,6 +1,6 @@ <?php require_once 'HTML/AJAX/JSON.php'; -// $Id: JSON.php,v 1.7 2005/09/27 15:14:28 jeichorn Exp $ +// $Id: JSON.php,v 1.8 2005/10/25 03:26:13 jeichorn Exp $ /** * JSON Serializer * @@ -12,9 +12,10 @@ * @version Release: @package_version@ * @link http://pear.php.net/package/PackageName */ +// {{{ class HTMLA_AJAX_Serialize_JSON class HTML_AJAX_Serializer_JSON { - + // {{{ variables-properties /** * JSON instance * @var HTML_AJAX_JSON @@ -27,44 +28,60 @@ * @access private */ var $_jsonext; - + // }}} + // {{{ constructor function HTML_AJAX_Serializer_JSON() { $this->_jsonext = $this->_detect(); - if(!$this->_jsonext) - { + if(!$this->_jsonext) { $this->_json =& new HTML_AJAX_JSON(); } } - + // }}} + // {{{ serialize + /** + * This function serializes and input passed to it. + * + * @access public + * @param string $input The input to serialize. + * @return string $input The serialized input. + */ function serialize($input) { - if($this->_jsonext) - { + if($this->_jsonext) { return json_encode($input); - } - else - { + } else { return $this->_json->encode($input); } } - + // }}} + // {{{ unserialize + /** + * this function unserializes the input passed to it. + * + * @access public + * @param string $input The input to unserialize + * @return string $input The unserialized input. + */ function unserialize($input) { - if($this->_jsonext) - { + if($this->_jsonext) { return json_decode($input); - } - else - { + } else { return $this->_json->decode($input); } } - + // }}} + // {{{ _detect + /** + * detcts the loaded extension + */ function _detect() { return extension_loaded('json'); } + // }}} } +// }}} /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ ?> http://cvs.php.net/diff.php/pear/HTML_AJAX/AJAX/Serializer/Null.php?r1=1.6&r2=1.7&ty=u Index: pear/HTML_AJAX/AJAX/Serializer/Null.php diff -u pear/HTML_AJAX/AJAX/Serializer/Null.php:1.6 pear/HTML_AJAX/AJAX/Serializer/Null.php:1.7 --- pear/HTML_AJAX/AJAX/Serializer/Null.php:1.6 Tue Sep 27 11:14:28 2005 +++ pear/HTML_AJAX/AJAX/Serializer/Null.php Mon Oct 24 23:26:13 2005 @@ -1,5 +1,5 @@ <?php -// $Id: Null.php,v 1.6 2005/09/27 15:14:28 jeichorn Exp $ +// $Id: Null.php,v 1.7 2005/10/25 03:26:13 jeichorn Exp $ /** * Null Serializer * http://cvs.php.net/diff.php/pear/HTML_AJAX/js/Dispatcher.js?r1=1.4&r2=1.5&ty=u Index: pear/HTML_AJAX/js/Dispatcher.js diff -u pear/HTML_AJAX/js/Dispatcher.js:1.4 pear/HTML_AJAX/js/Dispatcher.js:1.5 --- pear/HTML_AJAX/js/Dispatcher.js:1.4 Tue Sep 27 11:14:28 2005 +++ pear/HTML_AJAX/js/Dispatcher.js Mon Oct 24 23:26:13 2005 @@ -24,6 +24,11 @@ HTML_AJAX_Dispatcher.prototype = { /** + * Queue to use when making a request + */ + queue: 'default', + + /** * Timeout for async calls */ timeout: 20000, @@ -43,6 +48,7 @@ request.timeout = this.timeout; request.contentType = this.contentType; request.serializer = eval('new HTML_AJAX_Serialize_'+this.serializerType); + request.queue = this.queue; for(var i=0; i < args.length; i++) { request.addArg(i,args[i]); @@ -50,13 +56,15 @@ if ( this.mode == "async" ) { request.isAsync = true; + if (this.callback[callName]) { + var self = this; + request.callback = function(result) { self.callback[callName](result); } + } + } else { request.isAsync = false; } - var self = this; - request.callback = function(result) { self.callback[callName](result); } - return HTML_AJAX.makeRequest(request); } }; http://cvs.php.net/diff.php/pear/HTML_AJAX/js/HTML_AJAX.js?r1=1.3&r2=1.4&ty=u Index: pear/HTML_AJAX/js/HTML_AJAX.js diff -u pear/HTML_AJAX/js/HTML_AJAX.js:1.3 pear/HTML_AJAX/js/HTML_AJAX.js:1.4 --- pear/HTML_AJAX/js/HTML_AJAX.js:1.3 Tue Sep 27 11:14:28 2005 +++ pear/HTML_AJAX/js/HTML_AJAX.js Mon Oct 24 23:26:13 2005 @@ -16,15 +16,32 @@ var HTML_AJAX = { defaultServerUrl: false, defaultEncoding: 'Null', + queues: false, // get an HttpClient, at some point this might be actually smart httpClient: function() { return new HTML_AJAX_HttpClient(); }, - // make a request using an request object + // Pushing the given request to queue specified by it, in default operation this will immediately make a request + // request might be delayed or never happen depending on the queue setup + // making a sync request to a non immediate queue will cause you problems so just don't do it makeRequest: function(request) { - var client = HTML_AJAX.httpClient(); - client.request = request; - return client.makeRequest(); + if (!HTML_AJAX.queues[request.queue]) { + var e = new Error('Unknown Queue: '+request.queue); + if (HTML_AJAX.onError) { + HTML_AJAX.onError(e); + return false; + } + else { + throw(e); + } + } + else { + var qn = request.queue; + var q = HTML_AJAX.queues[qn]; + + HTML_AJAX.queues[request.queue].addRequest(request); + return HTML_AJAX.queues[request.queue].processRequest(); + } }, // get a serializer object for a specific encoding serializerForEncoding: function(encoding) { @@ -51,19 +68,22 @@ return HTML_AJAX.makeRequest(request); }, call: function(className,method,callback) { - var args = new Array(); - for(var i = 3; i < arguments.length; i++) { - args.push(arguments[i]); - } + var args = new Array(); + for(var i = 3; i < arguments.length; i++) { + args.push(arguments[i]); + } return HTML_AJAX.fullcall(HTML_AJAX.defaultServerUrl,HTML_AJAX.defaultEncoding,className,method,callback,args); }, grab: function(url,callback) { return HTML_AJAX.fullcall(url,'Null',false,null,callback,{}); }, replace: function(id) { + var callback = function(result) { + document.getElementById(id).innerHTML = result; + } if (arguments.length == 2) { // grab replacement - document.getElementById(id).innerHTML = HTML_AJAX.grab(arguments[1]); + HTML_AJAX.grab(arguments[1],callback); } else { // call replacement @@ -71,34 +91,28 @@ for(var i = 3; i < arguments.length; i++) { args.push(arguments[i]); } - document.getElementById(id).innerHTML = HTML_AJAX.call(arguments[1],arguments[2],false,args); + HTML_AJAX.fullcall(HTML_AJAX.defaultServerUrl,HTML_AJAX.defaultEncoding,arguments[1],arguments[2],callback,args); } }, - onOpen: function(className,methodName) { - var loading = document.getElementById('HTML_AJAX_LOADING'); - if (!loading) { - loading = document.createElement('div'); - loading.id = 'HTML_AJAX_LOADING'; - loading.innerHTML = 'Loading...'; - loading.style.position = 'absolute'; - loading.style.top = 0; - loading.style.right = 0; - loading.style.backgroundColor = 'red'; - loading.style.width = '80px'; - loading.style.padding = '4px'; - - document.getElementsByTagName('body').item(0).appendChild(loading); + append: function(id) { + var callback = function(result) { + document.getElementById(id).innerHTML += result; } - loading.style.display = 'block'; - }, - onLoad: function(className,methodName) { - var loading = document.getElementById('HTML_AJAX_LOADING'); - if (loading) { - loading.style.display = 'none'; + if (arguments.length == 2) { + // grab replacement + HTML_AJAX.grab(arguments[1],callback); } - }, - // A really basic error handler + else { + // call replacement + var args = new Array(); + for(var i = 3; i < arguments.length; i++) { + args.push(arguments[i]); + } + HTML_AJAX.fullcall(HTML_AJAX.defaultServerUrl,HTML_AJAX.defaultEncoding,arguments[1],arguments[2],callback,args); + } + }, /* + // A really basic error handler onError: function(e) { msg = ""; for(var i in e) { @@ -108,13 +122,21 @@ }, */ // Class postfix to content-type map - contentTypeMap: {'JSON':'application/json','Null':'text/plain','Error':'application/error'} + contentTypeMap: {'JSON':'application/json','Null':'text/plain','Error':'application/error'}, + // used internally to make queues work, override onLoad or onError to perform custom events when a request is complete + // fires on success and error + requestComplete: function(request,error) { + for(var i in HTML_AJAX.queues) { + if (HTML_AJAX.queues[i].requestComplete) { + HTML_AJAX.queues[i].requestComplete(request,error); + } + } + } } - // small classes that I don't want to put in there own file function HTML_AJAX_Serialize_Null() {} @@ -169,6 +191,7 @@ } } + function HTML_AJAX_Serialize_Error() {} HTML_AJAX_Serialize_Error.prototype = { contentType: 'application/error; charset=UTF-8', @@ -180,13 +203,73 @@ var ser = new HTML_AJAX_Serialize_JSON(); var data = new ser.unserialize(input); - var e = new Error('PHP Error'); + var e = new Error('PHP Error: '+data.errStr); for(var i in data) { e[i] = data[i]; } throw e; } } + +// Processing Queues + +// simple queue, just processes the request immediately +function HTML_AJAX_Queue_Immediate() {} +HTML_AJAX_Queue_Immediate.prototype = { + request: false, + addRequest: function(request) { + this.request = request; + }, + processRequest: function() { + var client = HTML_AJAX.httpClient(); + client.request = this.request; + return client.makeRequest(); + } + // requestComplete: function() {} // this is also possible but this queue doesn't need it +} + +// Single Buffer queue with interval +// works by attempting to send a request every x miliseconds +// if an item is currently in the queue when a new item is added it will be replaced +// simple queue, just processes the request immediately +// the first request starts the interval timer +function HTML_AJAX_Queue_Interval_SingleBuffer(interval) { + this.interval = interval; +} +HTML_AJAX_Queue_Interval_SingleBuffer.prototype = { + request: false, + _intervalId: false, + addRequest: function(request) { + this.request = request; + }, + processRequest: function() { + if (!this._intervalId) { + this.runInterval(); + this.start(); + } + }, + start: function() { + var self = this; + this._intervalId = setInterval(function() { self.runInterval() },this.interval); + }, + stop: function() { + clearInterval(this._intervalId); + }, + runInterval: function() { + if (this.request) { + var client = HTML_AJAX.httpClient(); + client.request = this.request; + this.request = false; + client.makeRequest(); + } + } +} + + +// create a default queue, has to happen after the Queue class has been defined +HTML_AJAX.queues = new Object(); +HTML_AJAX.queues['default'] = new HTML_AJAX_Queue_Immediate(); + /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ // Dispatcher.js /** @@ -215,6 +298,11 @@ HTML_AJAX_Dispatcher.prototype = { /** + * Queue to use when making a request + */ + queue: 'default', + + /** * Timeout for async calls */ timeout: 20000, @@ -234,6 +322,7 @@ request.timeout = this.timeout; request.contentType = this.contentType; request.serializer = eval('new HTML_AJAX_Serialize_'+this.serializerType); + request.queue = this.queue; for(var i=0; i < args.length; i++) { request.addArg(i,args[i]); @@ -241,13 +330,15 @@ if ( this.mode == "async" ) { request.isAsync = true; + if (this.callback[callName]) { + var self = this; + request.callback = function(result) { self.callback[callName](result); } + } + } else { request.isAsync = false; } - var self = this; - request.callback = function(result) { self.callback[callName](result); } - return HTML_AJAX.makeRequest(request); } }; @@ -319,6 +410,12 @@ } try { + if (this.request.onOpen) { + this.request.onOpen(); + } + else if (HTML_AJAX.onOpen) { + HTML_AJAX.onOpen(this.request); + } this.xmlhttp.open(this.request.requestType,this.request.completeUrl(),this.request.isAsync); // set onreadystatechange here since it will be reset after a completed call in Mozilla @@ -337,6 +434,7 @@ if (!this.request.isAsync) { if ( this.xmlhttp.status == 200 ) { + HTML_AJAX.requestComplete(this.request); if (this.request.onLoad) { this.request.onLoad(); } else if (HTML_AJAX.onLoad) { @@ -398,13 +496,16 @@ window.clearTimeout(this._timeout_id); if (this.xmlhttp.status == 200) { + HTML_AJAX.requestComplete(this.request); if (this.request.onLoad) { this.request.onLoad(); } else if (HTML_AJAX.onLoad ) { HTML_AJAX.onLoad(this.request); } - this.request.callback(this._decodeResponse()); + if (this.request.callback) { + this.request.callback(this._decodeResponse()); + } } else { @@ -430,13 +531,13 @@ // handle sending an error where it needs to go _handleError: function(e) { + HTML_AJAX.requestComplete(this.request,e); if (this.request.onError) { this.request.onError(e); } else if (HTML_AJAX.onError) { HTML_AJAX.onError(e,this.request); } else { - alert('throwing the exception'); throw e; } } @@ -492,6 +593,9 @@ // async callback method callback: null, + // Queue to push this request too + queue: 'default', + /** * Add an argument for the remote method * @param string argument name @@ -879,3 +983,196 @@ } }; /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ +// Loading.js +/** + * Default loading implementation + * + * @category HTML + * @package Ajax + * @author Joshua Eichorn <josh@bluga.net> + * @copyright 2005 Joshua Eichorn + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + */ + +HTML_AJAX.onOpen = function(request) { + var loading = document.getElementById('HTML_AJAX_LOADING'); + if (!loading) { + loading = document.createElement('div'); + loading.id = 'HTML_AJAX_LOADING'; + loading.innerHTML = 'Loading...'; + loading.style.position = 'absolute'; + loading.style.top = 0; + loading.style.right = 0; + loading.style.backgroundColor = 'red'; + loading.style.width = '80px'; + loading.style.padding = '4px'; + + document.body.insertBefore(loading,document.body.firstChild); + } + HTML_AJAX.onOpen_Timeout = window.setTimeout(function() { loading.style.display = 'block'; },500); +} +HTML_AJAX.onLoad = function(request) { + if (HTML_AJAX.onOpen_Timeout) { + window.clearTimeout(HTML_AJAX.onOpen_Timeout); + HTML_AJAX.onOpen_Timeout = false; + } + var loading = document.getElementById('HTML_AJAX_LOADING'); + if (loading) { + loading.style.display = 'none'; + } +} +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ +// util.js +/** + * Utility methods + * + * @category HTML + * @package Ajax + * @author David Coallier <davidc@php.net> + * @copyright 2005 David Coallier + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + */ +// {{{ HTML_AJAX_Util +/** + * All the utilities we will be using thorough the classes + */ +var HTML_AJAX_Util = { + // Set the element event + setElementEvent: function(id, event, handler) { + var element = document.getElementById(id); + if (typeof element.addEventListener != "undefined") { //Dom2 + element.addEventListener(event, handler, false); + } else if (typeof element.attachEvent != "undefined") { //IE 5+ + element.attachEvent("on" + event, handler); + } else { + if (element["on" + event] != null) { + var oldHandler = element["on" + event]; + element["on" + event] = function(e) { + oldHander(e); + handler(e); + }; + } else { + element["on" + event] = handler; + } + } + }, + // simple non recursive variable dumper, don't rely on its output staying the same, its just for debugging and will get smarter at some point + varDump: function(input) { + var r = ""; + for(var i in input) { + r += i+':'+input[i]+"\n"; + } + return r; + } + +} +// }}} +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ +// behavior.js +/** + +ModifiedBehavior v1.0 by Ron Lancaster based on Ben Nolan's Behaviour, June 2005 implementation. +Modified to use Dean Edward's CSS Query. + +Description +---------- + +Uses css selectors to apply javascript Behaviors to enable unobtrusive javascript in html documents. + +Dependencies +------------ + +Requires [Dean Edwards CSSQuery](http://dean.edwards.name/my/cssQuery/ "CSSQuery"). + +Usage +------ + + Behavior.register( + "b.someclass", + function(element) { + element.onclick = function(){ + alert(this.innerHTML); + } + } + ); + + Behavior.register( + "#someid u", + function(element) { + element.onmouseover = function(){ + this.innerHTML = "BLAH!"; + } + }, + getElementByID("parent") + ); + +Call `Behavior.apply()` to re-apply the rules (if you update the dom, etc). + +License +------ + +Reproduced under BSD licensed. Same license as Ben Nolan's implementation. + +More information for Ben Nolan's implementation: <http://ripcord.co.nz/behaviour/> + +*/ + +var Behavior = { + + // private data member + list : new Array(), + + // private method + addLoadEvent : function(func) { + var oldonload = window.onload; + + if (typeof window.onload != 'function') { + window.onload = func; + } else { + window.onload = function() { + oldonload(); + func(); + } + } + }, + + // void apply() : Applies the registered ruleset. + apply : function() { + for (i = 0; i < Behavior.list.length; i++) { + var rule = Behavior.list[i]; + var tags = cssQuery(rule.selector, rule.from); + if (tags) { + for (j = 0; j < tags.length; j++) { + rule.action(tags[j]); + } + } + } + }, + + // void register() : register a css selector, and the action (function) to take, + // from (optional) is a document, element or array of elements which is filtered by selector. + register : function(selector, action, from) { + Behavior.list.push(new BehaviorRule(selector, from, action)); + }, + + // void start() : initial application of ruleset at document load. + start : function() { + Behavior.addLoadEvent(function() { + Behavior.apply(); + }); + } +} + +function BehaviorRule(selector, from, action) { + this.selector = selector; + this.from = from; + this.action = action; +} + +Behavior.start();// cssQuery-p.js +/* + cssQuery, version 2.0.2 (2005-08-19) + Copyright: 2004-2005, Dean Edwards (http://dean.edwards.name/) + License: http://creativecommons.org/licenses/LGPL/2.1/ +*/ +eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('7 x=6(){7 1D="2.0.2";7 C=/\\s*,\\s*/;7 x=6(s,A){33{7 m=[];7 u=1z.32.2c&&!A;7 b=(A)?(A.31==22)?A:[A]:[1g];7 1E=18(s).1l(C),i;9(i=0;i<1E.y;i++){s=1y(1E[i]);8(U&&s.Z(0,3).2b("")==" *#"){s=s.Z(2);A=24([],b,s[1])}1A A=b;7 j=0,t,f,a,c="";H(j<s.y){t=s[j++];f=s[j++];c+=t+f;a="";8(s[j]=="("){H(s[j++]!=")")a+=s[j];a=a.Z(0,-1);c+="("+a+")"}A=(u&&V[c])?V[c]:21(A,t,f,a);8(u)V[c]=A}m=m.30(A)}2a x.2d;5 m}2Z(e){x.2d=e;5[]}};x.1Z=6(){5"6 x() {\\n [1D "+1D+"]\\n}"};7 V={};x.2c=L;x.2Y=6(s){8(s){s=1y(s).2b("");2a V[s]}1A V={}};7 29={};7 19=L;x.15=6(n,s){8(19)1i("s="+1U(s));29[n]=12 s()};x.2X=6(c){5 c?1i(c):o};7 D={};7 h={};7 q={P:/\\[([\\w-]+(\\|[\\w-]+)?)\\s*(\\W?=)?\\s*([^\\]]*)\\]/};7 T=[];D[" "]=6(r,f,t,n){7 e,i,j;9(i=0;i<f.y;i++){7 s=X(f[i],t,n);9(j=0;(e=s[j]);j++){8(M(e)&&14(e,n))r.z(e)}}};D["#"]=6(r,f,i){7 e,j;9(j=0;(e=f[j]);j++)8(e.B==i)r.z(e)};D["."]=6(r,f,c){c=12 1t("(^|\\\\s)"+c+"(\\\\s|$)");7 e,i;9(i=0;(e=f[i]);i++)8(c.l(e.1V))r.z(e)};D[":"]=6(r,f,p,a){7 t=h[p],e,i;8(t)9(i=0;(e=f[i]);i++)8(t(e,a))r.z(e)};h["2W"]=6(e){7 d=Q(e);8(d.1C)9(7 i=0;i<d.1C.y;i++){8(d.1C[i]==e)5 K}};h["2V"]=6(e){};7 M=6(e){5(e&&e.1c==1&&e.1f!="!")?e:23};7 16=6(e){H(e&&(e=e.2U)&&!M(e))28;5 e};7 G=6(e){H(e&&(e=e.2T)&&!M(e))28;5 e};7 1r=6(e){5 M(e.27)||G(e.27)};7 1P=6(e){5 M(e.26)||16(e.26)};7 1o=6(e){7 c=[];e=1r(e);H(e){c.z(e);e=G(e)}5 c};7 U=K;7 1h=6(e){7 d=Q(e);5(2S d.25=="2R")?/\\.1J$/i.l(d.2Q):2P(d.25=="2O 2N")};7 Q=6(e){5 e.2M||e.1g};7 X=6(e,t){5(t=="*"&&e.1B)?e.1B:e.X(t)};7 17=6(e,t,n){8(t=="*")5 M(e);8(!14(e,n))5 L;8(!1h(e))t=t.2L();5 e.1f==t};7 14=6(e,n){5!n||(n=="*")||(e.2K==n)};7 1e=6(e){5 e.1G};6 24(r,f,B){7 m,i,j;9(i=0;i<f.y;i++){8(m=f[i].1B.2J(B)){8(m.B==B)r.z(m);1A 8(m.y!=23){9(j=0;j<m.y;j++){8(m[j].B==B)r.z(m[j])}}}}5 r};8(![].z)22.2I.z=6(){9(7 i=0;i<1z.y;i++){o[o.y]=1z[i]}5 o.y};7 N=/\\|/;6 21(A,t,f,a){8(N.l(f)){f=f.1l(N);a=f[0];f=f[1]}7 r=[];8(D[t]){D[t](r,A,f,a)}5 r};7 S=/^[^\\s>+~]/;7 20=/[\\s#.:>+~()@]|[^\\s#.:>+~()@]+/g;6 1y(s){8(S.l(s))s=" "+s;5 s.P(20)||[]};7 W=/\\s*([\\s>+~(),]|^|$)\\s*/g;7 I=/([\\s>+~,]|[^(]\\+|^)([#.:@])/g;7 18=6(s){5 s.O(W,"$1").O(I,"$1*$2")};7 1u={1Z:6(){5"\'"},P:/^(\'[^\']*\')|("[^"]*")$/,l:6(s){5 o.P.l(s)},1S:6(s){5 o.l(s)?s:o+s+o},1Y:6(s){5 o.l(s)?s.Z(1,-1):s}};7 1s=6(t){5 1u.1Y(t)};7 E=/([\\/()[\\]?{}|*+-])/g;6 R(s){5 s.O(E,"\\\\$1")};x.15("1j-2H",6(){D[">"]=6(r,f,t,n){7 e,i,j;9(i=0;i<f.y;i++){7 s=1o(f[i]);9(j=0;(e=s[j]);j++)8(17(e,t,n))r.z(e)}};D["+"]=6(r,f,t,n){9(7 i=0;i<f.y;i++){7 e=G(f[i]);8(e&&17(e,t,n))r.z(e)}};D["@"]=6(r,f,a){7 t=T[a].l;7 e,i;9(i=0;(e=f[i]);i++)8(t(e))r.z(e)};h["2G-10"]=6(e){5!16(e)};h["1x"]=6(e,c){c=12 1t("^"+c,"i");H(e&&!e.13("1x"))e=e.1n;5 e&&c.l(e.13("1x"))};q.1X=/\\\\:/g;q.1w="@";q.J={};q.O=6(m,a,n,c,v){7 k=o.1w+m;8(!T[k]){a=o.1W(a,c||"",v||"");T[k]=a;T.z(a)}5 T[k].B};q.1Q=6(s){s=s.O(o.1X,"|");7 m;H(m=s.P(o.P)){7 r=o.O(m[0],m[1],m[2],m[3],m[4]);s=s.O(o.P,r)}5 s};q.1W=6(p,t,v){7 a={};a.B=o.1w+T.y;a.2F=p;t=o.J[t];t=t?t(o.13(p),1s(v)):L;a.l=12 2E("e","5 "+t);5 a};q.13=6(n){1d(n.2D()){F"B":5"e.B";F"2C":5"e.1V";F"9":5"e.2B";F"1T":8(U){5"1U((e.2A.P(/1T=\\\\1v?([^\\\\s\\\\1v]*)\\\\1v?/)||[])[1]||\'\')"}}5"e.13(\'"+n.O(N,":")+"\')"};q.J[""]=6(a){5 a};q.J["="]=6(a,v){5 a+"=="+1u.1S(v)};q.J["~="]=6(a,v){5"/(^| )"+R(v)+"( |$)/.l("+a+")"};q.J["|="]=6(a,v){5"/^"+R(v)+"(-|$)/.l("+a+")"};7 1R=18;18=6(s){5 1R(q.1Q(s))}});x.15("1j-2z",6(){D["~"]=6(r,f,t,n){7 e,i;9(i=0;(e=f[i]);i++){H(e=G(e)){8(17(e,t,n))r.z(e)}}};h["2y"]=6(e,t){t=12 1t(R(1s(t)));5 t.l(1e(e))};h["2x"]=6(e){5 e==Q(e).1H};h["2w"]=6(e){7 n,i;9(i=0;(n=e.1F[i]);i++){8(M(n)||n.1c==3)5 L}5 K};h["1N-10"]=6(e){5!G(e)};h["2v-10"]=6(e){e=e.1n;5 1r(e)==1P(e)};h["2u"]=6(e,s){7 n=x(s,Q(e));9(7 i=0;i<n.y;i++){8(n[i]==e)5 L}5 K};h["1O-10"]=6(e,a){5 1p(e,a,16)};h["1O-1N-10"]=6(e,a){5 1p(e,a,G)};h["2t"]=6(e){5 e.B==2s.2r.Z(1)};h["1M"]=6(e){5 e.1M};h["2q"]=6(e){5 e.1q===L};h["1q"]=6(e){5 e.1q};h["1L"]=6(e){5 e.1L};q.J["^="]=6(a,v){5"/^"+R(v)+"/.l("+a+")"};q.J["$="]=6(a,v){5"/"+R(v)+"$/.l("+a+")"};q.J["*="]=6(a,v){5"/"+R(v)+"/.l("+a+")"};6 1p(e,a,t){1d(a){F"n":5 K;F"2p":a="2n";1a;F"2o":a="2n+1"}7 1m=1o(e.1n);6 1k(i){7 i=(t==G)?1m.y-i:i-1;5 1m[i]==e};8(!Y(a))5 1k(a);a=a.1l("n");7 m=1K(a[0]);7 s=1K(a[1]);8((Y(m)||m==1)&&s==0)5 K;8(m==0&&!Y(s))5 1k(s);8(Y(s))s=0;7 c=1;H(e=t(e))c++;8(Y(m)||m==1)5(t==G)?(c<=s):(s>=c);5(c%m)==s}});x.15("1j-2m",6(){U=1i("L;/*@2l@8(@\\2k)U=K@2j@*/");8(!U){X=6(e,t,n){5 n?e.2i("*",t):e.X(t)};14=6(e,n){5!n||(n=="*")||(e.2h==n)};1h=1g.1I?6(e){5/1J/i.l(Q(e).1I)}:6(e){5 Q(e).1H.1f!="2g"};1e=6(e){5 e.2f||e.1G||1b(e)};6 1b(e){7 t="",n,i;9(i=0;(n=e.1F[i]);i++){1d(n.1c){F 11:F 1:t+=1b(n);1a;F 3:t+=n.2e;1a}}5 t}}});19=K;5 x}();',62,190,'|||||return|function|var|if|for||||||||pseudoClasses||||test|||this||AttributeSelector|||||||cssQuery|length|push|fr|id||selectors||case|nextElementSibling|while||tests|true|false|thisElement||replace|match|getDocument|regEscape||attributeSelectors|isMSIE|cache||getElementsByTagName|isNaN|slice|child||new|getAttribute|compareNamespace|addModule|previousElementSibling|compareTagName|parseSelector|loaded|break|_0|nodeType|switch|getTextContent|tagName|document|isXML|eval|css|_1|split|ch|parentNode|childElements|nthChild|disabled|firstElementChild|getText|RegExp|Quote|x22|PREFIX|lang|_2|arguments|else|all|links|version|se|childNodes|innerText|documentElement|contentType|xml|parseInt|indeterminate|checked|last|nth|lastElementChild|parse|_3|add|href|String|className|create|NS_IE|remove|toString|ST|select|Array|null|_4|mimeType|lastChild|firstChild|continue|modules|delete|join|caching|error|nodeValue|textContent|HTML|prefix|getElementsByTagNameNS|end|x5fwin32|cc_on|standard||odd|even|enabled|hash|location|target|not|only|empty|root|contains|level3|outerHTML|htmlFor|class|toLowerCase|Function|name|first|level2|prototype|item|scopeName|toUpperCase|ownerDocument|Document|XML|Boolean|URL|unknown|typeof|nextSibling|previousSibling|visited|link|valueOf|clearCache|catch|concat|constructor|callee|try'.split('|'),0,{})) http://cvs.php.net/diff.php/pear/HTML_AJAX/js/HTML_AJAX_lite.js?r1=1.3&r2=1.4&ty=u Index: pear/HTML_AJAX/js/HTML_AJAX_lite.js diff -u pear/HTML_AJAX/js/HTML_AJAX_lite.js:1.3 pear/HTML_AJAX/js/HTML_AJAX_lite.js:1.4 --- pear/HTML_AJAX/js/HTML_AJAX_lite.js:1.3 Tue Sep 27 11:14:28 2005 +++ pear/HTML_AJAX/js/HTML_AJAX_lite.js Mon Oct 24 23:26:13 2005 @@ -2,13 +2,27 @@ var HTML_AJAX = { defaultServerUrl: false, defaultEncoding: 'Null', +queues: false, httpClient: function() { return new HTML_AJAX_HttpClient(); }, makeRequest: function(request) { -var client = HTML_AJAX.httpClient(); -client.request = request; -return client.makeRequest(); +if (!HTML_AJAX.queues[request.queue]) { +var e = new Error('Unknown Queue: '+request.queue); +if (HTML_AJAX.onError) { +HTML_AJAX.onError(e); +return false; +} +else { +throw(e); +} +} +else { +var qn = request.queue; +var q = HTML_AJAX.queues[qn]; +HTML_AJAX.queues[request.queue].addRequest(request); +return HTML_AJAX.queues[request.queue].processRequest(); +} }, serializerForEncoding: function(encoding) { for(var i in HTML_AJAX.contentTypeMap) { @@ -42,40 +56,43 @@ return HTML_AJAX.fullcall(url,'Null',false,null,callback,{}); }, replace: function(id) { +var callback = function(result) { +document.getElementById(id).innerHTML = result; +} if (arguments.length == 2) { -document.getElementById(id).innerHTML = HTML_AJAX.grab(arguments[1]); +HTML_AJAX.grab(arguments[1],callback); } else { var args = new Array(); for(var i = 3; i < arguments.length; i++) { args.push(arguments[i]); } -document.getElementById(id).innerHTML = HTML_AJAX.call(arguments[1],arguments[2],false,args); +HTML_AJAX.fullcall(HTML_AJAX.defaultServerUrl,HTML_AJAX.defaultEncoding,arguments[1],arguments[2],callback,args); } }, -onOpen: function(className,methodName) { -var loading = document.getElementById('HTML_AJAX_LOADING'); -if (!loading) { -loading = document.createElement('div'); -loading.id = 'HTML_AJAX_LOADING'; -loading.innerHTML = 'Loading...'; -loading.style.position = 'absolute'; -loading.style.top = 0; -loading.style.right = 0; -loading.style.backgroundColor = 'red'; -loading.style.width = '80px'; -loading.style.padding = '4px'; -document.getElementsByTagName('body').item(0).appendChild(loading); +append: function(id) { +var callback = function(result) { +document.getElementById(id).innerHTML += result; } -loading.style.display = 'block'; -}, -onLoad: function(className,methodName) { -var loading = document.getElementById('HTML_AJAX_LOADING'); -if (loading) { -loading.style.display = 'none'; +if (arguments.length == 2) { +HTML_AJAX.grab(arguments[1],callback); +} +else { +var args = new Array(); +for(var i = 3; i < arguments.length; i++) { +args.push(arguments[i]); +} +HTML_AJAX.fullcall(HTML_AJAX.defaultServerUrl,HTML_AJAX.defaultEncoding,arguments[1],arguments[2],callback,args); } }, -contentTypeMap: {'JSON':'application/json','Null':'text/plain','Error':'application/error'} +contentTypeMap: {'JSON':'application/json','Null':'text/plain','Error':'application/error'}, +requestComplete: function(request,error) { +for(var i in HTML_AJAX.queues) { +if (HTML_AJAX.queues[i].requestComplete) { +HTML_AJAX.queues[i].requestComplete(request,error); +} +} +} } function HTML_AJAX_Serialize_Null() {} HTML_AJAX_Serialize_Null.prototype = { @@ -133,13 +150,58 @@ unserialize: function(input) { var ser = new HTML_AJAX_Serialize_JSON(); var data = new ser.unserialize(input); -var e = new Error('PHP Error'); +var e = new Error('PHP Error: '+data.errStr); for(var i in data) { e[i] = data[i]; } throw e; } } +function HTML_AJAX_Queue_Immediate() {} +HTML_AJAX_Queue_Immediate.prototype = { +request: false, +addRequest: function(request) { +this.request = request; +}, +processRequest: function() { +var client = HTML_AJAX.httpClient(); +client.request = this.request; +return client.makeRequest(); +} +} +function HTML_AJAX_Queue_Interval_SingleBuffer(interval) { +this.interval = interval; +} +HTML_AJAX_Queue_Interval_SingleBuffer.prototype = { +request: false, +_intervalId: false, +addRequest: function(request) { +this.request = request; +}, +processRequest: function() { +if (!this._intervalId) { +this.runInterval(); +this.start(); +} +}, +start: function() { +var self = this; +this._intervalId = setInterval(function() { self.runInterval() },this.interval); +}, +stop: function() { +clearInterval(this._intervalId); +}, +runInterval: function() { +if (this.request) { +var client = HTML_AJAX.httpClient(); +client.request = this.request; +this.request = false; +client.makeRequest(); +} +} +} +HTML_AJAX.queues = new Object(); +HTML_AJAX.queues['default'] = new HTML_AJAX_Queue_Immediate(); // Dispatcher.js function HTML_AJAX_Dispatcher(className,mode,callback,serverUrl,serializerType) { @@ -155,6 +217,7 @@ } } HTML_AJAX_Dispatcher.prototype = { +queue: 'default', timeout: 20000, doCall: function(callName,args) { @@ -165,16 +228,19 @@ request.timeout = this.timeout; request.contentType = this.contentType; request.serializer = eval('new HTML_AJAX_Serialize_'+this.serializerType); +request.queue = this.queue; for(var i=0; i < args.length; i++) { request.addArg(i,args[i]); }; if ( this.mode == "async" ) { request.isAsync = true; +if (this.callback[callName]) { +var self = this; +request.callback = function(result) { self.callback[callName](result); } +} } else { request.isAsync = false; } -var self = this; -request.callback = function(result) { self.callback[callName](result); } return HTML_AJAX.makeRequest(request); } }; @@ -225,6 +291,12 @@ this.init(); } try { +if (this.request.onOpen) { +this.request.onOpen(); +} +else if (HTML_AJAX.onOpen) { +HTML_AJAX.onOpen(this.request); +} this.xmlhttp.open(this.request.requestType,this.request.completeUrl(),this.request.isAsync); var self = this; this.xmlhttp.onreadystatechange = function() { self._readyStateChangeCallback(); } @@ -239,6 +311,7 @@ } if (!this.request.isAsync) { if ( this.xmlhttp.status == 200 ) { +HTML_AJAX.requestComplete(this.request); if (this.request.onLoad) { this.request.onLoad(); } else if (HTML_AJAX.onLoad) { @@ -288,13 +361,16 @@ case 4: window.clearTimeout(this._timeout_id); if (this.xmlhttp.status == 200) { +HTML_AJAX.requestComplete(this.request); if (this.request.onLoad) { this.request.onLoad(); } else if (HTML_AJAX.onLoad ) { HTML_AJAX.onLoad(this.request); } +if (this.request.callback) { this.request.callback(this._decodeResponse()); } +} else { var e = new Error('HTTP Error Making Request: ['+this.xmlhttp.status+'] '+this.xmlhttp.statusText); this._handleError(e); @@ -311,13 +387,13 @@ }, _handleError: function(e) { +HTML_AJAX.requestComplete(this.request,e); if (this.request.onError) { this.request.onError(e); } else if (HTML_AJAX.onError) { HTML_AJAX.onError(e,this.request); } else { -alert('throwing the exception'); throw e; } } @@ -336,6 +412,7 @@ timeout: 20000, args: null, callback: null, +queue: 'default', addArg: function(name, value) { if ( !this.args ) { @@ -664,3 +741,100 @@ return value(); } }; +// Loading.js +HTML_AJAX.onOpen = function(request) { +var loading = document.getElementById('HTML_AJAX_LOADING'); +if (!loading) { +loading = document.createElement('div'); +loading.id = 'HTML_AJAX_LOADING'; +loading.innerHTML = 'Loading...'; +loading.style.position = 'absolute'; +loading.style.top = 0; +loading.style.right = 0; +loading.style.backgroundColor = 'red'; +loading.style.width = '80px'; +loading.style.padding = '4px'; +document.body.insertBefore(loading,document.body.firstChild); +} +HTML_AJAX.onOpen_Timeout = window.setTimeout(function() { loading.style.display = 'block'; },500); +} +HTML_AJAX.onLoad = function(request) { +if (HTML_AJAX.onOpen_Timeout) { +window.clearTimeout(HTML_AJAX.onOpen_Timeout); +HTML_AJAX.onOpen_Timeout = false; +} +var loading = document.getElementById('HTML_AJAX_LOADING'); +if (loading) { +loading.style.display = 'none'; +} +} +// util.js +var HTML_AJAX_Util = { +setElementEvent: function(id, event, handler) { +var element = document.getElementById(id); +if (typeof element.addEventListener != "undefined") { //Dom2 +element.addEventListener(event, handler, false); +} else if (typeof element.attachEvent != "undefined") { //IE 5+ +element.attachEvent("on" + event, handler); +} else { +if (element["on" + event] != null) { +var oldHandler = element["on" + event]; +element["on" + event] = function(e) { +oldHander(e); +handler(e); +}; +} else { +element["on" + event] = handler; +} +} +}, +varDump: function(input) { +var r = ""; +for(var i in input) { +r += i+':'+input[i]+"\n"; +} +return r; +} +} +// behavior.js +var Behavior = { +list : new Array(), +addLoadEvent : function(func) { +var oldonload = window.onload; +if (typeof window.onload != 'function') { +window.onload = func; +} else { +window.onload = function() { +oldonload(); +func(); +} +} +}, +apply : function() { +for (i = 0; i < Behavior.list.length; i++) { +var rule = Behavior.list[i]; +var tags = cssQuery(rule.selector, rule.from); +if (tags) { +for (j = 0; j < tags.length; j++) { +rule.action(tags[j]); +} +} +} +}, +register : function(selector, action, from) { +Behavior.list.push(new BehaviorRule(selector, from, action)); +}, +start : function() { +Behavior.addLoadEvent(function() { +Behavior.apply(); +}); +} +} +function BehaviorRule(selector, from, action) { +this.selector = selector; +this.from = from; +this.action = action; +} +Behavior.start(); +// cssQuery-p.js +eval(function(p,a,c,k,e,d){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)d[e(c)]=k[c]||e(c);k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('7 x=6(){7 1D="2.0.2";7 C=/\\s*,\\s*/;7 x=6(s,A){33{7 m=[];7 u=1z.32.2c&&!A;7 b=(A)?(A.31==22)?A:[A]:[1g];7 1E=18(s).1l(C),i;9(i=0;i<1E.y;i++){s=1y(1E[i]);8(U&&s.Z(0,3).2b("")==" *#"){s=s.Z(2);A=24([],b,s[1])}1A A=b;7 j=0,t,f,a,c="";H(j<s.y){t=s[j++];f=s[j++];c+=t+f;a="";8(s[j]=="("){H(s[j++]!=")")a+=s[j];a=a.Z(0,-1);c+="("+a+")"}A=(u&&V[c])?V[c]:21(A,t,f,a);8(u)V[c]=A}m=m.30(A)}2a x.2d;5 m}2Z(e){x.2d=e;5[]}};x.1Z=6(){5"6 x() {\\n [1D "+1D+"]\\n}"};7 V={};x.2c=L;x.2Y=6(s){8(s){s=1y(s).2b("");2a V[s]}1A V={}};7 29={};7 19=L;x.15=6(n,s){8(19)1i("s="+1U(s));29[n]=12 s()};x.2X=6(c){5 c?1i(c):o};7 D={};7 h={};7 q={P:/\\[([\\w-]+(\\|[\\w-]+)?)\\s*(\\W?=)?\\s*([^\\]]*)\\]/};7 T=[];D[" "]=6(r,f,t,n){7 e,i,j;9(i=0;i<f.y;i++){7 s=X(f[i],t,n);9(j=0;(e=s[j]);j++){8(M(e)&&14(e,n))r.z(e)}}};D["#"]=6(r,f,i){7 e,j;9(j=0;(e=f[j]);j++)8(e.B==i)r.z(e)};D["."]=6(r,f,c){c=12 1t("(^|\\\\s)"+c+"(\\\\s|$)");7 e,i;9(i=0;(e=f[i]);i++)8(c.l(e.1V))r.z(e)};D[":"]=6(r,f,p,a){7 t=h[p],e,i;8(t)9(i=0;(e=f[i]);i++)8(t(e,a))r.z(e)};h["2W"]=6(e){7 d=Q(e);8(d.1C)9(7 i=0;i<d.1C.y;i++){8(d.1C[i]==e)5 K}};h["2V"]=6(e){};7 M=6(e){5(e&&e.1c==1&&e.1f!="!")?e:23};7 16=6(e){H(e&&(e=e.2U)&&!M(e))28;5 e};7 G=6(e){H(e&&(e=e.2T)&&!M(e))28;5 e};7 1r=6(e){5 M(e.27)||G(e.27)};7 1P=6(e){5 M(e.26)||16(e.26)};7 1o=6(e){7 c=[];e=1r(e);H(e){c.z(e);e=G(e)}5 c};7 U=K;7 1h=6(e){7 d=Q(e);5(2S d.25=="2R")?/\\.1J$/i.l(d.2Q):2P(d.25=="2O 2N")};7 Q=6(e){5 e.2M||e.1g};7 X=6(e,t){5(t=="*"&&e.1B)?e.1B:e.X(t)};7 17=6(e,t,n){8(t=="*")5 M(e);8(!14(e,n))5 L;8(!1h(e))t=t.2L();5 e.1f==t};7 14=6(e,n){5!n||(n=="*")||(e.2K==n)};7 1e=6(e){5 e.1G};6 24(r,f,B){7 m,i,j;9(i=0;i<f.y;i++){8(m=f[i].1B.2J(B)){8(m.B==B)r.z(m);1A 8(m.y!=23){9(j=0;j<m.y;j++){8(m[j].B==B)r.z(m[j])}}}}5 r};8(![].z)22.2I.z=6(){9(7 i=0;i<1z.y;i++){o[o.y]=1z[i]}5 o.y};7 N=/\\|/;6 21(A,t,f,a){8(N.l(f)){f=f.1l(N);a=f[0];f=f[1]}7 r=[];8(D[t]){D[t](r,A,f,a)}5 r};7 S=/^[^\\s>+~]/;7 20=/[\\s#.:>+~()@]|[^\\s#.:>+~()@]+/g;6 1y(s){8(S.l(s))s=" "+s;5 s.P(20)||[]};7 W=/\\s*([\\s>+~(),]|^|$)\\s*/g;7 I=/([\\s>+~,]|[^(]\\+|^)([#.:@])/g;7 18=6(s){5 s.O(W,"$1").O(I,"$1*$2")};7 1u={1Z:6(){5"\'"},P:/^(\'[^\']*\')|("[^"]*")$/,l:6(s){5 o.P.l(s)},1S:6(s){5 o.l(s)?s:o+s+o},1Y:6(s){5 o.l(s)?s.Z(1,-1):s}};7 1s=6(t){5 1u.1Y(t)};7 E=/([\\/()[\\]?{}|*+-])/g;6 R(s){5 s.O(E,"\\\\$1")};x.15("1j-2H",6(){D[">"]=6(r,f,t,n){7 e,i,j;9(i=0;i<f.y;i++){7 s=1o(f[i]);9(j=0;(e=s[j]);j++)8(17(e,t,n))r.z(e)}};D["+"]=6(r,f,t,n){9(7 i=0;i<f.y;i++){7 e=G(f[i]);8(e&&17(e,t,n))r.z(e)}};D["@"]=6(r,f,a){7 t=T[a].l;7 e,i;9(i=0;(e=f[i]);i++)8(t(e))r.z(e)};h["2G-10"]=6(e){5!16(e)};h["1x"]=6(e,c){c=12 1t("^"+c,"i");H(e&&!e.13("1x"))e=e.1n;5 e&&c.l(e.13("1x"))};q.1X=/\\\\:/g;q.1w="@";q.J={};q.O=6(m,a,n,c,v){7 k=o.1w+m;8(!T[k]){a=o.1W(a,c||"",v||"");T[k]=a;T.z(a)}5 T[k].B};q.1Q=6(s){s=s.O(o.1X,"|");7 m;H(m=s.P(o.P)){7 r=o.O(m[0],m[1],m[2],m[3],m[4]);s=s.O(o.P,r)}5 s};q.1W=6(p,t,v){7 a={};a.B=o.1w+T.y;a.2F=p;t=o.J[t];t=t?t(o.13(p),1s(v)):L;a.l=12 2E("e","5 "+t);5 a};q.13=6(n){1d(n.2D()){F"B":5"e.B";F"2C":5"e.1V";F"9":5"e.2B";F"1T":8(U){5"1U((e.2A.P(/1T=\\\\1v?([^\\\\s\\\\1v]*)\\\\1v?/)||[])[1]||\'\')"}}5"e.13(\'"+n.O(N,":")+"\')"};q.J[""]=6(a){5 a};q.J["="]=6(a,v){5 a+"=="+1u.1S(v)};q.J["~="]=6(a,v){5"/(^| )"+R(v)+"( |$)/.l("+a+")"};q.J["|="]=6(a,v){5"/^"+R(v)+"(-|$)/.l("+a+")"};7 1R=18;18=6(s){5 1R(q.1Q(s))}});x.15("1j-2z",6(){D["~"]=6(r,f,t,n){7 e,i;9(i=0;(e=f[i]);i++){H(e=G(e)){8(17(e,t,n))r.z(e)}}};h["2y"]=6(e,t){t=12 1t(R(1s(t)));5 t.l(1e(e))};h["2x"]=6(e){5 e==Q(e).1H};h["2w"]=6(e){7 n,i;9(i=0;(n=e.1F[i]);i++){8(M(n)||n.1c==3)5 L}5 K};h["1N-10"]=6(e){5!G(e)};h["2v-10"]=6(e){e=e.1n;5 1r(e)==1P(e)};h["2u"]=6(e,s){7 n=x(s,Q(e));9(7 i=0;i<n.y;i++){8(n[i]==e)5 L}5 K};h["1O-10"]=6(e,a){5 1p(e,a,16)};h["1O-1N-10"]=6(e,a){5 1p(e,a,G)};h["2t"]=6(e){5 e.B==2s.2r.Z(1)};h["1M"]=6(e){5 e.1M};h["2q"]=6(e){5 e.1q===L};h["1q"]=6(e){5 e.1q};h["1L"]=6(e){5 e.1L};q.J["^="]=6(a,v){5"/^"+R(v)+"/.l("+a+")"};q.J["$="]=6(a,v){5"/"+R(v)+"$/.l("+a+")"};q.J["*="]=6(a,v){5"/"+R(v)+"/.l("+a+")"};6 1p(e,a,t){1d(a){F"n":5 K;F"2p":a="2n";1a;F"2o":a="2n+1"}7 1m=1o(e.1n);6 1k(i){7 i=(t==G)?1m.y-i:i-1;5 1m[i]==e};8(!Y(a))5 1k(a);a=a.1l("n");7 m=1K(a[0]);7 s=1K(a[1]);8((Y(m)||m==1)&&s==0)5 K;8(m==0&&!Y(s))5 1k(s);8(Y(s))s=0;7 c=1;H(e=t(e))c++;8(Y(m)||m==1)5(t==G)?(c<=s):(s>=c);5(c%m)==s}});x.15("1j-2m",6(){U=1i("L;/*@2l@8(@\\2k)U=K@2j@*/");8(!U){X=6(e,t,n){5 n?e.2i("*",t):e.X(t)};14=6(e,n){5!n||(n=="*")||(e.2h==n)};1h=1g.1I?6(e){5/1J/i.l(Q(e).1I)}:6(e){5 Q(e).1H.1f!="2g"};1e=6(e){5 e.2f||e.1G||1b(e)};6 1b(e){7 t="",n,i;9(i=0;(n=e.1F[i]);i++){1d(n.1c){F 11:F 1:t+=1b(n);1a;F 3:t+=n.2e;1a}}5 t}}});19=K;5 x}();',62,190,'|||||return|function|var|if|for||||||||pseudoClasses||||test|||this||AttributeSelector|||||||cssQuery|length|push|fr|id||selectors||case|nextElementSibling|while||tests|true|false|thisElement||replace|match|getDocument|regEscape||attributeSelectors|isMSIE|cache||getElementsByTagName|isNaN|slice|child||new|getAttribute|compareNamespace|addModule|previousElementSibling|compareTagName|parseSelector|loaded|break|_0|nodeType|switch|getTextContent|tagName|document|isXML|eval|css|_1|split|ch|parentNode|childElements|nthChild|disabled|firstElementChild|getText|RegExp|Quote|x22|PREFIX|lang|_2|arguments|else|all|links|version|se|childNodes|innerText|documentElement|contentType|xml|parseInt|indeterminate|checked|last|nth|lastElementChild|parse|_3|add|href|String|className|create|NS_IE|remove|toString|ST|select|Array|null|_4|mimeType|lastChild|firstChild|continue|modules|delete|join|caching|error|nodeValue|textContent|HTML|prefix|getElementsByTagNameNS|end|x5fwin32|cc_on|standard||odd|even|enabled|hash|location|target|not|only|empty|root|contains|level3|outerHTML|htmlFor|class|toLowerCase|Function|name|first|level2|prototype|item|scopeName|toUpperCase|ownerDocument|Document|XML|Boolean|URL|unknown|typeof|nextSibling|previousSibling|visited|link|valueOf|clearCache|catch|concat|constructor|callee|try'.split('|'),0,{})) http://cvs.php.net/diff.php/pear/HTML_AJAX/js/HttpClient.js?r1=1.3&r2=1.4&ty=u Index: pear/HTML_AJAX/js/HttpClient.js diff -u pear/HTML_AJAX/js/HttpClient.js:1.3 pear/HTML_AJAX/js/HttpClient.js:1.4 --- pear/HTML_AJAX/js/HttpClient.js:1.3 Tue Sep 27 11:14:28 2005 +++ pear/HTML_AJAX/js/HttpClient.js Mon Oct 24 23:26:14 2005 @@ -64,6 +64,12 @@ } try { + if (this.request.onOpen) { + this.request.onOpen(); + } + else if (HTML_AJAX.onOpen) { + HTML_AJAX.onOpen(this.request); + } this.xmlhttp.open(this.request.requestType,this.request.completeUrl(),this.request.isAsync); // set onreadystatechange here since it will be reset after a completed call in Mozilla @@ -82,6 +88,7 @@ if (!this.request.isAsync) { if ( this.xmlhttp.status == 200 ) { + HTML_AJAX.requestComplete(this.request); if (this.request.onLoad) { this.request.onLoad(); } else if (HTML_AJAX.onLoad) { @@ -143,13 +150,16 @@ window.clearTimeout(this._timeout_id); if (this.xmlhttp.status == 200) { + HTML_AJAX.requestComplete(this.request); if (this.request.onLoad) { this.request.onLoad(); } else if (HTML_AJAX.onLoad ) { HTML_AJAX.onLoad(this.request); } - this.request.callback(this._decodeResponse()); + if (this.request.callback) { + this.request.callback(this._decodeResponse()); + } } else { @@ -175,13 +185,13 @@ // handle sending an error where it needs to go _handleError: function(e) { + HTML_AJAX.requestComplete(this.request,e); if (this.request.onError) { this.request.onError(e); } else if (HTML_AJAX.onError) { HTML_AJAX.onError(e,this.request); } else { - alert('throwing the exception'); throw e; } } http://cvs.php.net/diff.php/pear/HTML_AJAX/js/Main.js?r1=1.5&r2=1.6&ty=u Index: pear/HTML_AJAX/js/Main.js diff -u pear/HTML_AJAX/js/Main.js:1.5 pear/HTML_AJAX/js/Main.js:1.6 --- pear/HTML_AJAX/js/Main.js:1.5 Tue Sep 27 11:14:28 2005 +++ pear/HTML_AJAX/js/Main.js Mon Oct 24 23:26:14 2005 @@ -15,15 +15,32 @@ var HTML_AJAX = { defaultServerUrl: false, defaultEncoding: 'Null', + queues: false, // get an HttpClient, at some point this might be actually smart httpClient: function() { return new HTML_AJAX_HttpClient(); }, - // make a request using an request object + // Pushing the given request to queue specified by it, in default operation this will immediately make a request + // request might be delayed or never happen depending on the queue setup + // making a sync request to a non immediate queue will cause you problems so just don't do it makeRequest: function(request) { - var client = HTML_AJAX.httpClient(); - client.request = request; - return client.makeRequest(); + if (!HTML_AJAX.queues[request.queue]) { + var e = new Error('Unknown Queue: '+request.queue); + if (HTML_AJAX.onError) { + HTML_AJAX.onError(e); + return false; + } + else { + throw(e); + } + } + else { + var qn = request.queue; + var q = HTML_AJAX.queues[qn]; + + HTML_AJAX.queues[request.queue].addRequest(request); + return HTML_AJAX.queues[request.queue].processRequest(); + } }, // get a serializer object for a specific encoding serializerForEncoding: function(encoding) { @@ -50,19 +67,22 @@ return HTML_AJAX.makeRequest(request); }, call: function(className,method,callback) { - var args = new Array(); - for(var i = 3; i < arguments.length; i++) { - args.push(arguments[i]); - } + var args = new Array(); + for(var i = 3; i < arguments.length; i++) { + args.push(arguments[i]); + } return HTML_AJAX.fullcall(HTML_AJAX.defaultServerUrl,HTML_AJAX.defaultEncoding,className,method,callback,args); }, grab: function(url,callback) { return HTML_AJAX.fullcall(url,'Null',false,null,callback,{}); }, replace: function(id) { + var callback = function(result) { + document.getElementById(id).innerHTML = result; + } if (arguments.length == 2) { // grab replacement - document.getElementById(id).innerHTML = HTML_AJAX.grab(arguments[1]); + HTML_AJAX.grab(arguments[1],callback); } else { // call replacement @@ -70,34 +90,28 @@ for(var i = 3; i < arguments.length; i++) { args.push(arguments[i]); } - document.getElementById(id).innerHTML = HTML_AJAX.call(arguments[1],arguments[2],false,args); + HTML_AJAX.fullcall(HTML_AJAX.defaultServerUrl,HTML_AJAX.defaultEncoding,arguments[1],arguments[2],callback,args); } }, - onOpen: function(className,methodName) { - var loading = document.getElementById('HTML_AJAX_LOADING'); - if (!loading) { - loading = document.createElement('div'); - loading.id = 'HTML_AJAX_LOADING'; - loading.innerHTML = 'Loading...'; - loading.style.position = 'absolute'; - loading.style.top = 0; - loading.style.right = 0; - loading.style.backgroundColor = 'red'; - loading.style.width = '80px'; - loading.style.padding = '4px'; - - document.getElementsByTagName('body').item(0).appendChild(loading); - } - loading.style.display = 'block'; - }, - onLoad: function(className,methodName) { - var loading = document.getElementById('HTML_AJAX_LOADING'); - if (loading) { - loading.style.display = 'none'; + append: function(id) { + var callback = function(result) { + document.getElementById(id).innerHTML += result; + } + if (arguments.length == 2) { + // grab replacement + HTML_AJAX.grab(arguments[1],callback); + } + else { + // call replacement + var args = new Array(); + for(var i = 3; i < arguments.length; i++) { + args.push(arguments[i]); + } + HTML_AJAX.fullcall(HTML_AJAX.defaultServerUrl,HTML_AJAX.defaultEncoding,arguments[1],arguments[2],callback,args); } - }, - // A really basic error handler + }, /* + // A really basic error handler onError: function(e) { msg = ""; for(var i in e) { @@ -107,13 +121,21 @@ }, */ // Class postfix to content-type map - contentTypeMap: {'JSON':'application/json','Null':'text/plain','Error':'application/error'} + contentTypeMap: {'JSON':'application/json','Null':'text/plain','Error':'application/error'}, + // used internally to make queues work, override onLoad or onError to perform custom events when a request is complete + // fires on success and error + requestComplete: function(request,error) { + for(var i in HTML_AJAX.queues) { + if (HTML_AJAX.queues[i].requestComplete) { + HTML_AJAX.queues[i].requestComplete(request,error); + } + } + } } - // small classes that I don't want to put in there own file function HTML_AJAX_Serialize_Null() {} @@ -168,6 +190,7 @@ } } + function HTML_AJAX_Serialize_Error() {} HTML_AJAX_Serialize_Error.prototype = { contentType: 'application/error; charset=UTF-8', @@ -179,11 +202,71 @@ var ser = new HTML_AJAX_Serialize_JSON(); var data = new ser.unserialize(input); - var e = new Error('PHP Error'); + var e = new Error('PHP Error: '+data.errStr); for(var i in data) { e[i] = data[i]; } throw e; } } + +// Processing Queues + +// simple queue, just processes the request immediately +function HTML_AJAX_Queue_Immediate() {} +HTML_AJAX_Queue_Immediate.prototype = { + request: false, + addRequest: function(request) { + this.request = request; + }, + processRequest: function() { + var client = HTML_AJAX.httpClient(); + client.request = this.request; + return client.makeRequest(); + } + // requestComplete: function() {} // this is also possible but this queue doesn't need it +} + +// Single Buffer queue with interval +// works by attempting to send a request every x miliseconds +// if an item is currently in the queue when a new item is added it will be replaced +// simple queue, just processes the request immediately +// the first request starts the interval timer +function HTML_AJAX_Queue_Interval_SingleBuffer(interval) { + this.interval = interval; +} +HTML_AJAX_Queue_Interval_SingleBuffer.prototype = { + request: false, + _intervalId: false, + addRequest: function(request) { + this.request = request; + }, + processRequest: function() { + if (!this._intervalId) { + this.runInterval(); + this.start(); + } + }, + start: function() { + var self = this; + this._intervalId = setInterval(function() { self.runInterval() },this.interval); + }, + stop: function() { + clearInterval(this._intervalId); + }, + runInterval: function() { + if (this.request) { + var client = HTML_AJAX.httpClient(); + client.request = this.request; + this.request = false; + client.makeRequest(); + } + } +} + + +// create a default queue, has to happen after the Queue class has been defined +HTML_AJAX.queues = new Object(); +HTML_AJAX.queues['default'] = new HTML_AJAX_Queue_Immediate(); + /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ http://cvs.php.net/diff.php/pear/HTML_AJAX/js/Request.js?r1=1.3&r2=1.4&ty=u Index: pear/HTML_AJAX/js/Request.js diff -u pear/HTML_AJAX/js/Request.js:1.3 pear/HTML_AJAX/js/Request.js:1.4 --- pear/HTML_AJAX/js/Request.js:1.3 Tue Sep 27 11:14:28 2005 +++ pear/HTML_AJAX/js/Request.js Mon Oct 24 23:26:14 2005 @@ -47,6 +47,9 @@ // async callback method callback: null, + // Queue to push this request too + queue: 'default', + /** * Add an argument for the remote method * @param string argument name http://cvs.php.net/diff.php/pear/HTML_AJAX/js/build.php?r1=1.2&r2=1.3&ty=u Index: pear/HTML_AJAX/js/build.php diff -u pear/HTML_AJAX/js/build.php:1.2 pear/HTML_AJAX/js/build.php:1.3 --- pear/HTML_AJAX/js/build.php:1.2 Tue Sep 27 11:14:28 2005 +++ pear/HTML_AJAX/js/build.php Mon Oct 24 23:26:14 2005 @@ -15,7 +15,7 @@ $strip = true; } -$source = array('Main.js','Dispatcher.js','HttpClient.js','Request.js','JSON.js'); +$source = array('Main.js','Dispatcher.js','HttpClient.js','Request.js','JSON.js','Loading.js','util.js','behavior.js','cssQuery-p.js'); $stripPregs = array( '/^\s+$/', http://cvs.php.net/diff.php/pear/HTML_AJAX/js/util.js?r1=1.1&r2=1.2&ty=u Index: pear/HTML_AJAX/js/util.js diff -u pear/HTML_AJAX/js/util.js:1.1 pear/HTML_AJAX/js/util.js:1.2 --- pear/HTML_AJAX/js/util.js:1.1 Wed Sep 28 09:08:51 2005 +++ pear/HTML_AJAX/js/util.js Mon Oct 24 23:26:14 2005 @@ -1,35 +1,45 @@ -/** - * Utility methods - * - * @category HTML - * @package Ajax - * @author David Coallier <davidc@php.net> - * @copyright 2005 David Coallier - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - */ -// {{{ HTML_AJAX_Util -/** - * All the utilities we will be using thorough the classes - */ -var HTML_AJAX_Util = { - // Set the element event - setElementEvent: function(id, event, handler) { - var element = document.getElementById(id); - if (typeof element.addEventListener != "undefined") { //Dom2 - element.addEventListener(event, handler, false); - } else if (typeof element.attachEvent != "undefined") { //IE 5+ - element.attachEvent("on" + event, handler); - } else { - if (element["on" + event] != null) { - var oldHandler = element["on" + event]; - element["on" + event] = function(e) { - oldHander(e); - handler(e); - }; - } else { - element["on" + event] = handler; - } - } - } -} -// }}} +/** + * Utility methods + * + * @category HTML + * @package Ajax + * @author David Coallier <davidc@php.net> + * @copyright 2005 David Coallier + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + */ +// {{{ HTML_AJAX_Util +/** + * All the utilities we will be using thorough the classes + */ +var HTML_AJAX_Util = { + // Set the element event + setElementEvent: function(id, event, handler) { + var element = document.getElementById(id); + if (typeof element.addEventListener != "undefined") { //Dom2 + element.addEventListener(event, handler, false); + } else if (typeof element.attachEvent != "undefined") { //IE 5+ + element.attachEvent("on" + event, handler); + } else { + if (element["on" + event] != null) { + var oldHandler = element["on" + event]; + element["on" + event] = function(e) { + oldHander(e); + handler(e); + }; + } else { + element["on" + event] = handler; + } + } + }, + // simple non recursive variable dumper, don't rely on its output staying the same, its just for debugging and will get smarter at some point + varDump: function(input) { + var r = ""; + for(var i in input) { + r += i+':'+input[i]+"\n"; + } + return r; + } + +} +// }}} +/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
« previous php.pear.cvs (#35831) next »