Handlebars.registerHelper('translate', function(s) {
- debug("translating '" + s + "'");
return mkws.M(s);
});
// wrapper for jQuery lib
function _make_mkws_team($, teamName) {
var that = {};
- var m_termName = teamName;
+ var m_teamName = teamName;
var m_submitted = false;
var m_query; // initially undefined
var m_sort = 'relevance';
}
// navi
- var results = document.getElementById("mkwsRecords");
+ var results = $(".mkwsRecords.mkwsTeam_" + m_teamName);
var html = [];
for (var i = 0; i < data.hits.length; i++) {
html.push(renderDetails(m_curDetRecData));
}
}
- replaceHtml(results, html.join(''));
+ results.html(html.join(''));
}
}
}
- var termlist = document.getElementById("mkwsTermlists");
+ var termlist = $("#mkwsTermlists");
if (termlist)
- replaceHtml(termlist, acc.join(''));
+ termlist.html(acc.join(''));
}
// when search button pressed
function onFormSubmitEventHandler()
{
- newSearch(document.mkwsSearchForm.mkwsQuery.value);
+ that.newSearch(document.mkwsSearchForm.mkwsQuery.value);
return false;
}
- function newSearch(query, sort, targets, windowid)
+ that.newSearch = function(query, sort, targets, windowid)
{
debug("newSearch: " + query);
}
- 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)
{
var template = loadTemplate("Record");
debug("HTML search form");
$("#mkwsSearch").html('\
<form name="mkwsSearchForm" action="" >\
- <input id="mkwsQuery" type="text" size="' + mkws_config.query_width + '" />\
- <input id="mkwsButton" type="submit" value="' + M('Search') + '" />\
+ <input id="mkwsQuery" class="mkwsQuery mkwsTeam_AUTO" type="text" size="' + mkws_config.query_width + '" />\
+ <input id="mkwsButton" class="mkwsButton mkwsTeam_AUTO" type="submit" value="' + M('Search') + '" />\
</form>');
debug("HTML records");
$("#mkwsResults").html('\
<table width="100%" border="0" cellpadding="6" cellspacing="0">\
<tr>\
- <td id="mkwsTermlistContainer1" width="250" valign="top">\
- <div id="mkwsTermlists"></div>\
+ <td id="mkwsTermlistContainer1" class="mkwsTermlistContainer1 mkwsTeam_AUTO" width="250" valign="top">\
+ <div id="mkwsTermlists" class="mkwsTermlists mkwsTeam_AUTO"></div>\
</td>\
<td id="mkwsMOTDContainer" valign="top">\
- <div id="mkwsRanking"></div>\
- <div id="mkwsPager"></div>\
- <div id="mkwsNavi"></div>\
- <div id="mkwsRecords"></div>\
+ <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>\
</td>\
</tr>\
<tr>\
<td colspan="2">\
- <div id="mkwsTermlistContainer2"></div>\
+ <div id="mkwsTermlistContainer2" class="mkwsTermlistContainer2 mkwsTeam_AUTO"></div>\
</td>\
</tr>\
</table>');
debug("HTML targets");
$("#mkwsTargets").html('\
-<div id="mkwsBytarget">\
+<div id="mkwsBytarget" class="mkwsBytarget mkwsTeam_AUTO">\
No information available yet.\
</div>');
$("#mkwsTargets").css("display", "none");
// Backwards compatibility: the special-case undefined team
// ### Will not be necessary when non-default teams are working
- mkws.teams[''] = _make_mkws_team(j, undefined);
+ mkws.teams['AUTO'] = _make_mkws_team(j, "AUTO");
log("Made the unnamed MKWS team");
// Find all nodes with class (NOT id) mkwsRecords, and
/* default mkws config */
var config_default = {
use_service_proxy: true,
- pazpar2_url: "http://mkws.indexdata.com/service-proxy/",
- service_proxy_auth: "http://mkws.indexdata.com/service-proxy-auth",
+ pazpar2_url: "//mkws.indexdata.com/service-proxy/",
+ service_proxy_auth: "//mkws.indexdata.com/service-proxy-auth",
lang: "",
sort_options: [["relevance"], ["title:1", "title"], ["date:0", "newest"], ["date:1", "oldest"]],
perpage_options: [10, 20, 30, 50],
* for the site.
*/
function authenticate_session(auth_url, auth_domain, pp2_url) {
- debug("Run service proxy auth URL: " + auth_url);
+ console.log("Run service proxy auth URL: " + auth_url);
if (!auth_domain) {
auth_domain = pp2_url.replace(/^(https?:)?\/\/(.*?)\/.*/, '$2');
- debug("guessed auth_domain '" + auth_domain + "' from pp2_url '" + pp2_url + "'");
+ console.log("guessed auth_domain '" + auth_domain + "' from pp2_url '" + pp2_url + "'");
}
var request = new pzHttpRequest(auth_url, function(err) {
return;
}
- debug("Service proxy auth successfully done");
+ console.log("Service proxy auth successfully done");
mkws.authenticated = true;
run_auto_searches();
});
function run_auto_searches() {
console.log("running auto searches");
- $('[id^="mkwsRecords"]').each(function () {
- var node = $(this);
+ 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);
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 (teamName) s += " [teamName '" + teamName + "']";
if (sort) s += " sorted by '" + sort + "'";
if (targets) s += " in targets '" + targets + "'";
console.log(s);
- newSearch(query, sort, targets, windowid);
+ var team = mkws.teams[teamName];
+ console.log($.toJSON(team));
+ team.newSearch(query, sort, targets, teamName);
}
- });
+ }
}
})(jQuery);