]> git.mxchange.org Git - friendica-addons.git/blob - widgets/widgets.js
e6382d711d8ab403346fb16eb1ae908c3e7c40ed
[friendica-addons.git] / widgets / widgets.js
1 /**
2  * @author Fabio Comuni
3  */
4
5 var f9a_widget_$widget_id = {
6         entrypoint : "$entrypoint",
7         key     : "$key",
8         widgetid: "$widget_id",
9         argstr: "$args",
10         xmlhttp : null,
11         
12         getXHRObj : function(){
13                 if (window.XMLHttpRequest) {
14                         // code for IE7+, Firefox, Chrome, Opera, Safari
15                         this.xmlhttp = new XMLHttpRequest();
16                 } else {
17                         // code for IE6, IE5
18                         this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
19                 }
20         },
21         
22         dorequest : function(args, cb) {
23                 if (args===null) args = new Array();
24                 args['k']=this.key;
25                 args['s']=window.location.href;
26                 args['a']=this.argstr;
27                 var urlencodedargs = new Array();
28                 for(k in args){ 
29                         if (typeof args[k] != 'function')
30                                 urlencodedargs.push( encodeURIComponent(k)+"="+encodeURIComponent(args[k]) );
31                  }
32                 var url = this.entrypoint + "?"+ urlencodedargs.join("&");
33
34                 this.xmlhttp.open("GET", url  ,true);
35                 this.xmlhttp.send();
36                 this.xmlhttp.obj = this;
37                 this.xmlhttp.onreadystatechange=function(){
38                   if (this.readyState==4){
39                         if (this.status==200) {
40                         cb(this.obj, this.responseText);
41                         } else {
42                                 document.getElementById(this.obj.widgetid).innerHTML="Error loading widget.";
43                         }
44                   }
45                 } 
46
47         },
48         
49         requestcb: function(obj, responseText) {
50                 document.getElementById(obj.widgetid).innerHTML=responseText;
51         },
52         
53         load : function (){
54                 this.getXHRObj();
55                 this.dorequest(null, this.requestcb);
56         }
57
58 };
59
60 (function() {
61         f9a_widget_$widget_id.load();   
62 })();
63
64 document.writeln("<div id='$widget_id' class='f9k_widget'>");
65 document.writeln("<img id='$widget_id_ld' src='$loader'>");
66 document.writeln("</div>");