X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=2df7c1257f71f1c15c75bc81361ecc9372c4b649;hb=5f4b0ba8b12474e57a93010ce18900ccac950825;hp=abf8c0a16d727906e1b231b19d3baf8ce112e2b6;hpb=ff958c75b3eb12495cecbc7a54ddac04460fb47d;p=mkws-moved-to-github.git diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index abf8c0a..2df7c12 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -142,6 +142,29 @@ var mkws = { }; +// The following PubSub code is modified from the jQuery manual: +// https://api.jquery.com/jQuery.Callbacks/ +// +// Use as: +// mkws.queue("eventName").subscribe(function(param1, param2 ...) { ... }); +// mkws.queue("eventName").publish(arg1, arg2, ...); + +(function() { + var queues = {}; + mkws.queue = function(id) { + if (!queues[id]) { + var callbacks = $.Callbacks(); + queues[id] = { + publish: callbacks.fire, + subscribe: callbacks.add, + unsubscribe: callbacks.remove + }; + } + return queues[id]; + } +}()); + + // Define empty mkws_config for simple applications that don't define it. if (mkws_config == null || typeof mkws_config != 'object') { var mkws_config = {}; @@ -149,13 +172,15 @@ if (mkws_config == null || typeof mkws_config != 'object') { // Factory function for widget objects. -function widget($, team, node) { +function widget($, team, type, node) { var that = { team: team, + type: type, node: node }; - // ### More to do here, surely + // ### More to do here, surely: e.g. wiring into the team + mkws.debug("made widget(team=" + team + ", type=" + type + ", node=" + node); return that; } @@ -895,7 +920,7 @@ function team($, teamName) { // ### There is only one match here by design: fix not to bother looping $('.mkwsSearch.mkwsTeam_' + m_teamName).each(function (i, obj) { var node = this; - mkws.handle_node_with_team(node, function(tname) { + mkws.handle_node_with_team(this, function(tname) { $(node).html('\