text changes to registration mail content
[namibia] / public / js / vendor / MooTools.js
1 var APE = {
2         Config: {
3                 identifier: 'ape',
4                 init: true,
5                 frequency: 0,
6                 scripts: []
7         }
8 };
9
10 APE.Client = new Class({
11         
12         eventProxy: [],
13
14         fireEvent: function(type, args, delay){
15                 return this.core.fireEvent(type, args, delay);
16         },
17
18         addEvent: function(type, fn, internal){
19                 var newFn = fn.bind(this), ret = this;
20                 if(!$defined(this.core)) this.eventProxy.push([type, fn, internal]);
21                 else {
22                         ret = this.core.addEvent(type, newFn, internal);
23                         this.core.$originalEvents[type] = this.core.$originalEvents[type] || [];
24                         this.core.$originalEvents[type][fn] = newFn;
25                 }
26                 return ret;
27         },
28
29         onRaw: function(type, fn, internal) {
30                 return this.addEvent('raw_' + type.toLowerCase(), fn, internal); 
31         },
32
33         removeEvent: function(type, fn) {
34                 return this.core.removeEvent(type, fn);
35         },
36
37         onCmd: function(type, fn, internal) {
38                 return this.addEvent('cmd_' + type.toLowerCase(), fn, internal); 
39         },
40
41         onError: function(type, fn, internal) {
42                 return this.addEvent('error_' + type, fn, internal); 
43         },
44
45         load: function(config){ 
46                 config = $merge({}, APE.Config, config);
47
48                 // Init function called by core to init core variable
49                 config.init = function(core){
50                         this.core = core;
51                         for(var i = 0; i < this.eventProxy.length; i++){
52                                 this.addEvent.apply(this, this.eventProxy[i]);
53                         }
54                 }.bind(this);
55
56                 //set document.domain
57                 if (config.transport != 2) {
58                         if (config.domain != 'auto') document.domain = config.domain;
59                         if (config.domain == 'auto') document.domain = document.domain;
60                 }
61                 
62                 var tmp = JSON.decode(Cookie.read('APE_Cookie'), {'domain': document.domain});
63
64                 if(tmp) {
65                         config.frequency = tmp.frequency.toInt();
66                 } else {
67                         tmp = {'frequency': 0};
68                 }
69
70                 tmp.frequency = config.frequency + 1;
71
72                 Cookie.write('APE_Cookie', JSON.encode(tmp), {'domain': document.domain});
73                 
74                 var iframe = new Element('iframe', {
75                         id: 'ape_' + config.identifier,
76                         styles: {
77                                 display: 'none',
78                                 position: 'absolute',
79                                 left: -300,
80                                 top: -300
81                         }
82                 }).inject(document.body);
83
84                 iframe.addEvent('load',  function() { 
85                         if (!iframe.contentWindow.APE) setTimeout(iframe.onload, 100);//Sometimes IE fire the onload event, but the iframe is not loaded -_-
86                         else iframe.contentWindow.APE.init(config);
87                 });
88
89                 if (config.transport == 2) {//Special case for JSONP
90                         var doc = iframe.contentDocument;
91                         if (!doc) doc = iframe.contentWindow.document;
92
93                         //If the content of the iframe is created in DOM, the status bar will always load...
94                         //using document.write() is the only way to avoid status bar loading with JSONP
95                         doc.open();
96                         var theHtml = '<html><head>';
97                         for (var i = 0; i < config.scripts.length; i++) {
98                                 theHtml += '<script src="' + config.scripts[i] + '"></script>';
99                         }
100                         theHtml += '</head><body></body></html>';
101                         doc.write(theHtml);
102                         doc.close();
103                 } else { 
104                         //iframe.set('src', (config.secure ? 'https' : 'http') + '://' + config.frequency + '.' + config.server + '/?[{"cmd":"script","params":{"domain":"' + document.domain + '","scripts":["' + config.scripts.join('","') + '"]}}]');
105                         iframe.set('src', (config.secure ? 'https' : 'http') + '://' + config.server + '/?[{"cmd":"script","params":{"domain":"' + document.domain + '","scripts":["' + config.scripts.join('","') + '"]}}]');
106                         if (Browser.Engine.gecko) { 
107                                 // Firefox fix, see bug  #356558 
108                                 // https://bugzilla.mozilla.org/show_bug.cgi?id=356558
109                                 iframe.contentWindow.location.href = iframe.get('src');
110                         }
111                 }       
112
113         }
114         
115 });