X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=e61878d8172467243835863977d681b43d6bb740;hb=fd8e19788d91b39cf4cb550c805bf5cc05d0349e;hp=597e55b96ca5ab88c96d41c337001bec5a12d90c;hpb=e14aea2ca68c5b8975d53bab9877dac6370796f7;p=mkws-moved-to-github.git
diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js
index 597e55b..e61878d 100644
--- a/tools/htdocs/mkws.js
+++ b/tools/htdocs/mkws.js
@@ -10,7 +10,6 @@ Handlebars.registerHelper('json', function(obj) {
Handlebars.registerHelper('translate', function(s) {
- debug("translating '" + s + "'");
return mkws.M(s);
});
@@ -144,7 +143,7 @@ if (mkws_config == null || typeof mkws_config != 'object') {
// 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';
@@ -262,7 +261,7 @@ function _make_mkws_team($, teamName) {
}
// navi
- var results = document.getElementById("mkwsRecords");
+ var results = $(".mkwsRecords.mkwsTeam_" + m_teamName);
var html = [];
for (var i = 0; i < data.hits.length; i++) {
@@ -274,7 +273,7 @@ function _make_mkws_team($, teamName) {
html.push(renderDetails(m_curDetRecData));
}
}
- replaceHtml(results, html.join(''));
+ results.html(html.join(''));
}
@@ -328,9 +327,9 @@ function _make_mkws_team($, teamName) {
}
}
- var termlist = document.getElementById("mkwsTermlists");
+ var termlist = $("#mkwsTermlists");
if (termlist)
- replaceHtml(termlist, acc.join(''));
+ termlist.html(acc.join(''));
}
@@ -419,12 +418,12 @@ function _make_mkws_team($, teamName) {
// 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);
@@ -745,21 +744,6 @@ function _make_mkws_team($, teamName) {
}
- 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");
@@ -881,8 +865,8 @@ function _make_mkws_team($, teamName) {
debug("HTML search form");
$("#mkwsSearch").html('\
');
debug("HTML records");
@@ -898,19 +882,19 @@ function _make_mkws_team($, teamName) {
$("#mkwsResults").html('\
\
\
- \
- \
+ | \
+ \
| \
\
- \
- \
- \
- \
+ \
+ \
+ \
+ \
| \
\
\
\
- \
+ \
| \
\
');
@@ -989,7 +973,7 @@ function _make_mkws_team($, teamName) {
debug("HTML targets");
$("#mkwsTargets").html('\
-\
+
\
No information available yet.\
');
$("#mkwsTargets").css("display", "none");
@@ -1283,8 +1267,12 @@ function _mkws_jquery_plugin ($) {
// wrapper to call _make_mkws_team() after page load
(function (j) {
function log(s) {
- if (console && console.log) console.log(s);
+ if (typeof console === "undefined" || typeof console.log === "undefined") { /* ARGH!!! old IE */
+ return;
+ }
+ console.log(s);
}
+
// enable before page load, so we could call it before mkws() runs
_mkws_jquery_plugin(j);
@@ -1308,7 +1296,7 @@ function _mkws_jquery_plugin ($) {
// 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
@@ -1339,12 +1327,12 @@ function _mkws_jquery_plugin ($) {
});
if (mkws_config.use_service_proxy) {
- mkws.authenticate_session(mkws_config.service_proxy_auth,
- mkws_config.service_proxy_auth_domain,
- mkws_config.pazpar2_url);
+ authenticate_session(mkws_config.service_proxy_auth,
+ mkws_config.service_proxy_auth_domain,
+ mkws_config.pazpar2_url);
} else {
// raw pp2
- mkws.run_auto_searches();
+ run_auto_searches();
}
});
@@ -1399,12 +1387,12 @@ function _mkws_jquery_plugin ($) {
* The username/password is configured in the apache config file
* for the site.
*/
- mkws.authenticate_session = function(auth_url, auth_domain, pp2_url) {
- debug("Run service proxy auth URL: " + auth_url);
+ function authenticate_session(auth_url, auth_domain, pp2_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) {
@@ -1423,36 +1411,34 @@ function _mkws_jquery_plugin ($) {
return;
}
- debug("Service proxy auth successfully done");
+ console.log("Service proxy auth successfully done");
mkws.authenticated = true;
- mkws.run_auto_searches();
+ run_auto_searches();
});
}
- mkws.run_auto_searches = function() {
- debug("running 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 + "'";
- debug(s);
- newSearch(query, sort, targets, windowid);
+ console.log(s);
+ var team = mkws.teams[teamName];
+ console.log($.toJSON(team));
+ team.newSearch(query, sort, targets, teamName);
}
- });
+ }
}
})(jQuery);