📄 html_ajax_lite.js
字号:
request: false,addRequest: function(request) {this.request = request;},processRequest: function() {var client = HTML_AJAX.httpClient();client.request = this.request;return client.makeRequest();}}HTML_AJAX.queues = new Object();HTML_AJAX.queues['default'] = new HTML_AJAX_Queue_Immediate();// Queue.js/*** Various processing queues, use when you want to control how multiple requests are made* @category HTML* @package AJAX* @author Joshua Eichorn <josh@bluga.net>* @copyright 2005 Joshua Eichorn* @license http://www.opensource.org/licenses/lgpl-license.php LGPL*/function HTML_AJAX_Queue_Interval_SingleBuffer(interval,singleOutstandingRequest) {this.interval = interval;if (singleOutstandingRequest) {this.singleOutstandingRequest = true;}}HTML_AJAX_Queue_Interval_SingleBuffer.prototype = {request: false,_intervalId: false,singleOutstandingRequest: false,client: 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) {if (this.singleOutstandingRequest && this.client) {this.client.abort();}this.client = HTML_AJAX.httpClient();this.client.request = this.request;this.request = false;this.client.makeRequest();}}}function HTML_AJAX_Queue_Ordered() { }HTML_AJAX_Queue_Ordered.prototype = {request: false,order: 0,current: 0,callbacks: {},interned: {},addRequest: function(request) {request.order = this.order;this.request = request;this.callbacks[this.order] = this.request.callback;var self = this;this.request.callback = function(result) {self.processCallback(result,request.order);}},processRequest: function() {var client = HTML_AJAX.httpClient();client.request = this.request;client.makeRequest();this.order++;},requestComplete: function(request,e) {if (e) {this.current++;}},processCallback: function(result,order) {if (order == this.current) {this.callbacks[order](result);this.current++;}else {this.interned[order] = result;}while (this.interned[this.current]) {this.callbacks[this.current](this.interned[this.current]);this.current++;}}}function HTML_AJAX_Queue_Single() {}HTML_AJAX_Queue_Single.prototype = {request: false,client: false,addRequest: function(request) {this.request = request;},processRequest: function() {if (this.request) {if (this.client) {this.client.abort();}this.client = HTML_AJAX.httpClient();this.client.request = this.request;this.request = false;this.client.makeRequest();}}}/*** Priority queue** @author Arpad Ray <arpad@php.net>*/function HTML_AJAX_Queue_Priority_Item(item, time) {this.item = item;this.time = time;}HTML_AJAX_Queue_Priority_Item.prototype = {compareTo: function (other) {var ret = this.item.compareTo(other.item);if (ret == 0) {ret = this.time - other.time;}return ret;}}function HTML_AJAX_Queue_Priority_Simple(interval) {this.interval = interval;this.idleMax = 10; // keep the interval going with an empty queue for 10 intervalsthis.requestTimeout = 5; // retry uncompleted requests after 5 secondsthis.checkRetryChance = 0.1; // check for uncompleted requests to retry on 10% of intervalsthis._intervalId = 0;this._requests = [];this._removed = [];this._len = 0;this._removedLen = 0;this._idle = 0;}HTML_AJAX_Queue_Priority_Simple.prototype = {isEmpty: function () {return this._len == 0;},addRequest: function (request) {request = new HTML_AJAX_Queue_Priority_Item(request, new Date().getTime());++this._len;if (this.isEmpty()) {this._requests[0] = request;return;}for (i = 0; i < this._len - 1; i++) {if (request.compareTo(this._requests[i]) < 0) {this._requests.splice(i, 1, request, this._requests[i]);return;}}this._requests.push(request);},peek: function () {return (this.isEmpty() ? false : this._requests[0]);},requestComplete: function (request) {for (i = 0; i < this._removedLen; i++) {if (this._removed[i].item == request) {this._removed.splice(i, 1);--this._removedLen;out('removed from _removed');return true;}}return false;},processRequest: function() {if (!this._intervalId) {this._runInterval();this._start();}this._idle = 0;},_runInterval: function() {if (Math.random() < this.checkRetryChance) {this._doRetries();}if (this.isEmpty()) {if (++this._idle > this.idleMax) {this._stop();}return;}var client = HTML_AJAX.httpClient();if (!client) {return;}var request = this.peek();if (!request) {this._requests.splice(0, 1);return;}client.request = request.item;client.makeRequest();this._requests.splice(0, 1);--this._len;this._removed[this._removedLen++] = new HTML_AJAX_Queue_Priority_Item(request, new Date().getTime());},_doRetries: function () {for (i = 0; i < this._removedLen; i++) {if (this._removed[i].time + this._requestTimeout < new Date().getTime()) {this.addRequest(request.item);this._removed.splice(i, 1);--this._removedLen;return true;}}},_start: function() {var self = this;this._intervalId = setInterval(function() { self._runInterval() }, this.interval);},_stop: function() {clearInterval(this._intervalId);this._intervalId = 0;}};// clientPool.jsHTML_AJAX_Client_Pool = function(maxClients, startingClients){this.maxClients = maxClients;this._clients = [];this._len = 0;while (--startingClients > 0) {this.addClient();}}HTML_AJAX_Client_Pool.prototype = {isEmpty: function(){return this._len == 0;},addClient: function(){if (this.maxClients != 0 && this._len > this.maxClients) {return false;}var key = this._len++;this._clients[key] = new HTML_AJAX_HttpClient();return this._clients[key];},getClient: function (){for (var i = 0; i < this._len; i++) {if (!this._clients[i].callInProgress() && this._clients[i].callbackComplete) {return this._clients[i];}}var client = this.addClient();if (client) {return client;}return false;},removeClient: function (client){for (var i = 0; i < this._len; i++) {if (!this._clients[i] == client) {this._clients.splice(i, 1);return true;}}return false;},clear: function (){this._clients = [];this._len = 0;}};HTML_AJAX.clientPools['default'] = new HTML_AJAX_Client_Pool(0);// IframeXHR.js/*** XMLHttpRequest Iframe fallback** http://lxr.mozilla.org/seamonkey/source/extensions/xmlextras/tests/ - should work with these** @category HTML* @package AJAX* @author Elizabeth Smith <auroraeosrose@gmail.com>* @copyright 2005 Elizabeth Smith* @license http://www.opensource.org/licenses/lgpl-license.php LGPL*/HTML_AJAX_IframeXHR_instances = new Object();function HTML_AJAX_IframeXHR(){this._id = 'HAXHR_iframe_' + new Date().getTime();HTML_AJAX_IframeXHR_instances[this._id] = this;}HTML_AJAX_IframeXHR.prototype = {onreadystatechange: null, // Event handler for an event that fires at every state changereadyState: 0, // Object status integer: 0 = uninitialized 1 = loading 2 = loaded 3 = interactive 4 = completeresponseText: '', // String version of data returned from server processresponseXML: null, // DOM-compatible document object of data returned from server processstatus: 0, // Numeric code returned by server, such as 404 for "Not Found" or 200 for "OK"statusText: '', // String message accompanying the status codeiframe: true, // flag for iframe_id: null, // iframe id, unique to object(hopefully)_url: null, // url sent by open_method: null, // get or post_async: null, // sync or async sent by open_headers: new Object(), //request headers to send, actually sent as form vars_response: new Object(), //response headers received_phpclass: null, //class to send_phpmethod: null, //method to send_history: null, // opera has to have history mungingabort: function(){var iframe = document.getElementById(this._id);if (iframe) {document.body.removeChild(iframe);}if (this._timeout) {window.clearTimeout(this._timeout);}this.readyState = 1;if (typeof(this.onreadystatechange) == "function") {this.onreadystatechange();}},getAllResponseHeaders: function(){var string = '';for (i in this._response) {string += i + ' : ' + this._response[i] + "\n";}return string;},getResponseHeader: function(header){return (this._response[header] ? this._response[header] : null);},setRequestHeader: function(label, value) {this._headers[label] = value;return; },open: function(method, url, async, username, password){if (!document.body) {throw('CANNOT_OPEN_SEND_IN_DOCUMENT_HEAD');}if (!method || !url) {throw('NOT_ENOUGH_ARGUMENTS:METHOD_URL_REQUIRED');}this._method = (method.toUpperCase() == 'POST' ? 'POST' : 'GET');this._decodeUrl(url);this._async = async;if(!this._async && document.readyState && !window.opera) {throw('IE_DOES_NOT_SUPPORT_SYNC_WITH_IFRAMEXHR');}this.readyState = 1;if(typeof(this.onreadystatechange) == "function") {this.onreadystatechange();}},send: function(content){if (window.opera) {this._history = window.history.length;}var form = '<html><body><form method="'+ (this._url.indexOf('px=') < 0 ? this._method : 'post')+ '" action="' + this._url + '">';form += '<input name="Iframe_XHR" value="1" />';if (this._phpclass != null) {form += '<input name="Iframe_XHR_class" value="' + this._phpclass + '" />';}if (this._phpmethod != null) {form += '<input name="Iframe_XHR_method" value="' + this._phpmethod + '" />';}for (label in this._headers) {form += '<textarea name="Iframe_XHR_headers[]">' + label +':'+ this._headers[label] + '</textarea>';}form += '<textarea name="Iframe_XHR_id">' + this._id + '</textarea>';if (content != null && content.length > 0) {form += '<textarea name="Iframe_XHR_data">' + content + '</textarea>';}form += '<input name="Iframe_XHR_HTTP_method" value="' + this._method + '" />';form += '<s'+'cript>document.forms[0].submit();</s'+'cript></form></body></html>';form = "javascript:document.write('" + form.replace(/\'/g,"\\'") + "');void(0);";this.readyState = 2;if (typeof(this.onreadystatechange) == "function") {this.onreadystatechange();}try {var iframe = document.createElement('iframe');iframe.id = this._id;iframe.style.visibility = 'hidden';iframe.style.border = '0';iframe.style.width = '0';iframe.style.height = '0';if (document.all) {iframe.src = form;document.body.appendChild(iframe);} else {document.body.appendChild(iframe);iframe.src = form;}} catch(exception) {var html = '<iframe src="' + form +'" id="' + this._id + '" style="visibility:hidden;border:0;height:0;width:0;"></iframe>';document.body.innerHTML += html;}if (this._async == true) {if (this.readyState < 3) {this.readyState = 3;if(typeof(this.onreadystatechange) == "function") {this.onreadystatechange();}}} else {while (this.readyState != 4) {if (this.readyState < 3) {this.readyState = 3;if(typeof(this.onreadystatechange) == "function") {this.onreadystatechange();}}}}},isLoaded: function(headers, data){this.readyState = 4;this.status = 200;this.statusText = 'OK';this.responseText = data;this._response = headers;if (!this._response['Last-Modified']) {string += 'Last-Modified : ' + document.getElementById(this._id).lastModified + "\n";}if (!this._response['Content-Type']) {string += 'Content-Type : ' + document.getElementById(this._id).contentType + "\n";}if (this._response['Content-Type'] == 'application/xml'){return new DOMParser().parseFromString(this.responseText, 'application/xml');}if (window.opera && window.opera.version) {window.history.go(this._history - window.history.length);}if (typeof(this.onreadystatechange) == "function") {this.onreadystatechange();}document.body.removeChild(document.getElementById(this._id));},_decodeUrl: function(querystring){var url = unescape(location.href);url = url.substring(0, url.lastIndexOf("/") + 1);var item = querystring.split('?');this._url = url + item[0].substring(item[0].lastIndexOf("/") + 1,item[0].length);if(item[1]) {item = item[1].split('&');for (i in item) {var v = item[i].split('=');if (v[0] == 'c') {this._phpclass = v[1];} else if (v[0] == 'm') {this._phpmethod = v[1];}}}if (!this._phpclass || !this._phpmethod) {var cloc = window.location.href;this._url = cloc + (cloc.indexOf('?') >= 0 ? '&' : '?') + 'px=' + escape(HTML_AJAX_Util.absoluteURL(querystring));}}}// serializer/UrlSerializer.js/*** URL-encoding serializer** This class can be used to serialize and unserialize data in a* format compatible with PHP's handling of HTTP query strings.* Due to limitations of the format, all input is serialized as an* array or a string. See examples/serialize.url.examples.php** @version 0.0.1* @copyright 2005 Arpad Ray <arpad@php.net>* @license http://www.opensource.org/licenses/lgpl-license.php LGPL** See Main.js for Author/license details*/function HTML_AJAX_Serialize_Urlencoded() {}HTML_AJAX_Serialize_Urlencoded.prototype = {contentType: 'application/x-www-form-urlencoded; charset=UTF-8',base: '_HTML_AJAX',_keys: [],error: false,message: "",cont: "",/*** Serializes a variable** @param mixed inp the variable to serialize* @return string a string representation of the input,* which can be reconstructed by unserialize()*/serialize: function(input, _internal) {if (typeof input == 'undefined') {return '';}if (!_internal) {this._keys = [];}var ret = '', first = true;for (i = 0; i < this._keys.length; i++) {ret += (first ? HTML_AJAX_Util.encodeUrl(this._keys[i]) : '[' + HTML_AJAX_Util.encodeUrl(this._keys[i]) + ']');first = false;}ret += '=';switch (HTML_AJAX_Util.getType(input)) {case 'string':case 'number':ret += HTML_AJAX_Util.encodeUrl(input.toString());break;case 'boolean':ret += (input ? '1' : '0');break;case 'array':case 'object':ret = '';for (i in input) {this._keys.push(i);ret += this.serialize(input[i], true) + '&';this._keys.pop();}ret = ret.substr(0, ret.length - 1);}return ret;},/*** Reconstructs a serialized variable** @param string inp the string to reconstruct* @return array an array containing the variable represented by the input string, or void on failure*/unserialize: function(input) {if (!input.length || input.length == 0) {return;}if (!/^(\w+(\[[^\[\]]*\])*=[^&]*(&|$))+$/.test(input)) {this.raiseError("invalidly formed input", input);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -