X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=experiments%2Fspclient%2Fmkws.js;h=56e329868e0c0fc28c4385768d6d47e338e3f8ea;hb=d02f5b73ee4ae0e332fde2e7c29660cca8de69cc;hp=e7217ad0e9cd5b60c9a075f8944ded72fadd37f6;hpb=9be3659050370303cf91cb8b74303466565e455b;p=mkws-moved-to-github.git diff --git a/experiments/spclient/mkws.js b/experiments/spclient/mkws.js index e7217ad..56e3298 100644 --- a/experiments/spclient/mkws.js +++ b/experiments/spclient/mkws.js @@ -3,10 +3,10 @@ "use strict"; // HTML5: disable for debug >= 2 -/* - * global config object: mkws_config - * - * needs to be defined in the HTML header before +/* + * global config object: mkws_config + * + * needs to be defined in the HTML header before * including this JS file */ @@ -113,7 +113,7 @@ function my_oninit() { function my_onshow(data) { totalRec = data.merged; // move it out - var pager = document.getElementById("pager"); + var pager = document.getElementById("mkwsPager"); pager.innerHTML = ""; pager.innerHTML +='
' + M('Displaying') + ': ' + (data.start + 1) + ' ' + M('to') + ' ' + (data.start + data.num) + @@ -121,7 +121,7 @@ function my_onshow(data) { + data.total + ')
'; drawPager(pager); // navi - var results = document.getElementById("results"); + var results = document.getElementById("mkwsResults"); var html = []; for (var i = 0; i < data.hits.length; i++) { @@ -158,47 +158,52 @@ function my_onstat(data) { } function my_onterm(data) { - if (!mkws_config.termlist_menu) + // no facets + if (!mkws_config.facets || mkws_config.facets.length == 0) { + $("#mkwsTermlists").parent().hide(); return; - - var termlists = []; - termlists.push('
' + M('Termlists') + '
'); - - termlists.push('
'); - termlists.push('
' + M('Sources') + '
'); - for (var i = 0; i < data.xtargets.length && i < SourceMax; i++ ) { - termlists.push('' - + data.xtargets[i].name - + ' (' - + data.xtargets[i].freq - + ')
'); - } - termlists.push('
'); - - termlists.push('
'); - termlists.push('
' + M('Subjects') + '
'); - for (var i = 0; i < data.subject.length && i < SubjectMax; i++ ) { - termlists.push('' - + data.subject[i].name - + ' (' - + data.subject[i].freq - + ')
'); } - termlists.push('
'); - - termlists.push('
'); - termlists.push('
' + M('Authors') + '
'); - for (var i = 0; i < data.author.length && i < AuthorMax; i++ ) { - termlists.push('' - + data.author[i].name - + ' (' - + data.author[i].freq - + ')
'); + + // display if we first got results + $("#mkwsTermlists").parent().show(); + + var acc = []; + acc.push('
' + M('Termlists') + '
'); + var facets = mkws_config.facets; + + for(var i = 0; i < facets.length; i++) { + if (facets[i] == "sources") { + add_single_facet(acc, "Sources", data.xtargets, SourceMax, null); + } else if (facets[i] == "subjects") { + add_single_facet(acc, "Subjects", data.subject, SubjectMax, "su"); + } else if (facets[i] == "authors") { + add_single_facet(acc, "Authors", data.author, AuthorMax, "au"); + } else { + alert("bad facet configuration: '" + facets[i] + "'"); + } } - termlists.push('
'); - var termlist = document.getElementById("termlist"); - replaceHtml(termlist, termlists.join('')); + var termlist = document.getElementById("mkwsTermlists"); + replaceHtml(termlist, acc.join('')); +} + +function add_single_facet(acc, caption, data, max, cclIndex) { + acc.push('
'); + acc.push('
' + M(caption) + '
'); + for (var i = 0; i < data.length && i < max; i++ ) { + acc.push('' + data[i].name + '' + + ' (' + data[i].freq + ')
'); + } + acc.push('
'); } function my_onrecord(data) { @@ -496,7 +501,8 @@ function mkws_html_all(config) { switch_menu: true, /* show/hide Records|Targets menu */ lang_menu: true, /* show/hide language menu */ lang_display: [], /* display languages links for given languages, [] for all */ - termlist_menu: true, /* show/hide termlist */ + facets: ["sources", "subjects", "authors"], /* display facets, in this order, [] for none */ + debug: 0, /* debug level for development: 0..2 */ dummy: "dummy" @@ -508,7 +514,7 @@ function mkws_html_all(config) { } else if (mkws_config_default.debug !== 'undefined') { mkws_debug = mkws_config_default.debug; } - + /* override standard config values by function parameters */ for (var k in mkws_config_default) { if (typeof config[k] === 'undefined') @@ -520,10 +526,10 @@ function mkws_html_all(config) { debug("Reset query width: " + mkws_config.query_width); mkws_config.query_width = 50; } - - mkws_set_lang(mkws_config); + + mkws_set_lang(mkws_config); if (mkws_config.lang_menu) - mkws_html_lang(mkws_config); + mkws_html_lang(mkws_config); // For some reason, doing this programmatically results in // document.search.query being undefined, hence the raw HTML. @@ -539,7 +545,7 @@ function mkws_html_all(config) { \ \ \ \ \
\ -
\ +
\
\
\ @@ -549,18 +555,41 @@ function mkws_html_all(config) { ' + M('per page') + '.\ \
\ -
\ +
\ \ -
\ +
\
'); mkws_html_switch(config); + if (mkws_config.use_service_proxy) mkws_service_proxy_auth(config.service_proxy_auth); + if (mkws_config.responsive_design) + mkws_responsive_design(); + domReady(); + + // on first page, hide the termlist + $(document).ready(function() { $("#mkwsTermlists").parent().hide(); } ); +} + +/* Responsive web design - change layout on the fly depending on + * the current screen size width/height. Required for mobile devices. + */ +function mkws_responsive_design () { + var timeout = null; + + $(window).resize( function(e) { + if (timeout) + clearTimeout(timeout); + timeout = setTimeout(function () { mkws_mobile_resize() }, 100); + }); + + // initial check after page load + $(document).ready(function() { mkws_mobile_resize() }); } function mkws_set_lang(mkws_config) { @@ -570,14 +599,14 @@ function mkws_set_lang(mkws_config) { } else { mkws_config.lang = lang; } - + debug("Locale language: " + (mkws_config.lang ? mkws_config.lang : "none")); return mkws_config.lang; } function mkws_html_switch(config) { debug("HTML switch"); - + $("#mkwsSwitch").html($("", { href: '#', onclick: "switchView(\'records\')", @@ -648,7 +677,7 @@ function mkws_html_perpage(config) { function mkws_service_proxy_auth(auth_url) { if (!auth_url) auth_url = "http://mkws.indexdata.com/service-proxy-auth"; - + debug("Run service proxy auth URL: " + auth_url); var request = new pzHttpRequest(auth_url); @@ -677,7 +706,7 @@ function mkws_html_lang(mkws_config) { for (var i = 0; i < lang_display.length; i++) { hash[lang_display[i]] = 1; } - + for (var k in mkws_locale_lang) { if (hash[k] == 1 || lang_display.length == 0) list.push(k); @@ -690,23 +719,46 @@ function mkws_html_lang(mkws_config) { debug("Language menu for: " + list.join(", ")); /* the HTML part */ - var data = ""; + var data = ""; for(var i = 0; i < list.length; i++) { var l = list[i]; - + if (data) data += ' | '; - + if (lang == l) { data += ' ' + l + ' '; } else { data += ' ' + l + ' ' } } - + $("#mkwsLang").html(data); } +function mkws_mobile_resize () { + debug("resize width: " + $(window).height() + ", width: " + $(window).width()); + var list = ["mkwsSwitch"]; + var obj; + // alert($(window).width()); + + if ($(window).width() <= 980) { + for(var i = 0; i < list.length; i++) { + $("#" + list[i]).hide(); + } + + $("#mkwsTermlists").parent().hide(); + obj = $("#mkwsTermlists").parent().html(); + $("#mkwsShiftedTermlists").html("
" + obj); + } else { + for(var i = 0; i < list.length; i++) { + $("#" + list[i]).show(); + } + $("#mkwsTermlists").parent().show(); + $("#mkwsShiftedTermlists").html(""); + } +}; + /* locale */ function M(word) { var lang = mkws_config.lang; @@ -728,7 +780,7 @@ jQuery.extend({ nvpair[pair[0]] = pair[1]; }); return nvpair; - }, + }, pazpar2: function(data) { document.write('
\
\