Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/geochart/geochart.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
// Convert string to numeric.
for (let i = 0; i < csvData.length; ++i) {
for (let j = 0; j < csvData[i].length; ++j) {
if ($.isNumeric(csvData[i][j])) {
if (!isNaN(parseFloat(csvData[i][j])) && isFinite(csvData[i][j])) {
csvData[i][j] = parseFloat(csvData[i][j])
}
}
Expand Down
60 changes: 47 additions & 13 deletions components/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,55 @@
}
};

// Initial the jQuery Fixx plugin.
// once() prevents this listener being attached multiple times...
$(once('convivial_bootstrap_Header--fixx', '.bs-header--sticky ' + stickyElementSelector, context))
.fixx({
// Give the placeholder a class so we can specifically target only this one on the page.
placeholderClass: 'bs-header-placeholder',
// Simple vanilla JS sticky header
makeStickyHeader = function (selector, stickyClass = 'sticky-fixed') {
const element = document.querySelector(selector);
if (!element) return;

// Don't prepend the placeholder before the element, append it after.
placeholderPrepend: false,
// Create placeholder
const placeholder = document.createElement('div');
placeholder.className = 'bs-header-placeholder';
placeholder.style.display = 'none';
element.parentNode.insertBefore(placeholder, element.nextSibling);

// Keep the terminology the same.
stateFixedClass: stickyClass,
// Get initial position
const originalTop = element.offsetTop;
let isSticky = false;

// Pixel offset from screen-top of when the element becomes sticky.
startThreshold: 0
});
function handleScroll() {
const shouldStick = window.scrollY > originalTop;

if (shouldStick && !isSticky) {
// Make sticky
isSticky = true;
placeholder.style.height = element.offsetHeight + 'px';
placeholder.style.display = 'block';

element.style.position = 'fixed';
element.style.top = '0';
element.style.left = '0';
element.style.width = '100%';
element.classList.add(stickyClass);

} else if (!shouldStick && isSticky) {
// Remove sticky
isSticky = false;
placeholder.style.display = 'none';

element.style.position = '';
element.style.top = '';
element.style.left = '';
element.style.width = '';
element.classList.remove(stickyClass);
}
}

window.addEventListener('scroll', handleScroll);
}

$(once('convivial_bootstrap_Header--fixx', '.bs-header--sticky ' + stickyElementSelector, context)).each(function() {
makeStickyHeader('.bs-header--sticky ' + stickyElementSelector, stickyClass);
});

$(once('convivial_bootstrap_Header--window-change', context))
.on('resize scroll', function () {
Expand Down Expand Up @@ -111,5 +144,6 @@
}
});
}

};
})(jQuery, Drupal, once);
Loading