⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 html_ajax.js

📁 This is the script which used on 10minutemail.com for temporary email.
💻 JS
📖 第 1 页 / 共 5 页
字号:
		request.callback = callback;		switch (form.getAttribute('method').toLowerCase()) {		case 'post':			var headers = {};			headers['Content-Type'] = 'application/x-www-form-urlencoded';			request.customHeaders = headers;			request.requestType = 'POST';			request.requestUrl = action;			request.args = out;			break;		default:			if (action.indexOf('?') == -1) {				out = '?' + out.substr(0, out.length - 1);			}			request.requestUrl = action+out;			request.requestType = 'GET';		}		if(options) {			for(var i in options) {				request[i] = options[i];			}		}		HTML_AJAX.makeRequest(request);		return true;	}, // end formSubmit()	makeFormAJAX: function(form,target,options) {		form = HTML_AJAX_Util.getElement(form);		var preSubmit = false;		if(typeof form.onsubmit != 'undefined') {			preSubmit = form.onsubmit;			form.onsubmit = function() {};		}		form.HAOptions = options;		var handler = function(e) {			var form = HTML_AJAX_Util.eventTarget(e);			var valid = true;			if (preSubmit) {				valid = preSubmit();			}			if (valid) {				HTML_AJAX.formSubmit(form,target,form.HAOptions);			}			// cancel submission in IE			e.returnValue = false;			// cancel submission in FF			if (e.preventDefault) {				e.preventDefault();			}		}		HTML_AJAX_Util.registerEvent(form,'submit',handler);	}}// small classes that I don't want to put in there own filefunction HTML_AJAX_Serialize_Null() {}HTML_AJAX_Serialize_Null.prototype = {	contentType: 'text/plain; charset=utf-8',	serialize: function(input) {		return new String(input).valueOf();	},		unserialize: function(input) {		return new String(input).valueOf();		}}function HTML_AJAX_Serialize_XML() {}HTML_AJAX_Serialize_XML.prototype = {	contentType: 'application/xml; charset=utf-8',	serialize: function(input) {		var xml = '';		if(typeof(input) == 'object' && input)		{			for (var i = 0;i<input.length;i++)			{				xml += new XMLSerializer().serializeToString(input[i]);			}		}		return xml;	},	unserialize: function(input) {		return input;	}}// serialization class for JSON, wrapper for JSON.stringify in json.jsfunction HTML_AJAX_Serialize_JSON() {}HTML_AJAX_Serialize_JSON.prototype = {	contentType: 'application/json; charset=utf-8',	serialize: function(input) {		return HTML_AJAX_JSON.stringify(input);	},	unserialize: function(input) {		try {			return eval('('+input+')');		} catch(e) {			// sometimes JSON encoded input isn't created properly, if eval of it fails we use the more forgiving but slower parser so will at least get something			return HTML_AJAX_JSON.parse(input);		}	}}function HTML_AJAX_Serialize_Error() {}HTML_AJAX_Serialize_Error.prototype = {	contentType: 'application/error; charset=utf-8',	serialize: function(input) {		var ser = new HTML_AJAX_Serialize_JSON();		return ser.serialize(input);	},	unserialize: function(input) {		var ser = new HTML_AJAX_Serialize_JSON();		var data = new ser.unserialize(input);		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 immediatelyfunction 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();	}}// create a default queue, has to happen after the Queue class has been definedHTML_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 */// 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 timerfunction 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();		}	}}// Requests return in the same order they were called// this helps handle high latency situationsfunction 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) {		// something when wrong with the request lets stop waiting for it		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++;		}}}// Make a single request at once, canceling and currently outstanding requests when a new one is madefunction 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 intervals	this.requestTimeout = 5;	  // retry uncompleted requests after 5 seconds	this.checkRetryChance = 0.1;  // check for uncompleted requests to retry on 10% of intervals	this._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;	}};// create a default client pool with unlimited clientsHTML_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 = {// Data not sent with text/xml Content-Type will only be available via the responseText property	// properties available in safari/mozilla/IE xmlhttprequest object	onreadystatechange: null, // Event handler for an event that fires at every state change	readyState: 0, // Object status integer: 0 = uninitialized 1 = loading 2 = loaded 3 = interactive 4 = complete	responseText: '', // String version of data returned from server process	responseXML: null, // DOM-compatible document object of data returned from server process	status: 0, // Numeric code returned by server, such as 404 for "Not Found" or 200 for "OK"	statusText: '', // String message accompanying the status code	iframe: true, // flag for iframe	//these are private properties used internally to keep track of stuff	_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 munging	// Stops the current request	abort: function()	{		var iframe = document.getElementById(this._id);		if (iframe) {			document.body.removeChild(iframe);		}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -