// you need to disable use strict at the top of the file!!!
if (mkws.log_level >= 3) {
- console.log(arguments.callee.caller);
+ // Works in Chrome; not sure about elsewhere
+ console.trace();
} else if (mkws.log_level >= 2) {
console.log(">>> called from function " + arguments.callee.caller.name + ' <<<');
}
dummy: "dummy"
};
- mkws.config = Object.create(config_default);
+ mkws.config = mkws.objectInheritingFrom(config_default);
for (var k in overrides) {
mkws.config[k] = overrides[k];
}
};
+// This code is from Douglas Crockford's article "Prototypal Inheritance in JavaScript"
+// http://javascript.crockford.com/prototypal.html
+// mkws.objectInheritingFrom behaves the same as Object.create,
+// but since the latter is not available in IE8 we can't use it.
+//
+mkws.objectInheritingFrom = function(o) {
+ function F() {}
+ F.prototype = o;
+ return new F();
+}
+
+
+mkws.defaultTemplate = function(name) {
+ if (name === 'Record') {
+ return '\
+<table>\
+ <tr>\
+ <th>{{translate "Title"}}</th>\
+ <td>\
+ {{md-title}}\
+ {{#if md-title-remainder}}\
+ ({{md-title-remainder}})\
+ {{/if}}\
+ {{#if md-title-responsibility}}\
+ <i>{{md-title-responsibility}}</i>\
+ {{/if}}\
+ </td>\
+ </tr>\
+ {{#if md-date}}\
+ <tr>\
+ <th>{{translate "Date"}}</th>\
+ <td>{{md-date}}</td>\
+ </tr>\
+ {{/if}}\
+ {{#if md-author}}\
+ <tr>\
+ <th>{{translate "Author"}}</th>\
+ <td>{{md-author}}</td>\
+ </tr>\
+ {{/if}}\
+ {{#if md-electronic-url}}\
+ <tr>\
+ <th>{{translate "Links"}}</th>\
+ <td>\
+ {{#each md-electronic-url}}\
+ <a href="{{this}}">Link{{index1}}</a>\
+ {{/each}}\
+ </td>\
+ </tr>\
+ {{/if}}\
+ {{#if-any location having="md-subject"}}\
+ <tr>\
+ <th>{{translate "Subject"}}</th>\
+ <td>\
+ {{#first location having="md-subject"}}\
+ {{#if md-subject}}\
+ {{#commaList md-subject}}\
+ {{this}}{{/commaList}}\
+ {{/if}}\
+ {{/first}}\
+ </td>\
+ </tr>\
+ {{/if-any}}\
+ <tr>\
+ <th>{{translate "Locations"}}</th>\
+ <td>\
+ {{#commaList location}}\
+ {{attr "@name"}}{{/commaList}}\
+ </td>\
+ </tr>\
+</table>\
+';
+ } else if (name === "Summary") {
+ return '\
+<a href="#" id="{{_id}}" onclick="{{_onclick}}">\
+ <b>{{md-title}}</b>\
+</a>\
+{{#if md-title-remainder}}\
+ <span>{{md-title-remainder}}</span>\
+{{/if}}\
+{{#if md-title-responsibility}}\
+ <span><i>{{md-title-responsibility}}</i></span>\
+{{/if}}\
+';
+ } else if (name === "Image") {
+ return '\
+ <a href="#" id="{{_id}}" onclick="{{_onclick}}">\
+ {{#first md-thumburl}}\
+ <img src="{{this}}" alt="{{../md-title}}"/>\
+ {{/first}}\
+ <br/>\
+ </a>\
+';
+ }
+
+ var s = "There is no default '" + name +"' template!";
+ alert(s);
+ return s;
+};
+
+
// The following functions are dispatchers for team methods that
// are called from the UI using a team-name rather than implicit
// context.
mkws.teams[tname].limitQuery(field, value);
};
+mkws.limitCategory = function(tname, id) {
+ mkws.teams[tname].limitCategory(id);
+};
+
mkws.delimitTarget = function(tname, id) {
mkws.teams[tname].delimitTarget(id);
};
type = cname.replace(/^mkws/, '');
}
}
+
+ if (!teamName) teamName = "AUTO";
callback.call(node, teamName, type);
}
log("Service proxy auth successfully done");
mkws.authenticated = true;
var authName = $(data).find("displayName").text();
+ // 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);
+ mkws.teams[teamName].queue("authenticated").publish(authName, realm);
}
runAutoSearches();
}
- // I don't understand why I need this copy, but I do: mkws_config
- // is not visible inside the document.ready function, but the
- // saved copy is.
- var saved_config;
- if (typeof mkws_config === 'undefined') {
- log("setting empty config");
- saved_config = {};
- } else {
- log("using config: " + $.toJSON(mkws_config));
- saved_config = mkws_config;
+ function makeWidgetsWithin(level, node) {
+ node.find('[class^="mkws"],[class*=" mkws"]').each(function() {
+ handleNodeWithTeam(this, function(tname, type) {
+ var oldHTML = this.innerHTML;
+ var myTeam = mkws.teams[tname];
+ var myWidget = widget(j, myTeam, type, this);
+ myTeam.addWidget(myWidget);
+ var newHTML = this.innerHTML;
+ if (newHTML !== oldHTML) {
+ log("widget " + tname + ":" + type + " HTML changed from '" + oldHTML + "' to '" + newHTML + "': reparse!");
+ makeWidgetsWithin(level+1, $(this));
+ }
+ });
+ });
}
$(document).ready(function() {
+ var saved_config;
+ if (typeof mkws_config === 'undefined') {
+ log("setting empty config");
+ saved_config = {};
+ } else {
+ log("using config: " + $.toJSON(mkws_config));
+ saved_config = mkws_config;
+ }
mkws.setMkwsConfig(saved_config);
for (var key in mkws.config) {
}
}
- // For all MKWS-classed nodes that don't have a team
- // specified, set the team to AUTO.
- $('[class^="mkws"],[class*=" mkws"]').each(function() {
- if (!this.className.match(/mkwsTeam_/)) {
- log("adding AUTO team to node with class '" + this.className + "'");
- $(this).addClass('mkwsTeam_AUTO');
- }
- });
-
// Find all nodes with an MKWS class, and determine their team from
// the mkwsTeam_* class. Make all team objects.
var then = $.now();
}
});
});
- // Second pass: make the individual widget objects. This has
- // to be done separately, and after the team-creation, since
- // that sometimes makes new widget nodes (e.g. creating
- // mkwsTermlists inside mkwsResults.
- $('[class^="mkws"],[class*=" mkws"]').each(function() {
- handleNodeWithTeam(this, function(tname, type) {
- var myTeam = mkws.teams[tname];
- var myWidget = widget(j, myTeam, type, this);
- });
- });
+
+ makeWidgetsWithin(1, $(':root'));
+
var now = $.now();
log("Walking MKWS nodes took " + (now-then) + " ms");
+// for (var tName in mkws.teams) {
+// var myTeam = mkws.teams[tName]
+// var types = myTeam.widgetTypes();
+// log("TEAM '" + tName + "' = " + myTeam + " has widget types " + types);
+// for (var i = 0; i < types.length; i++) {
+// var type = types[i];
+// log(" has widget of type '" + type + "': " + myTeam.widget(type));
+// }
+// }
+
if (mkws.config.use_service_proxy) {
authenticateSession(mkws.config.service_proxy_auth,
mkws.config.service_proxy_auth_domain,