Skip to content

Commit

Permalink
Merge pull request #801 from aholachek/meta-tags
Browse files Browse the repository at this point in the history
added highwire metatags when abstract view is shown + trigger zotero …
  • Loading branch information
aholachek committed Feb 17, 2016
2 parents e230a22 + 7e69439 commit de89b8a
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/js/components/navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
19 changes: 19 additions & 0 deletions src/js/widgets/abstract/templates/metadata_template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<meta name="citation_title" content="{{title}}" data-highwire="true">
{{#each author}}
<meta name="citation_author" content="{{this}}" data-highwire="true">
{{/each}}
{{#if pubdate}}
<meta name="citation_publication_date" content="{{pubdate}}" data-highwire="true">
{{/if}}
{{#if pub}}
<meta name="citation_journal_title" content="{{pub}}" data-highwire="true">
{{/if}}
{{#if volume}}
<meta name="citation_volume" content="{{volume}}" data-highwire="true">
{{/if}}
{{#if issue}}
<meta name="citation_issue" content="{{issue}}" data-highwire="true">
{{/if}}
{{#if doi}}
<meta name="citation_doi" content="{{doi}}" data-highwire="true">
{{/if}}
10 changes: 10 additions & 0 deletions src/js/widgets/abstract/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -23,6 +24,7 @@ define([
Cache,
BaseWidget,
abstractTemplate,
metadataTemplate,
ApiQuery,
LinkGeneratorMixin,
PapersUtils,
Expand Down Expand Up @@ -81,6 +83,7 @@ define([
hasAffiliation: hasAffiliation,
abstract: doc.abstract,
title: title,
author : doc.author,
authorAff: authorAff,
authorAffExtra: authorAffExtra,
hasMoreAuthors: authorAffExtra.length,
Expand Down Expand Up @@ -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);

}

});
Expand Down
50 changes: 50 additions & 0 deletions test/mocha/js/widgets/abstract_widget.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]);


});


});

Expand Down

0 comments on commit de89b8a

Please sign in to comment.