/[meteor]/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 /trunk/public_html/meteor.js

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

googlecode.com/svn/trunk/public_html/meteor.js revision 3 by andrew.betts, Mon Nov 20 17:59:30 2006 UTC trunk/public_html/meteor.js revision 67 by dpavlin, Sat Mar 28 01:42:07 2009 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                    if (!Meteor.host) throw "Meteor host not specified";
81                    if (isNaN(Meteor.port)) throw "Meteor port not specified";
82                    if (!Meteor.channelcount) throw "No channels specified";
83                    if (Meteor.status) Meteor.disconnect();
84                    Meteor.log("Connecting");
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);                          if (Meteor.status != 6) Meteor.setstatus(0);
111          Meteor.servertimeoffset = timestamp - clienttime;                          Meteor.clearpoll();
112  }                          clearTimeout(Meteor.pingtimer);
113                            clearTimeout(Meteor.updatepollfreqtimer);
114                            clearTimeout(Meteor.frameloadtimer);
115                            if (typeof CollectGarbage == 'function') CollectGarbage();
116                            Meteor.log("Disconnected");
117                            try { Meteor.frameref.parentNode.removeChild(Meteor.frameref); delete Meteor.frameref; return true; } catch(e) { }
118                            try { Meteor.frameref.open(); Meteor.frameref.close(); return true; } catch(e) {}                      
119                    }
120            },
121            
122            selectStreamTransport: function() {
123                    try {
124                            var test = ActiveXObject;
125                            return "iframe";
126                    } catch (e) {}
127                    if ((typeof window.addEventStream) == "function") return "iframe";
128                    return "xhrinteractive";
129            },
130    
131            getSubsUrl: function() {
132                    var host = ((Meteor.mode=='simplepoll' || Meteor.mode=='smartpoll' || Meteor.mode=='longpoll') && Meteor.pollhost) ? Meteor.pollhost : Meteor.host;
133                    var surl = "http://" + host + ((Meteor.port==80)?"":":"+Meteor.port) + "/push/" + Meteor.hostid + "/" + Meteor.mode;
134                    for (var c in Meteor.channels) {
135                            surl += "/"+c;
136                            if (typeof Meteor.channels[c].lastmsgreceived != 'undefined') {
137                                    surl += ".r"+(Meteor.channels[c].lastmsgreceived+1);
138                            } else if (Meteor.channels[c].backtrack > 0) {
139                                    surl += ".b"+Meteor.channels[c].backtrack;
140                            } else if (Meteor.channels[c].backtrack != undefined) {
141                                    surl += ".h";
142                            }
143                    }
144                    surl += "?nc="+Meteor.time();
145                    return surl;
146            },
147    
148            loadFrame: function(url) {
149                    try {
150                            if (!Meteor.frameref) {
151                                    var transferDoc = new ActiveXObject("htmlfile");
152                                    Meteor.frameref = transferDoc;
153                            }
154                            Meteor.frameref.open();
155                            Meteor.frameref.write("<html><script>");
156                            Meteor.frameref.write("document.domain=\""+(document.domain)+"\";");
157                            Meteor.frameref.write("</"+"script></html>");
158                            Meteor.frameref.parentWindow.Meteor = Meteor;
159                            Meteor.frameref.close();
160                            var ifrDiv = Meteor.frameref.createElement("div");
161                            Meteor.frameref.appendChild(ifrDiv);
162                            ifrDiv.innerHTML = "<iframe src=\""+url+"\"></iframe>";
163                    } catch (e) {
164                            if (!Meteor.frameref) {
165                                    var ifr = document.createElement("IFRAME");
166                                    ifr.style.width = "10px";
167                                    ifr.style.height = "10px";
168                                    ifr.style.border = "none";
169                                    ifr.style.position = "absolute";
170                                    ifr.style.top = "-10px";
171                                    ifr.style.marginTop = "-10px";
172                                    ifr.style.zIndex = "-20";
173                                    ifr.Meteor = Meteor;
174                                    document.body.appendChild(ifr);
175                                    Meteor.frameref = ifr;
176                            }
177                            Meteor.frameref.setAttribute("src", url);
178                    }
179                    Meteor.log("Loading URL '"+url+"' into frame...");
180                    Meteor.frameloadtimer = setTimeout(Meteor.frameloadtimeout, 5000);
181            },
182    
183            pollmode: function() {
184                    Meteor.log("Ping timeout");
185                    if (Meteor.mode != "smartpoll") {
186                            Meteor.mode="smartpoll";
187                            Meteor.callbacks["changemode"]("poll");
188                            clearTimeout(Meteor.pingtimer);
189                            Meteor.lastpingtime = false;
190                    }
191                    Meteor.connect();
192            },
193    
194  Meteor.prototype.start = function() {          process: function(id, channel, data) {
195          this.persist = (this.maxmessages)?1:0;                  if (id == -1) {
196          this.smartpoll = (this.smartpoll)?1:0;                          Meteor.log("Ping");
197          this.mode = (this.mode=="stream")?"stream":"poll";                          Meteor.ping();
198          if (!this.subdomain || !this.channel) throw "Channel or Meteor subdomain host not specified";                  } else if (typeof(Meteor.channels[channel]) != "undefined") {
199          var now = new Date();                          Meteor.log("Message "+id+" received on channel "+channel+" (last id on channel: "+Meteor.channels[channel].lastmsgreceived+")\n"+data);
200          var t = now.getTime();                          Meteor.callbacks["process"](data);
201          if (typeof(this.transferDoc)=="object") {                          Meteor.channels[channel].lastmsgreceived = id;
202                  this.transferDoc.open();                          if (Meteor.mode=="smartpoll") {
203                  this.transferDoc.close();                                  Meteor.recvtimes[Meteor.recvtimes.length] = Meteor.time();
204                  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=";  
205                          }                          }
206                          ifrDiv.innerHTML = "<iframe id=\"meteorframe_"+this.instID+"\" src=\""+url+"&nocache="+t+"\" style=\"display: none;\"></iframe>";                  }
207                  } else {                  Meteor.setstatus(5);
208                          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;  
 }  
209    
210  Meteor.prototype.pollmode = function() {          ping: function() {
211          this.mode="poll";                  if (Meteor.pingtimer) {
212          this.start();                          clearTimeout(Meteor.pingtimer);
213          this.callback_changemode("poll");                          Meteor.pingtimer = setTimeout(Meteor.pollmode, Meteor.pingtimeout);
214  }                          Meteor.lastpingtime = Meteor.time();
215                    }
216                    Meteor.setstatus(5);
217            },
218    
219  Meteor.prototype.process = function(id, data) {          reset: function() {
220          if (id > this.lastmsgreceived) {                  if (Meteor.status != 6 && Meteor.status != 0) {
221                  this.callback_process(data);                          Meteor.log("Stream reset");
222                  if (id != -1) this.lastmsgreceived = id;                          Meteor.ping();
223                  if (this.mode=="poll") {                          Meteor.callbacks["reset"]();
224                          var now = new Date();                          var x = Meteor.pollfreq - (Meteor.time()-Meteor.lastrequest);
225                          var t = now.getTime();                          if (x < 10) x = 10;
226                          this.recvtimes[this.recvtimes.length] = t;                          setTimeout(Meteor.connect, x);
                         while (this.recvtimes.length > 5) this.recvtimes.shift();  
227                  }                  }
228          } else if (id == -1) {          },
                 this.ping();  
         }  
 }  
229    
230  Meteor.prototype.ping = function() {          eof: function() {
231          if (this.mode=="stream" && this.pingtimer) {                  Meteor.log("Received end of stream, will not reconnect");
232                  clearTimeout(this.pingtimer);                  Meteor.callbacks["eof"]();
233                  var f = this.pollmode.bind(this);                  Meteor.setstatus(6);
234                  this.pingtimer = setTimeout(f, this.pingtimeout);                  Meteor.disconnect();
235                  var now = new Date();          },
236                  this.lastpingtime = now.getTime();  
237          }          channelInfo: function(channel, id) {
238  }                  Meteor.channels[channel].lastmsgreceived = id;
239                    Meteor.log("Received channel info for channel "+channel+": resume from "+id);
240            },
241    
242  Meteor.prototype.reset = function() {          updatepollfreq: function() {
243          var now = new Date();                  var avg = 0;
244          var t = now.getTime();                  for (var i=1; i<Meteor.recvtimes.length; i++) {
245          var x = this.pollfreq - (t-this.lastrequest);                          avg += (Meteor.recvtimes[i]-Meteor.recvtimes[i-1]);
246          if (x < 10) x = 10;                  }
247          this.ping();                  avg += (Meteor.time()-Meteor.recvtimes[Meteor.recvtimes.length-1]);
248          this.callback_reset();                  avg /= Meteor.recvtimes.length;
249          setTimeout(this.start.bind(this), x);                  var target = avg/2;
250  }                  if (target < Meteor.pollfreq && Meteor.pollfreq > Meteor.minpollfreq) Meteor.pollfreq = Math.ceil(Meteor.pollfreq*0.9);
251                    if (target > Meteor.pollfreq && Meteor.pollfreq < Meteor.maxpollfreq) Meteor.pollfreq = Math.floor(Meteor.pollfreq*1.05);
252            },
253    
254            registerEventCallback: function(evt, funcRef) {
255                    Function.prototype.andThen=function(g) {
256                            var f=this;
257                            var a=Meteor.arguments
258                            return function(args) {
259                                    f(a);g(args);
260                            }
261                    };
262                    if (typeof Meteor.callbacks[evt] == "function") {
263                            Meteor.callbacks[evt] = (Meteor.callbacks[evt]).andThen(funcRef);
264                    } else {
265                            Meteor.callbacks[evt] = funcRef;
266                    }
267            },
268    
269  Meteor.prototype.eof = function() {          frameloadtimeout: function() {
270          this.callback_eof();                  Meteor.log("Frame load timeout");
271  }                  if (Meteor.frameloadtimer) clearTimeout(Meteor.frameloadtimer);
272                    Meteor.setstatus(3);
273                    Meteor.pollmode();
274            },
275    
276            extract_xss_domain: function(old_domain) {
277                    if (old_domain.match(/^(\d{1,3}\.){3}\d{1,3}$/)) return old_domain;
278                    domain_pieces = old_domain.split('.');
279                    return domain_pieces.slice(-2, domain_pieces.length).join(".");
280            },
281    
282            setstatus: function(newstatus) {
283                    // Statuses:    0 = Uninitialised,
284                    //                              1 = Loading stream,
285                    //                              2 = Loading controller frame,
286                    //                              3 = Controller frame timeout, retrying.
287                    //                              4 = Controller frame loaded and ready
288                    //                              5 = Receiving data
289                    //                              6 = End of stream, will not reconnect
290    
291                    if (Meteor.status != newstatus) {
292                            Meteor.status = newstatus;
293                            Meteor.callbacks["statuschanged"](newstatus);
294                    }
295            },
296    
297  Meteor.prototype.get = function(varname) {          log: function(logstr) {
298          eval("var a = this."+varname+";");                  if (Meteor.debugmode) {
299          if (typeof(a) == "undefined") throw "Cannot get value of "+varname;                          if (window.console) {
300          return a;                                  window.console.log(logstr);
301  }                          } else if (document.getElementById("meteorlogoutput")) {
302                                    document.getElementById("meteorlogoutput").innerHTML += logstr+"<br/>";
303                            }
304                    }
305            },
306    
307  Meteor.prototype.increasepolldelay = function() {          poll: function() {
308          this.pollfreq *= 2;                  Meteor.pollaborted = 0;
309  }                  try {
310                            clearTimeout(Meteor.polltimer);
311                    } catch (e) {};
312                    Meteor.lastrequest = Meteor.time();
313                    if (Meteor.polltimeout) Meteor.polltimer = setTimeout(Meteor.clearpoll, Meteor.polltimeout);
314                    var scripttag = document.createElement("SCRIPT");
315                    scripttag.type = "text/javascript";
316                    scripttag.src = Meteor.getSubsUrl();
317                    scripttag.id = "meteorpoll"+(++Meteor.pollnum);
318                    scripttag.className = "meteorpoll";
319                    document.getElementsByTagName("HEAD")[0].appendChild(scripttag);
320            },
321    
322            clearpoll: function() {
323                    if (document.getElementById('meteorpoll'+Meteor.pollnum)) {
324                            var s = document.getElementById('meteorpoll'+Meteor.pollnum);
325                            s.parentNode.removeChild(s);
326                    }
327                    if (Meteor.status == 5) {
328                            var x = parent.Meteor.pollfreq - (Meteor.time()-Meteor.lastrequest);
329                            if (x < 10) x = 10;
330                            setTimeout(Meteor.poll, x);
331                    }
332            },
333    
334  Meteor.prototype.updatepollfreq = function() {          time: function() {
         if (this.smartpoll) {  
335                  var now = new Date();                  var now = new Date();
336                  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);  
337          }          }
338  }  }
339    
340    var oldonunload = window.onunload;
341  Meteor.createCookie = function(name,value,days) {  if (typeof window.onunload != 'function') {
342          if (days) {          window.onunload = Meteor.disconnect;
343                  var date = new Date();  } else {
344                  date.setTime(date.getTime()+(days*24*60*60*1000));          window.onunload = function() {
345                  var expires = "; expires="+date.toGMTString();                  if (oldonunload) oldonunload();
346                    Meteor.disconnect();
347          }          }
         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);  
348  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26