danielwanja / flexonrails

Code samples for the Flex on Rais book.

This URL has Read+Write access

Daniel Wanja (author)
Sat May 02 20:15:30 -0700 2009
commit  01b6430e41a567e9d28fdce016f959223f7a0fa3
tree    d6750b24a9a85b5d4e3f2945d144a39d3bc4326e
parent  78729ee15cf582c2b2b5f1c879ed894226d5c403
flexonrails / 20_Server_Push_with_Juggernaut / rails / vendor / plugins / juggernaut_plugin / media / jquerynaut.js
100644 58 lines (48 sloc) 1.613 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Simply overwrites prototype specific functions
// with jquery specific versions
 
Juggernaut.fn.fire_event = function(fx_name) {
     $(document).trigger("juggernaut:" + fx_name);
   };
 
Juggernaut.fn.bindToWindow = function() {
    $(window).bind("load", this, function(e) {
      juggernaut = e.data;
      e.data.appendFlashObject();
    });
  };
 
Juggernaut.toJSON = function(hash) {
    return $.toJSON(hash) ;
  };
 
Juggernaut.parseJSON = function(string) {
    return $.parseJSON(string);
  };
 
Juggernaut.fn.swf = function(){
    return $('#' + this.options.swf_name)[0];
  };
  
Juggernaut.fn.appendElement = function() {
    this.element = $('<div id=juggernaut>');
    $("body").append(this.element);
  };
 
Juggernaut.fn.refreshFlashObject = function(){
    $(this.swf()).remove();
    this.appendFlashObject();
  };
 
Juggernaut.fn.reconnect = function(){
    if(this.options.reconnect_attempts){
      this.attempting_to_reconnect = true;
      this.fire_event('reconnect');
      this.logger('Will attempt to reconnect ' + this.options.reconnect_attempts + ' times, the first in ' + (this.options.reconnect_intervals || 3) + ' seconds');
      var self = this;
      for(var i=0; i < this.options.reconnect_attempts; i++){
        setTimeout(function(){
          if(!self.is_connected){
            self.logger('Attempting reconnect');
            if(!self.ever_been_connected){
              self.refreshFlashObject();
            } else {
              self.connect();
            }
          }
        }, (this.options.reconnect_intervals || 3) * 1000 * (i + 1));
        
      }
    }
  };