';
- targetDiv.innerHTML = table;
+ targetDiv.html(table);
}
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
+
// wait until the DOM is ready
function domReady ()
{
- document.mkwsSearchForm.onsubmit = onFormSubmitEventHandler;
- document.mkwsSearchForm.mkwsQuery.value = '';
+ $('.mkwsSearchForm.mkwsTeam_' + m_teamName).each(function (i, obj) {
+ debug("adding search-forms for team '" + m_teamName + "'");
+ var node = this;
+ mkws.handle_node_with_team(node, function(tname) {
+ debug("adding search-form '" + tname + "' for team '" + m_teamName + "'");
+ $(node).submit(onFormSubmitEventHandler);
+ });
+ });
+
if (document.mkwsSelect) {
+ debug("messing with mkwsSelect");
if (document.mkwsSelect.mkwsSort)
document.mkwsSelect.mkwsSort.onchange = onSelectDdChange;
if (document.mkwsSelect.mkwsPerpage)
@@ -439,14 +434,20 @@ function _make_mkws_team($, teamName) {
}
}
+
// when search button pressed
function onFormSubmitEventHandler()
{
- newSearch(document.mkwsSearchForm.mkwsQuery.value);
+ mkws.handle_node_with_team(this, function (tname) {
+ var val = $('.mkwsQuery.mkwsTeam_' + tname).val();
+ mkws.teams[tname].newSearch(val);
+ });
+
return false;
}
- function newSearch(query, sort, targets, windowid)
+
+ that.newSearch = function(query, sort, targets, windowid)
{
debug("newSearch: " + query);
@@ -460,25 +461,28 @@ function _make_mkws_team($, teamName) {
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
- submitted = true;
+ mkws.switchView(m_teamName, 'records'); // In case it's configured to start off as hidden
+ m_submitted = true;
}
+
function onSelectDdChange()
{
- if (!submitted) return false;
+ if (!m_submitted) return false;
resetPage();
loadSelect();
- m_paz.show(0, recPerPage, m_sort);
+ m_paz.show(0, m_recPerPage, m_sort);
return false;
}
+
function resetPage()
{
- curPage = 1;
- totalRec = 0;
+ m_curPage = 1;
+ m_totalRec = 0;
}
+
function triggerSearch (query, sort, targets, windowid)
{
var pp2filter = "";
@@ -486,7 +490,7 @@ function _make_mkws_team($, teamName) {
// Re-use previous query/sort if new ones are not specified
if (query) {
- mkws.query = query;
+ m_query = query;
}
if (sort) {
m_sort = sort;
@@ -521,21 +525,23 @@ function _make_mkws_team($, teamName) {
if (windowid) {
params.windowid = windowid;
}
- debug("triggerSearch(" + mkws.query + "): filters = " + $.toJSON(m_filters) + ", pp2filter = " + pp2filter + ", params = " + $.toJSON(params));
+ debug("triggerSearch(" + m_query + "): filters = " + $.toJSON(m_filters) + ", pp2filter = " + pp2filter + ", params = " + $.toJSON(params));
- m_paz.search(mkws.query, recPerPage, m_sort, pp2filter, undefined, params);
+ m_paz.search(m_query, m_recPerPage, m_sort, pp2filter, undefined, params);
}
+
function loadSelect ()
{
if (document.mkwsSelect) {
if (document.mkwsSelect.mkwsSort)
m_sort = document.mkwsSelect.mkwsSort.value;
if (document.mkwsSelect.mkwsPerpage)
- recPerPage = document.mkwsSelect.mkwsPerpage.value;
+ m_recPerPage = document.mkwsSelect.mkwsPerpage.value;
}
}
+
// limit the query after clicking the facet
mkws.limitQuery = function (field, value)
{
@@ -548,6 +554,7 @@ function _make_mkws_team($, teamName) {
return false;
}
+
// limit by target functions
mkws.limitTarget = function (id, name)
{
@@ -560,6 +567,7 @@ function _make_mkws_team($, teamName) {
return false;
}
+
mkws.delimitQuery = function (field, value)
{
debug("delimitQuery(field=" + field + ", value=" + value + ")");
@@ -620,10 +628,10 @@ function _make_mkws_team($, teamName) {
}
var filter = m_filters[i];
if (filter.id) {
- text += 'Source: ' + filter.name + '';
} else {
- text += filter.field + ': ' + filter.value + '';
}
@@ -637,10 +645,10 @@ function _make_mkws_team($, teamName) {
{
//client indexes pages from 1 but pz2 from 0
var onsides = 6;
- var pages = Math.ceil(totalRec / recPerPage);
+ var pages = Math.ceil(m_totalRec / m_recPerPage);
- var firstClkbl = ( curPage - onsides > 0 )
- ? curPage - onsides
+ var firstClkbl = (m_curPage - onsides > 0)
+ ? m_curPage - onsides
: 1;
var lastClkbl = firstClkbl + 2*onsides < pages
@@ -648,14 +656,14 @@ function _make_mkws_team($, teamName) {
: pages;
var prev = '<< ' + M('Prev') + ' | ';
- if (curPage > 1)
+ if (m_curPage > 1)
prev = ''
+'<< ' + M('Prev') + ' | ';
var middle = '';
for(var i = firstClkbl; i <= lastClkbl; i++) {
var numLabel = i;
- if(i == curPage)
+ if(i == m_curPage)
numLabel = '' + i + '';
middle += ' '
@@ -663,7 +671,7 @@ function _make_mkws_team($, teamName) {
}
var next = ' | ' + M('Next') + ' >>';
- if (pages - curPage > 0)
+ if (pages - m_curPage > 0)
next = ' | '
+ M('Next') + ' >>';
@@ -679,66 +687,69 @@ function _make_mkws_team($, teamName) {
+ prev + predots + middle + postdots + next + '
';
}
+
mkws.showPage = function (pageNum)
{
- curPage = pageNum;
- m_paz.showPage( curPage - 1 );
+ m_curPage = pageNum;
+ m_paz.showPage(m_curPage - 1);
}
- // simple paging functions
+ // simple paging functions
mkws.pagerNext = function () {
- if ( totalRec - recPerPage*curPage > 0) {
+ if (m_totalRec - m_recPerPage*m_curPage > 0) {
m_paz.showNext();
- curPage++;
+ m_curPage++;
}
}
+
mkws.pagerPrev = function () {
- if ( m_paz.showPrev() != false )
- curPage--;
+ if (m_paz.showPrev() != false)
+ m_curPage--;
}
- // switching view between targets and records
- mkws.switchView = function(view) {
- debug("switchView: " + view);
+ // switching view between targets and records
+ mkws.switchView = function(tname, view) {
+ debug("switchView(" + tname + ", " + view + ")");
- var targets = document.getElementById('mkwsTargets');
- var results = document.getElementById('mkwsResults') ||
- document.getElementById('mkwsRecords');
- var blanket = document.getElementById('mkwsBlanket');
- var motd = document.getElementById('mkwsMOTD');
+ var targets = $('.mkwsTargets.mkwsTeam_' + tname);
+ var results = $('.mkwsResults.mkwsTeam_' + tname + ',.mkwsRecords.mkwsTeam_' + tname);
+ var blanket = $('.mkwsBlanket.mkwsTeam_' + tname);
+ var motd = $('.mkwsMOTD.mkwsTeam_' + tname);
switch(view) {
case 'targets':
- if (targets) targets.style.display = "block";
- if (results) results.style.display = "none";
- if (blanket) blanket.style.display = "none";
- if (motd) motd.style.display = "none";
+ if (targets) targets.css('display', 'block');
+ if (results) results.css('display', 'none');
+ if (blanket) blanket.css('display', 'none');
+ if (motd) motd.css('display', 'none');
break;
case 'records':
- if (targets) targets.style.display = "none";
- if (results) results.style.display = "block";
- if (blanket) blanket.style.display = "block";
- if (motd) motd.style.display = "none";
+ if (targets) targets.css('display', 'none');
+ if (results) results.css('display', 'block');
+ if (blanket) blanket.css('display', 'block');
+ if (motd) motd.css('display', 'none');
break;
case 'none':
- if (targets) targets.style.display = "none";
- if (results) results.style.display = "none";
- if (blanket) blanket.style.display = "none";
- if (motd) motd.style.display = "none";
+ 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');
+ if (motd) motd.css('display', 'none');
break;
default:
alert("Unknown view '" + view + "'");
}
}
+
// detailed record drawing
- mkws.showDetails = function (prefixRecId) {
+ that.showDetails = function (prefixRecId) {
var recId = prefixRecId.replace('mkwsRec_', '');
- var oldRecId = curDetRecId;
- curDetRecId = recId;
+ var oldRecId = m_curDetRecId;
+ m_curDetRecId = recId;
// remove current detailed view if any
var detRecordDiv = document.getElementById('mkwsDet_'+oldRecId);
@@ -748,32 +759,18 @@ function _make_mkws_team($, teamName) {
// if the same clicked, just hide
if (recId == oldRecId) {
- curDetRecId = '';
- curDetRecData = null;
+ m_curDetRecId = '';
+ m_curDetRecData = null;
return;
}
// request the record
m_paz.record(recId);
}
- function replaceHtml(el, html) {
- var oldEl = typeof el === "string" ? document.getElementById(el) : el;
- /*@cc_on // Pure innerHTML is slightly faster in IE
- oldEl.innerHTML = html;
- return oldEl;
- @*/
- var newEl = oldEl.cloneNode(false);
- newEl.innerHTML = html;
- oldEl.parentNode.replaceChild(newEl, oldEl);
- /* Since we just removed the old element from the DOM, return a reference
- to the new element, which can be used to restore variable references. */
- return newEl;
- };
function renderDetails(data, marker)
{
- loadTemplate("Record");
- var template = mkws.templateRecord;
+ var template = loadTemplate("Record");
var details = template(data);
return '
' + details + '
';
}
@@ -781,16 +778,20 @@ function _make_mkws_team($, teamName) {
function loadTemplate(name)
{
- if (mkws['template' + name] === undefined) {
+ var template = mkws['template' + name];
+
+ if (template === undefined) {
var source = $("#mkwsTemplate" + name).html();
if (!source) {
source = defaultTemplate(name);
}
- var template = Handlebars.compile(source);
+ template = Handlebars.compile(source);
debug("compiled template '" + name + "'");
mkws['template' + name] = template;
}
+
+ return template;
}
@@ -886,38 +887,45 @@ function _make_mkws_team($, teamName) {
// For some reason, doing this programmatically results in
// document.mkwsSearchForm.mkwsQuery being undefined, hence the raw HTML.
debug("HTML search form");
- $("#mkwsSearch").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('\
\
\
-
\
- \
+
\
+ \
\
-
\
- \
- \
- \
- \
+
\
+ \
+ \
+ \
+ \
\
\
\
\
- \
+ \
\
\
');
@@ -939,64 +947,30 @@ function _make_mkws_team($, teamName) {
mkws_html_switch();
- if (mkws_config.use_service_proxy) {
- mkws_service_proxy_auth(mkws_config.service_proxy_auth,
- mkws_config.service_proxy_auth_domain,
- mkws_config.pazpar2_url);
- } else {
- // raw pp2
- run_auto_searches();
- }
-
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() });
}
+ debug("before domReady()");
domReady();
+ debug("after 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);
+ debug("for team '" + m_teamName + "', motd=" + motd + "(" + motd.length + "), container=" + container + "(" + container.length + ")");
+ 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);
}
}
- function run_auto_searches() {
- debug("running auto searches");
-
- $('[id^="mkwsRecords"]').each(function () {
- var node = $(this);
- var query = node.attr('autosearch');
-
- if (query) {
- var windowid = undefined;
- var id = node.attr('id');
- if (id.match(/^mkwsRecords_/, '')) {
- windowid = id.replace(/^mkwsRecords_/, '');
- }
-
- var sort = node.attr('sort');
- var targets = node.attr('targets');
- var s = "running auto search: '" + query + "'";
- if (windowid) s += " [windowid '" + windowid + "']";
- if (sort) s += " sorted by '" + sort + "'";
- if (targets) s += " in targets '" + targets + "'";
- debug(s);
- newSearch(query, sort, targets, windowid);
- }
- });
- }
-
-
// implement $.parseQuerystring() for parsing URL parameters
function parseQuerystring() {
var nvpair = {};
@@ -1009,6 +983,7 @@ function _make_mkws_team($, teamName) {
return nvpair;
}
+
function mkws_set_lang() {
var lang = parseQuerystring().lang || mkws_config.lang;
if (!lang || !mkws.locale_lang[lang]) {
@@ -1021,21 +996,25 @@ function _make_mkws_team($, teamName) {
return mkws_config.lang;
}
+
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('\
-