+ var request = new pzHttpRequest(auth_url, function(err) {
+ alert("HTTP call for authentication failed: " + err)
+ return;
+ }, auth_domain);
+
+ request.get(null, function(data) {
+ if (!$.isXMLDoc(data)) {
+ 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;
+ }
+
+ log("service proxy authentication successful");
+ 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, realm);
+ }
+
+ runAutoSearches();
+ });
+ }
+
+
+ function runAutoSearches() {
+ log("running auto searches");
+
+ for (var teamName in mkws.teams) {
+ mkws.teams[teamName].queue("ready").publish();
+ }
+ }
+
+
+ function selectorForAllWidgets() {
+ if (mkws.config && 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(selectorForAllWidgets()).each(function() {
+ handleNodeWithTeam(this, function(tname, type) {
+ var myTeam = mkws.teams[tname];
+ if (!myTeam) {
+ myTeam = mkws.teams[tname] = team($, tname);
+ log("made MKWS team '" + tname + "'");
+ }
+
+ var oldHTML = this.innerHTML;
+ var myWidget = widget($, myTeam, type, this);
+ myTeam.addWidget(myWidget);
+ var newHTML = this.innerHTML;
+ if (newHTML !== oldHTML) {
+ log("widget " + tname + ":" + type + " HTML changed: reparsing");
+ makeWidgetsWithin(level+1, $(this));
+ }
+ });
+ });
+ }
+
+
+ function init(rootsel) {
+ if (!rootsel) var rootsel = ':root';
+ 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) {
+ 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 + "'");
+ }
+ }
+ }