namibia
df0489e1eeeeab5a9bd44e1d84fce49924fe1bac
namibia / public / js / vendor / ape-source / Request / Request.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
APE.Request = new Class({ initialize: function(ape) { this.ape = ape; this.stack = new APE.Request.Stack(ape); this.cycledStack = new APE.Request.CycledStack(ape); this.chl = 1; this.callbackChl = new $H; //Fix presto bug (see send method) if (Browser.Engine.presto){ this.requestVar = { updated: false, args: [] }; this.requestObserver.periodical(10, this); } }, send: function(cmd, params, options, noWatch) { if (this.ape.requestDisabled) return; //Opera dirty fix if (Browser.Engine.presto && !noWatch) { this.requestVar.updated = true; this.requestVar.args.push([cmd, params, options]); return; } var opt = {}; if (!options) options = {}; opt.event = options.event || true; opt.requestCallback = options.requestCallback || null; opt.callback = options.callback; var ret = this.ape.transport.send(this.parseCmd(cmd, params, opt), opt); $clear(this.ape.pollerObserver); this.ape.pollerObserver = this.ape.poller.delay(this.ape.options.pollTime, this.ape); return ret; }, parseCmd: function(cmd, params, options) { var queryString = ''; var a = []; var o = {}; if ($type(cmd) == 'array') { var tmp, evParams; for (var i = 0; i < cmd.length; i++) { tmp = cmd[i]; o = {}; o.cmd = tmp.cmd; o.chl = this.chl++; if (!tmp.options) tmp.options = {}; tmp.params ? o.params = tmp.params : null; evParams = $extend({}, o.params); if (!$defined(tmp.options.sessid) || tmp.options.sessid !== false) o.sessid = this.ape.sessid; a.push(o); var ev = 'cmd_' + tmp.cmd.toLowerCase(); if (tmp.options.callback) this.callbackChl.set(o.chl, tmp.options.callback); if (tmp.options.requestCallback) options.requestCallback = tmp.options.requestCallback; if (options.event) { //Request is on a pipe, fire the event on the pipe if (o.params && o.params.pipe) { var pipe = this.ape.getPipe(o.params.pipe); if (pipe) evParams = [evParams, pipe]; } this.ape.fireEvent('onCmd', [tmp.cmd, evParams]); if (pipe) pipe.fireEvent(ev, evParams); this.ape.fireEvent(ev, evParams); } } } else { o.cmd = cmd; o.chl = this.chl++; params ? o.params = params : null; var evParams = $extend({}, params); if (!$defined(options.sessid) || options.sessid !== false) o.sessid = this.ape.sessid; a.push(o); var ev = 'cmd_' + cmd.toLowerCase(); if (options.callback) this.callbackChl.set(o.chl, options.callback); if (options.event) { //Request is on a pipe, fire the event on the pipe if (params && params.pipe) { var pipe = this.ape.getPipe(params.pipe); if (pipe) evParams = [evParams, pipe]; } this.ape.fireEvent('onCmd', [cmd, evParams]); if (pipe) pipe.fireEvent(ev, evParams); this.ape.fireEvent(ev, evParams); } } var transport = this.ape.options.transport; return JSON.stringify(a, function(key, value) { if (typeof(value) == 'string') { value = encodeURIComponent(value); //In case of JSONP data have to be escaped two times if (transport == 2) value = encodeURIComponent(value); return value; } else return value; }); }, /**** * This method is only used by opera. * Opera have a bug, when request are sent trought user action (ex : a click), opera throw a security violation when trying to make a XHR. * The only way is to set a class var and watch when this var change */ requestObserver: function(){ if (this.requestVar.updated) { var args = this.requestVar.args.shift(); this.requestVar.updated = (this.requestVar.args.length>0) ? true : false; args[3] = true; //Set noWatch argument to true this.send.run(args, this); } } }); |
Commits for namibiapublic/js/vendor/ape-source/Request/Request.js
Revision | Author | Commited | Message |
---|---|---|---|
df0489 ... | Mark | Fri 14 Oct, 2016 10:01:00 +0000 | initial commit |