1 APE.Transport.JSONP = new Class({
3 Implements: APE.Transport.SSE,
5 initialize: function(ape) {
7 this.requestFailObserver = [];
10 //If browser support servent sent event, switch to SSE / JSONP transport (not yet supported by APE server)
11 //if (this.SSESupport) this.ape.options.transport = 3;
13 window.parent.onkeyup = function(ev) {
14 if (ev.keyCode == 27) {
15 this.cancel();//Escape key
16 if (this.ape.status > 0) {
17 //if (!this.SSESupport)
18 //this.ape.request('CLOSE');
25 send: function(queryString, options) {
26 //Opera has some trouble with JSONP, so opera use mix of SSE & JSONP
27 /*if (this.SSESupport && !this.eventSource) { //SSE not yet supported by APE server
28 this.initSSE(queryString, options, this.readSSE.bind(this));
30 this.callback = options.requestCallback;
32 var request = document.createElement('script');
33 request.src = this.ape.serverUri + queryString;
34 document.head.appendChild(request);
35 this.requests.push(request);
37 this.requestFailObserver.push(this.ape.requestFail.delay(this.ape.options.pollTime + 10000, this.ape, [-1, request]));
39 if (Browser.Engine.gecko) {
40 //Firefox hack to avoid status bar always show a loading message
41 //Ok this hack is little bit weird but it works!
43 var tmp = document.createElement('iframe');
44 document.body.appendChild(tmp);
45 document.body.removeChild(tmp);
51 clearRequest: function(request) {
52 request.parentNode.removeChild(request);
54 if (request.clearAttributes) {
55 request.clearAttributes();
57 for (var prop in request) delete request[prop];
59 $clear(this.requestFailObserver.shift());
62 readSSE: function(data) {
63 this.ape.parseResponse(data, this.callback);
67 read: function(resp) {
68 $clear(this.requestFailObserver.shift());
69 this.clearRequest(this.requests.shift());
70 this.ape.parseResponse(resp, this.callback);
75 if (this.requests.length > 0) {
76 this.clearRequest(this.requests.shift());
81 /* if (this.SSESupport) {
82 return this.eventSource ? true : false;
84 return this.requests.length > 0 ? true : false;
91 APE.Transport.JSONP.browserSupport = function() { return true };