Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 6ebbcc3

Browse files
committed
ENH: refs #0377. Add javascript callback framework just like our php one
1 parent 5830e3b commit 6ebbcc3

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

core/public/js/layout/main.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,44 @@
1-
var json
1+
var json;
22
var itemselected = false;
3+
var midas = midas || {};
4+
5+
// Create the callbacks data structure
6+
midas.callbacks = midas.callbacks || {};
7+
8+
/**
9+
* Register a callback function from a module
10+
* @param name The name of the callback
11+
* @param module The module name registering the callback
12+
* @param fn The callback function
13+
*/
14+
midas.registerCallback = function(name, module, fn)
15+
{
16+
if(midas.callbacks[name] == undefined)
17+
{
18+
midas.callbacks[name] = {};
19+
}
20+
midas.callbacks[name][module] = fn;
21+
}
22+
23+
/**
24+
* Perform a callback.
25+
* @param name The name of the callback to run.
26+
* @param args A json object that will be passed to the registered callbacks.
27+
* @return A json object whose keys are the module names and whose values are
28+
* the return value for that module's registered callback.
29+
*/
30+
midas.doCallback = function(name, args)
31+
{
32+
if(midas.callbacks[name] == undefined)
33+
{
34+
return {};
35+
}
36+
var retVal = {};
37+
$.each(midas.callbacks[name], function(index, value) {
38+
retVal[index] = value(args);
39+
});
40+
return retVal;
41+
}
342

443
// Prevent error if console.log is called
544
if (typeof console != "object") {

0 commit comments

Comments
 (0)