X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=95c3b7467da4a4ff18715f28ed60d454cea9910f;hb=bbaad7fa6b2a2484c7bbdd87b50bd144ab5c1796;hp=b844b58023c00e22c7824d55ba8b65c297a7e5ee;hpb=14e154c511d693fbf864e84e3c8a38a253b5f7d4;p=mkws-moved-to-github.git diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index b844b58..95c3b74 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -142,12 +142,48 @@ 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, node) { + var that = { + team: team, + node: node + }; + + // ### More to do here, surely + + 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 @@ -502,6 +538,8 @@ function team($, teamName) { } debug("triggerSearch(" + m_query + "): filters = " + $.toJSON(m_filters) + ", pp2filter = " + pp2filter + ", params = " + $.toJSON(params)); + // We can use: params.torusquery = "udb=NAME" + // Note: that won't work when running against raw pazpar2 m_paz.search(m_query, m_perpage, m_sort, pp2filter, undefined, params); } @@ -1209,7 +1247,7 @@ function team($, teamName) { tname = cname.replace(/^mkwsTeam_/, ''); } } - callback(tname); + callback.call(this, tname); } @@ -1403,12 +1441,13 @@ function team($, teamName) { // the mkwsTeam_* class. Make all team objects. var then = $.now(); $('[class^="mkws"],[class*=" mkws"]').each(function () { - var node = this; - mkws.handle_node_with_team(node, function(tname) { + mkws.handle_node_with_team(this, function(tname) { if (!mkws.teams[tname]) { mkws.teams[tname] = team(j, tname); debug("Made MKWS team '" + tname + "'"); } + var myTeam = mkws.teams[tname] + var myWidget = widget(j, myTeam, this) }); }); var now = $.now();