1const loader = document.querySelector('#citations-loader'); 2const pluginContainer = document.querySelector('#citation-plugin'); 3const providerList = ['crossref', 'scopus', 'europepmc', 'google']; 4 5if (pluginContainer) { 6 fetchCitationsData(pluginContainer.getAttribute('data-citations-url')); 7} 8 9function fetchCitationsData(url) { 10 if (url) { 11 fetch(url, { 12 method: 'GET', 13 }).then(function (response) { 14 if (response.ok) { 15 return response.json(); 16 } else 17 throw new Error('Error getting API Data!'); 18 }).then((data) => { 19 displayTotalContent(data.content); 20 displayListContent(data.content); 21 if (undefined !== loader) { 22 loader.style.display = 'none'; 23 } 24 }).catch(error => { 25 if (undefined !== loader) { 26 loader.style.display = 'none'; 27 } 28 console.log(error); 29 }); 30 } 31} 32 33function displayTotalContent(data) { 34 let gridColumns = ''; 35 providerList.forEach(function (provider) { 36 if (data.hasOwnProperty(provider)) { 37 if ('google' === provider) { 38 pluginContainer.querySelector('.citations-count-google').style.display = 'block'; 39 gridColumns += '1fr '; 40 } else if (data[provider].hasOwnProperty('count')) { 41 pluginContainer.querySelector('.citations-count-' + provider + ' .badge_total').innerHTML = data[provider].count; 42 pluginContainer.querySelector('.citations-count-' + provider).style.display = 'block'; 43 gridColumns += '1fr '; 44 } 45 } 46 }); 47 gridColumns = gridColumns.trim(); 48 pluginContainer.querySelector('.citations-count').style.gridTemplateColumns = gridColumns; 49 if (gridColumns.length === 3) { 50 pluginContainer.querySelector('.citations-count').querySelector('img').style.maxWidth = '50%'; 51 } 52} 53 54function displayListContent(data) { 55 let list = pluginContainer.querySelector('.citations-list'); 56 providerList.forEach(function (provider) { 57 if (data.hasOwnProperty(provider)) { 58 if (data[provider].hasOwnProperty('citations') && data[provider]['citations'].length > 0) { 59 data[provider]['citations'].forEach(function (item) { 60 list.append(createListElement(item)); 61 }); 62 } 63 } 64 }); 65} 66 67 68function createListElement(item) { 69 let prototype = pluginContainer.querySelector('.cite-prototype').cloneNode(true); 70 prototype.classList.remove('cite-prototype'); 71 prototype.style.display = 'block'; 72 let source = item.hasOwnProperty('source') ? item.source.toLowerCase() : ''; 73 prototype.querySelector('.cite-img').src = pluginContainer.getAttribute('data-img-url') + source + '.png'; 74 prototype.querySelector('.cite-img').alt = capitalizeFirstLetter(source) + " Logo"; 75 if (item.hasOwnProperty('authors')) { 76 prototype.querySelector('.cite-author').innerHTML = item.authors; 77 } 78 if (item.hasOwnProperty('year')) { 79 prototype.querySelector('.cite-date').innerHTML = '(' + item.year + ')'; 80 } 81 if (item.hasOwnProperty('title')) { 82 prototype.querySelector('.cite-title').innerHTML = '<strong>' + item.title + '.</strong>'; 83 } 84 if (item.hasOwnProperty('journal') && item.journal !== '') { 85 prototype.querySelector('.cite-info').innerHTML += item.journal; 86 } 87 if (item.hasOwnProperty('volume') && item.volume !== '') { 88 prototype.querySelector('.cite-info').innerHTML += ', ' + item.volume; 89 } 90 if (item.hasOwnProperty('issue') && item.issue !== '') { 91 prototype.querySelector('.cite-info').innerHTML += '(' + item.issue + ')'; 92 } 93 if (item.hasOwnProperty('pages') && item.pages !== '') { 94 prototype.querySelector('.cite-info').innerHTML += ', ' + item.pages; 95 } 96 prototype.querySelector('.cite-info').innerHTML += '.'; 97 if (item.hasOwnProperty('doi') && item.doi !== '') { 98 prototype.querySelector('.cite-doi').innerHTML = '<a href="https://doi.org/' + item.doi + '" target="_blank" rel="noreferrer">' + item.doi + '</a>'; 99 } 100 101 return prototype; 102} 103 104 105function capitalizeFirstLetter(string) { 106 return string.charAt(0).toUpperCase() + string.slice(1); 107}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.