📄 html_ajax_lite.js
字号:
var e = new Error('HTTP Error Making Request: ['+this.xmlhttp.status+'] '+this.xmlhttp.statusText);this._handleError(e);}HTML_AJAX.requestComplete(this.request);break;}} catch (e) {this._handleError(e);}},_decodeResponse: function() {var content = null;try {content = this.xmlhttp.getResponseHeader('X-Content-Type');} catch(e) {}if(!content || content == null){content = this.xmlhttp.getResponseHeader('Content-Type');}if(content.indexOf(';') != -1){content = content.substring(0, content.indexOf(';'));}if(content == 'application/xml'){return this.xmlhttp.responseXML;}var unserializer = HTML_AJAX.serializerForEncoding(content);return unserializer.unserialize(this.xmlhttp.responseText);},_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 {throw e;}}}// Request.js/*** Class that contains everything needed to make a request* This includes:* The url were calling* If were calling a remote method, the class and method name* The payload, unserialized* The timeout for async calls* The callback method* Optional event handlers: onError, Load, Send* A serializer instance** @category HTML* @package AJAX* @author Joshua Eichorn <josh@bluga.net>* @copyright 2005 Joshua Eichorn* @license http://www.opensource.org/licenses/lgpl-license.php LGPL** See Main.js for author/license details*/function HTML_AJAX_Request(serializer) {this.serializer = serializer;}HTML_AJAX_Request.prototype = {serializer: null,isAsync: false,requestType: 'POST',requestUrl: '',className: null,methodName: null,timeout: 20000,args: null,callback: null,queue: 'default',priority: 0,customHeaders: {'X-Requested-With': 'XMLHttpRequest', 'X-Ajax-Engine': 'HTML_AJAX/0.5.2'},iframe: false,grab: false,multipart: false,phpCallback: false,/*** Add an argument for the remote method* @param string argument name* @param mixed value* @return void* @throws Error code 1004*/addArg: function(name, value){if ( !this.args ) {this.args = [];}if (!/[^a-zA-Z_0-9]/.test(name) ) {this.args[name] = value;} else {throw new Error('Invalid parameter name ('+name+')');}},/*** Get the payload in a serialized manner*/getSerializedPayload: function() {return this.serializer.serialize(this.args);},/*** Get the content type*/getContentType: function() {return this.serializer.contentType;},/*** Get the complete url, adding in any needed get params for rpc*/completeUrl: function() {if (this.className || this.methodName) {this.addGet('c', this.className);this.addGet('m', this.methodName);}if (this.phpCallback) {if (HTML_AJAX_Util.getType(this.phpCallback) == 'array') {this.phpCallback = this.phpCallback.join('.');}this.addGet('cb', this.phpCallback);}if (this.multipart) {this.addGet('multipart', '1');}return this.requestUrl;},/*** Compare to another request by priority*/compareTo: function(other) {if (this.priority == other.priority) {return 0;}return (this.priority > other.priority ? 1 : -1);},/*** Add a GET argument*/addGet: function(name, value) {var url = new String(this.requestUrl);url += (url.indexOf('?') < 0 ? '?' : '&') + escape(name) + '=' + escape(value);this.requestUrl = url;}}// serializer/JSON.js/*Copyright (c) 2005 JSON.orgPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The Software shall be used for Good, not Evil.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.*//*The global object JSON contains two methods.JSON.stringify(value) takes a JavaScript value and produces a JSON text.The value must not be cyclical.JSON.parse(text) takes a JSON text and produces a JavaScript value. It willthrow a 'JSONError' exception if there is an error.*/var HTML_AJAX_JSON = {copyright: '(c)2005 JSON.org',license: 'http://www.crockford.com/JSON/license.html',/*Stringify a JavaScript value, producing a JSON text.*/stringify: function (v) {var a = [];/*Emit a string.*/function e(s) {a[a.length] = s;}/*Convert a value.*/function g(x) {var c, i, l, v;switch (typeof x) {case 'object':if (x) {if (x instanceof Array) {e('[');l = a.length;for (i = 0; i < x.length; i += 1) {v = x[i];if (typeof v != 'undefined' &&typeof v != 'function') {if (l < a.length) {e(',');}g(v);}}e(']');return;} else if (typeof x.valueOf == 'function') {e('{');l = a.length;for (i in x) {v = x[i];if (typeof v != 'undefined' &&typeof v != 'function' &&(!v || typeof v != 'object' ||typeof v.valueOf == 'function')) {if (l < a.length) {e(',');}g(i);e(':');g(v);}}return e('}');}}e('null');return;case 'number':e(isFinite(x) ? +x : 'null');return;case 'string':l = x.length;e('"');for (i = 0; i < l; i += 1) {c = x.charAt(i);if (c >= ' ') {if (c == '\\' || c == '"') {e('\\');}e(c);} else {switch (c) {case '\b':e('\\b');break;case '\f':e('\\f');break;case '\n':e('\\n');break;case '\r':e('\\r');break;case '\t':e('\\t');break;default:c = c.charCodeAt();e('\\u00' + Math.floor(c / 16).toString(16) +(c % 16).toString(16));}}}e('"');return;case 'boolean':e(String(x));return;default:e('null');return;}}g(v);return a.join('');},/*Parse a JSON text, producing a JavaScript value.*/parse: function (text) {return(/^(\s+|[,:{}\[\]]|"(\\["\\\/bfnrtu]|[^\x00-\x1f"\\]+)*"|-?\d+(\.\d*)?([eE][+-]?\d+)?|true|false|null)+$/.test(text))&&eval('(' + text + ')');}};// serializer/haSerializer.js/*** HTML_AJAX_Serialize_HA - custom serialization** This class is used with the JSON serializer and the HTML_AJAX_Action php class* to allow users to easily write data handling and dom manipulation related to* ajax actions directly from their php code** See Main.js for Author/license details*/function HTML_AJAX_Serialize_HA() { }HTML_AJAX_Serialize_HA.prototype ={/*** Takes data from JSON - which should be parseable into a nice array* reads the action to take and pipes it to the right method** @param string payload incoming data from php* @return true on success, false on failure*/unserialize: function(payload){var actions = eval(payload);for(var i = 0; i < actions.length; i++){var action = actions[i];switch(action.action){case 'prepend':this._prependAttr(action.id, action.attributes);break;case 'append':this._appendAttr(action.id, action.attributes);break;case 'assign':this._assignAttr(action.id, action.attributes);break;case 'clear':this._clearAttr(action.id, action.attributes);break;case 'create':this._createNode(action.id, action.tag, action.attributes, action.type);break;case 'replace':this._replaceNode(action.id, action.tag, action.attributes);break;case 'remove':this._removeNode(action.id);break;case 'script':this._insertScript(action.data);break;case 'alert':this._insertAlert(action.data);break;}}},/* Dispatch Methods */_prependAttr: function(id, attributes){var node = document.getElementById(id);this._setAttrs(node, attributes, 'prepend');},_appendAttr: function(id, attributes){var node = document.getElementById(id);this._setAttrs(node, attributes, 'append');},_assignAttr: function(id, attributes){var node = document.getElementById(id);this._setAttrs(node, attributes);},_clearAttr: function(id, attributes){var node = document.getElementById(id);for(var i = 0; i < attributes.length; i++){if(attributes[i] == 'innerHTML'){HTML_AJAX_Util.setInnerHTML(node, '');}else if(attributes[i] == 'value'){node.value = '';}else{try{node.removeAttribute(attributes[i]);}catch(e){node[i] = undefined;}}}},_createNode: function(id, tag, attributes, type){var newnode = document.createElement(tag);this._setAttrs(newnode, attributes);switch(type){case 'append':document.getElementById(id).appendChild(newnode);breakcase 'prepend':var parent = document.getElementById(id);var sibling = parent.firstChild;parent.insertBefore(newnode, sibling);break;case 'insertBefore':var sibling = document.getElementById(id);var parent = sibling.parentNode;parent.insertBefore(newnode, sibling);break;case 'insertAfter':var sibling = document.getElementById(id);var parent = sibling.parentNode;var next = sibling.nextSibling;if(next == null){parent.appendChild(newnode);}else{parent.insertBefore(newnode, next);}break;}},_replaceNode: function(id, tag, attributes){var node = document.getElementById(id);var parent = node.parentNode;var newnode = document.createElement(tag);this._setAttrs(newnode, attributes);parent.replaceChild(newnode, node);},_removeNode: function(id){var node = document.getElementById(id);if(node){var parent = node.parentNode;parent.removeChild(node);}},_insertScript: function(data){eval(data);},_insertAlert: function(data){alert(data);},/* Helper Methods */_camelize: function(instr){var p = instr.split('-');var out = p[0];for(var i = 1; i < p.length; i++) {out += p[i].charAt(0).toUpperCase()+p[i].substring(1);}return out;},_setAttrs: function(node, attributes, type){switch(type){case 'prepend':for (var i in attributes){if(i == 'innerHTML'){HTML_AJAX_Util.setInnerHTML(node, attributes[i], 'append');}else if(i == 'style'){var styles = [];if(attributes[i].indexOf(';')){styles = attributes[i].split(';');}else{styles.push(attributes[i]);}for(var i = 0; i < styles.length; i++){var r = styles[i].match(/^\s*(.+)\s*:\s*(.+)\s*$/);if(r){node.style[this._camelize(r[1])] = r[2] + node.style[this._camelize(r[1])];}}}else{try{node[i] = attributes[i] + node[i];}catch(e){}node.setAttribute(i, attributes[i] + node[i]);}}break;case 'append':{for (var i in attributes){if(i == 'innerHTML'){HTML_AJAX_Util.setInnerHTML(node, attributes[i], 'append');}else if(i == 'style'){var styles = [];if(attributes[i].indexOf(';')){styles = attributes[i].split(';');}else{styles.push(attributes[i]);}for(var i = 0; i < styles.length; i++){var r = styles[i].match(/^\s*(.+)\s*:\s*(.+)\s*$/);if(r){node.style[this._camelize(r[1])] = node.style[this._camelize(r[1])] + r[2];}}}else{try{node[i] = node[i] + attributes[i];}catch(e){}node.setAttribute(i, node[i] + attributes[i]);}}break;}default:{for (var i in attributes){if(i == 'innerHTML'){HTML_AJAX_Util.setInnerHTML(node, attributes[i]);}else if(i == 'style'){var styles = [];if(attributes[i].indexOf(';')){styles = attributes[i].split(';');}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -