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