friendica/addon/widgets/widgets.js

65 lines
1.5 KiB
JavaScript
Raw Normal View History

2011-03-23 13:47:05 +01:00
/**
* @author Fabio Comuni
*/
2011-05-11 17:04:41 +02:00
var f9a_widget_$widget_id = {
2011-03-23 13:47:05 +01:00
entrypoint : "$entrypoint",
key : "$key",
widgetid: "$widget_id",
2011-05-11 17:04:41 +02:00
argstr: "$args",
2011-03-23 13:47:05 +01:00
xmlhttp : null,
getXHRObj : function(){
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
this.xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
},
dorequest : function(args, cb) {
if (args===null) args = new Array();
args['k']=this.key;
args['s']=window.location;
2011-05-11 17:04:41 +02:00
args['a']=this.argstr;
2011-03-23 13:47:05 +01:00
var urlencodedargs = new Array();
for(k in args){ urlencodedargs.push( encodeURIComponent(k)+"="+encodeURIComponent(args[k]) ); }
var url = this.entrypoint + "?"+ urlencodedargs.join("&");
this.xmlhttp.open("GET", url ,true);
this.xmlhttp.send();
2011-05-11 17:04:41 +02:00
this.xmlhttp.obj = this;
2011-03-23 13:47:05 +01:00
this.xmlhttp.onreadystatechange=function(){
if (this.readyState==4){
if (this.status==200) {
2011-05-11 17:04:41 +02:00
cb(this.obj, this.responseText);
2011-03-23 13:47:05 +01:00
} else {
2011-05-11 17:04:41 +02:00
document.getElementById(this.obj.widgetid).innerHTML="Error loading widget.";
2011-03-23 13:47:05 +01:00
}
}
}
},
2011-05-11 17:04:41 +02:00
requestcb: function(obj, responseText) {
document.getElementById(obj.widgetid).innerHTML=responseText;
2011-03-23 13:47:05 +01:00
},
load : function (){
this.getXHRObj();
this.dorequest(null, this.requestcb);
}
};
(function() {
2011-05-11 17:04:41 +02:00
f9a_widget_$widget_id.load();
2011-03-23 13:47:05 +01:00
})();
document.writeln("<div id='$widget_id' class='f9k_widget'>");
document.writeln("<img id='$widget_id_ld' src='$loader'>");
document.writeln("</div>");