From 5290659c2c5d6f5fe8dab957854470bba5b3d736 Mon Sep 17 00:00:00 2001 From: hallgren Date: Sun, 5 Sep 2010 18:06:45 +0000 Subject: Minibar: PGF server API: pass callback functions directly instead of passing function names as strings. --- src/runtime/javascript/minibar/support.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/runtime/javascript/minibar/support.js') diff --git a/src/runtime/javascript/minibar/support.js b/src/runtime/javascript/minibar/support.js index b322aae86..7c34bad82 100644 --- a/src/runtime/javascript/minibar/support.js +++ b/src/runtime/javascript/minibar/support.js @@ -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); } -- cgit v1.2.3