's available width more than the real
* scrollbar freed up -- and centered content visibly shifts LEFT.
* - If a visitor's actual scrollbar is WIDER than 14px, Barn2 under-
* compensates and centered content visibly shifts RIGHT.
*
* This explains why this bug has been so hard to pin down purely by remote
* testing: the direction and size of the shift depends on the gap between
* the visitor's real scrollbar width and Barn2's hardcoded 14px assumption,
* which can differ from one machine/browser/display-scaling setting to the
* next, and does not match the automation environment used to test fixes
* for most of this project.
*
* Two earlier attempts at a fix are superseded by this one:
* - An earlier version stacked our own `padding-right` compensation ON TOP
* of Barn2's `margin-right: 14px`, without disabling the latter -- this
* double-compensated (shrank twice) and just produced a different,
* similarly-sized shift in the opposite direction.
* - A later version removed our own compensation entirely, relying solely
* on Barn2's native 14px rule -- which is only correct for visitors whose
* real scrollbar happens to be exactly 14px wide.
*
* THIS FIX: measures the visitor's ACTUAL scrollbar width at runtime, then
* explicitly cancels Barn2's hardcoded `margin-right: 14px` (forces it back
* to 0) and applies our own `padding-right` set to the real measured value
* instead. This is a single, precise compensation instead of a hardcoded
* guess, so it should be correct regardless of the visitor's actual
* scrollbar width.
*
* Also compensates the floating chat-widget button (`.kodee-fab`,
* `position: fixed; right: 0`), which is unaffected by anything on * (fixed-position elements are positioned relative to the viewport, not to
* 's box) and needs its own, separate compensation.
*/
(function () {
'use strict';function init() {
var body = document.body;
if (!body) {
return;
}// Measure this visitor's actual real scrollbar width once, while the
// page is in its normal (unlocked) state.
var scrollbarWidth = window.innerWidth - document.documentElement.clientWidth;if (scrollbarWidth <= 0) {
// No real (space-taking) scrollbar on this visitor's browser --
// nothing to compensate for, and nothing to do.
return;
}function applyCompensation() {
var locked = body.hasAttribute('data-scroll-locked');if (locked) {
// Cancel Barn2's hardcoded 14px assumption and replace it with
// our own precisely-measured compensation.
body.style.setProperty('margin-right', '0px', 'important');
body.style.setProperty('padding-right', scrollbarWidth + 'px', 'important');
} else {
body.style.removeProperty('margin-right');
body.style.removeProperty('padding-right');
}var fab = document.querySelector('.kodee-fab');
if (fab) {
if (locked) {
var baseRightAttr = fab.getAttribute('data-rhf-base-right');
var baseRight;
if (baseRightAttr === null) {
baseRight = parseFloat(getComputedStyle(fab).right) || 0;
fab.setAttribute('data-rhf-base-right', String(baseRight));
} else {
baseRight = parseFloat(baseRightAttr);
}
fab.style.setProperty('right', (baseRight + scrollbarWidth) + 'px', 'important');
} else {
fab.style.removeProperty('right');
}
}
}var observer = new MutationObserver(applyCompensation);
observer.observe(body, { attributes: true, attributeFilter: ['data-scroll-locked'] });// Cover the (unlikely) case where the page loads already locked.
applyCompensation();
}if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init);
} else {
init();
}
})();
Something big is brewing! Our store is in the works and will be launching soon!
18+
Age verification required
This website sells firearms, ammunition, and related products. You must be 18 years of age or older to enter.
By clicking “I Agree” below you confirm that: · You are at least 18 years of age · You agree to our Terms & Conditions · You have read and understood our Privacy Policy