Skip to content

Instantly share code, notes, and snippets.

@benjaminkreen
Last active August 17, 2020 14:14
Show Gist options
  • Save benjaminkreen/e3754c295c5ddc47f7d3acce52c8e1f5 to your computer and use it in GitHub Desktop.
Save benjaminkreen/e3754c295c5ddc47f7d3acce52c8e1f5 to your computer and use it in GitHub Desktop.
var altmetricURL = 'https://api.altmetric.com/v1/doi/' + ArticleData.doi;
var dimensionsURL = 'https://metrics-api.dimensions.ai/doi/' + ArticleData.doi;
var counterURL = 'https://counter.plos.org/api/v1.0/stats/totals/doi/' + ArticleData.doi;
var URLs = [altmetricURL, dimensionsURL, counterURL];
var isMetricsView = location.pathname.indexOf('metrics') > 0
if (isMetricsView) {
var citedSection = new MetricsCitedSection();
var discussedSection = new MetricsDiscussedSection();
var savedSection = new MetricsSavedSection();
var recommendedSection = new MetricsRecommendedSection();
citedSection.$loadingEl
citedSection.$element.html('')
discussedSection.$loadingEl
discussedSection.$element.html('')
savedSection.$loadingEl
savedSection.$element.html('')
recommendedSection.$loadingEl
recommendedSection.$element.html('')
}
function createStdTiles(tileMap, $el, altData) {
var tileTemplate = _.template($('#metricsTileTemplateNoLink').html());
for (var altName in tileMap) {
var templateData = {
name: tileMap[altName],
source_name: tileMap[altName],
imgSrc: `${WombatConfig.imgPath}logo-${tileMap[altName]}.png`,
linkText: (altData[`cited_by_${altName}_count`] || altData.readers[altName] || 0)
}
$el.append(tileTemplate(templateData))
}
}
$.when(...URLs.map($.getJSON)).done(function(altResp, dimResp, counterResp) {
let altData = altResp[0];
let dimData = dimResp[0];
let counterData = counterResp[0];
// remove tweets
$('.twitter-container').remove()
// update media count
$('#media-coverage-count').text(`(${altData['cited_by_msm_count']})`)
// TODO: update media coverage linkout
var $anchor = $('#tabRelated').find('a')
$anchor.attr('href', altData.details_url)
$anchor.attr('target', '_blank')
// Signpost Render
var template = _.template($('#signpostsTemplate').html());
var templateData = {
saveCount: parseInt(altData.readers.mendeley),
citationCount: dimData.times_cited,
shareCount: altData.cited_by_fbwalls_count + altData.cited_by_tweeters_count,
viewCount: counterData['get-document'] + counterData['get-pdf']
};
$('#almSignposts').html(template(templateData));
if (isMetricsView) {
citedSection.$loadingEl.hide()
discussedSection.$loadingEl.hide()
savedSection.$loadingEl.hide()
recommendedSection.$loadingEl.hide()
var tileTemplate = _.template($('#metricsTileTemplateNoLink').html());
// citations
// url https://badge.dimensions.ai/badge?count=%20
var $dimTile = $(tileTemplate({name: 'Dimensions', source_name: 'dimensions', imgSrc: 'https://badge.dimensions.ai/badge?count=%20', linkText: dimData.times_cited}))
// ironout the wrinckles
$dimTile.find('img').css({height: '68px', background: 'white'})
citedSection.$element.append($dimTile)
citedSection.$element.show()
// discussed
var discMap = { fbwalls: 'facebook', wikipedia: 'wikipedia', rdts: 'reddit', tweeters: 'twitter' }
createStdTiles(discMap, discussedSection.$element, altData)
discussedSection.$element.show()
// saved section
var savedMap = { citeulike: 'citeulike', mendeley: 'mendeley' }
createStdTiles(savedMap, savedSection.$element, altData)
savedSection.$element.show()
// recommended section
// TODO: rh could be more that just f1000
var recMap = { rh: 'f1000' }
createStdTiles(recMap, recommendedSection.$element, altData)
recommendedSection.$element.show()
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment