123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- let pubFilters = {};
- let searchRegex;
- let filterValues;
- let $grid_pubs = $('#container-publications');
- if ($grid_pubs.length) {
- $grid_pubs.isotope({
- itemSelector: '.isotope-item',
- percentPosition: true,
- masonry: {
-
- columnWidth: '.grid-sizer',
- },
- filter: function () {
- let $this = $(this);
- let searchResults = searchRegex ? $this.text().match(searchRegex) : true;
- let filterResults = filterValues ? $this.is(filterValues) : true;
- return searchResults && filterResults;
- },
- });
-
- let $quickSearch = $('.filter-search').keyup(
- debounce(function () {
- searchRegex = new RegExp($quickSearch.val(), 'gi');
- $grid_pubs.isotope();
- }),
- );
- $('.pub-filters').on('change', function () {
- let $this = $(this);
-
- let filterGroup = $this[0].getAttribute('data-filter-group');
-
- pubFilters[filterGroup] = this.value;
-
- filterValues = concatValues(pubFilters);
-
- $grid_pubs.isotope();
-
- if (filterGroup === 'pubtype') {
-
- let url = $(this).val();
- if (url.substr(0, 9) === '.pubtype-') {
- window.location.hash = url.substr(9);
- } else {
- window.location.hash = '';
- }
- }
- });
- }
- function debounce(fn, threshold) {
- let timeout;
- threshold = threshold || 100;
- return function debounced() {
- clearTimeout(timeout);
- let args = arguments;
- let _this = this;
- function delayed() {
- fn.apply(_this, args);
- }
- timeout = setTimeout(delayed, threshold);
- };
- }
- function concatValues(obj) {
- let value = '';
- for (let prop in obj) {
- value += obj[prop];
- }
- return value;
- }
- function filter_publications() {
-
- if (!$grid_pubs.length) return;
- let urlHash = window.location.hash.replace('#', '');
- let filterValue = '*';
-
- if (urlHash != '' && !isNaN(urlHash)) {
- filterValue = '.pubtype-' + urlHash;
- }
-
- let filterGroup = 'pubtype';
- pubFilters[filterGroup] = filterValue;
- filterValues = concatValues(pubFilters);
-
- $grid_pubs.isotope();
-
- $('.pubtype-select').val(filterValue);
- }
- document.addEventListener('DOMContentLoaded', function () {
-
- if ($('.pub-filters-select')) {
- filter_publications();
-
-
- }
-
- $('.js-cite-modal').click(function (e) {
- e.preventDefault();
- let filename = $(this).attr('data-filename');
- let modal = $('#modal');
- modal.find('.modal-body code').load(filename, function (response, status, xhr) {
- if (status == 'error') {
- let msg = 'Error: ';
- $('#modal-error').html(msg + xhr.status + ' ' + xhr.statusText);
- } else {
- $('.js-download-cite').attr('href', filename);
- }
- });
- modal.modal('show');
- });
-
- $('.js-copy-cite').click(function (e) {
- e.preventDefault();
-
- let citation = document.querySelector('#modal .modal-body').innerHTML;
- navigator.clipboard
- .writeText(citation)
- .then(function () {
- console.debug('Citation copied!');
- })
- .catch(function () {
- console.error('Citation copy failed!');
- });
- });
- });
|