" + data[i].id +
" | " + data[i].hits +
" | " + data[i].diagnostic +
@@ -466,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);
@@ -486,24 +438,24 @@ function _make_mkws_team($, teamName) {
loadSelect(); // ### should use windowid
triggerSearch(query, sort, targets, windowid);
mkws.switchView('records'); // In case it's configured to start off as hidden
- submitted = true;
+ 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;
}
@@ -551,7 +503,7 @@ function _make_mkws_team($, teamName) {
}
debug("triggerSearch(" + m_query + "): filters = " + $.toJSON(m_filters) + ", pp2filter = " + pp2filter + ", params = " + $.toJSON(params));
- m_paz.search(m_query, recPerPage, m_sort, pp2filter, undefined, params);
+ m_paz.search(m_query, m_recPerPage, m_sort, pp2filter, undefined, params);
}
@@ -561,7 +513,7 @@ function _make_mkws_team($, teamName) {
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;
}
}
@@ -669,10 +621,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
@@ -680,14 +632,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 += ' '
@@ -695,7 +647,7 @@ function _make_mkws_team($, teamName) {
}
var next = ' | ' + M('Next') + ' >>';
- if (pages - curPage > 0)
+ if (pages - m_curPage > 0)
next = ' | '
+ M('Next') + ' >>';
@@ -714,23 +666,23 @@ function _make_mkws_team($, teamName) {
mkws.showPage = function (pageNum)
{
- curPage = pageNum;
- m_paz.showPage( curPage - 1 );
+ m_curPage = pageNum;
+ m_paz.showPage(m_curPage - 1);
}
// 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--;
}
@@ -772,8 +724,8 @@ function _make_mkws_team($, teamName) {
// detailed record drawing
mkws.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);
@@ -783,8 +735,8 @@ 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
@@ -792,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");
@@ -928,8 +865,8 @@ function _make_mkws_team($, teamName) {
debug("HTML search form");
$("#mkwsSearch").html('\
');
debug("HTML records");
@@ -945,19 +882,19 @@ function _make_mkws_team($, teamName) {
$("#mkwsResults").html('\
\
\
- \
- \
+ | \
+ \
| \
\
- \
- \
- \
- \
+ \
+ \
+ \
+ \
| \
\
\
\
- \
+ \
| \
\
');
@@ -979,19 +916,10 @@ 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() });
}
@@ -999,7 +927,7 @@ function _make_mkws_team($, teamName) {
domReady();
// on first page, hide the termlist
- $(document).ready(function() { $("#mkwsTermlists").hide(); } );
+ $(document).ready(function() { $("#mkwsTermlists").hide(); });
var motd = document.getElementById("mkwsMOTD");
var container = document.getElementById("mkwsMOTDContainer");
if (motd && container) {
@@ -1010,33 +938,6 @@ function _make_mkws_team($, teamName) {
}
- 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 = {};
@@ -1072,7 +973,7 @@ function _make_mkws_team($, teamName) {
debug("HTML targets");
$("#mkwsTargets").html('\
-\
+ \
No information available yet.\
');
$("#mkwsTargets").css("display", "none");
@@ -1119,42 +1020,6 @@ function _make_mkws_team($, teamName) {
}
- /*
- * Run service-proxy authentication in background (after page load).
- * The username/password is configured in the apache config file
- * for the site.
- */
- function mkws_service_proxy_auth(auth_url, auth_domain, pp2_url) {
- debug("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 + "'");
- }
-
- var request = new pzHttpRequest(auth_url, function(err) {
- alert("HTTP call for authentication failed: " + err)
- return;
- }, auth_domain);
-
- request.get(null, function(data) {
- if (!$.isXMLDoc(data)) {
- alert("service proxy auth response document is not valid XML document, give up!");
- return;
- }
- var status = $(data).find("status");
- if (status.text() != "OK") {
- alert("service proxy auth repsonse status: " + status.text() + ", give up!");
- return;
- }
-
- debug("Service proxy auth successfully done");
- mkws.authenticated = true;
- run_auto_searches();
- });
- }
-
-
/* create locale language menu */
function mkws_html_lang() {
var lang_default = "en";
@@ -1250,8 +1115,9 @@ function _make_mkws_team($, teamName) {
}
})();
- // done
- mkws.init = true;
+ // Bizarrely, 'that' is just an empty hash. All its state is in
+ // the closure variables defined earlier in this function.
+ return that;
};
@@ -1388,7 +1254,7 @@ function _mkws_jquery_plugin ($) {
} else if (config && config.layout == 'popup') {
debug("jquery plugin layout: popup with id: " + id_popup);
document.write(popup);
- $(document).ready( function() { init_popup(config); } );
+ $(document).ready(function() { init_popup(config); });
} else {
debug("jquery plugin layout: table");
document.write(table);
@@ -1400,11 +1266,178 @@ function _mkws_jquery_plugin ($) {
// wrapper to call _make_mkws_team() after page load
(function (j) {
+ function 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);
$(document).ready(function() {
- // if (console && console.log) console.log("on load ready");
- _make_mkws_team(j, null);
+ 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:
+ //
+ $('.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] = _make_mkws_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;
+ var list = classes.split(/\s+/)
+ var tname;
+ for (var i = 0; i < list.length; i++) {
+ var cname = list[i];
+ if (cname.match(/^mkwsTeam_/)) {
+ tname = cname.replace(/^mkwsTeam_/, '');
+ }
+ }
+ if (!tname)
+ tname = "AUTO";
+ callback(tname);
+ }
+
+
+ function default_mkws_config() {
+ /* default mkws config */
+ var config_default = {
+ use_service_proxy: true,
+ 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],
+ sort_default: "relevance",
+ perpage_default: 20,
+ query_width: 50,
+ show_lang: true, /* show/hide language menu */
+ 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 */
+ responsive_design_width: undefined, /* a page with less pixel width considered as narrow */
+ debug_level: 1, /* debug level for development: 0..2 */
+
+ dummy: "dummy"
+ };
+
+ /* Set global debug_level flag early so that debug() works */
+ if (typeof mkws_config.debug_level !== 'undefined') {
+ mkws.debug_level = mkws_config.debug_level;
+ } else if (typeof config_default.debug_level !== 'undefined') {
+ mkws.debug_level = config_default.debug_level;
+ }
+
+ // make sure the mkws_config is a valid hash
+ if (!$.isPlainObject(mkws_config)) {
+ debug("ERROR: mkws_config is not an JS object, ignore it....");
+ mkws_config = {};
+ }
+
+ /* override standard config values by function parameters */
+ for (var k in config_default) {
+ if (typeof mkws_config[k] === 'undefined')
+ mkws_config[k] = config_default[k];
+ //debug("Set config: " + k + ' => ' + mkws_config[k]);
+ }
+ }
+
+
+ /*
+ * Run service-proxy authentication in background (after page load).
+ * The username/password is configured in the apache config file
+ * for the site.
+ */
+ 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');
+ console.log("guessed auth_domain '" + auth_domain + "' from pp2_url '" + pp2_url + "'");
+ }
+
+ var request = new pzHttpRequest(auth_url, function(err) {
+ alert("HTTP call for authentication failed: " + err)
+ return;
+ }, auth_domain);
+
+ request.get(null, function(data) {
+ if (!$.isXMLDoc(data)) {
+ alert("service proxy auth response document is not valid XML document, give up!");
+ return;
+ }
+ var status = $(data).find("status");
+ if (status.text() != "OK") {
+ alert("service proxy auth repsonse status: " + status.text() + ", give up!");
+ return;
+ }
+
+ console.log("Service proxy auth successfully done");
+ mkws.authenticated = true;
+ run_auto_searches();
+ });
+ }
+
+
+ function run_auto_searches() {
+ console.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);
+
+ if (query) {
+ var sort = node.attr('sort');
+ var targets = node.attr('targets');
+ var s = "running auto search: '" + query + "'";
+ if (teamName) s += " [teamName '" + teamName + "']";
+ if (sort) s += " sorted by '" + sort + "'";
+ if (targets) s += " in targets '" + targets + "'";
+ console.log(s);
+ var team = mkws.teams[teamName];
+ console.log($.toJSON(team));
+ team.newSearch(query, sort, targets, teamName);
+ }
+ }
+ }
})(jQuery);
|