From: Dennis Schafroth Date: Wed, 2 Jun 2010 12:02:03 +0000 (+0200) Subject: Mobile Browser/iPhone App friendly demo X-Git-Tag: v1.4.2~7^2~38 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=a14c3ce9ee3f8b46f28fb3eaf99e4cb71d3fad18;p=pazpar2-moved-to-github.git Mobile Browser/iPhone App friendly demo A solution for smaller screens. Using tabs to (filter) select facets. The JavaScript also supports an iPhone Application mode where some of the UI is hidden, as this is being done in the Application. --- diff --git a/www/iphone/example_client.js b/www/iphone/example_client.js index fd9c37e..b728f95 100644 --- a/www/iphone/example_client.js +++ b/www/iphone/example_client.js @@ -18,10 +18,10 @@ my_paz = new pz2( { "onshow": my_onshow, "pazpar2path": pazpar2path, "oninit": my_oninit, "onstat": my_onstat, - "onterm": my_onterm, + "onterm": my_onterm_iphone, "termlist": "xtargets,subject,author", "onbytarget": my_onbytarget, - "usesessions" : usesessions, + "usesessions" : usesessions, "showResponseType": showResponseType, "onrecord": my_onrecord } ); // some state vars @@ -36,6 +36,9 @@ var submitted = false; var SourceMax = 16; var SubjectMax = 10; var AuthorMax = 10; +var tab = "recordview"; +var inApp = false; + // // pz2.js event handlers: @@ -61,16 +64,16 @@ function my_onshow(data) { var html = []; for (var i = 0; i < data.hits.length; i++) { var hit = data.hits[i]; - html.push('
' - +''+ (i + 1 + recPerPage * (curPage - 1)) +'. ' + html.push('
  • ' + /* +''+ (i + 1 + recPerPage * (curPage - 1)) +'. ' */ +'' - + hit["md-title"] +' '); - if (hit["md-title-remainder"] !== undefined) { - html.push('' + hit["md-title-remainder"] + ' '); - } + +'" onclick="showDetails(this.id);return false;">' + + hit["md-title"] +' '); if (hit["md-title-responsibility"] !== undefined) { - html.push(''+hit["md-title-responsibility"]+''); + html.push(''+hit["md-title-responsibility"]+' '); + if (hit["md-title-remainder"] !== undefined) { + html.push('' + hit["md-title-remainder"] + ' '); + } } if (hit.recid == curDetRecId) { html.push(renderDetails(curDetRecData)); @@ -92,22 +95,64 @@ function my_onstat(data) { + '/' + data.hits + ' :.'; } +function showhide(newtab) { + var showtermlist = false; + if (newtab != null) + tab = newtab; + + if (tab == "recordview") { + document.getElementById("recordview").style.display = ''; + } + else + document.getElementById("recordview").style.display = 'none'; + + if (tab == "xtargets") { + document.getElementById("term_xtargets").style.display = ''; + showtermlist = true; + } + else + document.getElementById("term_xtargets").style.display = 'none'; + if (tab == "subjects") { + document.getElementById("term_subjects").style.display = ''; + showtermlist = true; + } + else + document.getElementById("term_subjects").style.display = 'none'; + if (tab == "authors") { + document.getElementById("term_authors").style.display = ''; + showtermlist = true; + } + else + document.getElementById("term_authors").style.display = 'none'; + + if (showtermlist == false) + document.getElementById("termlist").style.display = 'none'; + else + document.getElementById("termlist").style.display = ''; +} + function my_onterm(data) { var termlists = []; - termlists.push('
    TERMLISTS:
    .::Sources
    '); + + termlists.push('
    '); + termlists.push('
    .::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('
    .::Subjects
    '); + termlists.push('
    '); + termlists.push('
    .::Subjects
    '); for (var i = 0; i < data.subject.length && i < SubjectMax; i++ ) { termlists.push('' + data.subject[i].name + ' (' + data.subject[i].freq + ')
    '); } - - termlists.push('
    .::Authors
    '); + termlists.push('
    '); + + termlists.push('
    '); + termlists.push('
    .::Authors
    '); for (var i = 0; i < data.author.length && i < AuthorMax; i++ ) { termlists.push('' + data.author[i].name @@ -115,8 +160,76 @@ function my_onterm(data) { + data.author[i].freq + ')
    '); } + termlists.push('
    '); var termlist = document.getElementById("termlist"); replaceHtml(termlist, termlists.join('')); + var d; +/* + for (d in ("xtargets", "subjects", "authors")) { + alert(d); + if (tab == d) + document.getElementById("term_" + d).style.display = ''; + else + document.getElementById("term_" +d ).style.display = 'none'; + } +*/ + showhide(); +} + +function serialize(array) { + var t = typeof (obj); + if (t != "object" || obj === null) { + // simple data type + return String(obj); + } else { + // recurse array or object + var n, v, json = [], arr = (obj && obj.constructor == Array); + for (n in obj) { + v = obj[n]; + t = typeof (v); + if (t == "string") + v = '"' + v + '"'; + else if (t == "object" && v !== null) + v = JSON.stringify(v); + json.push((arr ? "" : '"' + n + '":') + String(v)); + } + return (arr ? "" : "") + String(json) + (arr ? "]" : "}"); + } +} + +var termlist = {}; +function my_onterm_iphone(data) { + my_onterm(data); + var targets = ""; + for (var i = 0; i < data.xtargets.length; i++ ) { + + targets = targets + data.xtargets[i].id + "|" + data.xtargets[i].name + "|" + data.xtargets[i].freq + "\n"; + } + termlist["xtargets"] = targets; + var subjects = ""; + for (var i = 0; i < data.subject.length; i++ ) { + subjects = subjects + "-" + "|" + data.subject[i].name + "|" + data.subject[i].freq + "\n"; + } + termlist["subjects"] = subjects; + var authors = ""; + for (var i = 0; i < data.author.length; i++ ) { + authors = authors + "-" + "|" + data.author[i].name + "|" + data.author[i].freq + "\n"; + } + termlist["authors"] = authors; + //document.getElementById("log").innerHTML = targets + "\n" + subjects + "\n" + authors; + callback.send("termlist", "refresh"); +} + +function getTargets() { + return termlist['xtargets']; +} + +function getSubjects() { + return termlist['subjects']; +} + +function getAuthors() { + return termlist['authors']; } function my_onrecord(data) { @@ -131,6 +244,12 @@ function my_onrecord(data) { recordDiv.innerHTML += html; } +function my_onrecord_iphone(data) { + my_onrecord(data); + callback.send("record", data.recid, data, data.xtargets[i].freq); +} + + function my_onbytarget(data) { var targetDiv = document.getElementById("bytarget"); var table ='' @@ -158,6 +277,8 @@ function domReady () document.search.query.value = ''; document.select.sort.onchange = onSelectDdChange; document.select.perpage.onchange = onSelectDdChange; + if (!inApp) + document.getElementById("heading").style.display=""; } // when search button pressed @@ -201,6 +322,7 @@ function limitQuery (field, value) { document.search.query.value += ' and ' + field + '="' + value + '"'; onFormSubmitEventHandler(); + showhide("recordview"); } // limit by target functions @@ -215,6 +337,7 @@ function limitTarget (id, name) resetPage(); loadSelect(); triggerSearch(); + showhide("recordview"); return false; } diff --git a/www/iphone/index.html b/www/iphone/index.html index 01a13d8..e741145 100644 --- a/www/iphone/index.html +++ b/www/iphone/index.html @@ -6,13 +6,15 @@ Pazpar2 demo client - + + + - - + +
    -
    Target IDHitsDiags
    - + + + +
    +
    - - + +
    + +
  • + +
    - - +
    -
    @@ -95,6 +111,5 @@
    Copyright © 1999-2010 by Index Data
    - diff --git a/www/iphone/iphone.js b/www/iphone/iphone.js new file mode 100644 index 0000000..8a71600 --- /dev/null +++ b/www/iphone/iphone.js @@ -0,0 +1,86 @@ +var count = 0; +var termlist = {}; +var JSON = JSON || {}; +var inApp = false; + +var callback = {}; + +callback.init = function() { + if (!inApp) { + callback.type = 'browser'; + document.getElementById("heading").style.display=""; + } else + callback.type = 'iphone'; + + var searchdiv = document.getElementById("searchdiv"); + if (this.type != 'iphone') { + searchdiv.style.display = ''; + document.search.onsubmit = onFormSubmit; + } + else + searchdiv.style.display = 'none'; +}; + +String.prototype.replaceAll = function(stringToFind,stringToReplace) { + var temp = this; + var index = temp.indexOf(stringToFind); + while(index != -1){ + temp = temp.replace(stringToFind,stringToReplace); + index = temp.indexOf(stringToFind); + } + return temp; + } + +callback.send = function() +{ + var args = [].splice.call(arguments,0); + for (var i = 0; i < args.length; i++) { + if (args[i]) + args[i] = args[i].replaceAll(':','_'); + else + alert("args was null: " + i); + } + var message = "myapp:" + args.join(":"); + if (this.type == 'iphone') + document.location = message; + else + document.getElementById("log").innerHTML = message; +} + +// implement JSON.stringify serialization +JSON.stringify = JSON.stringify || function(obj) { + var t = typeof (obj); + if (t != "object" || obj === null) { + // simple data type + if (t == "string") + obj = '"' + obj + '"'; + return String(obj); + } else { + // recurse array or object + var n, v, json = [], arr = (obj && obj.constructor == Array); + for (n in obj) { + v = obj[n]; + t = typeof (v); + if (t == "string") + v = '"' + v + '"'; + else if (t == "object" && v !== null) + v = JSON.stringify(v); + json.push((arr ? "" : '"' + n + '":') + String(v)); + } + return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}"); + } +}; + +function search(message) { + document.search.query.value = message; + onFormSubmitEventHandler(); + return false; +} + +function loaded() { + callback.init(); +} + +function onFormSubmit() { + return search(document.search.query.value); +}