/** @author Oleg Krasnov (krasnov@artlebedev.ru) @created 2019.01.28 @copyright Art. Lebedev Studio (http://www.artlebedev.ru/) This source code follows Formatting section of Google Javascript Style Guide https://google.github.io/styleguide/jsguide.html#formatting */ /** * @constructor */ PromoUniversity = function() { /** * @type {!jQuery} * @private */ this.root_ = jQuery('#layout'); /** * @type {!jQuery} * @private */ this.courseSection_ = this.root_.find('.course'); /** * @type {!jQuery} * @private */ this.courseDescriptionSection_ = this.root_.find('.course_description'); /** * @type {!jQuery} * @private */ this.svgText_ = this.courseDescriptionSection_.find('.item'); /** * @type {!jQuery} * @private */ this.svgTextDescription_ = this.svgText_.find('.svg_description h3'); this.init_(); this.attachEvents_() }; /** * @private */ PromoUniversity.prototype.init_ = function() { for (var i = 0; i < this.courseSection_.length; i++) { new VerticalFixer( this.courseSection_.eq(i).find('.holder'), this.courseSection_.eq(i).find('.details'), this.courseSection_.eq(i).find('.program'), this.courseSection_.eq(i).find('.details'), 30); } }; /** * @private */ PromoUniversity.prototype.attachEvents_ = function() { var that = this; var prevActive = 0; var currentActive = 0; jQuery(window).scroll(function() { // var windowHeight = jQuery(window).height(); var windowWidth = jQuery(window).width(); var windowScrollTop = jQuery(window).scrollTop(); for (var i = 0; i < that.svgText_.length; i++) { var svgTextTopPosition = that.svgText_.eq(i).offset().top - 100; if (windowScrollTop > svgTextTopPosition) { currentActive = i; if ((currentActive === 0 || currentActive === 1) && windowWidth > 760) { that.svgTextDescription_.addClass('fixed'); } else if (currentActive === 2) { that.svgTextDescription_.removeClass('fixed'); } } else { if (i === 0 && currentActive === 0) { that.svgTextDescription_.removeClass('fixed'); } } } if (prevActive !== currentActive) { that.svgText_.removeClass('active'); that.svgText_.eq(currentActive).addClass('active'); prevActive = currentActive; } }); }; jQuery(document).ready(function() { new PromoUniversity(); });