// Generated by CoffeeScript 1.10.0 /** Better implementation of the typeof function See http://javascript.crockford.com/remedial.html @param {mixed} Mixed element to determine the typeof @return {string} Type of the element */ (function() { var base, base1, base2, dir, log, type; type = function(obj) { var classToType, i, len, myClass, name, ref; if (obj === void 0 || obj === null) { return String(obj); } classToType = new Object; ref = "Boolean Number String Function Array Date RegExp".split(" "); for (i = 0, len = ref.length; i < len; i++) { name = ref[i]; classToType["[object " + name + "]"] = name.toLowerCase(); } myClass = Object.prototype.toString.call(obj); if (myClass in classToType) { return classToType[myClass]; } return "object"; }; log = function(msg, ident) { if (ident == null) { ident = ''; } if (ident !== '') { ident = ident + ': '; } if ((typeof console !== "undefined" && console !== null ? console.log : void 0) != null) { return console.log("" + ident + msg); } }; dir = function(obj) { if ((typeof console !== "undefined" && console !== null ? console.dir : void 0) != null) { return console.dir(obj); } }; if (typeof window !== "undefined" && window !== null) { if (window.cjs == null) { window.cjs = {}; } if ((base = window.cjs).type == null) { base.type = type; } if ((base1 = window.cjs).log == null) { base1.log = log; } if ((base2 = window.cjs).dir == null) { base2.dir = dir; } } else { if (exports.type == null) { exports.type = type; } if (exports.log == null) { exports.log = log; } if (exports.dir == null) { exports.dir = dir; } } }).call(this); // Generated by CoffeeScript 1.10.0 /** @require Generic functions */ (function() { var BannerScroll, base; if (typeof window === "undefined" || window === null) { (typeof global !== "undefined" && global !== null ? global : window).cjs = require('../generic/generic'); } BannerScroll = (function() { BannerScroll.prototype.POSITION_FIXED = 'fixed'; BannerScroll.prototype.POSITION_ABSOLUTE = 'absolute'; BannerScroll.prototype.POSITION_STATIC = 'static'; function BannerScroll(wrapElement, jQuery) { this.wrapElement = wrapElement; this.jQuery = jQuery; this.originWrapElement = this.jQuery(this.wrapElement).clone(); this.position = null; this.originTop = this.getOffsetTop(); this.isManaged = false; this.remanageCallback = function() {}; this.remanageCallbackEmpty = true; } BannerScroll.prototype.getOriginWrapElement = function() { return this.originWrapElement; }; BannerScroll.prototype.getPosition = function() { return this.position; }; BannerScroll.prototype.resetPosition = function() { this.jQuery(this.getWrapElement()).css('top', ''); this.jQuery(this.getWrapElement()).removeClass("fixed-position"); this.jQuery(this.getWrapElement()).removeClass("absolute-position"); this.jQuery(this.getWrapElement()).addClass("static-position"); return this.position = this.POSITION_STATIC; }; BannerScroll.prototype.getWrapElement = function() { return this.wrapElement; }; BannerScroll.prototype.setToFixedPosition = function() { this.setRemanageCallback((function(context) { return function() { context.setToFixedPosition(); }; })(this)); if (!this.getIsManaged()) { return; } this.resetPosition(); this.setPosition(this.POSITION_FIXED); return this.jQuery(this.getWrapElement()).addClass("fixed-position"); }; BannerScroll.prototype.setToStaticPosition = function() { this.setRemanageCallback((function(context) { return function() { context.setToStaticPosition(); }; })(this)); if (!this.getIsManaged()) { return; } this.resetPosition(); this.setPosition(this.POSITION_STATIC); return this.jQuery(this.getWrapElement()).removeClass("fixed-position"); }; BannerScroll.prototype.setToAbsolutePosition = function(top) { top = this._calculateAbsoluteTopPosition(top); this.jQuery(this.getWrapElement()).css('left', ''); this.resetPosition(); this.jQuery(this.getWrapElement()).addClass("absolute-position"); this.setPosition(this.POSITION_ABSOLUTE); return this.jQuery(this.getWrapElement()).css("top", top + "px"); }; BannerScroll.prototype.setToAbsolutePositionAnimated = function(top, callback) { var $wrapElement, cb; top = top + 10; $wrapElement = this.jQuery(this.getWrapElement()); $wrapElement.css('left', ''); $wrapElement.removeClass("static-position"); $wrapElement.addClass("absolute-position"); this.setPosition(this.POSITION_ABSOLUTE); top = this._calculateAbsoluteTopPosition(top); cb = function() { return typeof callback === "function" ? callback() : void 0; }; $wrapElement.css("top", top + "px"); return cb(); }; BannerScroll.prototype._calculateAbsoluteTopPosition = function(top) { if (this.getWrapElement().parent().css('position') === 'relative' || this.getWrapElement().parent().css('position') === 'absolute') { top -= this.getWrapElement().parent().offset().top; } return top; }; BannerScroll.prototype.getOffsetTop = function() { return this.jQuery(this.getWrapElement()).offset().top; }; BannerScroll.prototype.getHeight = function() { var criteoTotalHeight, height; height = this.jQuery(this.getWrapElement()).outerHeight(true); criteoTotalHeight = 0; this.jQuery(this.getWrapElement()).find('div[id^="crt-"].ban_envelope:visible').each((function(_this) { return function(i, e) { return criteoTotalHeight += _this.jQuery(e).outerHeight(true); }; })(this)); return height - criteoTotalHeight; }; BannerScroll.prototype.setPosition = function(position) { this.position = position; }; BannerScroll.prototype.getIsAbsolutePosition = function() { return this.position === this.POSITION_ABSOLUTE; }; BannerScroll.prototype.getIsFixedPosition = function() { return this.position === this.POSITION_FIXED; }; BannerScroll.prototype.getIsStaticPosition = function() { return this.position === this.POSITION_STATIC; }; BannerScroll.prototype.getIsManaged = function() { return this.isManaged; }; BannerScroll.prototype.setIsManaged = function(isManaged) { this.isManaged = isManaged; }; BannerScroll.prototype.remanage = function() { this.setIsManaged(true); return this.callRemanageCallback(); }; BannerScroll.prototype.setRemanageCallback = function(remanageCallback) { this.remanageCallback = remanageCallback; return this.remanageCallbackEmpty = false; }; BannerScroll.prototype.getRemanageCallbackEmpty = function() { return this.remanageCallbackEmpty; }; BannerScroll.prototype.callRemanageCallback = function() { this.remanageCallbackEmpty = true; return this.remanageCallback(); }; return BannerScroll; })(); if (typeof window !== "undefined" && window !== null ? window.cjs : void 0) { if ((base = window.cjs).BannerScroll == null) { base.BannerScroll = BannerScroll; } } else { if (exports.BannerScroll == null) { exports.BannerScroll = BannerScroll; } } }).call(this); // Generated by CoffeeScript 1.10.0 /** @require Generic functions */ (function() { var BannerScrollManager, base; if (typeof window === "undefined" || window === null) { (typeof global !== "undefined" && global !== null ? global : window).cjs = require('../generic/generic'); } BannerScrollManager = (function() { function BannerScrollManager(jQuery, _isMobileDeviceGetter, _waypointGetter) { this.jQuery = jQuery; this._isMobileDeviceGetter = _isMobileDeviceGetter != null ? _isMobileDeviceGetter : (function() { return false; }); this._waypointGetter = _waypointGetter != null ? _waypointGetter : (function() { return null; }); this.banners = []; } BannerScrollManager.prototype.addBanner = function(banner) { return this.banners.push(banner); }; BannerScrollManager.prototype.getBanners = function() { return this.banners; }; BannerScrollManager.prototype.isMobileDevice = function() { return this._isMobileDeviceGetter(); }; BannerScrollManager.prototype.manage = function() { var banner, i, len, ref; ref = this.banners; for (i = 0, len = ref.length; i < len; i++) { banner = ref[i]; this.manageBanner(banner); } }; BannerScrollManager.prototype.manageBanner = function(banner) { if (banner.bannerObject.getIsManaged()) { return; } banner.bannerObject.setIsManaged(true); if (banner.stopElementsOnUpHitTopOfView != null) { this.manageStopElementsOnUpHitTopOfView(banner); } if (banner.startElementsOnDownHitTopOfView != null) { this.manageStartElementsOnDownHitTopOfView(banner); } if (!this.isMobileDevice()) { if (banner.stopElementsOnHitByBottom != null) { this.manageStopElementsOnHitByBottom(banner); } } else { this.manageMobileAnimation(banner); } if (banner.fullBannerHeightVisibleOrDisable === true && (banner.minWindowHeight === void 0 || banner.minWindowHeight < banner.bannerObject.getHeight())) { banner.minWindowHeight = banner.bannerObject.getHeight(); } if (banner.minWindowHeight != null) { this.manageMinWindowHeight(banner); } if (!this.isMobileDevice() && (banner.leftPositionHandleElement != null)) { this.manageLeftPosition(banner); } this.manageMinWindowHeightOnResize(banner); }; BannerScrollManager.prototype.manageLeftPosition = function(banner) { var m; m = function(b, context) { if (b.bannerObject.getPosition() !== cjs.BannerScroll.prototype.POSITION_ABSOLUTE) { context.jQuery(b.bannerObject.getWrapElement()).css('left', context.jQuery(banner.leftPositionHandleElement).offset().left - context.jQuery(window).scrollLeft()); } }; m(banner, this); this.jQuery(window).scroll((function(b, context) { return function() { return m(b, context); }; })(banner, this)); }; BannerScrollManager.prototype.unmanageBanner = function(banner) { return banner.bannerObject.setManaged(false); }; BannerScrollManager.prototype.manageMinWindowHeight = function(banner) { this.jQuery(window).resize((function(b, context) { return function() { return context.manageMinWindowHeightOnResize(b); }; })(banner, this)); }; BannerScrollManager.prototype.manageMinWindowHeightOnResize = function(banner) { var currentPosition, offsetTop; if (this.jQuery(window).height() < banner.minWindowHeight && banner.bannerObject.getIsManaged()) { currentPosition = banner.bannerObject.getPosition(); if (currentPosition === null) { banner.bannerObject.setIsManaged(false); return; } offsetTop = banner.bannerObject.getOffsetTop(); banner.bannerObject.setToStaticPosition(); banner.bannerObject.setRemanageCallback((function(banner, currentPosition, offsetTop) { return function() { switch (currentPosition) { case cjs.BannerScroll.prototype.POSITION_FIXED: return banner.bannerObject.setToFixedPosition(); case cjs.BannerScroll.prototype.POSITION_STATIC: return banner.bannerObject.setToStaticPosition(); case cjs.BannerScroll.prototype.POSITION_ABSOLUTE: return banner.bannerObject.setToAbsolutePosition(offsetTop); } }; })(banner, currentPosition, offsetTop)); banner.bannerObject.setIsManaged(false); } else if (this.jQuery(window).height() > banner.minWindowHeight && !banner.bannerObject.getIsManaged()) { banner.bannerObject.remanage(); } return this.jQuery(window).scroll(); }; BannerScrollManager.prototype.manageStopElementsOnUpHitTopOfView = function(banner) { var element, i, len, ref, results; ref = banner.stopElementsOnUpHitTopOfView; results = []; for (i = 0, len = ref.length; i < len; i++) { element = ref[i]; results.push(this.jQuery(element).waypoint((function(that, banner) { return function(direction) { if (direction === 'up') { that.jQuery(banner.bannerObject.getWrapElement()).stop(); return banner.bannerObject.setToStaticPosition(); } }; })(this, banner))); } return results; }; BannerScrollManager.prototype.manageStartElementsOnDownHitTopOfView = function(banner) { var element, i, len, ref, results; ref = banner.startElementsOnDownHitTopOfView; results = []; for (i = 0, len = ref.length; i < len; i++) { element = ref[i]; results.push(this.jQuery(element).waypoint((function(context, banner) { return function(direction) { var offsetTop; if (direction === 'down' && context.canMove(banner)) { if (!context.isMobileDevice()) { banner.bannerObject.setToFixedPosition(); return context.correctPosition(banner); } else if (banner.bannerObject.getIsManaged()) { offsetTop = context._getOffsetTopForAbsolutePosition(banner); return banner.bannerObject.setToAbsolutePositionAnimated(offsetTop); } } }; })(this, banner))); } return results; }; BannerScrollManager.prototype.manageStopElementsOnHitByBottom = function(banner) { var element, i, len, ref, results; ref = banner.stopElementsOnHitByBottom; results = []; for (i = 0, len = ref.length; i < len; i++) { element = ref[i]; results.push(this.jQuery(window).scroll((function(stopElementOnHitByBottom, context, banner) { return function() { if (banner.bannerObject.getIsFixedPosition()) { if (context.jQuery(stopElementOnHitByBottom).offset().top <= (banner.bannerObject.getOffsetTop() + banner.bannerObject.getHeight())) { banner.bannerObject.setToAbsolutePosition(context.jQuery(stopElementOnHitByBottom).offset().top - banner.bannerObject.getHeight()); return context.correctPosition(banner); } } else if (banner.bannerObject.getIsAbsolutePosition() && context.jQuery(stopElementOnHitByBottom).offset().top > (context.jQuery(window).scrollTop() + banner.bannerObject.getHeight())) { return banner.bannerObject.setToFixedPosition(); } }; })(element, this, banner))); } return results; }; BannerScrollManager.prototype.manageMobileAnimation = function(banner) { var offsetTop, timer; timer = 0; offsetTop = banner.bannerObject.getOffsetTop(); return this.jQuery(window).scroll((function(that, banner) { return function() { clearTimeout(timer); return timer = setTimeout(function() { if (!banner.bannerObject.getIsAbsolutePosition()) { return; } offsetTop = that._getOffsetTopForAbsolutePosition(banner); return banner.bannerObject.setToAbsolutePositionAnimated(offsetTop); }, 250); }; })(this, banner)); }; BannerScrollManager.prototype.canMove = function(banner) { var element, i, len, ref; if (banner.stopElementsOnHitByBottom) { ref = banner.stopElementsOnHitByBottom; for (i = 0, len = ref.length; i < len; i++) { element = ref[i]; if (this.jQuery(element).offset().top <= (banner.bannerObject.getOffsetTop() + banner.bannerObject.getHeight())) { return false; } } } return true; }; BannerScrollManager.prototype.correctPosition = function(banner) { var element, i, len, ref, results; if (banner.stopElementsOnHitByBottom) { ref = banner.stopElementsOnHitByBottom; results = []; for (i = 0, len = ref.length; i < len; i++) { element = ref[i]; if (this.jQuery(element).offset().top < (banner.bannerObject.getOffsetTop() + banner.bannerObject.getHeight())) { results.push(banner.bannerObject.setToAbsolutePosition(this.jQuery(element).offset().top - banner.bannerObject.getHeight())); } else { results.push(void 0); } } return results; } }; BannerScrollManager.prototype.correctPositionsOfAllBanners = function() { var banner, i, len, ref, results; ref = this.getBanners(); results = []; for (i = 0, len = ref.length; i < len; i++) { banner = ref[i]; results.push(this.correctPosition(banner)); } return results; }; BannerScrollManager.prototype._getBottomBoundaryOffsetTop = function(banner) { var element, elementOffsetTop, i, len, minOffsetTop, ref; minOffsetTop = this.jQuery('body').height(); if (banner.stopElementsOnHitByBottom) { ref = banner.stopElementsOnHitByBottom; for (i = 0, len = ref.length; i < len; i++) { element = ref[i]; elementOffsetTop = this.jQuery(element).offset().top; if (elementOffsetTop < minOffsetTop) { minOffsetTop = elementOffsetTop; } } } return minOffsetTop; }; BannerScrollManager.prototype._getOffsetTopForAbsolutePosition = function(banner) { var bottomBoundary, offsetTop; offsetTop = this.jQuery(window).scrollTop(); bottomBoundary = this._getBottomBoundaryOffsetTop(banner); if (bottomBoundary < offsetTop + banner.bannerObject.getHeight()) { offsetTop = bottomBoundary - banner.bannerObject.getHeight(); } return offsetTop; }; BannerScrollManager.prototype.refreshWaypoints = function() { var Waypoint, base; Waypoint = this._waypointGetter(); if (Waypoint != null) { return typeof Waypoint.refreshAll === "function" ? Waypoint.refreshAll() : void 0; } else { return typeof (base = this.jQuery).waypoints === "function" ? base.waypoints('refresh') : void 0; } }; return BannerScrollManager; })(); if (typeof window !== "undefined" && window !== null ? window.cjs : void 0) { if ((base = window.cjs).BannerScrollManager == null) { base.BannerScrollManager = BannerScrollManager; } } else { if (exports.BannerScrollManager == null) { exports.BannerScrollManager = BannerScrollManager; } } }).call(this);