1
0
forked from GitHub/gf-core

Minibar: PGF server API: pass callback functions directly instead of passing function names as strings.

This commit is contained in:
hallgren
2010-09-05 18:06:45 +00:00
parent b14592b0d3
commit c662d116f6
2 changed files with 47 additions and 35 deletions

View File

@@ -25,6 +25,18 @@ function jsonp(url,callback)
document.body.appendChild(script);
}
var json = {next:0};
// Like jsonp, but instead of passing the name of the ballback function, you
// pass the callback function directly, making it possible to use anonymous
// functions.
function jsonpf(url,callback)
{
var name="callback"+(json.next++);
json[name]=function(x) { delete json[name]; callback(x); }
jsonp(url,"json."+name);
}
/* --- HTML construction ---------------------------------------------------- */
function text(s) { return document.createTextNode(s); }