" + data[i].id +
" | " + data[i].hits +
" | " + data[i].diagnostic +
@@ -444,7 +404,14 @@ function _make_mkws_team($, teamName) {
// wait until the DOM is ready
function domReady ()
{
- document.mkwsSearchForm.onsubmit = onFormSubmitEventHandler;
+ $('.mkwsSearchForm').each(function (i, obj) {
+ var node = this;
+ debug("adding class 'foo' to node " + node);
+ mkws.handle_node_with_team(node, function(tname) {
+ $(node).submit(onFormSubmitEventHandler);
+ });
+ });
+
document.mkwsSearchForm.mkwsQuery.value = '';
if (document.mkwsSelect) {
if (document.mkwsSelect.mkwsSort)
@@ -458,12 +425,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);
@@ -487,7 +454,7 @@ function _make_mkws_team($, teamName) {
if (!m_submitted) return false;
resetPage();
loadSelect();
- mkws.paz.show(0, m_recPerPage, m_sort);
+ m_paz.show(0, m_recPerPage, m_sort);
return false;
}
@@ -543,7 +510,7 @@ function _make_mkws_team($, teamName) {
}
debug("triggerSearch(" + m_query + "): filters = " + $.toJSON(m_filters) + ", pp2filter = " + pp2filter + ", params = " + $.toJSON(params));
- mkws.paz.search(m_query, m_recPerPage, m_sort, pp2filter, undefined, params);
+ m_paz.search(m_query, m_recPerPage, m_sort, pp2filter, undefined, params);
}
@@ -663,7 +630,7 @@ function _make_mkws_team($, teamName) {
var onsides = 6;
var pages = Math.ceil(m_totalRec / m_recPerPage);
- var firstClkbl = ( m_curPage - onsides > 0 )
+ var firstClkbl = (m_curPage - onsides > 0)
? m_curPage - onsides
: 1;
@@ -707,21 +674,21 @@ function _make_mkws_team($, teamName) {
mkws.showPage = function (pageNum)
{
m_curPage = pageNum;
- mkws.paz.showPage( m_curPage - 1 );
+ m_paz.showPage(m_curPage - 1);
}
// simple paging functions
mkws.pagerNext = function () {
- if ( m_totalRec - m_recPerPage*m_curPage > 0) {
- mkws.paz.showNext();
+ if (m_totalRec - m_recPerPage*m_curPage > 0) {
+ m_paz.showNext();
m_curPage++;
}
}
mkws.pagerPrev = function () {
- if ( mkws.paz.showPrev() != false )
+ if (m_paz.showPrev() != false)
m_curPage--;
}
@@ -780,25 +747,10 @@ function _make_mkws_team($, teamName) {
return;
}
// request the record
- mkws.paz.record(recId);
+ 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)
{
var template = loadTemplate("Record");
@@ -918,11 +870,16 @@ 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
@@ -937,19 +894,19 @@ function _make_mkws_team($, teamName) {
$("#mkwsResults").html('\
\
\
- \
- \
+ | \
+ \
| \
\
- \
- \
- \
- \
+ \
+ \
+ \
+ \
| \
\
\
\
- \
+ \
| \
\
');
@@ -971,19 +928,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() });
}
@@ -991,7 +939,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) {
@@ -1002,33 +950,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 = {};
@@ -1064,7 +985,7 @@ function _make_mkws_team($, teamName) {
debug("HTML targets");
$("#mkwsTargets").html('\
-\
+ \
No information available yet.\
');
$("#mkwsTargets").css("display", "none");
@@ -1111,42 +1032,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";
@@ -1381,7 +1266,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);
@@ -1394,13 +1279,18 @@ 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);
$(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.
@@ -1416,32 +1306,150 @@ function _mkws_jquery_plugin ($) {
}
}
- // Backwards compatibility: the special-case undefined team
- mkws.teams[''] = _make_mkws_team(j, undefined);
- log("Made the unnamed MKWS team");
-
// Find all nodes with class (NOT id) mkwsRecords, and
// determine their team from the mkwsTeam_* class. So:
//
- $('.mkwsResults, .mkwsRecords, .mkwsTermlists').each(function () {
+ $('.mkwsSearch, .mkwsResults, .mkwsRecords, .mkwsTermlists').each(function () {
var node = this;
- var classes = this.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_/, '');
+ 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) {
- alert("No MKWS team specified for mkwsRecords element with classes '" + classes + "'");
- } else 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 (!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);
|