X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=75a88c7732ede3629a4134690aa1e3c236c77b2e;hb=d3b27e0d579da1535397fe464b5fb0476f0c0020;hp=c7396844d6cca587506bc448926fa6c24822b423;hpb=ec95c20272197409599daa60edd48298a72312a4;p=mkws-moved-to-github.git diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index c739684..75a88c7 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -142,12 +142,50 @@ 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 = {}; } +// Factory function for widget objects. +function widget($, team, type, node) { + var that = { + team: team, + type: type, + node: node + }; + + // ### More to do here, surely: e.g. wiring into the team + mkws.debug("made widget(team=" + team + ", type=" + type + ", node=" + node); + + return that; +} + + // Factory function for team objects. As much as possible, this uses // only member variables (prefixed "m_") and inner functions with // private scope. Some functions are visibl as member-functions to be @@ -882,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('\