From 7e69439030aaf1530c93eb701162a32e1bc51825 Mon Sep 17 00:00:00 2001 From: Alex Holachek Date: Wed, 17 Feb 2016 12:40:14 -0500 Subject: [PATCH] added highwire metatags when abstract view is shown + trigger zotero event --- src/js/components/navigator.js | 3 ++ .../abstract/templates/metadata_template.html | 19 +++++++ src/js/widgets/abstract/widget.js | 10 ++++ test/mocha/js/widgets/abstract_widget.spec.js | 50 +++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 src/js/widgets/abstract/templates/metadata_template.html diff --git a/src/js/components/navigator.js b/src/js/components/navigator.js index 84bcaeb75..de8b14743 100644 --- a/src/js/components/navigator.js +++ b/src/js/components/navigator.js @@ -97,6 +97,9 @@ define(['underscore', { trigger: transition.trigger || false, replace: replace } ); } + + //clear any metadata added to head on the previous page + $("head").find("meta[data-highwire]").remove(); }, handleMissingTransition: function() { diff --git a/src/js/widgets/abstract/templates/metadata_template.html b/src/js/widgets/abstract/templates/metadata_template.html new file mode 100644 index 000000000..6f2d46865 --- /dev/null +++ b/src/js/widgets/abstract/templates/metadata_template.html @@ -0,0 +1,19 @@ + +{{#each author}} + +{{/each}} +{{#if pubdate}} + +{{/if}} +{{#if pub}} + +{{/if}} +{{#if volume}} + +{{/if}} +{{#if issue}} + +{{/if}} +{{#if doi}} + +{{/if}} \ No newline at end of file diff --git a/src/js/widgets/abstract/widget.js b/src/js/widgets/abstract/widget.js index 6602f35f2..3c34ddf15 100644 --- a/src/js/widgets/abstract/widget.js +++ b/src/js/widgets/abstract/widget.js @@ -9,6 +9,7 @@ define([ 'cache', 'js/widgets/base/base_widget', 'hbs!./templates/abstract_template', + 'hbs!./templates/metadata_template', 'js/components/api_query', 'js/mixins/link_generator_mixin', 'js/mixins/papers_utils', @@ -23,6 +24,7 @@ define([ Cache, BaseWidget, abstractTemplate, + metadataTemplate, ApiQuery, LinkGeneratorMixin, PapersUtils, @@ -81,6 +83,7 @@ define([ hasAffiliation: hasAffiliation, abstract: doc.abstract, title: title, + author : doc.author, authorAff: authorAff, authorAffExtra: authorAffExtra, hasMoreAuthors: authorAffExtra.length, @@ -152,7 +155,14 @@ define([ onRender : function(){ this.$(".icon-help").popover({trigger : "hover", placement : "right", html :true}); + if (MathJax) MathJax.Hub.Queue(["Typeset", MathJax.Hub, this.el]); + + $("head").append(metadataTemplate(this.model.toJSON())); + var ev = document.createEvent('HTMLEvents'); + ev.initEvent('ZoteroItemUpdated', true, true); + document.dispatchEvent(ev); + } }); diff --git a/test/mocha/js/widgets/abstract_widget.spec.js b/test/mocha/js/widgets/abstract_widget.spec.js index 1b18590d3..740df3b47 100644 --- a/test/mocha/js/widgets/abstract_widget.spec.js +++ b/test/mocha/js/widgets/abstract_widget.spec.js @@ -129,6 +129,56 @@ define(['backbone', 'marionette', 'jquery', 'js/widgets/abstract/widget', }); + it("should populate the document head with highwire-style metatags + trigger events to inform citation managers of update", function(){ + var aw = new AbstractWidget(); + aw.activate(minsub.beehive.getHardenedInstance()); + minsub.publish(minsub.DISPLAY_DOCUMENTS, minsub.createQuery({'q': 'bibcode:foo'})); + var $w = aw.render().$el; + $("#test").append($w); + $("head [data-highwire]").remove(); + + + //check that bbb fired the correct events to contact reference manager + var fired = false; + document.addEventListener('ZoteroItemUpdated', function(){fired = true}, false); + + expect(fired).to.be.false; + + // normally the query comes back with the __show parameter, but in the test we'll help it + aw.model.set(aw._docs['foo']); + + expect(fired).to.be.true; + + expect( + $("head [data-highwire]") + .map(function(ind, el){return {name : el.name, content : el.content} }) + .get() + ).to.eql([ + { + "name": "citation_title", + "content": "Planetary Ephemerides" + }, + { + "name": "citation_author", + "content": "Lieske, J. H." + }, + { + "name": "citation_author", + "content": "Standish, E. M." + }, + { + "name": "citation_publication_date", + "content": "1981-00-00" + }, + { + "name": "citation_journal_title", + "content": "IAU Colloq. 56: Reference Coordinate Systems for Earth Dynamics" + } + ]); + + + }); + });