From bf718328810eee3ee636268da4bfe738096c0b24 Mon Sep 17 00:00:00 2001 From: Paul Pound Date: Mon, 17 Jul 2017 15:41:03 -0300 Subject: [PATCH] started on formating eds book search results --- js/jquery.arrayUtilities.min.js | 1 + roblib_search.module | 2 - targets/eds/js/eds_results.js | 67 ++++++++++++++------------- targets/eds/js/eds_results_article.js | 1 - 4 files changed, 36 insertions(+), 35 deletions(-) create mode 100755 js/jquery.arrayUtilities.min.js diff --git a/js/jquery.arrayUtilities.min.js b/js/jquery.arrayUtilities.min.js new file mode 100755 index 0000000..61113ef --- /dev/null +++ b/js/jquery.arrayUtilities.min.js @@ -0,0 +1 @@ +(function(e){var t={};var n=function(e){for(var t=0;t'); @@ -29,11 +28,25 @@ Drupal.behaviors.roblib_search_eds = { items.push(''+val2.Data+''); }) } - items.push('
'); - jQuery.each(val.RecordInfo.BibRelationships.HasContributorRelationships, function(key3, authors){ - items.push(authors.NameFull+';'+' '); + pubYear = val.RecordInfo.BibRelationships.IsPartOfRelationships["date"][0]["Y"]; + if(pubYear == 'undefined') { + pubYear = "Unknown"; + } + if (typeof val.Items.TypPub !== 'undefined') { + jQuery.each(val.Items.TypPub, function(key6, typpub){ + strs = typpub.Data.split('; '); + types = roblib_intersects(strs, ['Book', 'eBook']); + items.push('
'+pubYear+' - '+ types.join(', ') + '
'); }) - items.push('
'); + } + items.push('
'); + roblib_authors = ""; + jQuery.each(val.RecordInfo.BibRelationships.HasContributorRelationships, function(key3, author){ + roblib_authors += author.NameFull; + }) + roblib_authors = roblib_shorten(roblib_authors, 50, " "); + items.push(roblib_authors); + items.push('
'); if (typeof val.Items.Src !== 'undefined') { jQuery.each(val.Items.Src, function(key4, source){ items.push('
'+source.Data+'
'); @@ -44,11 +57,6 @@ Drupal.behaviors.roblib_search_eds = { items.push('
'+pubinfo.Data+'
'); }) } - if (typeof val.Items.TypPub !== 'undefined') { - jQuery.each(val.Items.TypPub, function(key6, typpub){ - items.push('
'+typpub.Label+': '+typpub.Data+'
'); - }) - } items.push('
'+val.DbLabel+'
'); @@ -72,27 +80,22 @@ Drupal.behaviors.roblib_search_eds = { } } -function edsPopulatePopupDivs(content, val, counter){ - content[counter] = ''; - try{ - jQuery.each(val.DetailedRecord, function(key, value){ - if (content.length < 5 && - (value.Group == 'PubInfo' || value.Group =="TypPub" || value.Group == "TypeDoc" || value.Group =="Su" || value.Group == "Au")) { - content[counter] += '
' + value.Label + ': ' ; - content[counter] += ' ' + value.Data +'
';(value.Group =='Ab' || value.Group == 'Note' ) - } else if (content[counter].length < 5 && (value.Group == "Note" || value.Group== "Ab")) { - content[counter] += '
' + value.Label + ': ' ; - content[counter] += ' ' + value.Data +'
'; - } else if (content[counter].length < 3 && (value.Group == 'TOC' || value.Group == 'Src')) { - content[counter] += '
' + value.Label + ': ' ; - content[counter] += ' ' + value.Data +'
'; - } else if (content[counter].length < 1 && value.Group == 'Ti') { - content[counter] += '
' + value.Label + ': ' ; - content[counter] += ' ' + value.Data +'
'; - } - }) - } catch (err) { - // do nothing as there is no data to work with - } +function roblib_intersects(a, b) { + var d = {}; + var results = []; + for (var i = 0; i < b.length; i++) { + d[b[i]] = true; + } + for (var j = 0; j < a.length; j++) { + if (d[a[j]]) + results.push(a[j]); + } + return results; } +function roblib_shorten(str, maxLen, separator) { + if (str.length <= maxLen) return str; + return str.substr(0, str.lastIndexOf(separator, maxLen)) + ' et al.'; +} + + diff --git a/targets/eds/js/eds_results_article.js b/targets/eds/js/eds_results_article.js index 5cd9cf8..0340568 100644 --- a/targets/eds/js/eds_results_article.js +++ b/targets/eds/js/eds_results_article.js @@ -19,7 +19,6 @@ Drupal.behaviors.roblib_search_eds_articles = { var content = new Array(); jQuery.each(data.records, function(key, val) { id = 'roblib-search-eds-article-' + counter; - edsPopulatePopupDivs(content, val, counter); divs[counter++] = id; if (typeof val.Items !== 'undefined') {