]> git.mxchange.org Git - friendica-addons.git/blob - widgets/widgets.js
45d36c4d7d184aa120ea6e001a3ec59856e45bfc
[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;
26                 args['a']=this.argstr;
27                 var urlencodedargs = new Array();
28                 for(k in args){ urlencodedargs.push( encodeURIComponent(k)+"="+encodeURIComponent(args[k]) ); }
29         
30                 var url = this.entrypoint + "?"+ urlencodedargs.join("&");
31
32                 this.xmlhttp.open("GET", url  ,true);
33                 this.xmlhttp.send();
34                 this.xmlhttp.obj = this;
35                 this.xmlhttp.onreadystatechange=function(){
36                   if (this.readyState==4){
37                         if (this.status==200) {
38                         cb(this.obj, this.responseText);
39                         } else {
40                                 document.getElementById(this.obj.widgetid).innerHTML="Error loading widget.";
41                         }
42                   }
43                 } 
44
45         },
46         
47         requestcb: function(obj, responseText) {
48                 document.getElementById(obj.widgetid).innerHTML=responseText;
49         },
50         
51         load : function (){
52                 this.getXHRObj();
53                 this.dorequest(null, this.requestcb);
54         }
55
56 };
57
58 (function() {
59         f9a_widget_$widget_id.load();   
60 })();
61
62 document.writeln("<div id='$widget_id' class='f9k_widget'>");
63 document.writeln("<img id='$widget_id_ld' src='$loader'>");
64 document.writeln("</div>");