};
+// 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
}
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);
}
if (template === undefined) {
// Fall back to generic template if there is no team-specific one
- var node = $("#mkwsTemplate" + name + ".mkwsTeam_" + m_teamName)
+ var node = $(".mkwsTemplate_" + name + ".mkwsTeam_" + m_teamName)
if (!node.length) {
- node = $("#mkwsTemplate" + name + ".mkwsTeam_ALL")
+ node = $(".mkwsTemplate_" + name + ".mkwsTeam_ALL")
}
var source = node.html();
// ### 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('\
<form name="mkwsSearchForm" class="mkwsSearchForm mkwsTeam_' + tname + '" action="" >\
<input class="mkwsQuery mkwsTeam_' + tname + '" type="text" size="' + mkws_config.query_width + '" />\
$('.mkwsSearchForm.mkwsTeam_' + m_teamName).each(function (i, obj) {
debug("adding search-forms for team '" + m_teamName + "'");
var node = this;
- mkws.handle_node_with_team(node, function(tname) {
+ mkws.handle_node_with_team(this, function(tname) {
debug("adding search-form '" + tname + "' for team '" + m_teamName + "'");
$(node).submit(onFormSubmitEventHandler);
});
tname = cname.replace(/^mkwsTeam_/, '');
}
}
- callback(tname);
+ callback.call(this, tname);
}
// Find all nodes with an class, and determine their team from
// 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();
+ debug("Walking MKWS nodes took " + (now-then) + " ms");
if (mkws_config.use_service_proxy) {
authenticate_session(mkws_config.service_proxy_auth,