Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into darkmode
Browse files Browse the repository at this point in the history
  • Loading branch information
shinyichen committed May 19, 2021
2 parents e1acf46 + ced0e1f commit 02459e0
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 32 deletions.
1 change: 1 addition & 0 deletions grunt/aliases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,4 @@ release:
- cssmin
- htmlmin
- imagemin
- uglify
83 changes: 61 additions & 22 deletions src/js/widgets/abstract/templates/abstract_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,74 @@ <h2 class="s-abstract-title">

<div id="authors-and-aff" class="s-authors-and-aff">
<ul class="list-inline">
{{#each authorAff}} {{#if @last}}
{{#each authorAff}}
<li class="author">
<a href="#search/q=author:{{this.[2]}}&sort=date%20desc,%20bibcode%20desc"
>{{this.[0]}}</a
><span class="affiliation hide"> (<i>{{this.[1]}}</i>)</span>
<a href="#search/q=author:{{this.[5]}}&sort=date%20desc,%20bibcode%20desc">
{{this.[0]}}
</a>
<span>
{{#compare this.[2] '-' operator="!=="}}
<a class="orcid-author" href="#search/q=orcid:{{this.[2]}}&sort=date%20desc,%20bibcode%20desc">
<img class="inactive" src="../../styles/img/orcid-inactive.svg" alt="search by orcid">
<img class="active hidden" src="../../styles/img/orcid-active.svg" alt="search by orcid">
</a>
{{else}}
{{#compare this.[3] '-' operator="!=="}}
<a class="orcid-author" href="#search/q=orcid:{{this.[3]}}&sort=date%20desc,%20bibcode%20desc">
<img class="inactive" src="../../styles/img/orcid-inactive.svg" alt="search by orcid">
<img class="active hidden" src="../../styles/img/orcid-active.svg" alt="search by orcid">
</a>
{{else}}
{{#compare this.[4] '-' operator="!=="}}
<a class="orcid-author" href="#search/q=orcid:{{this.[4]}}&sort=date%20desc,%20bibcode%20desc">
<img class="inactive" src="../../styles/img/orcid-inactive.svg" alt="search by orcid">
<img class="active hidden" src="../../styles/img/orcid-active.svg" alt="search by orcid">
</a>
{{/compare}}
{{/compare}}
{{/compare}}
</span>
<span class="affiliation hide"> (<i>{{this.[1]}}</i>)</span>{{#if @last}}{{else}};{{/if}}
</li>
{{else}}
<li class="author">
<a href="#search/q=author:{{this.[2]}}&sort=date%20desc,%20bibcode%20desc"
>{{this.[0]}}</a
><span class="affiliation hide"> (<i>{{this.[1]}}</i>)</span>;
</li>
{{/if}} {{/each}} {{#if hasMoreAuthors}}
{{/each}}

{{#if hasMoreAuthors}}
<li class="author extra-dots">
; <a data-target="more-authors" title="Show all authors">...</a>
</li>
{{/if}} {{#each authorAffExtra}} {{#if @last}}
<li class="author extra hide">
<a href="#search/q=author:{{this.[2]}}&sort=date%20desc,%20bibcode%20desc"
>{{this.[0]}}</a
><span class="affiliation hide"> (<i>{{this.[1]}}</i>)</span>
</li>
{{else}}
{{/if}}

{{#each authorAffExtra}}
<li class="author extra hide">
<a href="#search/q=author:{{this.[2]}}&sort=date%20desc,%20bibcode%20desc"
>{{this.[0]}}</a
><span class="affiliation hide"> (<i>{{this.[1]}}</i>)</span>;
<a href="#search/q=author:{{this.[5]}}&sort=date%20desc,%20bibcode%20desc">
{{this.[0]}}
</a>
<span>
{{#compare this.[2] '-' operator="!=="}}
<a class="orcid-author" href="#search/q=orcid:{{this.[2]}}&sort=date%20desc,%20bibcode%20desc">
<img class="inactive" src="../../styles/img/orcid-inactive.svg" alt="search by orcid">
<img class="active hidden" src="../../styles/img/orcid-active.svg" alt="search by orcid">
</a>
{{else}}
{{#compare this.[3] '-' operator="!=="}}
<a class="orcid-author" href="#search/q=orcid:{{this.[3]}}&sort=date%20desc,%20bibcode%20desc">
<img class="inactive" src="../../styles/img/orcid-inactive.svg" alt="search by orcid">
<img class="active hidden" src="../../styles/img/orcid-active.svg" alt="search by orcid">
</a>
{{else}}
{{#compare this.[4] '-' operator="!=="}}
<a class="orcid-author" href="#search/q=orcid:{{this.[4]}}&sort=date%20desc,%20bibcode%20desc">
<img class="inactive" src="../../styles/img/orcid-inactive.svg" alt="search by orcid">
<img class="active hidden" src="../../styles/img/orcid-active.svg" alt="search by orcid">
</a>
{{/compare}}
{{/compare}}
{{/compare}}
</span>
<span class="affiliation hide"> (<i>{{this.[1]}}</i>)</span>{{#if @last}}{{else}};{{/if}}
</li>
{{/if}} {{/each}}
{{/each}}

</ul>
</div>
{{/if}}
Expand Down
56 changes: 50 additions & 6 deletions src/js/widgets/abstract/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,28 @@ define([
// remove html-encoding from affiliations
doc.aff = doc.aff.map(_.unescape);

const numAuthors = doc.author.length;
const defaultList = _.range(numAuthors).map(() => '-');
if (doc.aff.length) {
doc.hasAffiliation = _.without(doc.aff, '-').length;

// joining author and aff
doc.authorAff = _.zip(doc.author, doc.aff);
doc.authorAff = _.zip(
doc.author,
doc.aff,
doc.orcid_pub ? doc.orcid_pub : defaultList,
doc.orcid_user ? doc.orcid_user : defaultList,
doc.orcid_other ? doc.orcid_other : defaultList
);
} else if (doc.author) {
doc.hasAffiliation = false;
doc.authorAff = _.zip(doc.author, _.range(doc.author.length));
doc.authorAff = _.zip(
doc.author,
_.range(doc.author.length),
doc.orcid_pub ? doc.orcid_pub : defaultList,
doc.orcid_user ? doc.orcid_user : defaultList,
doc.orcid_other ? doc.orcid_other : defaultList
);
}

if (doc.page && doc.page.length) {
Expand All @@ -90,7 +105,7 @@ define([
// now add urls
if (doc.authorAff) {
_.each(doc.authorAff, function(el, index) {
doc.authorAff[index][2] = encodeURIComponent(
doc.authorAff[index][5] = encodeURIComponent(
'"' + el[0] + '"'
).replace(/%20/g, '+');
});
Expand Down Expand Up @@ -178,6 +193,26 @@ define([
'click a[target="next"]': 'onClick',
'click a[data-target="DOI"]': 'emitAnalytics',
'click a[data-target="arXiv"]': 'emitAnalytics',
'mouseenter .orcid-author': 'highlightOrcidAuthor',
'mouseleave .orcid-author': 'unhighlightOrcidAuthor',
},

highlightOrcidAuthor: function(e) {
const $target = $(e.currentTarget);
const $active = $target.find('.active');
if ($active.hasClass('hidden')) {
$active.removeClass('hidden');
$target.find('.inactive').addClass('hidden');
}
},

unhighlightOrcidAuthor: function(e) {
const $target = $(e.currentTarget);
const $inactive = $target.find('.inactive');
if ($inactive.hasClass('hidden')) {
$inactive.removeClass('hidden');
$target.find('.active').addClass('hidden');
}
},

toggleMoreAuthors: function() {
Expand Down Expand Up @@ -296,7 +331,7 @@ define([

defaultQueryArguments: {
fl:
'identifier,[citations],abstract,author,bibcode,citation_count,comment,doi,id,keyword,page,property,pub,pub_raw,pubdate,pubnote,read_count,title,volume',
'identifier,[citations],abstract,author,orcid_pub,orcid_user,orcid_other,bibcode,citation_count,comment,doi,id,keyword,page,property,pub,pub_raw,pubdate,pubnote,read_count,title,volume',
rows: 1,
},

Expand Down Expand Up @@ -450,9 +485,15 @@ define([
const ps = this.getPubSub();
const query = this.getCurrentQuery().clone();
query.unlock();
const { bibcode, author } = this.model.toJSON();
const {
bibcode,
author,
orcid_pub,
orcid_user,
orcid_other,
} = this.model.toJSON();
query.set('q', `identifier:${bibcode}`);
query.set('fl', ['aff']);
query.set('fl', ['aff', 'orcid_pub', 'orcid_user', 'orcid_other']);
query.set('rows', 1);
ps.publish(
ps.EXECUTE_REQUEST,
Expand All @@ -472,6 +513,9 @@ define([
) {
const newEntries = this.model.parse({
author: author,
orcid_pub: orcid_pub,
orcid_user: orcid_user,
orcid_other: orcid_other,
aff: resp.response.docs[0].aff,
});
this._docs[bibcode] = {
Expand Down
9 changes: 9 additions & 0 deletions src/styles/sass/ads-sass/visualizations.scss
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,15 @@ $group-circle-active: lighten($brand-warning, 10%);
}
}

.orcid-author img {
height: 20px;
width: auto;
}

.orcid-author:hover {
text-decoration: none;
}

.selected-link {
stroke: darken($brand-warning, 10%);
stroke-width: 2px;
Expand Down
25 changes: 21 additions & 4 deletions test/mocha/js/widgets/abstract_widget.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ define(['backbone', 'marionette', 'jquery', 'js/widgets/abstract/widget',
"pubdate": "1981-00-00",
"title": ["Planetary Ephemerides <A href=\"test-url\">TEST</A>"],
"aff": ["Heidelberg, Universität, Heidelberg, Germany", "California Institute of Technology, Jet Propulsion Laboratory, Pasadena, CA"],
"orcid_pub": ["1234", "-"],
"orcid_user": ["4321", "5678"],
"orcid_other": ["-", "8765"],
"citation_count" : 5,
"[citations]" : { num_citations : 3, num_references: 34 },
read_count: 30,
Expand Down Expand Up @@ -122,10 +125,10 @@ define(['backbone', 'marionette', 'jquery', 'js/widgets/abstract/widget',
expect(aw._docs['foo'].pubdate).to.equal("1981-00-00");
expect(aw._docs['foo'].formattedDate).to.equal("1981");
expect(aw._docs['foo'].pub).to.equal("IAU Colloq. 56: Reference Coordinate Systems for Earth Dynamics");
expect(aw._docs['foo'].authorAff[0]).to.eql(["Lieske, J. H.","Heidelberg, Universität, Heidelberg, Germany","%22Lieske%2C+J.+H.%22"]);
expect(aw._docs['foo'].authorAff[0]).to.eql(["Lieske, J. H.","Heidelberg, Universität, Heidelberg, Germany","1234","4321","-","%22Lieske%2C+J.+H.%22"]);
expect(aw._docs['foo'].authorAff[1]).to.eql([
"Standish, E. M.",
"California Institute of Technology, Jet Propulsion Laboratory, Pasadena, CA",
"California Institute of Technology, Jet Propulsion Laboratory, Pasadena, CA","-","5678","8765",
"%22Standish%2C+E.+M.%22"
]);
expect(aw._docs['foo'].authorAffExtra).to.eql(undefined);
Expand All @@ -142,8 +145,22 @@ define(['backbone', 'marionette', 'jquery', 'js/widgets/abstract/widget',
expect(spy.callCount).to.eql(2);
expect(aw._docs['foo'].hasAffiliation).to.eql(2);
expect(aw._docs['foo'].hasMoreAuthors).to.eql(1);
expect(aw._docs['foo'].authorAff[0]).to.eql(["Lieske, J. H.","Heidelberg, Universität, Heidelberg, Germany","%22Lieske%2C+J.+H.%22"]);
expect(aw._docs['foo'].authorAffExtra[0]).to.eql(["Standish, E. M.","California Institute of Technology, Jet Propulsion Laboratory, Pasadena, CA","%22Standish%2C+E.+M.%22"]);
expect(aw._docs['foo'].authorAff[0]).to.eql([
'Lieske, J. H.',
'Heidelberg, Universität, Heidelberg, Germany',
'1234',
'4321',
'-',
'%22Lieske%2C+J.+H.%22',
]);
expect(aw._docs['foo'].authorAffExtra[0]).to.eql([
'Standish, E. M.',
'California Institute of Technology, Jet Propulsion Laboratory, Pasadena, CA',
'-',
'5678',
'8765',
'%22Standish%2C+E.+M.%22',
]);

});

Expand Down

0 comments on commit 02459e0

Please sign in to comment.