Skip to content

Commit

Permalink
Add a NestedRelatedItems js module to handle toggling of related items.
Browse files Browse the repository at this point in the history
  • Loading branch information
jkeck committed Nov 28, 2017
1 parent 76b6826 commit 8fe1c46
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
//= require blacklight_gallery
//= require blacklight_heatmaps
//= require blacklight_oembed
//= require nested_related_items
//= require openseadragon
//= require spotlight
//= require sul-exhibits-template
Expand Down
63 changes: 63 additions & 0 deletions app/assets/javascripts/nested_related_items.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/* global Blacklight */
/* global NestedRelatedItems */

(function (global) {
var NestedRelatedItems;

NestedRelatedItems = {
options: { itemSelector: 'li.mods_display_nested_related_item' },
init: function (el) {
var _this = this;

_this.listItems(el).each(function() {
$(this).removeClass('open');
_this.addToggleLink($(this));
});
},

listItems: function(list) {
return list.find(this.options.itemSelector);
},

addToggleLink: function(content) {
var dl = content.find('dl');

if(dl.length > 0) {
// Hide and remove the dl (so we can deal with just the text below)
dl.hide();
dl.detach();
// Replace the content of the list item
// with the current text wrapped in a link
content.html(this.linkElement(content));
// Add the dl back in
content.append(dl);
}
},

linkElement: function(content) {
var _this = this;
var link = $('<a href="javascript:;">' + content.text() + '</a>');
link.on('click', function() {
_this.toggleMetadata($(this));
});

return link;
},

toggleMetadata: function(item) {
var listItem = item.parent('li');
listItem.toggleClass('open');
listItem.find('dl').toggle();
}
};

global.NestedRelatedItems = NestedRelatedItems;
}(this));

Blacklight.onLoad(function () {
'use strict';

$('.mods_display_nested_related_items').each(function (i, element) {
NestedRelatedItems.init($(element)); // eslint-disable-line no-undef
});
});
17 changes: 17 additions & 0 deletions spec/features/metadata_display_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,21 @@
expect(page).to have_css 'dd', text: /Property rights reside with/
end
end

describe 'nested related items', js: true do
before do
visit metadata_exhibit_solr_document_path(exhibit_id: exhibit.slug, id: 'gk885tn1705')
end

