X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmkws-core.js;h=91761153c6cce3cf3f7cf44f462bb2553fb3aa04;hb=d9ea1e26483a9f2a6ae9a441ec88937604a414cb;hp=cc8c63f485737f220115a54ac93f8bf874c7ed90;hpb=28433f47f69eaf289b86d681c0ef72e38ba3042f;p=mkws-moved-to-github.git diff --git a/src/mkws-core.js b/src/mkws-core.js index cc8c63f..9176115 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: {}, @@ -78,12 +78,6 @@ var mkws = { }; -// Define empty mkws_config for simple applications that don't define it. -if (mkws_config == null || typeof mkws_config != 'object') { - var mkws_config = {}; -} - - mkws.log = function(string) { if (!mkws.log_level) return; @@ -102,6 +96,16 @@ mkws.log = function(string) { }; +mkws.objectWithParent = function(parent) { + function thing() {} // Must be function so `prototype' works + + thing.prototype = parent; + var res = new thing(); + thing.prototype = null; + return res; +}; + + mkws.registerWidgetType = function(name, fn) { mkws.widgetType2function[name] = fn; mkws.log("registered widget-type '" + name + "'"); @@ -113,6 +117,8 @@ mkws.promotionFunction = function(name) { mkws.defaultMkwsConfig = function() { + mkws.config = mkws_config || {}; + /* default mkws config */ var config_default = { use_service_proxy: true, @@ -137,8 +143,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; @@ -148,13 +154,53 @@ 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]); } }; +// The following functions are dispatchers for team methods that +// are called from the UI using a team-name rather than implicit +// context. +mkws.switchView = function(tname, view) { + mkws.teams[tname].switchView(view); +}; + +mkws.showDetails = function(tname, prefixRecId) { + mkws.teams[tname].showDetails(prefixRecId); +}; + +mkws.limitTarget = function(tname, id, name) { + mkws.teams[tname].limitTarget(id, name); +}; + +mkws.limitQuery = function(tname, field, value) { + mkws.teams[tname].limitQuery(field, value); +}; + +mkws.delimitTarget = function(tname, id) { + mkws.teams[tname].delimitTarget(id); +}; + +mkws.delimitQuery = function(tname, field, value) { + mkws.teams[tname].delimitQuery(field, value); +}; + +mkws.showPage = function(tname, pageNum) { + mkws.teams[tname].showPage(pageNum); +}; + +mkws.pagerPrev = function(tname) { + mkws.teams[tname].pagerPrev(); +}; + +mkws.pagerNext = function(tname) { + mkws.teams[tname].pagerNext(); +}; + + // wrapper to call team() after page load (function(j) { var log = mkws.log; @@ -188,7 +234,7 @@ mkws.defaultMkwsConfig = function() { 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 && @@ -217,47 +263,6 @@ mkws.defaultMkwsConfig = function() { }; - // The following functions are dispatchers for team methods that - // are called from the UI using a team-name rather than implicit - // context. Apart from mkws.log, they are the ONLY public UI to - // this module. - mkws.switchView = function(tname, view) { - mkws.teams[tname].switchView(view); - }; - - mkws.showDetails = function(tname, prefixRecId) { - mkws.teams[tname].showDetails(prefixRecId); - }; - - mkws.limitTarget = function(tname, id, name) { - mkws.teams[tname].limitTarget(id, name); - }; - - mkws.limitQuery = function(tname, field, value) { - mkws.teams[tname].limitQuery(field, value); - }; - - mkws.delimitTarget = function(tname, id) { - mkws.teams[tname].delimitTarget(id); - }; - - mkws.delimitQuery = function(tname, field, value) { - mkws.teams[tname].delimitQuery(field, value); - }; - - mkws.showPage = function(tname, pageNum) { - mkws.teams[tname].showPage(pageNum); - }; - - mkws.pagerPrev = function(tname) { - mkws.teams[tname].pagerPrev(); - }; - - mkws.pagerNext = function(tname) { - mkws.teams[tname].pagerNext(); - }; - - /* * Run service-proxy authentication in background (after page load). * The username/password is configured in the apache config file @@ -311,23 +316,29 @@ mkws.defaultMkwsConfig = function() { $(document).ready(function() { mkws.defaultMkwsConfig(); - if (mkws_config.query_width < 5 || mkws_config.query_width > 150) { - log("Reset query width: " + mkws_config.query_width); - mkws_config.query_width = 50; - } - - 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.responsive_design_width) { + 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.responsive_design_width) { // Responsive web design - change layout on the fly based on // current screen width. Required for mobile devices. $(window).resize(resizePage); @@ -335,12 +346,6 @@ mkws.defaultMkwsConfig = function() { $(document).ready(resizePage); } - // 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); - } - // Backwards compatibility: set new magic class names on any // elements that have the old magic IDs. var ids = [ "Switch", "Lang", "Search", "Pager", "Navi", @@ -388,10 +393,10 @@ mkws.defaultMkwsConfig = function() { 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();