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

Diff of /googlecode.com/svn/trunk/public_html/meteor.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3 by andrew.betts, Mon Nov 20 17:59:30 2006 UTC revision 62 by andrew.betts, Thu Nov 27 00:33:21 2008 UTC
# Line 1  Line 1 
1  // Set domain at highest level  /*
2  var domainparts = document.domain.split(".");  stream: xhrinteractive, iframe, serversent
3  document.domain = domainparts[domainparts.length-2]+"."+domainparts[domainparts.length-1];  longpoll
4    smartpoll
5  Function.prototype.bind = function(obj) {  simplepoll
6          var method = this,  */
7          temp = function() {  
8                  return method.apply(obj, arguments);  Meteor = {
9          };  
10          return temp;          callbacks: {
11  }                  process: function() {},
12  Function.prototype.andThen=function(g) {                  reset: function() {},
13          var f=this;                  eof: function() {},
14          var a=this.arguments                  statuschanged: function() {},
15          return function(args) {                  changemode: function() {}
16                  f(a);g(args);          },
17          }          channelcount: 0,
18  };          channels: {},
19            debugmode: false,
20  function Meteor(instID) {          frameref: null,
21            host: null,
22          this.lastmsgreceived = -1;          hostid: null,
23          this.transferDoc = false;          maxpollfreq: 60000,
24          this.pingtimer = false;          minpollfreq: 2000,
25          this.updatepollfreqtimer = false;          mode: "stream",
26          this.lastrequest = 0;          pingtimeout: 20000,
27          this.recvtimes = new Array();          pingtimer: null,
28          this.MHostId = false;          pollfreq: 3000,
29          this.callback_process = function() {};          port: 80,
30          this.callback_reset = function() {};          pollaborted: false,
31          this.callback_eof = function() {};          pollhost: null,
32          this.callback_changemode = function() {};          pollnum: 0,
33          this.persist = true;          polltimeout: 30000,
34            polltimer: null,
35          // Documented public properties          recvtimes: [],
36          this.channel = false;          lastrequest: null,
37          this.subdomain = "data";          status: 0,
38          this.dynamicpageaddress = "push";          updatepollfreqtimer: null,
39          this.backtrack = 0;  
40          this.smartpoll = true;          isSupportedBrowser: function() {
41          this.pollfreq = 2000;                  var v;
42          this.minpollfreq = 2000;                  if (v = navigator.userAgent.match(/compatible\; MSIE\ ([0-9\.]+)\;/i)) {
43          this.mode = "stream";                          if (parseFloat(v[1]) <= 5.5) return false;
44          this.polltimeout=30000;                  } else if (v = navigator.userAgent.match(/Gecko\/([0-9]+)/i)) {
45          this.maxmessages=0;                          if (parseInt(v[1]) <= 20051015) return false;
46          this.pingtimeout = 10000;                  } else if (v = navigator.userAgent.match(/WebKit\/([0-9\.]+)/i)) {
47                            if (parseFloat(v[1]) < 400) return false;
48          // Set or retrieve host id.  Cookie takes this form:                  }
49          // MeteorID=123:6356353/124:098320454;                  return true;
50          var MeteIds = Meteor.readCookie("MeteorID");          },
         var regex1 = new RegExp("^([0-9\:\/M]+\/)*"+instID+"\:([^\/]+)(\/[0-9\:\/M]+)*$");  
         var regex2 = new RegExp("^([0-9\:\/M]+\/)*M\:([^\/]+)(\/[0-9\:\/M]+)*$");  
         if (typeof(instID) == "Number" && regex1.exec(MeteIds)) {  
                 this.MHostId = ma[2];  
         } else if (typeof(instID) == "Number") {  
                 this.MHostId = Math.floor(Math.random()*1000000);  
                 var newcookie = (MeteIds)?MeteIds+"/":"";  
                 newcookie += instID+":"+this.MHostId;  
                 Meteor.createCookie("MeteorID", newcookie);  
         } else if (ma = regex2.exec(MeteIds)) {  
                 this.MHostId = ma[2];  
         } else {  
                 this.MHostId = Math.floor(Math.random()*1000000);  
                 var newcookie = (MeteIds)?MeteIds+"/":"";  
                 newcookie += "M:"+this.MHostId;  
                 Meteor.createCookie("MeteorID", newcookie);  
         }  
         this.instID = (typeof(instID) != "undefined") ? instID : 0;  
 }  
   
 Meteor.instances = new Array();  
 Meteor.servertimeoffset = 0;  
51    
52  Meteor.create = function(instID) {          register: function(ifr) {
53          if (!instID) instID = 0;                  ifr.p = Meteor.process;
54          Meteor.instances[instID] = new Meteor(instID);                  ifr.r = Meteor.reset;
55          return Meteor.instances[instID];                  ifr.eof = Meteor.eof;
56  }                  ifr.ch = Meteor.channelInfo;
57                    clearTimeout(Meteor.frameloadtimer);
58                    Meteor.setstatus(4);
59                    Meteor.log("Frame registered");
60            },
61    
62            joinChannel: function(channelname, backtrack) {
63                    if (typeof(Meteor.channels[channelname]) != "undefined") throw "Cannot join channel "+channelname+": already subscribed";
64                    Meteor.channels[channelname] = {backtrack:backtrack};
65                    Meteor.log("Joined channel "+channelname);
66                    Meteor.channelcount++;
67                    if (Meteor.status != 0 && Meteor.status != 6) Meteor.connect();
68            },
69    
70            leaveChannel: function(channelname) {
71                    if (typeof(Meteor.channels[channelname]) == "undefined") throw "Cannot leave channel "+channelname+": not subscribed";
72                    delete Meteor.channels[channelname];
73                    Meteor.log("Left channel "+channelname);
74                    Meteor.channelcount--;
75                    if (Meteor.channelcount && Meteor.status != 0 && Meteor.status != 6) Meteor.connect();
76                    else Meteor.disconnect();
77            },
78    
79            connect: function() {
80                    Meteor.log("Connecting");
81                    if (!Meteor.host) throw "Meteor host not specified";
82                    if (isNaN(Meteor.port)) throw "Meteor port not specified";
83                    if (!Meteor.channelcount) throw "No channels specified";
84                    if (Meteor.status) Meteor.disconnect();
85                    Meteor.setstatus(1);
86                    if (!Meteor.hostid) Meteor.hostid = Meteor.time()+""+Math.floor(Math.random()*1000000)
87                    document.domain = Meteor.extract_xss_domain(document.domain);
88                    if (Meteor.mode=="stream") Meteor.mode = Meteor.selectStreamTransport();
89                    Meteor.log("Selected "+Meteor.mode+" transport");
90                    if (Meteor.mode=="xhrinteractive" || Meteor.mode=="iframe" || Meteor.mode=="serversent") {
91                            if (Meteor.mode == "iframe") {
92                                    Meteor.loadFrame(Meteor.getSubsUrl());
93                            } else {
94                                    Meteor.loadFrame("http://"+Meteor.host+((Meteor.port==80)?"":":"+Meteor.port)+"/stream.html");
95                            }
96                            clearTimeout(Meteor.pingtimer);
97                            Meteor.pingtimer = setTimeout(Meteor.pollmode, Meteor.pingtimeout);
98    
99  Meteor.register = function(ifr) {                  } else {
100          instid = new String(ifr.window.frameElement.id);                          Meteor.recvtimes[0] = Meteor.time();
101          instid = instid.replace("meteorframe_", "");                          if (Meteor.updatepollfreqtimer) clearTimeout(Meteor.updatepollfreqtimer);
102          ifr.p = this.instances[instid].process.bind(this.instances[instid]);                          if (Meteor.mode=='smartpoll') Meteor.updatepollfreqtimer = setInterval(Meteor.updatepollfreq, 10000);
103          ifr.r = this.instances[instid].reset.bind(this.instances[instid]);                          if (Meteor.mode=='longpoll') Meteor.pollfreq = Meteor.minpollfreq;
104          ifr.eof = this.instances[instid].eof.bind(this.instances[instid]);                          Meteor.poll();
105          ifr.get = this.instances[instid].get.bind(this.instances[instid]);                  }
106          ifr.increasepolldelay = this.instances[instid].increasepolldelay.bind(this.instances[instid]);          },
 }  
107    
108  Meteor.setServerTime = function(timestamp) {          disconnect: function() {
109          var now = new Date();                  if (Meteor.status) {
110          var clienttime = (now.getTime() / 1000);                          clearTimeout(Meteor.pingtimer);
111          Meteor.servertimeoffset = timestamp - clienttime;                          clearTimeout(Meteor.updatepollfreqtimer);
112  }                          clearTimeout(Meteor.frameloadtimer);
113                            if (typeof CollectGarbage == 'function') CollectGarbage();
114                            if (Meteor.status != 6) Meteor.setstatus(0);
115                            Meteor.log("Disconnected");
116                            try { Meteor.frameref.parentNode.removeChild(Meteor.frameref); delete Meteor.frameref; return true; } catch(e) { }
117                            try { Meteor.frameref.open(); Meteor.frameref.close(); return true; } catch(e) {}                      
118                    }
119            },
120            
121            selectStreamTransport: function() {
122                    try {
123                            var test = ActiveXObject;
124                            return "iframe";
125                    } catch (e) {}
126                    if ((typeof window.addEventStream) == "function") return "iframe";
127                    return "xhrinteractive";
128            },
129    
130            getSubsUrl: function() {
131                    var host = ((Meteor.mode=='simplepoll' || Meteor.mode=='smartpoll' || Meteor.mode=='longpoll') && Meteor.pollhost) ? Meteor.pollhost : Meteor.host;
132                    var surl = "http://" + host + ((Meteor.port==80)?"":":"+Meteor.port) + "/push/" + Meteor.hostid + "/" + Meteor.mode;
133                    for (var c in Meteor.channels) {
134                            surl += "/"+c;
135                            if (typeof Meteor.channels[c].lastmsgreceived != 'undefined') {
136                                    surl += ".r"+(Meteor.channels[c].lastmsgreceived+1);
137                            } else if (Meteor.channels[c].backtrack > 0) {
138                                    surl += ".b"+Meteor.channels[c].backtrack;
139                            } else if (Meteor.channels[c].backtrack != undefined) {
140                                    surl += ".h";
141                            }
142                    }
143                    surl += "?nc="+Meteor.time();
144                    return surl;
145            },
146    
147            loadFrame: function(url) {
148                    try {
149                            if (!Meteor.frameref) {
150                                    var transferDoc = new ActiveXObject("htmlfile");
151                                    Meteor.frameref = transferDoc;
152                            }
153                            Meteor.frameref.open();
154                            Meteor.frameref.write("<html><script>");
155                            Meteor.frameref.write("document.domain=\""+(document.domain)+"\";");
156                            Meteor.frameref.write("</"+"script></html>");
157                            Meteor.frameref.parentWindow.Meteor = Meteor;
158                            Meteor.frameref.close();
159                            var ifrDiv = Meteor.frameref.createElement("div");
160                            Meteor.frameref.appendChild(ifrDiv);
161                            ifrDiv.innerHTML = "<iframe src=\""+url+"\"></iframe>";
162                    } catch (e) {
163                            if (!Meteor.frameref) {
164                                    var ifr = document.createElement("IFRAME");
165                                    ifr.style.width = "10px";
166                                    ifr.style.height = "10px";
167                                    ifr.style.border = "none";
168                                    ifr.style.position = "absolute";
169                                    ifr.style.top = "-10px";
170                                    ifr.style.marginTop = "-10px";
171                                    ifr.style.zIndex = "-20";
172                                    ifr.Meteor = Meteor;
173                                    document.body.appendChild(ifr);
174                                    Meteor.frameref = ifr;
175                            }
176                            Meteor.frameref.setAttribute("src", url);
177                    }
178                    Meteor.log("Loading URL '"+url+"' into frame...");
179                    Meteor.frameloadtimer = setTimeout(Meteor.frameloadtimeout, 5000);
180            },
181    
182            pollmode: function() {
183                    Meteor.log("Ping timeout");
184                    if (Meteor.mode != "smartpoll") {
185                            Meteor.mode="smartpoll";
186                            Meteor.callbacks["changemode"]("poll");
187                            clearTimeout(Meteor.pingtimer);
188                            Meteor.lastpingtime = false;
189                    }
190                    Meteor.connect();
191            },
192    
193  Meteor.prototype.start = function() {          process: function(id, channel, data) {
194          this.persist = (this.maxmessages)?1:0;                  if (id == -1) {
195          this.smartpoll = (this.smartpoll)?1:0;                          Meteor.log("Ping");
196          this.mode = (this.mode=="stream")?"stream":"poll";                          Meteor.ping();
197          if (!this.subdomain || !this.channel) throw "Channel or Meteor subdomain host not specified";                  } else if (typeof(Meteor.channels[channel]) != "undefined") {
198          var now = new Date();                          Meteor.log("Message "+id+" received on channel "+channel+" (last id on channel: "+Meteor.channels[channel].lastmsgreceived+")\n"+data);
199          var t = now.getTime();                          Meteor.callbacks["process"](data);
200          if (typeof(this.transferDoc)=="object") {                          Meteor.channels[channel].lastmsgreceived = id;
201                  this.transferDoc.open();                          if (Meteor.mode=="smartpoll") {
202                  this.transferDoc.close();                                  Meteor.recvtimes[Meteor.recvtimes.length] = Meteor.time();
203                  delete this.transferDoc;                                  while (Meteor.recvtimes.length > 5) Meteor.recvtimes.shift();
         }  
         if (document.getElementById("meteorframe_"+this.instID)) {  
                 document.body.removeChild(document.getElementById("meteorframe_"+this.instID));  
         }  
         if (this.mode=="stream") {  
                 if (document.all) {  
                         this.transferDoc = new ActiveXObject("htmlfile");  
                         this.transferDoc.open();  
                         this.transferDoc.write("<html>");  
                         this.transferDoc.write("<script>document.domain=\""+(document.domain)+"\";</"+"script>");  
                         this.transferDoc.write("</html>");  
                         var selfref = this;  
                         this.transferDoc.parentWindow.Meteor = Meteor;  
                         this.transferDoc.close();  
                         var ifrDiv = this.transferDoc.createElement("div");  
                         this.transferDoc.appendChild(ifrDiv);  
                         var url = "http://"+this.subdomain+"."+location.hostname+"/"+this.dynamicpageaddress+"?channel="+this.channel+"&id="+this.MHostId;  
                         if (this.lastmsgreceived >= 0) {  
                                 url += "&restartfrom="+this.lastmsgreceived;  
                         } else if (this.backtrack > 0) {  
                                 url += "&backtrack="+this.backtrack;  
                         } else if (this.backtrack < 0 || isNaN(this.backtrack)) {  
                                 url += "&restartfrom=";  
204                          }                          }
205                          ifrDiv.innerHTML = "<iframe id=\"meteorframe_"+this.instID+"\" src=\""+url+"&nocache="+t+"\" style=\"display: none;\"></iframe>";                  }
206                  } else {                  Meteor.setstatus(5);
207                          var ifr = document.createElement("IFRAME");          },
                         ifr.style.width = "10px";  
                         ifr.style.height = "10px";  
                         ifr.style.border = "none";  
                         ifr.style.position = "absolute";  
                         ifr.style.top = "-10px";  
                         ifr.style.marginTop = "-10px";  
                         ifr.style.zIndex = "-20";  
                         ifr.id = "meteorframe_"+this.instID;  
                         document.body.appendChild(ifr);  
                         ifr.src = "http://"+this.subdomain+"."+location.hostname+"/stream.html?nocache="+t;  
                 }  
                 var f = this.pollmode.bind(this);  
                 clearTimeout(this.pingtimer);  
                 this.pingtimer = setTimeout(f, this.pingtimeout);  
   
         } else {  
                 var ifr = document.createElement("IFRAME");  
                 ifr.style.width = "10px";  
                 ifr.style.height = "10px";  
                 ifr.style.border = "none";  
                 if (document.all) {  
                         ifr.style.display = "none";  
                 } else {  
                         ifr.style.position = "absolute";  
                         ifr.style.marginTop = "-10px";  
                         ifr.style.zIndex = "-20";  
                 }  
                 ifr.id = "meteorframe_"+this.instID;  
                 document.body.appendChild(ifr);  
                 ifr.src = "http://"+this.subdomain+"."+location.hostname+"/poll.html?nocache="+t;  
                 this.recvtimes[0] = t;  
                 if (this.updatepollfreqtimer) clearTimeout(this.updatepollfreqtimer);  
                 this.updatepollfreqtimer = setInterval(this.updatepollfreq.bind(this), 2500);  
         }  
         this.lastrequest = t;  
 }  
208    
209  Meteor.prototype.pollmode = function() {          ping: function() {
210          this.mode="poll";                  if (Meteor.pingtimer) {
211          this.start();                          clearTimeout(Meteor.pingtimer);
212          this.callback_changemode("poll");                          Meteor.pingtimer = setTimeout(Meteor.pollmode, Meteor.pingtimeout);
213  }                          Meteor.lastpingtime = Meteor.time();
214                    }
215                    Meteor.setstatus(5);
216            },
217    
218  Meteor.prototype.process = function(id, data) {          reset: function() {
219          if (id > this.lastmsgreceived) {                  if (Meteor.status != 6 && Meteor.status != 0) {
220                  this.callback_process(data);                          Meteor.log("Stream reset");
221                  if (id != -1) this.lastmsgreceived = id;                          Meteor.ping();
222                  if (this.mode=="poll") {                          Meteor.callbacks["reset"]();
223                          var now = new Date();                          var x = Meteor.pollfreq - (Meteor.time()-Meteor.lastrequest);
224                          var t = now.getTime();                          if (x < 10) x = 10;
225                          this.recvtimes[this.recvtimes.length] = t;                          setTimeout(Meteor.connect, x);
                         while (this.recvtimes.length > 5) this.recvtimes.shift();  
226                  }                  }
227          } else if (id == -1) {          },
                 this.ping();  
         }  
 }  
228    
229  Meteor.prototype.ping = function() {          eof: function() {
230          if (this.mode=="stream" && this.pingtimer) {                  Meteor.log("Received end of stream, will not reconnect");
231                  clearTimeout(this.pingtimer);                  Meteor.callbacks["eof"]();
232                  var f = this.pollmode.bind(this);                  Meteor.setstatus(6);
233                  this.pingtimer = setTimeout(f, this.pingtimeout);                  Meteor.disconnect();
234                  var now = new Date();          },
235                  this.lastpingtime = now.getTime();  
236          }          channelInfo: function(channel, id) {
237  }                  Meteor.channels[channel].lastmsgreceived = id;
238                    Meteor.log("Received channel info for channel "+channel+": resume from "+id);
239            },
240    
241  Meteor.prototype.reset = function() {          updatepollfreq: function() {
242          var now = new Date();                  var avg = 0;
243          var t = now.getTime();                  for (var i=1; i<Meteor.recvtimes.length; i++) {
244          var x = this.pollfreq - (t-this.lastrequest);                          avg += (Meteor.recvtimes[i]-Meteor.recvtimes[i-1]);
245          if (x < 10) x = 10;                  }
246          this.ping();                  avg += (Meteor.time()-Meteor.recvtimes[Meteor.recvtimes.length-1]);
247          this.callback_reset();                  avg /= Meteor.recvtimes.length;
248          setTimeout(this.start.bind(this), x);                  var target = avg/2;
249  }                  if (target < Meteor.pollfreq && Meteor.pollfreq > Meteor.minpollfreq) Meteor.pollfreq = Math.ceil(Meteor.pollfreq*0.9);
250                    if (target > Meteor.pollfreq && Meteor.pollfreq < Meteor.maxpollfreq) Meteor.pollfreq = Math.floor(Meteor.pollfreq*1.05);
251            },
252    
253            registerEventCallback: function(evt, funcRef) {
254                    Function.prototype.andThen=function(g) {
255                            var f=this;
256                            var a=Meteor.arguments
257                            return function(args) {
258                                    f(a);g(args);
259                            }
260                    };
261                    if (typeof Meteor.callbacks[evt] == "function") {
262                            Meteor.callbacks[evt] = (Meteor.callbacks[evt]).andThen(funcRef);
263                    } else {
264                            Meteor.callbacks[evt] = funcRef;
265                    }
266            },
267    
268  Meteor.prototype.eof = function() {          frameloadtimeout: function() {
269          this.callback_eof();                  Meteor.log("Frame load timeout");
270  }                  if (Meteor.frameloadtimer) clearTimeout(Meteor.frameloadtimer);
271                    Meteor.setstatus(3);
272                    Meteor.pollmode();
273            },
274    
275            extract_xss_domain: function(old_domain) {
276                    if (old_domain.match(/^(\d{1,3}\.){3}\d{1,3}$/)) return old_domain;
277                    domain_pieces = old_domain.split('.');
278                    return domain_pieces.slice(-2, domain_pieces.length).join(".");
279            },
280    
281            setstatus: function(newstatus) {
282                    // Statuses:    0 = Uninitialised,
283                    //                              1 = Loading stream,
284                    //                              2 = Loading controller frame,
285                    //                              3 = Controller frame timeout, retrying.
286                    //                              4 = Controller frame loaded and ready
287                    //                              5 = Receiving data
288                    //                              6 = End of stream, will not reconnect
289    
290                    if (Meteor.status != newstatus) {
291                            Meteor.status = newstatus;
292                            Meteor.callbacks["statuschanged"](newstatus);
293                    }
294            },
295    
296  Meteor.prototype.get = function(varname) {          log: function(logstr) {
297          eval("var a = this."+varname+";");                  if (Meteor.debugmode) {
298          if (typeof(a) == "undefined") throw "Cannot get value of "+varname;                          if (window.console) {
299          return a;                                  window.console.log(logstr);
300  }                          } else if (document.getElementById("meteorlogoutput")) {
301                                    document.getElementById("meteorlogoutput").innerHTML += logstr+"<br/>";
302                            }
303                    }
304            },
305    
306  Meteor.prototype.increasepolldelay = function() {          poll: function() {
307          this.pollfreq *= 2;                  Meteor.pollaborted = 0;
308  }                  try {
309                            clearTimeout(Meteor.polltimer);
310                    } catch (e) {};
311                    Meteor.lastrequest = Meteor.time();
312                    if (Meteor.polltimeout) Meteor.polltimer = setTimeout(Meteor.clearpoll, Meteor.polltimeout);
313                    var scripttag = document.createElement("SCRIPT");
314                    scripttag.type = "text/javascript";
315                    scripttag.src = Meteor.getSubsUrl();
316                    scripttag.id = "meteorpoll"+(++Meteor.pollnum);
317                    scripttag.className = "meteorpoll";
318                    document.getElementsByTagName("HEAD")[0].appendChild(scripttag);
319            },
320    
321            clearpoll: function() {
322                    var s = document.getElementById('meteorpoll'+Meteor.pollnum);
323                    if (typeof s != 'undefined') s.parentNode.removeChild(s);
324                    if (Meteor.status) {
325                            var x = parent.Meteor.pollfreq - (Meteor.time()-Meteor.lastrequest);
326                            if (x < 10) x = 10;
327                            setTimeout(Meteor.poll, x);
328                    }
329            },
330    
331  Meteor.prototype.updatepollfreq = function() {          time: function() {
         if (this.smartpoll) {  
332                  var now = new Date();                  var now = new Date();
333                  var t = now.getTime();                  return now.getTime();
                 var avg = 0;  
                 for (var i=1; i<this.recvtimes.length; i++) {  
                         var x = (this.recvtimes[i]-this.recvtimes[i-1]);  
                         avg += (x>60000)? 60000 : x;  
                 }  
                 x = (t-this.recvtimes[this.recvtimes.length-1]);  
                 avg += (x>180000)? 180000 : x;  
                 avg /= this.recvtimes.length;  
                 if ((avg/3) < this.pollfreq && (avg/3) >= this.minpollfreq) this.pollfreq = Math.ceil(this.pollfreq*0.9);  
                 if ((avg/3) > this.pollfreq) this.pollfreq = Math.floor(this.pollfreq*1.05);  
         }  
 }  
   
 Meteor.prototype.registerEventCallback = function(evt, funcRef) {  
         if (evt=="process") {  
                 this.callback_process = (this.callback_process).andThen(funcRef);  
         } else if (evt=="reset") {  
                 this.callback_reset = (this.callback_reset).andThen(funcRef);  
         } else if (evt=="eof") {  
                 this.callback_eof = (this.callback_eof).andThen(funcRef);  
         } else if (evt=="changemode") {  
                 this.callback_changemode = (this.callback_changemode).andThen(funcRef);  
334          }          }
335  }  }
336    
337    var oldonunload = window.onunload;
338  Meteor.createCookie = function(name,value,days) {  if (typeof window.onunload != 'function') {
339          if (days) {          window.onunload = Meteor.disconnect;
340                  var date = new Date();  } else {
341                  date.setTime(date.getTime()+(days*24*60*60*1000));          window.onunload = function() {
342                  var expires = "; expires="+date.toGMTString();                  if (oldonunload) oldonunload();
343                    Meteor.disconnect();
344          }          }
         else var expires = "";  
         document.cookie = name+"="+value+expires+"; path=/";  
 }  
   
 Meteor.readCookie = function(name) {  
         var nameEQ = name + "=";  
         var ca = document.cookie.split(';');  
         for(var i=0;i < ca.length;i++) {  
                 var c = ca[i];  
                 while (c.charAt(0)==' ') c = c.substring(1,c.length);  
                 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);  
         }  
         return null;  
 }  
   
 Meteor.eraseCookie = function(name) {  
         createCookie(name,"",-1);  
345  }  }

Legend:
Removed from v.3  
changed lines
  Added in v.62

  ViewVC Help
Powered by ViewVC 1.1.26