const $ = require('jquery'); class Topics { constructor(section) { this.section = section.addClass('initiated'); this.cols = section.find('.col'); const fullOffset = Math.ceil(this.cols.length / 3) * 3 - this.cols.last().index() - 1; if (fullOffset === 0) { return; } let firstHalfWidth = this.cols.length - fullOffset * 2; if (firstHalfWidth < 0) { firstHalfWidth = 0; } this.cols.eq(firstHalfWidth).addClass('width-half').nextAll().addClass('width-half'); } } $('body').on('ihk-init dynamic-component-loaded gfi-dynamic-init', function () { $('.topics:not(.initiated)').each(function(i) { new Topics($(this)); }); })