var console, _log; (function(){ if(typeof console == 'undefined'){ _log = function(a, b, c){/*alert('' + a + b + c)*/}; }else{ _log = function(){ console.log.apply(console, arguments) }; } })(); if (typeof window.OpenResty == "undefined") { (function() { var undefined; var browser = (function(){ var u = navigator.userAgent.toLowerCase(), a = /(msie|firefox|camino|chrome|opera|safari|netscape|konqueror|lynx)/, b = /(msie|firefox|chrome|opera|safari|camino|netscape|netscape6|konqueror|lynx|version)(\/|\s)([a-z0-9\.\+]*?)(\;|dev|rel|\s|$)/; var un = 'unknown', x = 'X', r = { name: (a.exec(u) || [un, un])[1] }; r[r.name] = true; r.version = (b.exec(u) || [x, x, x, x])[3]; return r; })(); var OpenResty = { callbackMap: {}, isDone: {}, counter: 0 }; OpenResty.Client = function (params) { if (params == undefined) params = {}; this.callback = params.callback; var server = params.server; if (!/^https?:\/\//.test(server)) { server = 'http://' + server; } this.server = server; this.user = params.user; //this.password = params.password; }; var $ClientP = OpenResty.Client.prototype; $ClientP.isSuccess = function (res) { // alert(JSON.stringify(res)); return !(typeof res == 'object' && res.errcode); }; $ClientP.logout = function () { this.get('/=/logout'); }; $ClientP.login = function (user, password) { this.user = user; var userCallback = this.callback; if (typeof userCallback == 'string') { userCallback = eval(userCallback); } var self = this; this.callback = function (data) { //alert(data.session); self.session = data.session; userCallback(data); }; if (password == null) password = ''; else password = hex_md5(password); //this.callback = 'save_session'; this.get('/=/login/' + user + '/' + password); }; $ClientP.postByGet = function (url) { var args, content; if (arguments.length == 3) { args = arguments[1]; content = arguments[2]; } else { content = arguments[1]; } if (!args) args = {}; url = url.replace(/^\/=\//, '/=/post/'); content = JSON.stringify(content); //alert("type of content: " + typeof(content)); //alert("content: " + content); args._data = content; this.get(url, args); }; $ClientP.genId = (function (n) { //return ( Math.random() * 1000000 ); return function() { return n++ }; //return this.counter++; })(new Date().getTime()); /* post: for large data transform crossdomain ~ y/n _post_by_form({ form: form, url: fullURL, content: { data: content }, preventCache: true, method: "post", handleAs: 'html', handle: function () { self.get('/=/last/response/' + args._last_response); } }); */ var _post_forms_div, _post_forms = {}; OpenResty.Client._post_forms = _post_forms; $ClientP._post_by_form = function (url, content, args) { if (!_post_forms_div) { _post_forms_div = document.createElement('div'); var _s = _post_forms_div.style; _s.position = 'absolute'; _s.left = '-1000px'; _s.width = '500px'; _s.height = '1px'; _s.overflow = 'hidden'; _s = null; document.body.appendChild(_post_forms_div); } var reqId = args._last_response; if (reqId in _post_forms) { throw "the post already exist!!"; } var self = this; var obj = { reqId: reqId }; _post_forms[reqId] = obj; var submitted = false; // var onloadCount = 0; obj.onload = function() { if (!submitted) return; // alert('contentLoad ' + (++onloadCount) + ' times\n' + this); var _iframe = obj.iframe; // maybe we can process response under same domain delete obj.onload; _post_forms_div.removeChild(_iframe); var _form = obj.form; _post_forms_div.removeChild(obj.form); _iframe = null; _form = null; delete obj.iframe; delete obj.form; delete _post_forms[reqId]; obj = null; self.get('/=/last/response/' + reqId); }; var form_id = 'OpenResty_form_' + reqId, iframe_id = 'OpenResty_iframe_' + reqId; var _5 = 'http://ajax.googleapis.com/ajax/libs/dojo/1.3.2/dojo/resources/blank.html'; var _iframe; var _6 = browser.msie ? '