function my_onstat(data, teamName) {
debug("stat for " + teamName);
- var stat = document.getElementById("mkwsStat");
- if (stat == null)
+ var stat = $('.mkwsStat.mkwsTeam_' + teamName);
+ if (stat.length === 0)
return;
- stat.innerHTML = '<span class="head">' + M('Status info') + '</span>' +
+ stat.html('<span class="head">' + M('Status info') + '</span>' +
' -- ' +
'<span class="clients">' + M('Active clients') + ': ' + data.activeclients + '/' + data.clients + '</span>' +
' -- ' +
- '<span class="records">' + M('Retrieved records') + ': ' + data.records + '/' + data.hits + '</span>';
+ '<span class="records">' + M('Retrieved records') + ': ' + data.records + '/' + data.hits + '</span>');
}
debug("target for " + teamName);
var targetDiv = $('.mkwsBytarget.mkwsTeam_' + teamName);
if (!targetDiv) {
- // No mkwsTargets div.
return;
}
resetPage(); // ### the globals it resents should be indexed by windowid
loadSelect(); // ### should use windowid
triggerSearch(query, sort, targets, windowid);
- mkws.switchView('records'); // In case it's configured to start off as hidden
+ mkws.switchView(m_teamName, 'records'); // In case it's configured to start off as hidden
m_submitted = true;
}
// switching view between targets and records
- mkws.switchView = function(view) {
- debug("switchView: " + view);
+ mkws.switchView = function(tname, view) {
+ debug("switchView(" + tname + ", " + view + ")");
- //var targets = document.getElementById('mkwsTargets');
- var targets = $('#mkwsTargets');
- var results = $('#mkwsResults,#mkwsRecords');
+ var targets = $('.mkwsTargets.mkwsTeam_' + tname);
+ var results = $('.mkwsResults.mkwsTeam_' + tname + ',.mkwsRecords.mkwsTeam_' + tname);
var blanket = $('#mkwsBlanket');
var motd = $('#mkwsMOTD');
if (motd) motd.css('display', 'none');
break;
case 'none':
- alert("mkws.switchView('none') shouldn't happen");
+ alert("mkws.switchView(" + tname + ", 'none') shouldn't happen");
if (targets) targets.css('display', 'none');
if (results) results.css('display', 'none');
if (blanket) blanket.css('display', 'none');
// For some reason, doing this programmatically results in
// document.mkwsSearchForm.mkwsQuery being undefined, hence the raw HTML.
debug("HTML search form");
- $('.mkwsSearch').each(function (i, obj) {
+ // ### 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) {
$(node).html('\
});
debug("HTML records");
- // If the application has an #mkwsResults, populate it in the
- // usual way. If not, assume that it's a smarter application that
- // defines its own subcomponents:
- // #mkwsTermlists
- // #mkwsRanking
- // #mkwsPager
- // #mkwsNavi
- // #mkwsRecords
- if ($("#mkwsResults").length) {
- $("#mkwsResults").html('\
+ // If the team has a .mkwsResults, populate it in the usual
+ // way. If not, assume that it's a smarter application that
+ // defines its own subcomponents, some or all of the
+ // following:
+ // .mkwsTermlists
+ // .mkwsRanking
+ // .mkwsPager
+ // .mkwsNavi
+ // .mkwsRecords
+ if ($(".mkwsResults.mkwsTeam_" + m_teamName).length) {
+ $(".mkwsResults.mkwsTeam_" + m_teamName).html('\
<table width="100%" border="0" cellpadding="6" cellspacing="0">\
<tr>\
- <td id="mkwsTermlistContainer1" class="mkwsTermlistContainer1 mkwsTeam_AUTO" width="250" valign="top">\
- <div id="mkwsTermlists" class="mkwsTermlists mkwsTeam_AUTO"></div>\
+ <td class="mkwsTermlistContainer1 mkwsTeam_' + m_teamName + '" width="250" valign="top">\
+ <div id="mkwsTermlists" class="mkwsTermlists mkwsTeam_' + m_teamName + '"></div>\
</td>\
<td id="mkwsMOTDContainer" valign="top">\
- <div id="mkwsRanking" class="mkwsRanking mkwsTeam_AUTO"></div>\
- <div id="mkwsPager" class="mkwsPager mkwsTeam_AUTO"></div>\
- <div id="mkwsNavi" class="mkwsNavi mkwsTeam_AUTO"></div>\
- <div id="mkwsRecords" class="mkwsRecords mkwsTeam_AUTO"></div>\
+ <div id="mkwsRanking" class="mkwsRanking mkwsTeam_' + m_teamName + '"></div>\
+ <div id="mkwsPager" class="mkwsPager mkwsTeam_' + m_teamName + '"></div>\
+ <div id="mkwsNavi" class="mkwsNavi mkwsTeam_' + m_teamName + '"></div>\
+ <div id="mkwsRecords" class="mkwsRecords mkwsTeam_' + m_teamName + '"></div>\
</td>\
</tr>\
<tr>\
<td colspan="2">\
- <div id="mkwsTermlistContainer2" class="mkwsTermlistContainer2 mkwsTeam_AUTO"></div>\
+ <div class="mkwsTermlistContainer2 mkwsTeam_' + m_teamName + '"></div>\
</td>\
</tr>\
</table>');
if (mkws_config.responsive_design_width) {
// Responsive web design - change layout on the fly based on
// current screen width. Required for mobile devices.
- $(window).resize(function(e) { mkws_resize_page() });
+ $(window).resize(function(e) { mkws.resize_page() });
// initial check after page load
- $(document).ready(function() { mkws_resize_page() });
+ $(document).ready(function() { mkws.resize_page() });
}
domReady();
debug("HTML switch for team " + m_teamName);
var node = $(".mkwsSwitch.mkwsTeam_" + m_teamName);
- node.append($('<a href="#" class="mkwsSwitch_records" onclick="mkws.switchView(\'records\')">' + M('Records') + '</a>'));
+ node.append($('<a href="#" onclick="mkws.switchView(\'' + m_teamName + '\', \'records\')">' + M('Records') + '</a>'));
node.append($("<span/>", { text: " | " }));
- node.append($('<a href="#" class="mkwsSwitch_targets" onclick="mkws.switchView(\'targets\')">' + M('Targets') + '</a>'));
+ node.append($('<a href="#" onclick="mkws.switchView(\'' + m_teamName + '\', \'targets\')">' + M('Targets') + '</a>'));
debug("HTML targets");
var node = $(".mkwsTargets.mkwsTeam_" + m_teamName);
/* display a list of configured languages, or all */
var lang_options = mkws_config.lang_options || [];
- var hash = {};
+ var toBeIncluded = {};
for (var i = 0; i < lang_options.length; i++) {
- hash[lang_options[i]] = 1;
+ toBeIncluded[lang_options[i]] = true;
}
for (var k in mkws.locale_lang) {
- if (hash[k] == 1 || lang_options.length == 0)
+ if (toBeIncluded[k] || lang_options.length == 0)
list.push(k);
}
// add english link
- if (lang_options.length == 0 || hash[lang_default] == 1)
+ if (lang_options.length == 0 || toBeIncluded[lang_default])
list.push(lang_default);
debug("Language menu for: " + list.join(", "));
}
}
- $("#mkwsLang").html(data);
+ $(".mkwsLang.mkwsTeam_" + m_teamName).html(data);
}
- function mkws_resize_page () {
- var list = ["mkwsSwitch"];
-
- var width = mkws_config.responsive_design_width;
- var parentId = $("#mkwsTermlists").parent().attr('id');
-
- if ($(window).width() <= width &&
- parentId === "mkwsTermlistContainer1") {
- debug("changing from wide to narrow: " + $(window).width());
- $("#mkwsTermlists").appendTo($("#mkwsTermlistContainer2"));
- $("#mkwsTermlistContainer1").hide();
- $("#mkwsTermlistContainer2").show();
- for(var i = 0; i < list.length; i++) {
- $("#" + list[i]).hide(); // ### make team-aware
- }
- } else if ($(window).width() > width &&
- parentId === "mkwsTermlistContainer2") {
- debug("changing from narrow to wide: " + $(window).width());
- $("#mkwsTermlists").appendTo($("#mkwsTermlistContainer1"));
- $("#mkwsTermlistContainer1").show();
- $("#mkwsTermlistContainer2").hide();
- for(var i = 0; i < list.length; i++) {
- $("#" + list[i]).show(); // ### make team-aware
- }
- }
- };
-
-
/* locale */
function M(word) {
var lang = mkws_config.lang;
var id = 'mkws' + ids[i];
var node = $('#' + id);
if (node.attr('id')) {
- node.addClass(id + " mkwsTeam_AUTO");
- log("added magic classes to '" + node.attr('id') + "'");
+ node.addClass(id);
+ log("added magic class to '" + node.attr('id') + "'");
}
}
+ // For all MKWS-classed nodes that don't have a team
+ // specified, set the team to AUTO.
+ $('div[class^="mkws"],div[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 class (NOT id) mkwsRecords, and
// determine their team from the mkwsTeam_* class. So:
// <div class="mkwsRecords mkwsTeam_foo"/>
tname = cname.replace(/^mkwsTeam_/, '');
}
}
- if (!tname)
- tname = "AUTO";
callback(tname);
}
+ mkws.resize_page = function () {
+ var list = ["mkwsSwitch"];
+
+ var width = mkws_config.responsive_design_width;
+ var parent = $(".mkwsTermlists").parent();
+ log("parent = " + parent + ", length = " + parent.length);
+
+ if ($(window).width() <= width &&
+ parent.hasClass("mkwsTermlistContainer1")) {
+ log("changing from wide to narrow: " + $(window).width());
+ $(".mkwsTermlistContainer1").hide();
+ $(".mkwsTermlistContainer2").show();
+ for (var tname in mkws.teams) {
+ $(".mkwsTermlists.mkwsTeam_" + tname).appendTo($(".mkwsTermlistContainer2.mkwsTeam_" + tname));
+ for(var i = 0; i < list.length; i++) {
+ $("." + list[i] + ".mkwsTeam_" + tname).hide();
+ }
+ }
+ } else if ($(window).width() > width &&
+ parent.hasClass("mkwsTermlistContainer2")) {
+ log("changing from narrow to wide: " + $(window).width());
+ $(".mkwsTermlistContainer1").show();
+ $(".mkwsTermlistContainer2").hide();
+ for (var tname in mkws.teams) {
+ $(".mkwsTermlists.mkwsTeam_" + tname).appendTo($(".mkwsTermlistContainer1.mkwsTeam_" + tname));
+ for(var i = 0; i < list.length; i++) {
+ $("." + list[i] + ".mkwsTeam_" + tname).show();
+ }
+ }
+ }
+ };
+
+
mkws.showDetails = function (prefixRecId, tname) {
mkws.teams[tname].showDetails(prefixRecId);
}
* for the site.
*/
function authenticate_session(auth_url, auth_domain, pp2_url) {
- console.log("Run service proxy auth URL: " + auth_url);
+ log("Run service proxy auth URL: " + auth_url);
if (!auth_domain) {
auth_domain = pp2_url.replace(/^(https?:)?\/\/(.*?)\/.*/, '$2');
- console.log("guessed auth_domain '" + auth_domain + "' from pp2_url '" + pp2_url + "'");
+ log("guessed auth_domain '" + auth_domain + "' from pp2_url '" + pp2_url + "'");
}
var request = new pzHttpRequest(auth_url, function(err) {
return;
}
- console.log("Service proxy auth successfully done");
+ log("Service proxy auth successfully done");
mkws.authenticated = true;
run_auto_searches();
});
function run_auto_searches() {
- console.log("running auto searches");
+ log("running auto searches");
for (var teamName in mkws.teams) {
// ### should check mkwsTermlist as well, for facet-only teams
var node = $('.mkwsRecords.mkwsTeam_' + teamName);
var query = node.attr('autosearch');
- console.log("teamName '" + teamName + "', node=" + node + ", class='" + node.className + "', query=" + query);
+ log("teamName '" + teamName + "', node=" + node + ", class='" + node.className + "', query=" + query);
if (query) {
var sort = node.attr('sort');
if (teamName) s += " [teamName '" + teamName + "']";
if (sort) s += " sorted by '" + sort + "'";
if (targets) s += " in targets '" + targets + "'";
- console.log(s);
+ log(s);
var team = mkws.teams[teamName];
- console.log($.toJSON(team));
+ log($.toJSON(team));
team.newSearch(query, sort, targets, teamName);
}
}