/[meteor]/googlecode.com/svn/trunk/public_html/poll.html
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /googlecode.com/svn/trunk/public_html/poll.html

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations)
Wed Oct 10 22:25:57 2007 UTC (11 years, 11 months ago) by andrew.betts
File MIME type: text/html
File size: 2875 byte(s)


1 <html>
2 <body>
3 <script type="text/javascript">
4 window.onError = null;
5 var domainparts = document.domain.split(".");
6 var thisdomain = document.domain;
7 var topdomain = domainparts[domainparts.length-2]+"."+domainparts[domainparts.length-1];
8 document.domain = topdomain;
9 var lastrequesttime = 0;
10 var pollreq = false;
11 var polltimer = false;
12 var i=0;
13 var isaborted = 0;
14 parent.Meteor.register(this);
15
16 Function.prototype.bind = function(obj) {
17 var method = this,
18 temp = function() {
19 return method.apply(obj, arguments);
20 };
21 return temp;
22 }
23
24 function newXmlHttp() {
25 var xmlhttp;
26 /*@cc_on @*/
27 /*@if (@_jscript_version >= 5)
28 try {
29 xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
30 } catch (e) {
31 try {
32 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
33 } catch (E) {
34 xmlhttp = false;
35 }
36 }
37 @end @*/
38 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
39 xmlhttp = new XMLHttpRequest();
40 }
41 return xmlhttp;
42 }
43
44 function poll() {
45 isaborted = 0;
46 try {
47 clearTimeout(polltimer);
48 } catch (e) {}
49 var byteoffset = 0;
50 var newdata;
51 document.domain = topdomain;
52 var url = get("subsurl");
53 if (typeof(url)!="undefined") {
54 var now = new Date();
55 var t = now.getTime();
56 url += "&template=2&nocache="+t;
57 try {
58 document.domain = thisdomain;
59 } catch (e) {}
60 pollreq = newXmlHttp();
61 pollreq.onreadystatechange = handleresponse;
62 pollreq.open("GET", url, true);
63 lastrequesttime = t;
64 if (get("polltimeout")) polltimer = setTimeout(ptimeout, get("polltimeout"));
65 pollreq.send(null);
66 }
67 document.domain=topdomain;
68 }
69
70 function handleresponse() {
71 if (typeof(pollreq) == "object" && pollreq.readyState == 4 && !isaborted) {
72 try {
73 clearTimeout(polltimer);
74 } catch (e) {}
75 if (typeof(topdomain) == "undefined") return false;
76 document.domain=topdomain;
77 newdata = pollreq.responseText;
78 var x = newdata.indexOf("parent.Meteor.setServerTime(");
79 if (x != -1) {
80 y = newdata.indexOf(");", x);
81 if (y != -1) eval(newdata.substring(x,y+2));
82 }
83 while (1) {
84 var x = newdata.indexOf("<s"+"cript>p(");
85 if (x != -1) {
86 y = newdata.indexOf("</"+"script>", x);
87 if (y != -1) {
88 eval(newdata.substring((x+8),y));
89 newdata = newdata.substring(y+9);
90 } else {
91 break;
92 }
93 } else {
94 break;
95 }
96 }
97 var now = new Date();
98 var t = now.getTime();
99 var x = get("pollfreq") - (t-lastrequesttime);
100 if (x < 10) x = 10;
101 setTimeout(poll, x);
102 }
103 }
104
105 function ptimeout() {
106 isaborted = 1;
107 pollreq.abort();
108 delete pollreq;
109 clearTimeout(polltimer);
110 var now = new Date();
111 var t = now.getTime();
112 var x = get("pollfreq") - (t-lastrequesttime);
113 if (x < 10) x = 10;
114 setTimeout(poll, x);
115 }
116
117 function guard() {
118 var url = get("subsurl");
119 if (typeof(url)=="undefined") {
120 pollreq.abort();
121 delete pollreq;
122 clearTimeout(polltimer);
123 }
124 setTimeout('guard()', 1000);
125 }
126
127 poll();
128 guard();
129
130
131 </script>
132 </body>
133 </html>

  ViewVC Help
Powered by ViewVC 1.1.26