it 'are togglable' do
within '.mods_display_nested_related_items' do
expect(page).to have_css('dl', visible: false)
expect(page).to have_css('li a', text: 'Constituent Title')
click_link 'Constituent Title'
expect(page).to have_css('dl', visible: true)
expect(page).to have_css('dt', text: /Note:/i)
expect(page).to have_css('dd', text: 'Constituent note')
end
end
end
end
2 changes: 1 addition & 1 deletion spec/fixtures/sample_solr_docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@
"exhibit_default-exhibit_tags_ssim": null,
"spotlight_resource_id_ssim": null,
"spotlight_resource_type_ssim": "dor_harvesters",
"modsxml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<mods:mods xmlns:xforms=\"http://www.w3.org/2002/xforms\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:mods=\"http://www.loc.gov/mods/v3\" xmlns:xxforms=\"http://orbeon.org/oxf/xml/xforms\">\n <mods:identifier type=\"local\" displayLabel=\"Norwich ID\">NOR 0148</mods:identifier>\n <mods:titleInfo type=\"main\">\n <mods:title>Afrique Physique.</mods:title>\n </mods:titleInfo>\n <mods:originInfo>\n <mods:dateCreated encoding=\"w3cdtf\" keyDate=\"yes\" qualifier=\"inferred\">1891</mods:dateCreated>\n <mods:place>\n <mods:placeTerm type=\"text\">Paris</mods:placeTerm>\n </mods:place>\n <mods:publisher>Migeon, J.</mods:publisher>\n </mods:originInfo>\n <mods:physicalDescription>\n <mods:extent>31 x 42 cm</mods:extent>\n </mods:physicalDescription>\n <mods:subject>\n <mods:cartographics>\n <mods:scale>Scale in kilometers</mods:scale>\n <mods:coordinates>(W 18°--E 51°/N 37°--S 35°)</mods:coordinates>\n </mods:cartographics>\n </mods:subject>\n <mods:subject authority=\"lcsh\">\n <mods:geographic authorityURI=\"http://id.loc.gov/authorities/subjects/sh85001569\">Africa--Maps</mods:geographic>\n </mods:subject>\n <mods:typeOfResource>cartographic</mods:typeOfResource>\n <mods:name type=\"personal\" authority=\"naf\" xlink:href=\"http://id.loc.gov/authorities/names/no2010043385\">\n <mods:namePart>Migeon, J.</mods:namePart>\n <mods:role>\n <mods:roleTerm type=\"text\" authority=\"marcrelator\">creator</mods:roleTerm>\n </mods:role>\n </mods:name>\n <mods:name type=\"personal\" authority=\"naf\" xlink:href=\"http://id.loc.gov/authorities/names/no2013137479\">\n <mods:namePart>Lorsignol, G.</mods:namePart>\n <mods:role>\n <mods:roleTerm type=\"text\" authority=\"marcrelator\">engraver</mods:roleTerm>\n </mods:role>\n </mods:name>\n <mods:titleInfo type=\"translated\">\n <mods:title>Physical map of Africa.</mods:title>\n </mods:titleInfo>\n <mods:note>Insets: Engraving of diamond fields by Fillatreau and Soudain. Heights of peaks and depths of lakes in Africa.</mods:note>\n <mods:note>Colored</mods:note>\n <mods:note displayLabel=\"References\" type=\"reference\">Norwich, I., Pam Kolbe, and Jeffrey C Stone. Norwich's Maps of Africa: An Illustrated and Annotated Carto-Bibliography. 2nd ed. / rev. and edited by Jeffrey C. Stone. Norwich, Vt.: Terra Nova Press, 1997, map 0148, p. 167</mods:note>\n <mods:note displayLabel=\"Provenance\" type=\"provenance\">Dr. Oscar I. Norwich</mods:note>\n <mods:genre>map</mods:genre>\n <mods:genre>Digital maps</mods:genre>\n <mods:relatedItem type=\"otherFormat\" displayLabel=\"Georeferenced Map\">\n <mods:titleInfo>\n <mods:title>Afrique Physique (Raster Image)</mods:title>\n </mods:titleInfo>\n <mods:location>\n <mods:url>http://purl.stanford.edu/zb162wk6653</mods:url>\n </mods:location>\n </mods:relatedItem>\n <mods:relatedItem type=\"host\">\n <mods:titleInfo>\n <mods:title>Dr. Oscar I. Norwich collection of maps of Africa and its islands, 1486 - ca. 1865</mods:title>\n </mods:titleInfo>\n <mods:location>\n <mods:url>https://purl.stanford.edu/qb438pg7646</mods:url>\n </mods:location>\n <mods:typeOfResource collection=\"yes\"/>\n </mods:relatedItem>\n <mods:accessCondition type=\"useAndReproduction\">To obtain permission to publish or reproduce, please contact the Special Collections Public Services Librarian at speccollref@stanford.edu.</mods:accessCondition>\n <mods:accessCondition type=\"copyright\">Property rights reside with the repository. Copyright © Stanford University. All Rights Reserved.</mods:accessCondition>\n</mods:mods>\n",
"modsxml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<mods:mods xmlns:xforms=\"http://www.w3.org/2002/xforms\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns:mods=\"http://www.loc.gov/mods/v3\" xmlns:xxforms=\"http://orbeon.org/oxf/xml/xforms\">\n <mods:identifier type=\"local\" displayLabel=\"Norwich ID\">NOR 0148</mods:identifier>\n <mods:titleInfo type=\"main\">\n <mods:title>Afrique Physique.</mods:title>\n </mods:titleInfo>\n <mods:originInfo>\n <mods:dateCreated encoding=\"w3cdtf\" keyDate=\"yes\" qualifier=\"inferred\">1891</mods:dateCreated>\n <mods:place>\n <mods:placeTerm type=\"text\">Paris</mods:placeTerm>\n </mods:place>\n <mods:publisher>Migeon, J.</mods:publisher>\n </mods:originInfo>\n <mods:physicalDescription>\n <mods:extent>31 x 42 cm</mods:extent>\n </mods:physicalDescription>\n <mods:subject>\n <mods:cartographics>\n <mods:scale>Scale in kilometers</mods:scale>\n <mods:coordinates>(W 18°--E 51°/N 37°--S 35°)</mods:coordinates>\n </mods:cartographics>\n </mods:subject>\n <mods:subject authority=\"lcsh\">\n <mods:geographic authorityURI=\"http://id.loc.gov/authorities/subjects/sh85001569\">Africa--Maps</mods:geographic>\n </mods:subject>\n <mods:typeOfResource>cartographic</mods:typeOfResource>\n <mods:name type=\"personal\" authority=\"naf\" xlink:href=\"http://id.loc.gov/authorities/names/no2010043385\">\n <mods:namePart>Migeon, J.</mods:namePart>\n <mods:role>\n <mods:roleTerm type=\"text\" authority=\"marcrelator\">creator</mods:roleTerm>\n </mods:role>\n </mods:name>\n <mods:name type=\"personal\" authority=\"naf\" xlink:href=\"http://id.loc.gov/authorities/names/no2013137479\">\n <mods:namePart>Lorsignol, G.</mods:namePart>\n <mods:role>\n <mods:roleTerm type=\"text\" authority=\"marcrelator\">engraver</mods:roleTerm>\n </mods:role>\n </mods:name>\n <mods:titleInfo type=\"translated\">\n <mods:title>Physical map of Africa.</mods:title>\n </mods:titleInfo>\n <mods:note>Insets: Engraving of diamond fields by Fillatreau and Soudain. Heights of peaks and depths of lakes in Africa.</mods:note>\n <mods:note>Colored</mods:note>\n <mods:note displayLabel=\"References\" type=\"reference\">Norwich, I., Pam Kolbe, and Jeffrey C Stone. Norwich's Maps of Africa: An Illustrated and Annotated Carto-Bibliography. 2nd ed. / rev. and edited by Jeffrey C. Stone. Norwich, Vt.: Terra Nova Press, 1997, map 0148, p. 167</mods:note>\n <mods:note displayLabel=\"Provenance\" type=\"provenance\">Dr. Oscar I. Norwich</mods:note>\n <mods:genre>map</mods:genre>\n <mods:genre>Digital maps</mods:genre>\n <mods:relatedItem type=\"otherFormat\" displayLabel=\"Georeferenced Map\">\n <mods:titleInfo>\n <mods:title>Afrique Physique (Raster Image)</mods:title>\n </mods:titleInfo>\n <mods:location>\n <mods:url>http://purl.stanford.edu/zb162wk6653</mods:url>\n </mods:location>\n </mods:relatedItem>\n <mods:relatedItem type=\"host\">\n <mods:titleInfo>\n <mods:title>Dr. Oscar I. Norwich collection of maps of Africa and its islands, 1486 - ca. 1865</mods:title>\n </mods:titleInfo>\n <mods:location>\n <mods:url>https://purl.stanford.edu/qb438pg7646</mods:url>\n </mods:location>\n <mods:typeOfResource collection=\"yes\"/>\n </mods:relatedItem>\n <mods:relatedItem type=\"constituent\">\n <mods:titleInfo>\n <mods:title>Constituent Title</mods:title>\n </mods:titleInfo>\n <mods:note>Constituent note</mods:note>\n </mods:relatedItem>\n <mods:accessCondition type=\"useAndReproduction\">To obtain permission to publish or reproduce, please contact the Special Collections Public Services Librarian at speccollref@stanford.edu.</mods:accessCondition>\n <mods:accessCondition type=\"copyright\">Property rights reside with the repository. Copyright © Stanford University. All Rights Reserved.</mods:accessCondition>\n</mods:mods>\n",
"title_245a_search": "Afrique Physique.",
"title_245_search": "Afrique Physique.",
"title_variant_search": [
Expand Down

0 comments on commit 8fe1c46

Please sign in to comment.