📄 html_ajax.js
字号:
// The actual URL the request is sent to requestUrl: '', // Remote Class className: null, // Remote Method methodName: null, // Timeout in milliseconds for requests timeout: 20000, // unserialized data, for rpc calls use add args, to send raw data just set this directly args: null, // async callback method callback: null, // Queue to push this request too queue: 'default', // default priority priority: 0, // a hash of headers to add to add to this request customHeaders: {'X-Requested-With': 'XMLHttpRequest', 'X-Ajax-Engine': 'HTML_AJAX/0.5.2'}, // true if this request will be sent using iframes iframe: false, // is this a grab request? if so we need to proxy for iframes grab: false, // true if this request should expect a multipart response multipart: false, // remote callback 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 will throw 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, ''); } // value can't be removed else if(attributes[i] == 'value') { node.value = ''; } // I'd use hasAttribute first but IE is stupid stupid stupid 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); break case '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; //this one is tricky, if it's the last one we use append child...ewww 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 */ // should we move this to HTML_AJAX_Util???, just does the - case which we need for style _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) { // innerHTML is extremely flakey - use util method for it if(i == 'innerHTML') { HTML_AJAX_Util.setInnerHTML(node, attributes[i], 'append'); } //IE doesn't support setAttribute on style so we need to break it out and set each property individually 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) { // innerHTML is extremely flakey - use util method for it if(i == 'innerHTML') { HTML_AJAX_Util.setInnerHTML(node, a
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -