forked from andyzeng/andyzeng.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
105 lines (93 loc) · 3.06 KB
/
main.js
File metadata and controls
105 lines (93 loc) · 3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
document.addEventListener('DOMContentLoaded', function() {
const pdfLink = document.querySelector('.pdf-link');
const overlay = document.getElementById('pdf-overlay');
const closeBtn = document.querySelector('.close-btn');
const pdfEmbed = document.getElementById('pdf-embed');
pdfLink.addEventListener('click', function(e) {
e.preventDefault();
const pdfPath = this.getAttribute('data-pdf');
pdfEmbed.setAttribute('src', pdfPath);
overlay.style.display = 'block';
});
closeBtn.addEventListener('click', function() {
overlay.style.display = 'none';
});
overlay.addEventListener('click', function(e) {
if (e.target === overlay) {
overlay.style.display = 'none';
}
});
});
// Isotope grid.
var $grid = $('.grid').isotope({
itemSelector: '.list-item',
layoutMode: 'fitRows',
transitionDuration: 0,
stagger: 10,
initLayout: false,
getSortData: {
name: '.name',
symbol: '.symbol',
number: '.number parseInt',
category: '[data-category]',
weight: function( itemElem ) {
var weight = $( itemElem ).find('.weight').text();
return parseFloat( weight.replace( /[\(\)]/g, '') );
}
}
});
// Bind filter button click.
$('#filters').on( 'click', 'button', function() {
var filterValue = $( this ).attr('data-filter');
localStorage.setItem('filterValue', filterValue);
$grid.isotope({ filter: filterValue });
});
// Change is-checked class on buttons.
$('.button-group').each( function( i, buttonGroup ) {
var $buttonGroup = $( buttonGroup );
$buttonGroup.on( 'click', 'button', function() {
$buttonGroup.find('.is-checked').removeClass('is-checked');
$( this ).addClass('is-checked');
});
});
function update_isotope() {
// Retrieve cached button click.
var defaultFilterValue = localStorage.getItem('filterValue');
if (defaultFilterValue == null) {
defaultFilterValue = ".highlight"
}
$grid.isotope({ filter: defaultFilterValue });
var buttons = document.getElementsByClassName("button");
for (var currButton of buttons) {
if (currButton.getAttribute('data-filter') == defaultFilterValue) {
currButton.classList.add('is-checked');
} else {
currButton.classList.remove('is-checked');
}
}
}
function toggle_bio() {
var x = document.getElementById("more-bio");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
function toggle_highlights() {
var x = document.getElementById("main-highlights");
var y = document.getElementById("more-highlights");
var b = document.getElementById("toggle_highlights_button")
if (y.style.display === "none") {
x.style.display = "none";
y.style.display = "block";
b.innerHTML = "Show less"
update_isotope();
} else {
x.style.display = "block";
y.style.display = "none";
b.innerHTML = "Show more"
update_isotope();
}
}
update_isotope();