(function () { var perform = function () { (function ($) { $.expr[":"].onScreen = function (elem) { var $window = $(window); var viewport_top = $window.scrollTop(); var viewport_height = $window.height(); var viewport_bottom = viewport_top + viewport_height; var $elem = $(elem); var top = $elem.offset().top; var height = $elem.height(); var bottom = top + height; return (top >= viewport_top && top < viewport_bottom) || (bottom > viewport_top && bottom <= viewport_bottom) || (height > viewport_height && top <= viewport_top && bottom >= viewport_bottom) } })(window.jQuery); (function ($) { var Timer = function (time, onEnd) { this._time = time; this._onEnd = onEnd; this._instance = null; }; Timer.prototype.start = function () { var self = this; if (this._instance) { return; } this._instance = setTimeout(function () { if (self._onEnd) { self._onEnd(); } self.stop(); }, this._time * 1000); }; Timer.prototype.stop = function () { if (this._instance) { clearTimeout(this._instance); } this._instance = null; }; var deferred = (function () { var _timers = {}; return function (key, callback, time) { if (_timers[key]) { clearTimeout(_timers[key]); } _timers[key] = setTimeout(callback, time); } })(); var CallbackPopup = function (pages) { this.checkPages(pages); }; CallbackPopup.prototype.showPopup = function (causedBy) { if (this._popupFired) { return; } if ($('body').hasClass('modal-open')){ return; } this.appendModal(); $('#modal-usage-callback-service').modal('show'); this._popupFired = true; }; CallbackPopup.prototype.appendModal = function () { if (this._modalAppended) { return; } var markup = [ '' ]; $('body').append(markup.join('')); this._modalAppended = true; }; CallbackPopup.prototype.checkPages = function (pages) { var self = this; this._page = null; pages.forEach(function (page) { if (!self._page && location.href.match(page.url)) { log('Callback armed.', page); self._page = page; page.tests.call(self); } }); }; CallbackPopup.prototype.userInactive = function (time) { time = time || 10; var self = this; var timer = new Timer(time, function () { self.showPopup('userInactive'); }); timer.start(); $(window).on('scroll resize mousemove keyup touchmove click', function () { deferred('userInactive', function () { timer.stop(); timer.start(); }, 100); }); }; CallbackPopup.prototype.footer = function (time) { time = time || 5; var self = this; var timer = new Timer(time, function () { self.showPopup('footer'); }); var $footer = $('#bottom'); $(window).on('scroll resize', function () { deferred('footer', function () { if ($footer.is(':onScreen')) { timer.stop(); timer.start(); } else { timer.stop(); } }, 100); }); }; CallbackPopup.prototype.faq = function (containerId, specialFaqs, tabs, time) { specialFaqs = specialFaqs || false; tabs = tabs || false; time = time || 5; var self = this; var $node = $('#' + containerId); var faqs_click = []; var tabs_clicked = []; if ($node.length === 0) { return; } var timer = new Timer(time, function () { self.showPopup('faq'); }); var checkConditions = function () { var start = false; if (tabs) { tabs_clicked.forEach(function (tabAnchor) { if (tabs.indexOf(tabAnchor) > -1) { start = true; console.log('OK: TABS'); } }); } if (specialFaqs) { faqs_click.forEach(function (faqAnchor) { if (specialFaqs.indexOf(faqAnchor) > -1) { start = true; console.log('OK: SPECIALFAQS'); } }); } if (faqs_click.length > 4) { start = true; console.log('OK: FAQS CLICKED'); } if (start) { timer.stop(); timer.start(); } }; $node.on('click', '.panel > a', function () { var href = $(this).attr('href'); if (faqs_click.indexOf(href) === -1) { faqs_click.push(href); } checkConditions(); }); if (tabs) { $node.on('click', '.nav-tab > a', function () { var href = $(this).attr('href'); if (tabs_clicked.indexOf(href) === -1) { tabs_clicked.push(href); } checkConditions(); }); } $(window).on('scroll resize', function () { deferred('faq', function () { if ($node.is(':onScreen')) { checkConditions(); } else { timer.stop(); } }, 100); }); }; new CallbackPopup([ { url: '\/service\/vertrag-tarif\/vertragsverlaengerung', actionProd: 'service', descriptionProd: 'callback_vvl', tests: function () { this.userInactive(); this.footer(); this.faq( 'id-12867844', [ '#id-12865980', '#id-12866000' ], [ '#id-12867832' ] ); } }, { url: '\/service\/vertrag-tarif\/mobilfunk(?!\\/\\?partnerId=Hotline&medium=IVR)', actionProd: 'service', descriptionProd: 'callback_mobilfunkvertrag', tests: function () { this.userInactive(); this.footer(); this.faq( 'id-12854022', [ '#id-13010096', '#id-13010084', '#id-12853800' ], [ '#id-12854062' ] ); } }, { url: '\/service\/vertrag-tarif\/optionen-und-packs', actionProd: 'service', descriptionProd: 'callback_optionen', tests: function () { this.userInactive(); this.footer(); this.faq( 'id-12854474', [ '#id-12855250' ], null ); } }, { url: '\/tarife\/ausland-und-roaming', actionProd: 'service', descriptionProd: 'callback_roaming', tests: function () { this.userInactive(); this.footer(); this.faq( 'id-13007194', [ '#id-12987098' ], null ); } }, { url: '\/service\/vertrag-tarif\/rufnummernmitnahme', actionProd: 'service', descriptionProd: 'callback_mnp', tests: function () { this.userInactive(); this.footer(); this.faq( 'id-12866924', [ '#id-12935988', '#id-13063216', '#id-12866962' ], null ); } }, { url: '\/service\/vertrag-tarif\/kuendigung', actionProd: 'service', descriptionProd: 'callback_kuendigung', tests: function () { this.userInactive(); this.footer(); } } ]); })(window.jQuery); function log() { if (document.cookie.indexOf('CALLBACK_DEBUG') > -1){ console.log.apply(console, Array.prototype.slice.call(arguments)); //lol } } }; if (document.readyState === 'loading') { window.addEventListener("load", function (event) { perform(); }); } else { perform(); } })();