text changes to registration mail content
[namibia] / public / ape-source / Transport / Transport.JSONP.js
1 APE.Transport.JSONP = new Class({
2         
3         Implements: APE.Transport.SSE,
4
5         initialize: function(ape) {
6                 this.ape = ape;
7                 this.requestFailObserver = [];
8                 this.requests = [];
9                 
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;
12                 
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');
19                                         this.ape.check();
20                                 }
21                         }
22                 }.bind(this);
23         },
24
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));
29                 } else { */
30                         this.callback = options.requestCallback;
31
32                         var request = document.createElement('script');
33                         request.src = this.ape.serverUri + queryString;
34                         document.head.appendChild(request);
35                         this.requests.push(request);
36                         //Detect timeout
37                         this.requestFailObserver.push(this.ape.requestFail.delay(this.ape.options.pollTime + 10000, this.ape, [-1, request]));
38
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!
42                                 (function() {
43                                         var tmp = document.createElement('iframe');
44                                         document.body.appendChild(tmp);
45                                         document.body.removeChild(tmp);
46                                 }).delay(200);
47                         }
48                 //}
49         },
50
51         clearRequest: function(request) {
52                 request.parentNode.removeChild(request);
53                 //Avoid memory leaks
54                 if (request.clearAttributes) {
55                         request.clearAttributes();
56                 } else { 
57                         for (var prop in request) delete request[prop];
58                 }
59                 $clear(this.requestFailObserver.shift());
60         },
61
62         readSSE: function(data) {
63                 this.ape.parseResponse(data, this.callback);
64                 this.callback = null;
65         },
66
67         read: function(resp) {
68                 $clear(this.requestFailObserver.shift());
69                 this.clearRequest(this.requests.shift());
70                 this.ape.parseResponse(resp, this.callback);
71                 this.callback = null;
72         },
73
74         cancel: function() {
75                 if (this.requests.length > 0) {
76                         this.clearRequest(this.requests.shift());
77                 }
78         },
79
80         running: function() {
81                 /* if (this.SSESupport) {
82                         return this.eventSource ? true : false;
83                 } else { */
84                         return this.requests.length > 0 ? true : false;
85                 //}
86         }
87
88         
89 });
90
91 APE.Transport.JSONP.browserSupport = function() { return true };