X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=tools%2Fhtdocs%2Fmkws.js;h=1d0b793588332c3d1b6e7fdabe85fb3c3113df6c;hb=72a1f990ea55524c3d4bacec12f858754ab94e62;hp=2abcfcab53c28bfeb722c57825b21ee07a6fbc5e;hpb=eac2786173549080d8a0816d8b921f70c97f71c2;p=mkws-moved-to-github.git diff --git a/tools/htdocs/mkws.js b/tools/htdocs/mkws.js index 2abcfca..1d0b793 100644 --- a/tools/htdocs/mkws.js +++ b/tools/htdocs/mkws.js @@ -65,13 +65,19 @@ Handlebars.registerHelper('commaList', function(items, options) { }); +Handlebars.registerHelper('index1', function(obj) { + return obj.data.index + 1; +}); + + // Set up global mkws object. Contains truly global state such as SP // authentication, and a hash of team objects, indexed by windowid. // var mkws = { authenticated: false, - debug_level: undefined, // will be initialised from mkws_config + debug_level: 1, // Will be overridden from mkws_config, but + // initial value allows jQuery popup to use logging. paz: undefined, // will be set up during initialisation teams: {}, locale_lang: { @@ -168,6 +174,7 @@ function team($, teamName) { "last": $.now() }; var m_paz; // will be initialised below + var m_template = {}; var debug = function (s) { @@ -329,11 +336,13 @@ function team($, teamName) { for (var i = 0; i < data.length && i < max; i++) { acc.push('
'); acc.push('\ - {{translate "URL"}}\ + {{translate "Links"}}\ \ {{#each md-electronic-url}}\ - {{this}}
\ + Link{{index1}}\ {{/each}}\ \ \ @@ -805,7 +831,8 @@ function team($, teamName) { \ {{#first location having="md-subject"}}\ {{#if md-subject}}\ - {{md-subject}}\ + {{#commaList md-subject}}\ + {{this}}{{/commaList}}\ {{/if}}\ {{/first}}\ \ @@ -849,8 +876,6 @@ function team($, teamName) { 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"); // ### There is only one match here by design: fix not to bother looping $('.mkwsSearch.mkwsTeam_' + m_teamName).each(function (i, obj) { @@ -858,8 +883,8 @@ function team($, teamName) { mkws.handle_node_with_team(node, function(tname) { $(node).html('\
\ - \ - \ + \ + \
'); }); }); @@ -879,13 +904,13 @@ function team($, teamName) { \ \ \ \ \ \ @@ -1076,6 +1101,53 @@ function team($, teamName) { } + that.run_auto_search = function() { + // ### should check mkwsTermlist as well, for facet-only teams + var node = $('.mkwsRecords.mkwsTeam_' + m_teamName); + var query = node.attr('autosearch'); + if (!query) + return; + + if (query.match(/^!param!/)) { + var param = query.replace(/^!param!/, ''); + query = getParameterByName(param); + debug("obtained query '" + query + "' from param '" + param + "'"); + if (!query) { + alert("This page has a MasterKey widget that needs a query specified by the '" + param + "' parameter"); + } + } else if (query.match(/^!path!/)) { + var index = query.replace(/^!path!/, ''); + var path = window.location.pathname.split('/'); + query = path[path.length - index]; + debug("obtained query '" + query + "' from path-component '" + index + "'"); + if (!query) { + alert("This page has a MasterKey widget that needs a query specified by the path-component " + index); + } + } + + debug("node=" + node + ", class='" + node.className + "', query=" + query); + + var sort = node.attr('sort'); + var targets = node.attr('targets'); + var s = "running auto search: '" + query + "'"; + if (sort) s += " sorted by '" + sort + "'"; + if (targets) s += " in targets '" + targets + "'"; + debug(s); + + this.newSearch(query, sort, targets, m_teamName); + } + + + // This function is taken from a StackOverflow answer + // http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript/901144#901144 + function getParameterByName(name) { + name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); + var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), + results = regex.exec(location.search); + return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); + } + + /* locale */ function M(word) { var lang = mkws_config.lang; @@ -1295,23 +1367,7 @@ function team($, teamName) { debug("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'); - debug("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 + "'"; - debug(s); - var team = mkws.teams[teamName]; - debug($.toJSON(team)); - team.newSearch(query, sort, targets, teamName); - } + mkws.teams[teamName].run_auto_search(); } }
\ -
\ +
\
\ -
\ -
\ -
\ -
\ +
\ +
\ +
\ +
\