From 7d285924818fe961c40cc27201cdc20e5729fb6e Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Fri, 28 Mar 2014 11:00:12 +0000 Subject: [PATCH] Copy mkws_config into mkws.config, and thereafter use that --- src/mkws-core.js | 44 +++++++++++++++++++++++--------------------- src/mkws-team.js | 46 +++++++++++++++++++++++----------------------- src/mkws-widgets.js | 4 ++-- 3 files changed, 48 insertions(+), 46 deletions(-) diff --git a/src/mkws-core.js b/src/mkws-core.js index 893951c..3dd1af9 100644 --- a/src/mkws-core.js +++ b/src/mkws-core.js @@ -11,7 +11,7 @@ // var mkws = { authenticated: false, - log_level: 1, // Will be overridden from mkws_config, but + log_level: 1, // Will be overridden from mkws.config, but // initial value allows jQuery popup to use logging. teams: {}, widgetType2function: {}, @@ -123,6 +123,8 @@ mkws.promotionFunction = function(name) { mkws.defaultMkwsConfig = function() { + mkws.config = mkws_config; + /* default mkws config */ var config_default = { use_service_proxy: true, @@ -147,8 +149,8 @@ mkws.defaultMkwsConfig = function() { // Set global log_level flag early so that log() works // Fall back to old "debug_level" setting for backwards compatibility - var tmp = mkws_config.log_level; - if (typeof(tmp) === 'undefined') tmp = mkws_config.debug_level; + var tmp = mkws.config.log_level; + if (typeof(tmp) === 'undefined') tmp = mkws.config.debug_level; if (typeof(tmp) !== 'undefined') { mkws.log_level = tmp; @@ -158,9 +160,9 @@ mkws.defaultMkwsConfig = function() { /* 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]; - //log("Set config: " + k + ' => ' + mkws_config[k]); + if (typeof mkws.config[k] === 'undefined') + mkws.config[k] = config_default[k]; + //log("Set config: " + k + ' => ' + mkws.config[k]); } }; @@ -238,7 +240,7 @@ mkws.pagerNext = function(tname) { function resizePage() { var list = ["mkwsSwitch", "mkwsLang"]; - var width = mkws_config.responsive_design_width; + var width = mkws.config.responsive_design_width; var parent = $(".mkwsTermlists").parent(); if ($(window).width() <= width && @@ -320,29 +322,29 @@ mkws.pagerNext = function(tname) { $(document).ready(function() { mkws.defaultMkwsConfig(); - for (var key in mkws_config) { - if (mkws_config.hasOwnProperty(key)) { + 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]; + mkws.locale_lang[lang] = mkws.config[key]; log("Added locally configured language '" + lang + "'"); } } } - if (mkws_config.query_width < 5 || mkws_config.query_width > 150) { - log("Reset query width: " + mkws_config.query_width); - mkws_config.query_width = 50; + if (mkws.config.query_width < 5 || mkws.config.query_width > 150) { + log("Reset query width: " + mkws.config.query_width); + mkws.config.query_width = 50; } // 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; - log("adjust protocol independent links: " + mkws_config.pazpar2_url); + if (mkws.config.pazpar2_url.match(/^\/\//)) { + mkws.config.pazpar2_url = document.location.protocol + mkws.config.pazpar2_url; + log("adjust protocol independent links: " + mkws.config.pazpar2_url); } - if (mkws_config.responsive_design_width) { + 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(resizePage); @@ -397,10 +399,10 @@ mkws.pagerNext = function(tname) { var now = $.now(); log("Walking MKWS nodes took " + (now-then) + " ms"); - if (mkws_config.use_service_proxy) { - authenticateSession(mkws_config.service_proxy_auth, - mkws_config.service_proxy_auth_domain, - mkws_config.pazpar2_url); + 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(); diff --git a/src/mkws-team.js b/src/mkws-team.js index c26ab04..4202cb7 100644 --- a/src/mkws-team.js +++ b/src/mkws-team.js @@ -56,24 +56,24 @@ function team($, teamName) { log("start running MKWS"); - m_sortOrder = mkws_config.sort_default; - m_perpage = mkws_config.perpage_default; + m_sortOrder = mkws.config.sort_default; + m_perpage = mkws.config.perpage_default; log("Create main pz2 object"); // create a parameters array and pass it to the pz2's constructor // then register the form submit event with the pz2.search function // autoInit is set to true on default m_paz = new pz2({ "windowid": teamName, - "pazpar2path": mkws_config.pazpar2_url, - "usesessions" : mkws_config.use_service_proxy ? false : true, + "pazpar2path": mkws.config.pazpar2_url, + "usesessions" : mkws.config.use_service_proxy ? false : true, "oninit": onInit, "onbytarget": onBytarget, "onstat": onStat, - "onterm": (mkws_config.facets.length ? onTerm : undefined), + "onterm": (mkws.config.facets.length ? onTerm : undefined), "onshow": onShow, "onrecord": onRecord, "showtime": 500, //each timer (show, stat, term, bytarget) can be specified this way - "termlist": mkws_config.facets.join(',') + "termlist": mkws.config.facets.join(',') }); @@ -234,7 +234,7 @@ function team($, teamName) { { log("newSearch: " + query); - if (mkws_config.use_service_proxy && !mkws.authenticated) { + if (mkws.config.use_service_proxy && !mkws.authenticated) { alert("searching before authentication"); return; } @@ -361,13 +361,13 @@ function team($, teamName) { */ function mkwsHtmlAll() { mkwsSetLang(); - if (mkws_config.show_lang) + if (mkws.config.show_lang) mkwsHtmlLang(); log("HTML search form"); findnode('.mkwsSearch').html('\
\ - \ + \ \
'); @@ -402,10 +402,10 @@ function team($, teamName) { '); var ranking_data = '
'; - if (mkws_config.show_sort) { + if (mkws.config.show_sort) { ranking_data += M('Sort by') + ' ' + mkwsHtmlSort() + ' '; } - if (mkws_config.show_perpage) { + if (mkws.config.show_perpage) { ranking_data += M('and show') + ' ' + mkwsHtmlPerpage() + ' ' + M('per page') + '.'; } ranking_data += '
'; @@ -430,26 +430,26 @@ function team($, teamName) { function mkwsSetLang() { - var lang = getParameterByName("lang") || mkws_config.lang; + var lang = getParameterByName("lang") || mkws.config.lang; if (!lang || !mkws.locale_lang[lang]) { - mkws_config.lang = "" + mkws.config.lang = "" } else { - mkws_config.lang = lang; + mkws.config.lang = lang; } - log("Locale language: " + (mkws_config.lang ? mkws_config.lang : "none")); - return mkws_config.lang; + log("Locale language: " + (mkws.config.lang ? mkws.config.lang : "none")); + return mkws.config.lang; } /* create locale language menu */ function mkwsHtmlLang() { var lang_default = "en"; - var lang = mkws_config.lang || lang_default; + 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 lang_options = mkws.config.lang_options || []; var toBeIncluded = {}; for (var i = 0; i < lang_options.length; i++) { toBeIncluded[lang_options[i]] = true; @@ -489,8 +489,8 @@ function team($, teamName) { log("HTML sort, m_sortOrder = '" + m_sortOrder + "'"); var sort_html = ''; - for(var i = 0; i < mkws_config.perpage_options.length; i++) { - var key = mkws_config.perpage_options[i]; + for(var i = 0; i < mkws.config.perpage_options.length; i++) { + var key = mkws.config.perpage_options[i]; perpage_html += '