// authentication, and a hash of team objects, indexed by team-name.
//
var mkws = {
+ $: $, // Our own local copy of the jQuery object
authenticated: false,
log_level: 1, // Will be overridden from mkws.config, but
// initial value allows jQuery popup to use logging.
sort_default: "relevance",
perpage_default: 20,
query_width: 50,
- show_lang: true, /* show/hide language menu */
- show_sort: true, /* show/hide sort menu */
- show_perpage: true, /* show/hide perpage menu */
- lang_options: [], /* display languages links for given languages, [] for all */
+ show_lang: true, /* show/hide language menu */
+ show_sort: true, /* show/hide sort menu */
+ show_perpage: true, /* show/hide perpage menu */
+ lang_options: [], /* display languages links for given languages, [] for all */
facets: ["xtargets", "subject", "author"], /* display facets, in this order, [] for none */
responsive_design_width: undefined, /* a page with less pixel width considered as narrow */
log_level: 1, /* log level for development: 0..2 */
<td>\
{{md-title}}\
{{#if md-title-remainder}}\
- ({{md-title-remainder}})\
+ ({{md-title-remainder}})\
{{/if}}\
{{#if md-title-responsibility}}\
- <i>{{md-title-responsibility}}</i>\
+ <i>{{md-title-responsibility}}</i>\
{{/if}}\
</td>\
</tr>\
<th>{{mkws-translate "Links"}}</th>\
<td>\
{{#each md-electronic-url}}\
- <a href="{{this}}">Link{{mkws-index1}}</a>\
+ <a href="{{this}}">Link{{mkws-index1}}</a>\
{{/each}}\
</td>\
</tr>\
<th>{{mkws-translate "Subject"}}</th>\
<td>\
{{#mkws-first location having="md-subject"}}\
- {{#if md-subject}}\
- {{#mkws-commaList md-subject}}\
- {{this}}{{/mkws-commaList}}\
- {{/if}}\
+ {{#if md-subject}}\
+ {{#mkws-commaList md-subject}}\
+ {{this}}{{/mkws-commaList}}\
+ {{/if}}\
{{/mkws-first}}\
</td>\
</tr>\
<th>{{mkws-translate "Locations"}}</th>\
<td>\
{{#mkws-commaList location}}\
- {{mkws-attr "@name"}}{{/mkws-commaList}}\
+ {{mkws-attr "@name"}}{{/mkws-commaList}}\
</td>\
</tr>\
</table>\
return '\
<a href="#" id="{{_id}}" onclick="{{_onclick}}">\
{{#mkws-first md-thumburl}}\
- <img src="{{this}}" alt="{{../md-title}}"/>\
+ <img src="{{this}}" alt="{{../md-title}}"/>\
{{/mkws-first}}\
- <br/>\
+ <br/>\
</a>\
';
}
// wrapper to call team() after page load
(function(j) {
var log = mkws.log;
+ var $ = j; // XXX
function handleNodeWithTeam(node, callback) {
// First branch for DOM objects; second branch for jQuery objects
for (var i = 0; i < list.length; i++) {
var cname = list[i];
if (cname.match(/^mkwsTeam_/)) {
- teamName = cname.replace(/^mkwsTeam_/, '');
+ teamName = cname.replace(/^mkwsTeam_/, '');
} else if (cname.match(/^mkws/)) {
- type = cname.replace(/^mkws/, '');
+ type = cname.replace(/^mkws/, '');
}
}
var w1 = team.widget(t + "-Container-" + from);
var w2 = team.widget(t + "-Container-" + to);
if (w1) {
- $(w1.node).hide();
+ w1.jqnode.hide();
}
if (w2) {
- $(w2.node).show();
- $(w.node).appendTo($(w2.node));
+ w2.jqnode.show();
+ w.jqnode.appendTo(w2.jqnode);
}
});
team.queue("resize-" + to).publish();
request.get(null, function(data) {
if (!$.isXMLDoc(data)) {
- alert("service proxy auth response document is not valid XML document, give up!");
- return;
+ alert("service proxy auth response document is not valid XML document, give up!");
+ return;
}
var status = $(data).find("status");
if (status.text() != "OK") {
- alert("service proxy auth response status: " + status.text() + ", give up!");
- return;
+ alert("service proxy auth response status: " + status.text() + ", give up!");
+ return;
}
log("Service proxy auth successfully done");
// You'd think there would be a better way to do this:
var realm = $(data).find("realm:not(realmAttributes realm)").text();
for (var teamName in mkws.teams) {
- mkws.teams[teamName].queue("authenticated").publish(authName, realm);
+ mkws.teams[teamName].queue("authenticated").publish(authName, realm);
}
runAutoSearches();
}
+ function selectorForAllWidgets() {
+ if (mkws.config.scan_all_nodes) {
+ // This is the old version, which works by telling jQuery to
+ // find every node that has a class beginning with "mkws". In
+ // theory it should be slower than the class-based selector; but
+ // instrumentation suprisnigly shows this is consistently
+ // faster. It also has the advantage that any widgets of
+ // non-registered types are logged as warnings rather than
+ // silently ignored.
+ return '[class^="mkws"],[class*=" mkws"]';
+ } else {
+ // This is the new version, which works by looking up the
+ // specific classes of all registered widget types and their
+ // resize containers. Because all it requires jQuery to do is
+ // some hash lookups in pre-built tables, it should be very
+ // fast; but it silently ignores widgets of unregistered types.
+ var s = "";
+ for (var type in mkws.widgetType2function) {
+ if (s) s += ',';
+ s += '.mkws' + type;
+ s += ',.mkws' + type + "-Container-wide";
+ s += ',.mkws' + type + "-Container-narrow";
+ }
+ return s;
+ }
+ }
+
+
function makeWidgetsWithin(level, node) {
- node.find('[class^="mkws"],[class*=" mkws"]').each(function() {
+ node.find(selectorForAllWidgets()).each(function() {
handleNodeWithTeam(this, function(tname, type) {
- var oldHTML = this.innerHTML;
var myTeam = mkws.teams[tname];
+ if (!myTeam) {
+ myTeam = mkws.teams[tname] = team(j, tname);
+ log("Made MKWS team '" + tname + "'");
+ }
+
+ var oldHTML = this.innerHTML;
var myWidget = widget(j, myTeam, type, this);
myTeam.addWidget(myWidget);
var newHTML = this.innerHTML;
for (var key in mkws.config) {
if (mkws.config.hasOwnProperty(key)) {
- if (key.match(/^language_/)) {
- var lang = key.replace(/^language_/, "");
- // Copy custom languages into list
- mkws.locale_lang[lang] = mkws.config[key];
- log("Added locally configured language '" + lang + "'");
- }
+ if (key.match(/^language_/)) {
+ var lang = key.replace(/^language_/, "");
+ // Copy custom languages into list
+ mkws.locale_lang[lang] = mkws.config[key];
+ log("Added locally configured language '" + lang + "'");
+ }
}
}
// Backwards compatibility: set new magic class names on any
// elements that have the old magic IDs.
var ids = [ "Switch", "Lang", "Search", "Pager", "Navi",
- "Results", "Records", "Targets", "Ranking",
- "Termlists", "Stat", "MOTD" ];
+ "Results", "Records", "Targets", "Ranking",
+ "Termlists", "Stat", "MOTD" ];
for (var i = 0; i < ids.length; i++) {
var id = 'mkws' + ids[i];
var node = $('#' + id);
if (node.attr('id')) {
- node.addClass(id);
- log("added magic class to '" + node.attr('id') + "'");
+ node.addClass(id);
+ log("added magic class to '" + node.attr('id') + "'");
}
}
- // Find all nodes with an MKWS class, and determine their team from
- // the mkwsTeam_* class. Make all team objects.
var then = $.now();
- $('[class^="mkws"],[class*=" mkws"]').each(function() {
- handleNodeWithTeam(this, function(tname, type) {
- if (!mkws.teams[tname]) {
- mkws.teams[tname] = team(j, tname);
- log("Made MKWS team '" + tname + "'");
- }
- });
- });
-
makeWidgetsWithin(1, $(':root'));
-
var now = $.now();
+
log("Walking MKWS nodes took " + (now-then) + " ms");
/*
if (mkws.config.use_service_proxy) {
authenticateSession(mkws.config.service_proxy_auth,
- mkws.config.service_proxy_auth_domain,
- mkws.config.pazpar2_url);
+ mkws.config.service_proxy_auth_domain,
+ mkws.config.pazpar2_url);
} else {
// raw pp2
runAutoSearches();