\
@@ -910,208 +1167,182 @@ function _make_mkws_team($, teamName) {
}
- /*
- * All the HTML stuff to render the search forms and
- * result pages.
- */
- function mkws_html_all() {
- mkws_set_lang();
- if (mkws_config.show_lang)
- mkws_html_lang();
-
- // For some reason, doing this programmatically results in
- // document.mkwsSearchForm.mkwsQuery being undefined, hence the raw HTML.
- debug("HTML search form");
- $("#mkwsSearch").html('\
-');
+ // main
+ (function() {
+ try {
+ mkwsHtmlAll()
+ }
- 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('\
-
\
-
\
-
\
- \
-
\
-
\
- \
- \
- \
- \
-
\
-
\
-
\
-
\
- \
-
\
-
\
-
');
+ catch (e) {
+ mkws_config.error = e.message;
+ // alert(e.message);
}
+ })();
- if ($("#mkwsRanking").length) {
- var ranking_data = '';
- ranking_data += '';
+ // Bizarrely, 'that' is just an empty hash. All its state is in
+ // the closure variables defined earlier in this function.
+ return that;
+};
- $("#mkwsRanking").html(ranking_data);
- }
- mkws_html_switch();
+// wrapper to call team() after page load
+(function (j) {
+ mkws.debug = function (string) {
+ if (!mkws.debug_level)
+ return;
- 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 (typeof console === "undefined" || typeof console.log === "undefined") { /* ARGH!!! old IE */
+ return;
}
- 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() });
- // initial check after page load
- $(document).ready(function() { mkws_resize_page() });
+ // you need to disable use strict at the top of the file!!!
+ if (mkws.debug_level >= 3) {
+ console.log(arguments.callee.caller);
+ } else if (mkws.debug_level >= 2) {
+ console.log(">>> called from function " + arguments.callee.caller.name + ' <<<');
}
-
- 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) {
- // Move the MOTD from the provided element down into the container
- motd.parentNode.removeChild(motd);
- container.appendChild(motd);
+ console.log(string);
+ }
+ var debug = mkws.debug;
+
+
+ mkws.handleNodeWithTeam = function(node, callback) {
+ // First branch for DOM objects; second branch for jQuery objects
+ var classes = node.className || node.attr('class');
+ if (!classes) {
+ // For some reason, if we try to proceed when classes is
+ // undefined, we don't get an error message, but this
+ // function and its callers, up several stack level,
+ // silently return. What a crock.
+ mkws.debug("handleNodeWithTeam() called on node with no classes");
+ return;
+ }
+ var list = classes.split(/\s+/)
+ var teamName, type;
+
+ for (var i = 0; i < list.length; i++) {
+ var cname = list[i];
+ if (cname.match(/^mkwsTeam_/)) {
+ teamName = cname.replace(/^mkwsTeam_/, '');
+ } else if (cname.match(/^mkws/)) {
+ type = cname.replace(/^mkws/, '');
+ }
}
+ callback.call(node, teamName, type);
}
- function run_auto_searches() {
- debug("running auto searches");
+ mkws.resizePage = function () {
+ var list = ["mkwsSwitch", "mkwsLang"];
- $('[id^="mkwsRecords"]').each(function () {
- var node = $(this);
- var query = node.attr('autosearch');
+ var width = mkws_config.responsive_design_width;
+ var parent = $(".mkwsTermlists").parent();
- if (query) {
- var windowid = undefined;
- var id = node.attr('id');
- if (id.match(/^mkwsRecords_/, '')) {
- windowid = id.replace(/^mkwsRecords_/, '');
+ if ($(window).width() <= width &&
+ parent.hasClass("mkwsTermlistContainer1")) {
+ debug("changing from wide to narrow: " + $(window).width());
+ $(".mkwsTermlistContainer1").hide();
+ $(".mkwsTermlistContainer2").show();
+ for (var tname in mkws.teams) {
+ $(".mkwsTermlists.mkwsTeam_" + tname).appendTo($(".mkwsTermlistContainer2.mkwsTeam_" + tname));
+ for(var i = 0; i < list.length; i++) {
+ $("." + list[i] + ".mkwsTeam_" + tname).hide();
}
-
- 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);
}
- });
- }
+ } else if ($(window).width() > width &&
+ parent.hasClass("mkwsTermlistContainer2")) {
+ debug("changing from narrow to wide: " + $(window).width());
+ $(".mkwsTermlistContainer1").show();
+ $(".mkwsTermlistContainer2").hide();
+ for (var tname in mkws.teams) {
+ $(".mkwsTermlists.mkwsTeam_" + tname).appendTo($(".mkwsTermlistContainer1.mkwsTeam_" + tname));
+ for(var i = 0; i < list.length; i++) {
+ $("." + list[i] + ".mkwsTeam_" + tname).show();
+ }
+ }
+ }
+ };
- // implement $.parseQuerystring() for parsing URL parameters
- function parseQuerystring() {
- var nvpair = {};
- var qs = window.location.search.replace('?', '');
- var pairs = qs.split('&');
- $.each(pairs, function(i, v){
- var pair = v.split('=');
- nvpair[pair[0]] = pair[1];
- });
- return nvpair;
+ mkws.switchView = function(tname, view) {
+ mkws.teams[tname].switchView(view);
}
-
- function mkws_set_lang() {
- var lang = parseQuerystring().lang || mkws_config.lang;
- if (!lang || !mkws.locale_lang[lang]) {
- mkws_config.lang = ""
- } else {
- mkws_config.lang = lang;
- }
-
- debug("Locale language: " + (mkws_config.lang ? mkws_config.lang : "none"));
- return mkws_config.lang;
+ mkws.showDetails = function (tname, prefixRecId) {
+ mkws.teams[tname].showDetails(prefixRecId);
}
+ mkws.limitTarget = function (tname, id, name) {
+ mkws.teams[tname].limitTarget(id, name);
+ }
- function mkws_html_switch() {
- debug("HTML switch");
-
- $("#mkwsSwitch").append($('' + M('Records') + ''));
- $("#mkwsSwitch").append($("", { text: " | " }));
- $("#mkwsSwitch").append($('' + M('Targets') + ''));
-
- debug("HTML targets");
- $("#mkwsTargets").html('\
-
\
- No information available yet.\
-
');
- $("#mkwsTargets").css("display", "none");
+ mkws.limitQuery = function (tname, field, value) {
+ mkws.teams[tname].limitQuery(field, value);
}
+ mkws.delimitTarget = function (tname, id) {
+ mkws.teams[tname].delimitTarget(id);
+ }
- function mkws_html_sort() {
- debug("HTML sort, m_sort = '" + m_sort + "'");
- var sort_html = '';
+ mkws.pagerPrev = function (tname) {
+ mkws.teams[tname].pagerPrev();
+ }
- return sort_html;
+ mkws.pagerNext = function (tname) {
+ mkws.teams[tname].pagerNext();
}
- function mkws_html_perpage() {
- debug("HTML perpage");
- var perpage_html = '';
- return perpage_html;
+ // 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]);
+ }
}
@@ -1120,7 +1351,7 @@ function _make_mkws_team($, teamName) {
* The username/password is configured in the apache config file
* for the site.
*/
- function mkws_service_proxy_auth(auth_url, auth_domain, pp2_url) {
+ function authenticateSession(auth_url, auth_domain, pp2_url) {
debug("Run service proxy auth URL: " + auth_url);
if (!auth_domain) {
@@ -1146,260 +1377,100 @@ function _make_mkws_team($, teamName) {
debug("Service proxy auth successfully done");
mkws.authenticated = true;
- run_auto_searches();
+ runAutoSearches();
});
}
- /* create locale language menu */
- function mkws_html_lang() {
- var lang_default = "en";
- var lang = mkws_config.lang || lang_default;
- var list = [];
-
- /* display a list of configured languages, or all */
- var lang_options = mkws_config.lang_options || [];
- var hash = {};
- for (var i = 0; i < lang_options.length; i++) {
- hash[lang_options[i]] = 1;
- }
-
- for (var k in mkws.locale_lang) {
- if (hash[k] == 1 || lang_options.length == 0)
- list.push(k);
- }
-
- // add english link
- if (lang_options.length == 0 || hash[lang_default] == 1)
- list.push(lang_default);
-
- debug("Language menu for: " + list.join(", "));
-
- /* the HTML part */
- var data = "";
- for(var i = 0; i < list.length; i++) {
- var l = list[i];
-
- if (data)
- data += ' | ';
+ function runAutoSearches() {
+ debug("running auto searches");
- if (lang == l) {
- data += ' ' + l + ' ';
- } else {
- data += ' ' + l + ' '
- }
+ for (var teamName in mkws.teams) {
+ mkws.teams[teamName].runAutoSearch();
}
-
- $("#mkwsLang").html(data);
}
- function mkws_resize_page () {
- var list = ["mkwsSwitch"];
+ $(document).ready(function() {
+ debug("on load ready");
+ defaultMkwsConfig();
- var width = mkws_config.responsive_design_width;
- var parentId = $("#mkwsTermlists").parent().attr('id');
+ if (mkws_config.query_width < 5 || mkws_config.query_width > 150) {
+ debug("Reset query width: " + mkws_config.query_width);
+ mkws_config.query_width = 50;
+ }
- if ($(window).width() <= width &&
- parentId === "mkwsTermlistContainer1") {
- debug("changing from wide to narrow: " + $(window).width());
- $("#mkwsTermlists").appendTo($("#mkwsTermlistContainer2"));
- $("#mkwsTermlistContainer1").hide();
- $("#mkwsTermlistContainer2").show();
- for(var i = 0; i < list.length; i++) {
- $("#" + list[i]).hide();
- }
- } else if ($(window).width() > width &&
- parentId === "mkwsTermlistContainer2") {
- debug("changing from narrow to wide: " + $(window).width());
- $("#mkwsTermlists").appendTo($("#mkwsTermlistContainer1"));
- $("#mkwsTermlistContainer1").show();
- $("#mkwsTermlistContainer2").hide();
- for(var i = 0; i < list.length; i++) {
- $("#" + list[i]).show();
+ for (var key in mkws_config) {
+ if (mkws_config.hasOwnProperty(key)) {
+ if (key.match(/^language_/)) {
+ var lang = key.replace(/^language_/, "");
+ // Copy custom languages into list
+ mkws.locale_lang[lang] = mkws_config[key];
+ debug("Added locally configured language '" + lang + "'");
+ }
}
}
- };
-
-
- /* locale */
- function M(word) {
- var lang = mkws_config.lang;
-
- if (!lang || !mkws.locale_lang[lang])
- return word;
-
- return mkws.locale_lang[lang][word] || word;
- }
-
- // main
- (function() {
- try {
- mkws_html_all()
+ 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.resizePage() });
+ // initial check after page load
+ $(document).ready(function() { mkws.resizePage() });
}
- catch (e) {
- mkws_config.error = e.message;
- // alert(e.message);
+ // protocol independent link for pazpar2: "//mkws/sp" -> "https://mkws/sp"
+ if (mkws_config.pazpar2_url.match(/^\/\//)) {
+ mkws_config.pazpar2_url = document.location.protocol + mkws_config.pazpar2_url;
+ debug("adjust protocol independent links: " + mkws_config.pazpar2_url);
}
- })();
-
- // done
- mkws.init = true;
-};
-
-
-/*
- * implement jQuery plugin $.pazpar2({})
- */
-function _mkws_jquery_plugin ($) {
- var debug_level = 1;
-
- function debug (string) {
- if (!debug_level)
- return;
-
- if (typeof console === "undefined" || typeof console.log === "undefined")
- return;
-
- console.log("jquery.pazpar2: " + string);
- }
-
- function init_popup(obj) {
- var config = obj ? obj : {};
- var height = config.height || 760;
- var width = config.width || 880;
- var id_button = config.id_button || "input#mkwsButton";
- var id_popup = config.id_popup || "#mkwsPopup";
-
- debug("popup height: " + height + ", width: " + width);
-
- // make sure that jquery-ui was loaded afte jQuery core lib, e.g.:
- //
- if (!$.ui) {
- debug("Error: jquery-ui.js is missing, did you include it after jQuery core in the HTML file?");
- return;
+ // 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", "MOTD" ];
+ for (var i = 0; i < ids.length; i++) {
+ var id = 'mkws' + ids[i];
+ var node = $('#' + id);
+ if (node.attr('id')) {
+ node.addClass(id);
+ debug("added magic class to '" + node.attr('id') + "'");
+ }
}
- $(id_popup).dialog({
- closeOnEscape: true,
- autoOpen: false,
- height: height,
- width: width,
- modal: true,
- resizable: true,
- buttons: {
- Cancel: function() {
- $(this).dialog("close");
- }
- },
- close: function() { }
+ // For all MKWS-classed nodes that don't have a team
+ // specified, set the team to AUTO.
+ $('[class^="mkws"],[class*=" mkws"]').each(function () {
+ if (!this.className.match(/mkwsTeam_/)) {
+ debug("adding AUTO team to node with class '" + this.className + "'");
+ $(this).addClass('mkwsTeam_AUTO');
+ }
});
- $(id_button)
- .button()
- .click(function() {
- $(id_popup).dialog("open");
+ // Find all nodes with an class, and determine their team from
+ // the mkwsTeam_* class. Make all team objects.
+ var then = $.now();
+ $('[class^="mkws"],[class*=" mkws"]').each(function () {
+ mkws.handleNodeWithTeam(this, function(tname, type) {
+ if (!mkws.teams[tname]) {
+ mkws.teams[tname] = team(j, tname);
+ debug("Made MKWS team '" + tname + "'");
+ }
+ var myTeam = mkws.teams[tname];
+ var myWidget = widget(j, myTeam, type, this);
});
- };
+ });
+ var now = $.now();
+ debug("Walking MKWS nodes took " + (now-then) + " ms");
- $.extend({
-
- // service-proxy or pazpar2
- pazpar2: function(config) {
- var id_popup = config.id_popup || "#mkwsPopup";
- id_popup = id_popup.replace(/^#/, "");
-
- // simple layout
- var div = '\
-\
-\
-\
-\
-\
-';
-
- // new table layout
- var table = '\
-\
- \
-
\
-
\
-
\
- \
- \
- \
-
\
-
\
-
\
-
\
-
\
- \
- \
- \
- \
- \
-
\
-
\
-
\
-
\
-
\
-
\
- \
-
\
-
\
-
\
-
\
-
\
- \
-
\
-
\
-
';
-
- var popup = '\
-\
-
\
- \
- \
- \
- \
- \
-
'
-
- if (config && config.layout == 'div') {
- debug("jquery plugin layout: div");
- document.write(div);
- } else if (config && config.layout == 'popup') {
- debug("jquery plugin layout: popup with id: " + id_popup);
- document.write(popup);
- $(document).ready( function() { init_popup(config); } );
- } else {
- debug("jquery plugin layout: table");
- document.write(table);
- }
+ if (mkws_config.use_service_proxy) {
+ authenticateSession(mkws_config.service_proxy_auth,
+ mkws_config.service_proxy_auth_domain,
+ mkws_config.pazpar2_url);
+ } else {
+ // raw pp2
+ runAutoSearches();
}
});
-};
-
-
-// wrapper to call _make_mkws_team() after page load
-(function (j) {
- // 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);
- });
})(jQuery);