(function(f) {var _np=(window.P._namespace("PremiumAplusModule"));if(_np.guardFatal){_np.guardFatal(f)(_np);}else{f(_np);}}(function(P) {
P.now('premium-module-5-comparison-table-scroller').execute(function(init){
if (init) {
return;
}
P.register('premium-module-5-comparison-table-scroller', function(){
return function() {
P.when('jQuery', 'a-popover', 'A', 'ready').execute(function($, popover, A) {
function initCompTable(module) {
/**
* Premium comparison table: popover trigger module
*/
var comparisonName = $(module).data('comparison-name');
(function() {
var $additionalInfo = $('.aplus-v2 .aplus-popover-trigger');
$additionalInfo.each(function(i, trigger) {
return popover.create(trigger, $(trigger).data());
});
$additionalInfo.hover(
function() {
$(this).focus();
}
);
})();
/**
* Premium comparison table: adjust column width module
*/
(function() {
var VISIBLE_COLUMNS = 4.2; /* How many visible columns on load */
var MIN_WIDTH = 230;
var getWidth = function() {
return $(this).outerWidth();
}
/* cache selectors */
var
$container = $('.aplus-v2 .comparison-table #'+comparisonName),
$header = $('.aplus-v2 .comparison-table #'+comparisonName+' td.attribute'),
$slider = $('.aplus-v2 .comparison-table #'+comparisonName+' .table-slider'),
$columns = $('.aplus-v2 .comparison-table #'+comparisonName+' .aplus-data-column'),
$activeColumn = $('.aplus-v2 .comparison-table #'+comparisonName+' .aplus-data-column.active.active-item');
/* Formula for determining desired column width */
var calculatedColumnWidth = Math.floor(
($container.innerWidth() - $header.innerWidth()) / VISIBLE_COLUMNS
);
var childWidths = $activeColumn.map(getWidth).get();
var maxChildWidth = Math.max(MIN_WIDTH, Math.max.apply(Math, childWidths));
var minColumnWidth = $columns.innerWidth();
/* set the min-width of each column to the calulated width or minWidth */
$columns.css(
'min-width',
Math.max(MIN_WIDTH, (calculatedColumnWidth < minColumnWidth
? calculatedColumnWidth
: minColumnWidth))
);
$activeColumn.css('width', maxChildWidth);
/* show the component */
$container.removeClass('loading');
})();
/**
* Premium comparison table: sticky attribute & column
*/
(function() {
/* cache selectors */
const comparisonTable = document.querySelector('.aplus-v2 .comparison-table #'+comparisonName);
const header = comparisonTable.querySelector('td.attribute');
const fixedColumn = comparisonTable.querySelector('td.active');
const attributeColumnObserver = new ResizeObserver((entries) => {
for (let entry of entries) {
const bounds = entry.target.getBoundingClientRect().width;
const activeCellWidth = window.getComputedStyle(fixedColumn).left;
if (bounds + "px" !== activeCellWidth) {
const activeCells = document.querySelectorAll('.aplus-data-column.active');
activeCells.forEach(cell => cell.style.left = bounds + "px");
}
}
})
attributeColumnObserver.observe(header)
})();
/**
* Premium comparison table: top scroll bar
*/
(function() {
/* cache selectors */
var
$header = $('.aplus-v2 .comparison-table #'+comparisonName+' td.attribute'),
$fixedColumn = $('.aplus-v2 .comparison-table #'+comparisonName+' td.active'),
$scrollWrapperTop = $('.aplus-v2 .comparison-table #'+comparisonName+' .scroll-wrapper-top'),
$scrollWrapperBottom = $('.aplus-v2 .comparison-table #'+comparisonName+' .scroll-wrapper-bottom'),
$scrollWidth = $('.aplus-v2 .comparison-table #'+comparisonName+' .scroll-width'),
$scrollBar = $('.aplus-v2 .comparison-table #'+comparisonName+' .scroll-bar');
/* confirm fixed column exists and can add width to the total width of the scroll bar */
var fixedColumnWidth = $fixedColumn.innerWidth();
if ( fixedColumnWidth === null ) {
fixedColumnWidth = 0;
}
/* set width of scrollBar */
$scrollBar.css('width', $scrollWidth.innerWidth() + fixedColumnWidth + $header.innerWidth());
/* connect scrolls together */
$scrollWrapperTop.scroll(function() {
$scrollWrapperBottom.scrollLeft($scrollWrapperTop.scrollLeft());
});
$scrollWrapperBottom.scroll(function() {
$scrollWrapperTop.scrollLeft($scrollWrapperBottom.scrollLeft());
});
})();
}
$('.aplus-v2 .premium-aplus-module-5 .table-container').each(function(index, module) {
initCompTable(module);
});
});
}
});
});
}));