X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=src%2Fmkws-core.js;h=73f2b8db206fd74be30abddd0df38755ab63e71d;hb=6ec745d7d8ac73996838bf3e2c2c8b124cbaf31f;hp=b44ca58930275bb1f2ff48e8aa08ec4fd4bb7bca;hpb=f46b615e92b693ca8bea0eb3fb0fab65c4fbf46e;p=mkws-moved-to-github.git diff --git a/src/mkws-core.js b/src/mkws-core.js index b44ca58..73f2b8d 100644 --- a/src/mkws-core.js +++ b/src/mkws-core.js @@ -109,24 +109,6 @@ mkws.log = function(string) { }; -// Incredible that the standard JavaScript runtime doesn't define a -// unique windowId. Instead, we have to make one up. And since there's -// no global area shared between windows, the best we can do for -// ensuring uniqueness is generating a random ID and crossing our -// fingers. We stash this in window.name, as it's the only place to -// keep data that is preserved across reloads and within-site -// navigation. pz2.js picks this up and uses it as part of the -// cookie-name, to ensure each tab gets its own session. -if (window.name) { - mkws.log("Using existing window.name '" + window.name + "'"); -} else { - // Ten chars from 26 alpha-numerics = 36^10 = 3.65e15 combinations. - // At one per second, it will take 116 million years to duplicate a session - window.name = Math.random().toString(36).slice(2, 12); - mkws.log("Generated new window.name '" + window.name + "'"); -} - - // Translation function. mkws.M = function(word) { var lang = mkws.config.lang; @@ -168,13 +150,13 @@ mkws.setMkwsConfig = function(overrides) { var config_default = { use_service_proxy: true, - pazpar2_url: "//mkws.indexdata.com/service-proxy/", - service_proxy_auth: undefined, // generally rolled from the next three properties - // Was: //mkws.indexdata.com/service-proxy-auth - pp2_hostname: "mkws.indexdata.com", - sp_path: "service-proxy-auth", - sp_auth_query: undefined, // Will be: "command=auth&action=perconfig", - sp_auth_credentials: undefined, + pazpar2_url: undefined, + pp2_hostname: "sp-mkws.indexdata.com", + pp2_path: "service-proxy", + service_proxy_auth: undefined, + sp_auth_path: "service-proxy/", + sp_auth_query: "command=auth&action=perconfig", + sp_auth_credentials: "XXX/XXX", // Should be undefined: see bug MKSP-125. lang: "", sort_options: [["relevance"], ["title:1", "title"], ["date:0", "newest"], ["date:1", "oldest"]], perpage_options: [10, 20, 30, 50], @@ -257,6 +239,50 @@ mkws.pagerNext = function(tname) { }; +mkws.pazpar2_url = function() { + if (mkws.config.pazpar2_url) { + mkws.log("using pre-baked pazpar2_url '" + mkws.config.pazpar2_url + "'"); + return mkws.config.pazpar2_url; + } else { + var s = document.location.protocol + "//" + mkws.config.pp2_hostname + "/" + mkws.config.pp2_path + "/"; + mkws.log("generated pazpar2_url '" + s + "'"); + return s; + } +}; + + +// We put a session token in window.name, as it's the only place to +// keep data that is preserved across reloads and within-site +// navigation. pz2.js picks this up and uses it as part of the +// cookie-name, to ensure we get a new session when we need one. +// +// We want to use different sessions for different windows/tabs (so +// they don't receive each other's messages), different hosts and +// different paths on a host (since in general these will +// authenticate as different libraries). So the window name needs to +// include the hostname and the path from the URL, plus the token. +// +var token; +if (window.name) { + token = window.name.replace(/.*\//, ''); + mkws.log("Reusing existing window token '" + token + "'"); +} else { + // Incredible that the standard JavaScript runtime doesn't define a + // unique windowId. Instead, we have to make one up. And since there's + // no global area shared between windows, the best we can do for + // ensuring uniqueness is generating a random ID and crossing our + // fingers. + // + // Ten chars from 26 alpha-numerics = 36^10 = 3.65e15 combinations. + // At one per second, it will take 116 million years to duplicate a token + token = Math.random().toString(36).slice(2, 12); + mkws.log("Generated new window token '" + token + "'"); +} + +window.name = window.location.hostname + window.location.pathname + '/' + token; +mkws.log("Using window.name '" + window.name + "'"); + + // wrapper to provide local copy of the jQuery object. (function($) { var log = mkws.log; @@ -471,21 +497,6 @@ mkws.pagerNext = function(tname) { if (message) greet += " :: " + message; mkws.log(greet); - // TODO: Let's remove this soon - // 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); - log("added magic class to '" + node.attr('id') + "'"); - } - } - // MKWS is not active until init() has been run against an object with widget nodes. // We only set initial configuration when MKWS is first activated. if (!mkws.isActive) { @@ -533,9 +544,9 @@ mkws.pagerNext = function(tname) { } // protocol independent link for pazpar2: "//mkws/sp" -> "https://mkws/sp" - if (mkws.config.pazpar2_url.match(/^\/\//)) { + if (mkws.pazpar2_url().match(/^\/\//)) { mkws.config.pazpar2_url = document.location.protocol + mkws.config.pazpar2_url; - log("adjusted protocol independent link to " + mkws.config.pazpar2_url); + log("adjusted protocol independent link to " + mkws.pazpar2_url()); } if (mkws.config.responsive_design_width) { @@ -574,7 +585,7 @@ mkws.pagerNext = function(tname) { } else { var s = '//'; s += config.auth_hostname ? config.auth_hostname : config.pp2_hostname; - s += '/' + config.sp_path; + s += '/' + config.sp_auth_path; var q = config.sp_auth_query; if (q) { s += '?' + q; @@ -592,7 +603,7 @@ mkws.pagerNext = function(tname) { if (mkws.config.use_service_proxy && !mkws.authenticated && !mkws.authenticating) { authenticateSession(sp_auth_url(mkws.config), mkws.config.service_proxy_auth_domain, - mkws.config.pazpar2_url); + mkws.pazpar2_url()); } else if (!mkws.authenticating) { // raw pp2 or we have a session already open runAutoSearches();