');
@@ -345,9 +351,9 @@ function team($, teamName) {
if (!pzIndex) {
// Special case: target selection
acc.push('target_id='+data[i].id+' ');
- action = 'mkws.limitTarget(this.getAttribute(\'target_id\'),this.firstChild.nodeValue)';
+ action = 'mkws.limitTarget(\'' + m_teamName + '\', this.getAttribute(\'target_id\'),this.firstChild.nodeValue)';
} else {
- action = 'mkws.limitQuery(\'' + pzIndex + '\', this.firstChild.nodeValue)';
+ action = 'mkws.limitQuery(\'' + m_teamName + '\', \'' + pzIndex + '\', this.firstChild.nodeValue)';
}
acc.push('onclick="' + action + ';return false;">' + data[i].name + ''
+ '
' + data[i].freq + ' ');
@@ -358,7 +364,7 @@ function team($, teamName) {
function my_onrecord(data, args, teamName) {
- debug("record for " + teamName);
+ debug("record");
// FIXME: record is async!!
clearTimeout(m_paz.recordTimer);
// in case on_show was faster to redraw element
@@ -372,10 +378,9 @@ function team($, teamName) {
function my_onbytarget(data, teamName) {
- debug("target for " + teamName);
- var targetDiv = document.getElementById("mkwsBytarget");
+ debug("target");
+ var targetDiv = $('.mkwsBytarget.mkwsTeam_' + teamName);
if (!targetDiv) {
- // No mkwsTargets div.
return;
}
@@ -396,7 +401,7 @@ function team($, teamName) {
}
table += '';
- targetDiv.innerHTML = table;
+ targetDiv.html(table);
}
////////////////////////////////////////////////////////////////////////////////
@@ -415,13 +420,12 @@ function team($, teamName) {
});
});
- document.mkwsSearchForm.mkwsQuery.value = '';
- if (document.mkwsSelect) {
- if (document.mkwsSelect.mkwsSort)
- document.mkwsSelect.mkwsSort.onchange = onSelectDdChange;
- if (document.mkwsSelect.mkwsPerpage)
- document.mkwsSelect.mkwsPerpage.onchange = onSelectDdChange;
- }
+ var node = $('.mkwsSort.mkwsTeam_' + m_teamName);
+ if (node.length)
+ node.change(onSelectDdChange);
+ node = $('.mkwsPerpage.mkwsTeam_' + m_teamName);
+ if (node.length)
+ node.change(onSelectDdChange);
}
@@ -447,11 +451,11 @@ function team($, teamName) {
}
m_filters = []
- redraw_navi(); // ### should use windowid
+ redraw_navi();
resetPage(); // ### the globals it resents should be indexed by windowid
- loadSelect(); // ### should use windowid
+ loadSelect();
triggerSearch(query, sort, targets, windowid);
- mkws.switchView('records'); // In case it's configured to start off as hidden
+ that.switchView('records'); // In case it's configured to start off as hidden
m_submitted = true;
}
@@ -523,20 +527,24 @@ function team($, teamName) {
function loadSelect ()
{
- if (document.mkwsSelect) {
- if (document.mkwsSelect.mkwsSort)
- m_sort = document.mkwsSelect.mkwsSort.value;
- if (document.mkwsSelect.mkwsPerpage)
- m_recPerPage = document.mkwsSelect.mkwsPerpage.value;
+ var node = $('.mkwsSort.mkwsTeam_' + m_teamName);
+ if (node.length && node.val() != m_sort) {
+ debug("changing m_sort from " + m_sort + " to " + node.val());
+ m_sort = node.val();
+ }
+ node = $('.mkwsPerpage.mkwsTeam_' + m_teamName);
+ if (node.length && node.val() != m_recPerPage) {
+ debug("changing m_recPerPage from " + m_recPerPage + " to " + node.val());
+ m_recPerPage = node.val();
}
}
- // limit the query after clicking the facet
- mkws.limitQuery = function (field, value)
+ // limit by target functions
+ that.limitTarget = function (id, name)
{
- debug("limitQuery(field=" + field + ", value=" + value + ")");
- m_filters.push({ field: field, value: value });
+ debug("limitTarget(id=" + id + ", name=" + name + ")");
+ m_filters.push({ id: id, name: name });
redraw_navi();
resetPage();
loadSelect();
@@ -545,11 +553,11 @@ function team($, teamName) {
}
- // limit by target functions
- mkws.limitTarget = function (id, name)
+ // limit the query after clicking the facet
+ that.limitQuery = function (field, value)
{
- debug("limitTarget(id=" + id + ", name=" + name + ")");
- m_filters.push({ id: id, name: name });
+ debug("limitQuery(field=" + field + ", value=" + value + ")");
+ m_filters.push({ field: field, value: value });
redraw_navi();
resetPage();
loadSelect();
@@ -558,15 +566,13 @@ function team($, teamName) {
}
- mkws.delimitQuery = function (field, value)
+ that.delimitTarget = function (id)
{
- debug("delimitQuery(field=" + field + ", value=" + value + ")");
+ debug("delimitTarget(id=" + id + ")");
var newFilters = [];
for (var i in m_filters) {
var filter = m_filters[i];
- if (filter.field &&
- field == filter.field &&
- value == filter.value) {
+ if (filter.id) {
debug("delimitTarget() removing filter " + $.toJSON(filter));
} else {
debug("delimitTarget() keeping filter " + $.toJSON(filter));
@@ -583,16 +589,18 @@ function team($, teamName) {
}
- mkws.delimitTarget = function (id)
+ that.delimitQuery = function (field, value)
{
- debug("delimitTarget(id=" + id + ")");
+ debug("delimitQuery(field=" + field + ", value=" + value + ")");
var newFilters = [];
for (var i in m_filters) {
var filter = m_filters[i];
- if (filter.id) {
- debug("delimitTarget() removing filter " + $.toJSON(filter));
+ if (filter.field &&
+ field == filter.field &&
+ value == filter.value) {
+ debug("delimitQuery() removing filter " + $.toJSON(filter));
} else {
- debug("delimitTarget() keeping filter " + $.toJSON(filter));
+ debug("delimitQuery() keeping filter " + $.toJSON(filter));
newFilters.push(filter);
}
}
@@ -608,7 +616,7 @@ function team($, teamName) {
function redraw_navi ()
{
- var navi = document.getElementById('mkwsNavi');
+ var navi = $('.mkwsNavi.mkwsTeam_' + m_teamName);
if (!navi) return;
var text = "";
@@ -618,21 +626,26 @@ function team($, teamName) {
}
var filter = m_filters[i];
if (filter.id) {
- text += 'Source:
' + filter.name + ' ';
+ text += M('source') + ':
' + filter.name + ' ';
} else {
- text += filter.field + ':
' + filter.value + ' ';
}
}
- navi.innerHTML = text;
+ navi.html(text);
}
- function drawPager (pagerDiv)
+ function drawPager (data)
{
+ var s = '
' + M('Displaying') + ': '
+ + (data.start + 1) + ' ' + M('to') + ' ' + (data.start + data.num) +
+ ' ' + M('of') + ' ' + data.merged + ' (' + M('found') + ': '
+ + data.total + ')
';
+
//client indexes pages from 1 but pz2 from 0
var onsides = 6;
var pages = Math.ceil(m_totalRec / m_recPerPage);
@@ -673,8 +686,10 @@ function team($, teamName) {
if (lastClkbl < pages)
postdots = '...';
- pagerDiv.innerHTML += '
'
+ s += '
'
+ prev + predots + middle + postdots + next + '
';
+
+ return s;
}
@@ -701,14 +716,11 @@ function team($, teamName) {
// switching view between targets and records
- mkws.switchView = function(view) {
- debug("switchView: " + view);
-
- //var targets = document.getElementById('mkwsTargets');
- var targets = $('#mkwsTargets');
- var results = $('#mkwsResults,#mkwsRecords');
- var blanket = $('#mkwsBlanket');
- var motd = $('#mkwsMOTD');
+ that.switchView = function(view) {
+ var targets = $('.mkwsTargets.mkwsTeam_' + m_teamName);
+ var results = $('.mkwsResults.mkwsTeam_' + m_teamName + ',.mkwsRecords.mkwsTeam_' + m_teamName);
+ var blanket = $('.mkwsBlanket.mkwsTeam_' + m_teamName);
+ var motd = $('.mkwsMOTD.mkwsTeam_' + m_teamName);
switch(view) {
case 'targets':
@@ -724,7 +736,7 @@ function team($, teamName) {
if (motd) motd.css('display', 'none');
break;
case 'none':
- alert("mkws.switchView('none') shouldn't happen");
+ alert("mkws.switchView(" + m_teamName + ", 'none') shouldn't happen");
if (targets) targets.css('display', 'none');
if (results) results.css('display', 'none');
if (blanket) blanket.css('display', 'none');
@@ -755,6 +767,7 @@ function team($, teamName) {
return;
}
// request the record
+ debug("showDetails() requesting record '" + recId + "'");
m_paz.record(recId);
}
@@ -878,7 +891,8 @@ function team($, teamName) {
// 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('\
@@ -890,39 +904,41 @@ function team($, teamName) {
});
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('\
\
\
- \
-
\
+ \
+
\
\
- \
-
\
- \
-
\
-
\
+ \
+
\
+ \
+
\
+
\
\
\
\
\
-
\
+
\
\
\
');
}
- if ($("#mkwsRanking").length) {
+ var node = $(".mkwsRanking.mkwsTeam_" + m_teamName);
+ if (node.length) {
var ranking_data = '';
- ranking_data += '
';
- $("#mkwsRanking").html(ranking_data);
+ node.html(ranking_data);
}
mkws_html_switch();
@@ -939,21 +955,20 @@ function team($, teamName) {
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();
// on first page, hide the termlist
- $(document).ready(function() { $("#mkwsTermlists").hide(); });
- var motd = document.getElementById("mkwsMOTD");
- var container = document.getElementById("mkwsMOTDContainer");
- if (motd && container) {
+ $(document).ready(function() { $(".mkwsTermlists.mkwsTeam_" + m_teamName).hide(); });
+ var motd = $(".mkwsMOTD.mkwsTeam_" + m_teamName);
+ var container = $(".mkwsMOTDContainer.mkwsTeam_" + m_teamName);
+ if (motd.length && container.length) {
// Move the MOTD from the provided element down into the container
- motd.parentNode.removeChild(motd);
- container.appendChild(motd);
+ motd.appendTo(container);
}
}
@@ -985,24 +1000,26 @@ function team($, teamName) {
function mkws_html_switch() {
- debug("HTML switch");
+ debug("HTML switch for team " + m_teamName);
- $("#mkwsSwitch").append($('
' + M('Records') + ' '));
- $("#mkwsSwitch").append($("
", { text: " | " }));
- $("#mkwsSwitch").append($('
' + M('Targets') + ' '));
+ var node = $(".mkwsSwitch.mkwsTeam_" + m_teamName);
+ node.append($('
' + M('Records') + ' '));
+ node.append($("
", { text: " | " }));
+ node.append($('
' + M('Targets') + ' '));
debug("HTML targets");
- $("#mkwsTargets").html('\
-
\
+ var node = $(".mkwsTargets.mkwsTeam_" + m_teamName);
+ node.html('\
+
\
No information available yet.\
');
- $("#mkwsTargets").css("display", "none");
+ node.css("display", "none");
}
function mkws_html_sort() {
debug("HTML sort, m_sort = '" + m_sort + "'");
- var sort_html = '
';
+ var sort_html = '';
for(var i = 0; i < mkws_config.sort_options.length; i++) {
var opt = mkws_config.sort_options[i];
@@ -1023,7 +1040,7 @@ function team($, teamName) {
function mkws_html_perpage() {
debug("HTML perpage");
- var perpage_html = '';
+ var perpage_html = '';
for(var i = 0; i < mkws_config.perpage_options.length; i++) {
var key = mkws_config.perpage_options[i];
@@ -1048,18 +1065,18 @@ function team($, 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(", "));
@@ -1079,38 +1096,10 @@ function team($, teamName) {
}
}
- $("#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();
- }
- } 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();
- }
- }
- };
-
-
/* locale */
function M(word) {
var lang = mkws_config.lang;
@@ -1296,49 +1285,6 @@ function _mkws_jquery_plugin ($) {
// enable before page load, so we could call it before mkws() runs
_mkws_jquery_plugin(j);
- $(document).ready(function() {
- log("on load ready");
- default_mkws_config();
-
- // 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" ];
- for (var i = 0; i < ids.length; i++) {
- 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') + "'");
- }
- }
-
- // Find all nodes with class (NOT id) mkwsRecords, and
- // determine their team from the mkwsTeam_* class. So:
- //
- $('.mkwsSearch, .mkwsResults, .mkwsRecords, .mkwsTermlists').each(function () {
- var node = this;
- mkws.handle_node_with_team(node, function(tname) {
- if (mkws.teams[tname]) {
- log("MKWS team '" + tname + "' already exists, skipping");
- } else {
- mkws.teams[tname] = team(j, tname);
- log("Made MKWS team '" + tname + "'");
- }
- });
- });
-
- if (mkws_config.use_service_proxy) {
- authenticate_session(mkws_config.service_proxy_auth,
- mkws_config.service_proxy_auth_domain,
- mkws_config.pazpar2_url);
- } else {
- // raw pp2
- run_auto_searches();
- }
- });
-
mkws.handle_node_with_team = function(node, callback) {
var classes = node.className;
@@ -1350,16 +1296,66 @@ function _mkws_jquery_plugin ($) {
tname = cname.replace(/^mkwsTeam_/, '');
}
}
- if (!tname)
- tname = "AUTO";
callback(tname);
}
- mkws.showDetails = function (prefixRecId, tname) {
+ mkws.resize_page = function () {
+ var list = ["mkwsSwitch", "mkwsLang"];
+
+ var width = mkws_config.responsive_design_width;
+ var parent = $(".mkwsTermlists").parent();
+
+ 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.switchView = function(tname, view) {
+ mkws.teams[tname].switchView(view);
+ }
+
+ mkws.showDetails = function (tname, prefixRecId) {
mkws.teams[tname].showDetails(prefixRecId);
}
+ mkws.limitTarget = function (tname, id, name) {
+ mkws.teams[tname].limitTarget(id, name);
+ }
+
+ mkws.limitQuery = function (tname, field, value) {
+ mkws.teams[tname].limitQuery(field, value);
+ }
+
+ mkws.delimitTarget = function (tname, id) {
+ mkws.teams[tname].delimitTarget(id);
+ }
+
+ mkws.delimitQuery = function (tname, field, value) {
+ mkws.teams[tname].delimitQuery(field, value);
+ }
+
function default_mkws_config() {
/* default mkws config */
@@ -1377,7 +1373,7 @@ function _mkws_jquery_plugin ($) {
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: ["sources", "subjects", "authors"], /* display facets, in this order, [] for none */
+ facets: ["xtargets", "subject", "author"], /* display facets, in this order, [] for none */
responsive_design_width: undefined, /* a page with less pixel width considered as narrow */
debug_level: 1, /* debug level for development: 0..2 */
@@ -1412,11 +1408,11 @@ function _mkws_jquery_plugin ($) {
* 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) {
@@ -1435,7 +1431,7 @@ function _mkws_jquery_plugin ($) {
return;
}
- console.log("Service proxy auth successfully done");
+ log("Service proxy auth successfully done");
mkws.authenticated = true;
run_auto_searches();
});
@@ -1443,13 +1439,13 @@ function _mkws_jquery_plugin ($) {
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');
@@ -1458,11 +1454,61 @@ function _mkws_jquery_plugin ($) {
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);
}
}
}
+
+
+ $(document).ready(function() {
+ log("on load ready");
+ default_mkws_config();
+
+ // 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" ];
+ 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') + "'");
+ }
+ }
+
+ // 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 class, and determine their team from
+ // the mkwsTeam_* class. Make all team objects.
+ $('[class^="mkws"],[class*=" mkws"]').each(function () {
+ var node = this;
+ mkws.handle_node_with_team(node, function(tname) {
+ if (!mkws.teams[tname]) {
+ mkws.teams[tname] = team(j, tname);
+ log("Made MKWS team '" + tname + "'");
+ }
+ });
+ });
+
+ if (mkws_config.use_service_proxy) {
+ authenticate_session(mkws_config.service_proxy_auth,
+ mkws_config.service_proxy_auth_domain,
+ mkws_config.pazpar2_url);
+ } else {
+ // raw pp2
+ run_auto_searches();
+ }
+ });
})(jQuery);