/** * @constructor */ PromoHistory = function() { /** * @type {!jQuery} * @private */ this.root_ = jQuery('#layout'); /** * @type {!Number} * @private */ this.sectionMainHeight_ = this.root_.find('section.main').outerHeight(); /** * @type {!jQuery} * @private */ this.progress_ = this.root_.find('.progress'); /** * @type {!jQuery} * @private */ this.quickTransitionWrapper_ = this.root_.find('.quick-transition-wrapper'); /** * @type {!jQuery} * @private */ this.quickTransitionContent_ = this.quickTransitionWrapper_.find('.quick-transition-content'); /** * @type {!jQuery} * @private */ this.quickTransition_ = this.quickTransitionWrapper_.find('.quick-transition'); /** * @type {!jQuery} * @private */ this.arrowIconPrev_ = this.quickTransitionWrapper_.find('span.prev'); /** * @type {!jQuery} * @private */ this.arrowIconNext_ = this.quickTransitionWrapper_.find('span.next'); /** * @type {!jQuery} * @private */ this.sectionContent_ = this.root_.find('.section-content'); /** * @type {!jQuery} * @private */ this.events_ = this.sectionContent_.find('.column'); /** * @type {!jQuery} * @private */ this.mainHeaderImages_ = this.root_.find('.main-header-images').find('img'); /** * @type {!jQuery} * @private */ this.up_ = this.root_.find('.up'); /** * @type {!Number} * @private */ this.mainHeaderImage_ = 1; /** * @type {!Boolean} * @private */ this.mouseDown_ = false; /** * @type {!Number} * @private */ this.clientX_ = 0; /** * @type {!Number} * @private */ this.scrollLeft_ = 0; /** * @type {!Array} * @private */ this.eventPositions_ = []; /** * @type {!Number} * @private */ this.currentYear_ = -1; this.init_(); this.mainHeaderImagesVisible_(); this.attachEvents_(); }; /** * @private */ PromoHistory.prototype.init_ = function() { var that = this; for (var i = 0; i < this.events_.length; i++) { new VerticalFixer( this.events_.eq(i).find('.holder'), this.events_.eq(i).find('.year'), this.events_.eq(i).find('.desc'), this.events_.eq(i).find('.year'), 20); } }; /** * @private */ PromoHistory.prototype.mainHeaderImagesVisible_ = function() { var that = this; setTimeout(function() { if (that.mainHeaderImage_ >= that.mainHeaderImages_.length) { that.mainHeaderImage_ = 0; } that.mainHeaderImages_.removeAttr('class'); that.mainHeaderImages_.eq(that.mainHeaderImage_).addClass('visible'); that.mainHeaderImagesVisible_(); that.mainHeaderImage_++; }, 15000); }; /** * @private */ PromoHistory.prototype.attachEvents_ = function() { var that = this; var scrollLeft = 0; var quickTransitionContentWidth = 0; var mousemove = false; this.quickTransition_.on('mousedown touchstart', function(event) { this.mouseDown_ = true; this.clientX_ = event.clientX || event.originalEvent.touches[0].clientX; scrollLeft = that.scrollLeft_; quickTransitionContentWidth = that.quickTransitionContent_.width(); that.quickTransitionContent_.addClass('mouse-down'); }).on('mouseup touchend', function() { this.mouseDown_ = false; that.quickTransitionContent_.removeClass('mouse-down'); }).on('mousemove touchmove', function(event) { if (this.mouseDown_) { mousemove = true; var clientX = event.clientX || event.originalEvent.touches[0].clientX; that.scrollLeft_ = scrollLeft + this.clientX_ - clientX; if (that.scrollLeft_ >= 0) { that.arrowIconPrev_.removeClass('disabled'); } else { that.scrollLeft_ = 0; that.arrowIconPrev_.addClass('disabled'); } if ((that.scrollLeft_ + that.quickTransition_.width()) > quickTransitionContentWidth) { that.scrollLeft_ = quickTransitionContentWidth - that.quickTransition_.width(); that.arrowIconNext_.addClass('disabled'); return; } else { that.arrowIconNext_.removeClass('disabled'); } that.quickTransitionContent_.css({'transform': 'translateX(-' + that.scrollLeft_ + 'px)'}); } }).on('mouseleave touchend', function() { this.mouseDown_ = false; that.quickTransitionContent_.removeClass('mouse-down'); }).on('click', '.item', function(event) { if (mousemove === false) { var anchor = jQuery(event.currentTarget).data('anchor'); that.scrollTo_(anchor); } mousemove = false; }); this.arrowIconNext_.on('click', function() { that.arrowIconPrev_.removeClass('disabled'); that.scrollLeft_ = that.scrollLeft_ + that.quickTransition_.width() / 2; quickTransitionContentWidth = that.quickTransitionContent_.width(); if ((that.scrollLeft_ + that.quickTransition_.width()) > quickTransitionContentWidth) { that.scrollLeft_ = quickTransitionContentWidth - that.quickTransition_.width(); that.arrowIconNext_.addClass('disabled'); } that.quickTransitionContent_.css({'transform': 'translateX(-' + that.scrollLeft_ + 'px)'}); }); this.arrowIconPrev_.on('click', function() { that.arrowIconNext_.removeClass('disabled'); that.scrollLeft_ = that.scrollLeft_ - that.quickTransition_.width() / 2; quickTransitionContentWidth = that.quickTransitionContent_.width(); if (that.scrollLeft_ <= 0) { that.scrollLeft_ = 0; that.arrowIconPrev_.addClass('disabled'); } that.quickTransitionContent_.css({'transform': 'translateX(-' + that.scrollLeft_ + 'px)'}); }); this.up_.on('click', function() { jQuery('html, body').animate({ scrollTop: jQuery('html').offset().top }, 1000); that.up_.removeClass('hover'); }); this.up_.on('mouseover', function() { that.up_.addClass('hover'); }); this.up_.on('mouseout', function() { that.up_.removeClass('hover'); }); jQuery(window).on('scroll load resize', function() { if (jQuery(window).scrollTop() > jQuery(window).height()) { if (that.up_.hasClass('not-visible')) { that.up_.removeClass('not-visible'); } } else { if (!that.up_.hasClass('not-visible')) { that.up_.addClass('not-visible'); } } that.progress_.toggleClass('stopped', jQuery(window).scrollTop() > that.sectionMainHeight_); that.progress_.find('div').css({'width': (jQuery(window).scrollTop() / (jQuery(that.root_).outerHeight() - jQuery(window).height())) * 100 + '%'}); for (var i = 0, len = that.eventPositions_.length; i < len; i++) { if (that.currentYear_ === -1 || that.eventPositions_[i] > jQuery(window).scrollTop()) { if (that.currentYear_ !== i) { that.sectionContent_.find('.years div').removeAttr('class').eq(i).addClass('active'); } that.currentYear_ = i; return; } } }); }; /** * @param {!string} anchor * @private */ PromoHistory.prototype.scrollTo_ = function(anchor) { jQuery('html, body').animate({ scrollTop: jQuery(this.events_.find('.year:contains("' + anchor + '")')).offset().top }, 1000); }; jQuery(document).ready(function() { new PromoHistory(); });