(function ($, dla, Hammer, llMobile) { $(document).ready(function () { var quickpicksLotteries = ['megaMillions', 'euroMillions', 'euroJackpot', 'powerBall', 'austriaLotto', 'swedishLotto', 'german6aus49', 'irishLotto', 'swissLotto']; var copyConfig = { 'en-GB': { 'doubleOrNothing': true, 'root': '/', 'shoppingCartLink': '/shoppingcart', 'login': 'Login', 'register': ' Register', 'home': 'HOME', 'toCart': 'to cart', 'not': 'Not', 'logout': 'log out', 'back': 'Back', 'day': 'day', 'days': 'days', 'hours': 'hrs', 'minutes': 'mins', 'seconds': 'secs', 'quickpick': 'Quickpick', 'quickpicks': 'Quickpicks', 'only': 'Only', 'resultsFor': 'Results from', 'betslip': 'Betslip', 'syndicates': 'Syndicates', 'results': 'Results', 'magazine': 'Magazine', 'faq': 'Help & FAQ', 'month': { 1: 'Jan', 2: 'Feb', 3: 'Mar', 4: 'Apr', 5: 'May', 6: 'Jun', 7: 'Jul', 8: 'Aug', 9: 'Sep', 10: 'Oct', 11: 'Nov', 12: 'Dec' }, 'links': { 'syndicates': '/syndicates', 'results': '/results-winning-numbers', 'magazine': '/magazine', 'faq': '/help', 'account': '/account' } }, 'en': { 'doubleOrNothing': false, 'root': '/en', 'shoppingCartLink': '/en/shoppingcart', 'login': 'Login', 'register': ' Register', 'home': 'HOME', 'toCart': 'to cart', 'not': 'Not', 'logout': 'log out', 'back': 'Back', 'day': 'day', 'days': 'days', 'hours': 'hrs', 'minutes': 'mins', 'seconds': 'secs', 'quickpick': 'Quickpick', 'quickpicks': 'Quickpicks', 'only': 'Only', 'resultsFor': 'Results from', 'betslip': 'Betslip', 'syndicates': 'Syndicates', 'results': 'Results', 'magazine': 'Magazine', 'faq': 'Help & FAQ', 'month': { 1: 'Jan', 2: 'Feb', 3: 'Mar', 4: 'Apr', 5: 'May', 6: 'Jun', 7: 'Jul', 8: 'Aug', 9: 'Sep', 10: 'Oct', 11: 'Nov', 12: 'Dec' }, 'links': { 'syndicates': '', 'results': '/results-winning-numbers', 'magazine': '', 'faq': '/help', 'account': '/en/account' } }, 'en-CA': { 'doubleOrNothing': false, 'root': '/ca', 'shoppingCartLink': '/ca/shoppingcart', 'login': 'Login', 'register': ' Register', 'home': 'HOME', 'toCart': 'to cart', 'not': 'Not', 'logout': 'log out', 'back': 'Back', 'day': 'day', 'days': 'days', 'hours': 'hrs', 'minutes': 'mins', 'seconds': 'secs', 'quickpick': 'Quickpick', 'quickpicks': 'Quickpicks', 'only': 'Only', 'resultsFor': 'Results from', 'betslip': 'Betslip', 'syndicates': 'Syndicates', 'results': 'Results', 'magazine': 'Magazine', 'faq': 'Help & FAQ', 'month': { 1: 'Jan', 2: 'Feb', 3: 'Mar', 4: 'Apr', 5: 'May', 6: 'Jun', 7: 'Jul', 8: 'Aug', 9: 'Sep', 10: 'Oct', 11: 'Nov', 12: 'Dec' }, 'links': { 'syndicates': '', 'results': '/results-winning-numbers', 'magazine': '', 'faq': '/help', 'account': '/ca/account' } }, 'en-AU': { 'doubleOrNothing': true, 'root': '/', 'shoppingCartLink': '/shoppingcart', 'login': 'Login', 'register': ' Register', 'home': 'HOME', 'toCart': 'to cart', 'not': 'Not', 'logout': 'log out', 'back': 'Back', 'day': 'day', 'days': 'days', 'hours': 'hrs', 'minutes': 'mins', 'seconds': 'secs', 'quickpick': 'Quicky', 'quickpicks': 'Quickies', 'only': 'Only', 'resultsFor': 'Results from', 'betslip': 'Betslip', 'syndicates': 'Syndicates', 'results': 'Results', 'magazine': 'Magazine', 'faq': 'Help & FAQ', 'month': { 1: 'Jan', 2: 'Feb', 3: 'Mar', 4: 'Apr', 5: 'May', 6: 'Jun', 7: 'Jul', 8: 'Aug', 9: 'Sep', 10: 'Oct', 11: 'Nov', 12: 'Dec' }, 'links': { 'syndicates': '/syndicates', 'results': '/results', 'magazine': '/magazine', 'faq': '/help', 'account': '/account' } }, 'en-IE': { 'doubleOrNothing': true, 'root': '/', 'shoppingCartLink': '/shoppingcart', 'login': 'Login', 'register': ' Register', 'home': 'HOME', 'toCart': 'to cart', 'not': 'Not', 'logout': 'log out', 'back': 'Back', 'day': 'day', 'days': 'days', 'hours': 'hrs', 'minutes': 'mins', 'seconds': 'secs', 'quickpick': 'Quickpick', 'quickpicks': 'Quickpicks', 'only': 'Only', 'resultsFor': 'Results from', 'betslip': 'Betslip', 'syndicates': 'Syndicates', 'results': 'Results', 'magazine': 'Magazine', 'faq': 'Help & FAQ', 'month': { 1: 'Jan', 2: 'Feb', 3: 'Mar', 4: 'Apr', 5: 'May', 6: 'Jun', 7: 'Jul', 8: 'Aug', 9: 'Sep', 10: 'Oct', 11: 'Nov', 12: 'Dec' }, 'links': { 'syndicates': '/syndicates', 'results': '/results-winning-numbers', 'magazine': '/magazine', 'faq': '/help', 'account': '/account' } }, 'de': { 'reduced': true, 'doubleOrNothing': true, 'root': '/', 'shoppingCartLink': '/warenkorb', 'login': 'Anmelden', 'register': 'Neues Konto', 'home': 'Startseite', 'toCart': 'Warenkorb', 'not': 'Nicht', 'logout': 'Abmelden', 'back': 'Zurück', 'day': 'Tag', 'days': 'Tage', 'hours': 'Std.', 'minutes': 'Min.', 'seconds': 'Sek.', 'quickpick': 'Zufallstipp', 'quickpicks': 'Zufallstipps', 'only': 'Nur', 'resultsFor': 'Zahlen vom', 'betslip': 'Tippschein', 'syndicates': 'Spielgemeinschaften', 'results': 'Zahlen & Quoten', 'magazine': 'Magazin', 'faq': 'Hilfe & FAQ', 'month': { 1: 'Jan.', 2: 'Feb.', 3: 'Mär.', 4: 'Apr.', 5: 'Mai', 6: 'Jun.', 7: 'Jul.', 8: 'Aug.', 9: 'Sep.', 10: 'Oct.', 11: 'Nov.', 12: 'Dez.' }, 'links': { 'syndicates': '', 'results': '/zahlen-quoten', 'magazine': '/magazin', 'faq': '/hilfe', 'account': '/meinlottoland' } }, 'de-CH': { 'reduced': true, 'doubleOrNothing': true, 'root': '/ch', 'shoppingCartLink': '/ch/warenkorb', 'login': 'Anmelden', 'register': 'Neues Konto', 'home': 'Startseite', 'toCart': 'Warenkorb', 'not': 'Nicht', 'logout': 'Abmelden', 'back': 'Zurück', 'day': 'Tag', 'days': 'Tage', 'hours': 'Std.', 'minutes': 'Min.', 'seconds': 'Sek.', 'quickpick': 'Zufallstipp', 'quickpicks': 'Zufallstipps', 'only': 'Nur', 'resultsFor': 'Zahlen vom', 'betslip': 'Tippschein', 'syndicates': 'Spielgemeinschaften', 'results': 'Zahlen & Quoten', 'magazine': 'Magazin', 'faq': 'Hilfe & FAQ', 'month': { 1: 'Jan.', 2: 'Feb.', 3: 'Mär.', 4: 'Apr.', 5: 'Mai', 6: 'Jun.', 7: 'Jul.', 8: 'Aug.', 9: 'Sep.', 10: 'Oct.', 11: 'Nov.', 12: 'Dez.' }, 'links': { 'syndicates': '', 'results': '/zahlen-quoten', 'magazine': '/magazin', 'faq': '/hilfe', 'account': '/ch/meinlottoland' } }, 'de-AT': { 'doubleOrNothing': true, 'root': '/', 'shoppingCartLink': '/warenkorb', 'login': 'Anmelden', 'register': 'Neues Konto', 'home': 'Startseite', 'toCart': 'Warenkorb', 'not': 'Nicht', 'logout': 'Abmelden', 'back': 'Zurück', 'day': 'Tag', 'days': 'Tage', 'hours': 'Std.', 'minutes': 'Min.', 'seconds': 'Sek.', 'quickpick': 'Zufallstipp', 'quickpicks': 'Zufallstipps', 'only': 'Nur', 'resultsFor': 'Zahlen vom', 'betslip': 'Tippschein', 'syndicates': 'Spielgemeinschaften', 'results': 'Zahlen & Quoten', 'magazine': 'Magazin', 'faq': 'Hilfe & FAQ', 'month': { 1: 'Jan.', 2: 'Feb.', 3: 'Mär.', 4: 'Apr.', 5: 'Mai', 6: 'Jun.', 7: 'Jul.', 8: 'Aug.', 9: 'Sep.', 10: 'Oct.', 11: 'Nov.', 12: 'Dez.' }, 'links': { 'syndicates': '', 'results': '/zahlen-quoten', 'magazine': '/magazin', 'faq': '/hilfe', 'account': '/meinlottoland' } } }; var addLotteryOptsToRestyledMenu = function () { var lotteryOptionsMenu = { lang: '', loggedIn: '', isReduced: '', injectHtml: function () { var self = this; var copy = copyConfig[self.lang]; var optsMenu = '' + '
' + '
' + '
' + copy.back + '
' + '
' + '
' + '
' + '' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '
' + '' + '
'; $('.page-menu-and-main-restyle .page-menu').append(optsMenu); }, injectLotteryOptsLinks: function () { var self = this; $('.page-menu-and-main-restyle .menu-lotteries ul.list li').each(function () { var lotteryId = self.getLotteryId($(this)); var lotteryData = $('.js-lotteryInfo.' + lotteryId); var isInList = quickpicksLotteries.indexOf(lotteryId) > -1; if (lotteryData.length && isInList) { var url = $(this).find('a').prop('href'); var optLink = '
'; $(this).append(optLink); } }); }, getRelativeLink: function (url) { var host = window.location.hostname; var port = window.location.port; if (port) { host = host + ':' + port; } return url.split(host + '/')[1]; }, getLotteryId: function ($lotteryLi) { var itemClass = $lotteryLi.prop('class') || $lotteryLi.find('a').text().trim().toLowerCase().replace(/ /g, '-'); return itemClass.split(' ')[0]; }, addEventListeners: function () { var self = this; $('.page-menu-and-main-restyle .opts').click(function () { self.openLotteryOpts($(this).data('lottery'), $(this).data('url')); }); $('.page-menu-and-main-restyle .backBtn').click(function () { self.closeLotteryOpts(); }); $('.page-menu-and-main-restyle .menu-button').click(function (event) { event.preventDefault(); self.closeLotteryOpts(); }); $(window).resize(self.fixAndroidViewport); }, // get seconds to next draw, returns an object with the number of days hours // minutes and seconds based on the time sent 2017/12/24 23:00:34 getTimeTo: function (time) { var day, month, year, hour; if (typeof time !== 'undefined') { if (time.indexOf('/') !== -1) { day = time.split('/')[0]; month = time.split('/')[1]; year = time.split('/')[2].split(' ')[0]; } else { day = time.split('.')[0]; month = time.split('.')[1]; year = time.split('.')[2].split(' ')[0]; } } else { day = time.split('.')[0]; month = time.split('.')[1]; year = time.split('.')[2].split(' ')[0]; } hour = time.split(' ')[1]; time = year + '/' + month + '/' + day + ' ' + hour; Date.prototype.stdTimezoneOffset = function () { var jan = new Date(this.getFullYear(), 0, 1); var jul = new Date(this.getFullYear(), 6, 1); return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset()); }; Date.prototype.dst = function () { return this.getTimezoneOffset() - this.stdTimezoneOffset(); }; var timezoneOffset; var now = new Date(); var nowInMilliseconds = now.getTime(); var timeInMilliseconds = new Date(time).getTime(); if (now.dst() < 0) { timezoneOffset = now.getTimezoneOffset() * 60000 + 3600000; } else if (now.dst() > 0) { timezoneOffset = now.getTimezoneOffset() * 60000 - 3600000; } else { timezoneOffset = now.getTimezoneOffset() * 60000; } var timeInSeconds = Math.round( (timeInMilliseconds - nowInMilliseconds - timezoneOffset) / 1000 ); var timeObj = { days: Math.floor(timeInSeconds / 86400), hours: Math.floor((timeInSeconds % 86400) / 3600), minutes: Math.floor(((timeInSeconds % 86400) % 3600) / 60), seconds: ((timeInSeconds % 86400) % 3600) % 60 }; return timeObj; }, // get the ticket price for the passed lottery and number of quickpicks getLotteryPrice: function (lottery, index) { var self = this; var price = index === 0 ? $('.js-lotteryInfo.' + lottery).data('quickpickTicketPrice') : $('.js-lotteryInfo.' + lottery).data('doubleQuickpickTicketPrice'); $('.lotteryOpts .cta').eq(index).find('.value').text( copyConfig[self.lang].only + ' ' + dla.helper.formatPricePlain(price) ); $('.lotteryOpts .cta').eq(index).attr( 'data-track-name', 'RwdMobile-SecNav-Quickpick-' + lottery ).addClass('track'); }, updateLotteryOpts: function (lottery, targetUrl) { var self = this; var domain = window.location.hostname + (window.location.port ? ':' + window.location.port : ''); if (self.lang === 'en') domain += '/' + self.lang; var url = '//' + domain + '/api/drawings/' + lottery + '?currency=' + dla.resources.currency; var prevLotto = $('.lotteryOpts').data('lottery'); // only call this function if open the lottery is different from last time if (lottery !== prevLotto) { $('.lotteryOpts').addClass(lottery); $('.lotteryOpts').removeClass(prevLotto); $('.lotteryOpts').data('lottery', lottery); $.get(url, function (data) { // get time to next draw var timer = self.getTimeTo(data.next.closingDate.replace(',', '')); var timerStr = ''; if (timer.days > 0) { var dayX = (timer.days === 1) ? 'day' : 'days'; timerStr = timer.days + ' ' + copyConfig[self.lang][dayX] + ' ' + timer.hours + ' ' + copyConfig[self.lang].hours; } else if (timer.hours > 0) { timerStr = timer.hours + ' ' + copyConfig[self.lang].hours + ' ' + timer.minutes + ' ' + copyConfig[self.lang].minutes; } else if (timer.minutes > 0) { timerStr = timer.minutes + ' ' + copyConfig[self.lang].minutes; } $('.lotteryOpts .right .counter').text(timerStr); // set the jackpot value var jackpot = data.next.specialMarketingJackpot || data.next.marketingJackpot || data.next.jackpot; $('.lotteryOpts .right .jackpot').html(dla.helper.formatJackpot(jackpot)); // set last draws numbers var numbers = data.last.numbers || []; if (lottery === 'worldMillions' && data.last.numbers.length === 1) { numbers = ('' + data.last.numbers[0]).split(''); } var stars = { megaMillions: data.last.megaballs, euroMillions: data.last.stars, euroJackpot: data.last.euroNumbers, powerBall: data.last.powerballs, austriaLotto: data.last.Zusatzzahl, swedishLotto: data.last.bonus, german6aus49: data.last.superzahl, irishLotto: data.last.bonus, swissLotto: data.last.luckyNumber }; $('.lotteryOpts .results .numbers').html(''); for (var i = 0; i < numbers.length; i++) { $('.lotteryOpts .results .numbers').append( '' + numbers[i] + '' ); } for (var j = 0; j < stars[lottery].length; j++) { $('.lotteryOpts .results .numbers').append( '' + stars[lottery][j] + '' ); } if (lottery === 'megaMillions' || lottery === 'powerBall') { var extra = data.last.megaplier || data.last.powerplay; $('.lotteryOpts .results .numbers').append( 'x' + extra + '' ); } else if (lottery === 'german6aus49') { $('.lotteryOpts .results .numbers').append( '' + data.last.superzahl + '' ); } // hide magazine for WorldMillions and Swiss Lotto if (lottery === 'worldMillions' || lottery === 'swissLotto') { $('a.magazine, a.syndicates').hide(); } else { $('a.magazine, a.syndicates').show(); // if (magazine.is(':hidden')) magazine.show(); } // check WorldMillions length or complete with zeroes if (lottery === 'worldMillions' && numbers.length < 8) { var diff = 8 - numbers.length; var zeroes = ''; for (var d = 0; d < diff; d++) { zeroes += '0'; } $('.numbers').prepend(zeroes); } var daySpacer = ' '; var dowSpacer = ' '; if (self.lang === 'de' || self.lang === 'de-AT') dowSpacer = ', '; if (self.lang === 'de' || self.lang === 'de-AT') daySpacer = '. '; if (self.lang === 'de' && data.last.date.day < 10) { data.last.date.day = '0' + data.last.date.day; } $('.lotteryOpts .results .text').text( copyConfig[self.lang].resultsFor + ' ' + data.last.date.dayOfWeek + dowSpacer + data.last.date.day + daySpacer + copyConfig[self.lang].month[data.last.date.month] + ' ' + new Date().getFullYear() ); // set the links $('.lotteryOpts ul a').each(function () { var href = $(this).data('link'); // because german lotto is stupid if (lottery === 'german6aus49' && href === '/zahlen-quoten') { href = '/lottozahlen-quoten'; } href = '/' + targetUrl + href; // because lottoland is run by monkeys // irishLotto is all over the place if (lottery === 'irishLotto') { var link = $(this).data('link'); if (link === '/results-winning-numbers') { href = '/irish-lottery/results-winning-numbers'; } else if (link === '/magazine') { href = '/lotto/magazine'; } else if (link === '/help') { href = '/irishlotto/help'; } } $(this).prop('href', href).attr( 'data-track-name', 'RwdMobile-SecNav-Link-' + $(this).prop('class') ).addClass('track'); }); // lotteryOpts links lottery name var lotteryName = $('.page-menu .' + lottery + ' a.page-link').text().trim() + ' '; $('.lotteryOpts ul li span').text( lotteryName ); // for australia we need to change the name of the lottery for // the results pages in some lotteries if (self.lang === 'en-AU' && lottery === 'powerBall') { lotteryName = 'US Powerball '; $('.lotteryOpts ul li span').eq(2).text(lotteryName); } // set hotLabel $('.lotteryOpts .hotLabel').html(''); $('.lotteryOpts .hotLabel').text( $('.' + lottery + ' .hotLabel').text() ); // get lottery prices and set link var link = ''; var track = '&trck5=sidemenu_' + self.lang + '_mobile.' + lottery; var doubleLink = ''; var doubleOrNothing = $('.js-lotteryInfo.' + lottery).data('showDoubleQuickpick'); var quickpickLines = $('.js-lotteryInfo.' + lottery).data('quickpickLines'); var doubleQuickpickLines = $('.js-lotteryInfo.' + lottery).data('doubleQuickpickLines'); if (typeof copyConfig[self.lang].shoppingCartLink !== 'undefined') { link = copyConfig[self.lang].shoppingCartLink + '?tickets=' + $('.js-lotteryInfo.' + lottery).data('encodedQuickpickTicket'); doubleLink = copyConfig[self.lang].shoppingCartLink + '?tickets=' + $('.js-lotteryInfo.' + lottery).data('encodedDoubleQuickpickTicket'); link += track + quickpickLines + '.games'; doubleLink += track + doubleQuickpickLines + '.games'; } else { link = '/' + lottery.toLowerCase(); doubleLink = link; } $('.lotteryOpts .cta').eq(0).data('link', link); $('.lotteryOpts .cta .text span').html( (quickpickLines || 1) + ' ' + (quickpickLines > 1 ? copyConfig[self.lang].quickpicks : copyConfig[self.lang].quickpick) ); self.getLotteryPrice(lottery, 0); // double or nothing feature if (doubleOrNothing) { $('.lotteryOpts .cta.double').show().data('link', doubleLink).fadeIn() .find('.text span').html( doubleQuickpickLines + ' ' + copyConfig[self.lang].quickpicks ); self.getLotteryPrice(lottery, 1); } else { $('.lotteryOpts .cta.double').hide(); } if (!$('.js-lotteryInfo.' + lottery).data('showQuickpick')) { $('.lotteryOpts .cta').hide(); } self.updateLotteryOptsEvents(); }); } }, updateLotteryOptsEvents: function () { // lottery options quickpicks cta click redirects to the shopping cart // if the lottery is not defined in the quickipick array it will send // the user to the lottery page $('.lotteryOpts .cta').click(function () { window.open($(this).data('link'), '_self'); }); }, openLotteryOpts: function (lottery, url) { var self = this; self.showLotteryOpts(); self.updateLotteryOpts(lottery, url); }, closeLotteryOpts: function () { var self = this; $('.lotteryOpts').addClass('close'); $('.lotteryOpts').removeClass('open'); $('.page-menu').css('overflow-y', 'scroll'); $('.page-menu').css('overflow-x', ''); $('.page-menu').height(''); $('.lotteryOpts-overlay').hide(); setTimeout(function () { $('.lotteryOpts').hide(); }, 500); self.fixAndroidViewport(); }, showLotteryOpts: function () { var self = this; // need to reset the position to 0 otherwise it bugs out var ch = ($('#cookieHint:visible').length > 0) ? $('#cookieHint').innerHeight() : 0; $('.lotteryOpts').css({ 'top': 0, 'display': 'block' }).css( 'top', ($('.lotteryOpts').offset().top * -1) + ch + 'px' ); $('.lotteryOpts').addClass('open'); $('.lotteryOpts').removeClass('close'); $('.page-menu').css('overflow', 'hidden'); $('.page-menu').height('100%'); $('.lotteryOpts-overlay').show(); $('.lotteryOpts-overlay').off('click').on('click', function () { self.closeLotteryOpts(); }); self.fixAndroidViewport(); }, fixAndroidViewport: function () { $('body').height(window.innerHeight); }, watcher: function () { }, init: function () { var self = this; self.lang = $('html').prop('lang'); var languages = Object.keys(copyConfig); if (languages.indexOf(self.lang) >= 0) { self.loggedIn = ($('#trackingInfo').data('playerLoggedIn')) ? 'loggedIn' : ''; self.isReduced = $('#trackingInfo').data('reducedMode'); self.injectHtml(); self.injectLotteryOptsLinks(); if (!self.isReduced) { self.addEventListeners(); self.watcher(); } } } }; lotteryOptionsMenu.init(); }; var runScriptForMobileMenu = function () { var isRestyledMenu = $('.page-menu-and-main-restyle').length > 0; if (isRestyledMenu) { addLotteryOptsToRestyledMenu(); } }; runScriptForMobileMenu(); }); })(window.jQuery, window.dla, window.Hammer, window.llMobile);