/* lazy */ /* Bengin pushbar mySidebar*/ jQuery(document).ready(function ($) { var pushbar = new Pushbar({ blur: true, overlay: true, }); if ($("#bottomMobileAdvs").html().length < 160) { $("#bottomMobileAdvs").hide(); } if (document.getElementsByClassName("sticky-sidebar").length > 0) { var el = $('.sticky-sidebar'), stickyTop = el.offset().top, stickyHeight = el.outerHeight(true), latestScroll = 0, top = 0; $(window).scroll(function () { var limit = $('.footer').offset().top - stickyHeight - 10; var windowTop = $(window).scrollTop(); if (stickyTop < windowTop) { el.css({ position: 'fixed', top: top + 45 }); el.addClass('show-fix'); } else { el.removeClass('show-fix'); el.css({ position: 'relative', top: + 45 }); } if (limit < windowTop) { var diff = limit - windowTop; el.css({ top: diff }); el.removeClass('show-fix'); } latestScroll = windowTop; }); } }); class Pushbar { constructor(config = { overlay: true, blur: false }) { this.activeBar = null; this.overlay = false; if (config.overlay) { this.overlay = document.createElement('div'); this.overlay.classList.add('pushbar_overlay'); document.querySelector('body').appendChild(this.overlay); } if (config.blur) { const mainContent = document.querySelector('.pushbar_main_content'); if (mainContent) { mainContent.classList.add('pushbar_blur'); } } this.bindEvents(); } get opened() { const { activeBar } = this; return Boolean(activeBar instanceof HTMLElement && activeBar.classList.contains('opened')); } get activeBarId() { const { activeBar } = this; return activeBar instanceof HTMLElement && activeBar.getAttribute('data-pushbar-id'); } static dispatchOpen(pushbar) { const event = new CustomEvent('pushbar_opening', { bubbles: true, detail: { pushbar } }); pushbar.dispatchEvent(event); } static dispatchClose(pushbar) { const event = new CustomEvent('pushbar_closing', { bubbles: true, detail: { pushbar } }); pushbar.dispatchEvent(event); } static findElementById(pushbarId) { return document.querySelector(`[data-pushbar-id="${pushbarId}"]`); } handleOpenEvent(e) { e.preventDefault(); const pushbarId = e.currentTarget.getAttribute('data-pushbar-target'); if (pushbarId) { this.open(pushbarId); } } handleCloseEvent(e) { e.preventDefault(); this.close(); } handleKeyEvent(e) { if (this.opened && e.keyCode === 27) { this.close(); } } bindEvents() { const triggers = document.querySelectorAll('[data-pushbar-target]'); const closers = document.querySelectorAll('[data-pushbar-close]'); triggers.forEach(trigger => trigger.addEventListener('click', e => this.handleOpenEvent(e), false)); closers.forEach(closer => closer.addEventListener('click', e => this.handleCloseEvent(e), false)); if (this.overlay) { this.overlay.addEventListener('click', e => this.handleCloseEvent(e), false); } document.addEventListener('keyup', e => this.handleKeyEvent(e)); } open(pushbarId) { // Current bar is already opened if (String(pushbarId) === this.activeBarId && this.opened) { return; } // Get new pushbar target const pushbar = Pushbar.findElementById(pushbarId); if (!pushbar) return; // Close active bar (if exists) if (this.opened) { this.close(); } Pushbar.dispatchOpen(pushbar); pushbar.classList.add('opened'); const Root = document.querySelector('body'); Root.classList.add('pushbar_locked'); Root.setAttribute('pushbar', pushbarId); this.activeBar = pushbar; } close() { const { activeBar } = this; if (!activeBar) return; Pushbar.dispatchClose(activeBar); activeBar.classList.remove('opened'); const Root = document.querySelector('body'); Root.classList.remove('pushbar_locked'); Root.removeAttribute('pushbar'); this.activeBar = null; } } /* End pushbar mySidebar*/ /* Bengin headerscroll */ function touchMove() { headercroll() } function onScroll() { headercroll() } function headercroll() { var e = $(window).scrollTop(); if (e - lastPosition) { /* nav_header */ if (nav_header >= e ? ($(".nav_header").removeClass("nav_hidden"), $(".nav_header")) : e > lastPosition ? e > nav_header + 50 && e > menuOffsetTop && ($(".nav_header").removeClass("nav_show").addClass("nav_hidden"), $(".nav_header")) : lastPosition > e + 5 && e > nav_header && $(".nav_header").removeClass("nav_show").removeClass("nav_hidden")) /* icons menu */ if (e > lastPosition) { } else { if (e > menuOffsetTop) { $("#opennav").removeClass("ic-none") $(".nav_header").removeClass("nav_hidden").addClass("nav_show"); } else { $("#opennav").addClass("ic-none") $(".nav_header").removeClass("nav_hidden").removeClass("nav_show"); } } lastPosition = e } } var lastPosition = 0, nav_header = 0, menuOffsetTop = $(".nav_header").length ? $(".nav_header").offset().top : 0; document.addEventListener("scroll", onScroll); /* End headerscroll */ /* Bengin ac-menu */ $(function () { var ac = function (el, multiple) { this.el = el || {}; // more then one submenu open? this.multiple = multiple || false; var dropdownlink = this.el.find('.ac_icon'); dropdownlink.on('click', { el: this.el, multiple: this.multiple }, this.dropdown); }; ac.prototype.dropdown = function (e) { var $el = e.data.el, $this = $(this), //this is the ul.submenuItems $next = $this.next(); $next.slideToggle(); $this.parent().toggleClass('ac_open'); /* show only if (!e.data.multiple) {$el.find('.ac_content').not($next).slideUp().parent().removeClass('ac_open');} */ } var ac = new ac($('.ac-menu'), false); }) /* End ac-menu */ /* Bengin remove mobile */ var mq = window.matchMedia('all and (max-width: 960px)'); if (mq.matches) { $(function () { $('.aside-160').remove(); $('.aside-300').remove(); $('.menu_down').remove(); $('.hide').remove(); }); } /* Bengin remove PC */ var mq = window.matchMedia('all and (min-width: 960px)'); if (mq.matches) { $(function () { $('.pushbar').remove(); $('.pushbar_overlay').remove(); }); } /* Bengin Backtotop */ jQuery(function ($) { $(".backtotop"); var oldscrollTop = 0; $(window).scroll(function () { if ($(this).scrollTop() - oldscrollTop < 0) { $(".backtotop").addClass('show_backtotop'); } else { $(".backtotop").removeClass('show_backtotop'); } oldscrollTop = $(this).scrollTop(); }); }); /* End Backtotop */ function validateDate(date) { var matches = /^(\d{4})[-\/](\d{2})[-\/](\d{2})$/.exec(date); if (matches == null) return false; var d = matches[3]; var m = matches[2] - 1; var y = matches[1]; var composedDate = new Date(y, m, d), isValid = composedDate.getDate() == d && composedDate.getMonth() == m && composedDate.getFullYear() == y; return { Date: composedDate, IsValid: isValid }; } function validateNumberDetector(numbers, dateFrom, dateTo, callback) { if (/^[0-9,]+$/.test(numbers)) { if (/\d/.test(numbers)) { var obj1 = validateDate(dateFrom), obj2 = validateDate(dateTo); if (obj1.IsValid && obj2.IsValid && obj1.Date < obj2.Date) { callback(obj1, obj2); } else { if (!obj1.IsValid || !obj2.IsValid) { alert('Ngày chọn không hợp lệ (ngày/tháng/năm).'); } else if (obj1.Date >= obj2.Date) { alert('Ngày chọn không hợp lệ (Vui lòng nhập ngày kết thúc lớn hơn ngày bắt đầu).'); } } } else { alert('Bạn có thể thống kê một hoặc nhiều số: Ví dụ: 36 hoặc 68,86'); } } else { if (numbers.trim().length > 0) alert('Bạn có thể thống kê một hoặc nhiều số: Ví dụ: 36 hoặc 68,86'); else alert('Mời bạn nhập đầy đủ các thông tin để xem thống kê. \r\n Bạn có thể thống kê một hoặc nhiều số: Ví dụ: 36 hoặc 68,86'); } return false; } function formatDate(date, delimiter) { var y = date.getFullYear(), m = date.getMonth() + 1, d = date.getDate(); return (d < 10 ? '0' + d : d) + delimiter + (m < 10 ? '0' + m : m) + delimiter + y; } function getHNTime() { var offset = 7; var d = new Date(); localTime = d.getTime(); localOffset = d.getTimezoneOffset() * 60000; // obtain UTC time in msec utc = localTime + localOffset; // create new Date object for different city // using supplied offset var nd = new Date(utc + (3600000 * offset)); return nd; } function changCurrentLotteryLive() { var d = getHNTime(); var h = d.getHours(); var m = d.getMinutes(); var gg = d.getDate(); var dd = d.getMonth() + 1; var ff = d.getFullYear(); var ee = "kqngay_" + (gg < 10 ? "0" + gg : "" + gg) + (dd < 10 ? "0" + dd : "" + dd) + ff; var curentUrl = window.location.href; var curentOrg = window.location.origin; if (curentUrl.indexOf("#") >= 0) { curentUrl = curentUrl.split("#")[0]; } if (curentUrl.indexOf("?") >= 0) { curentUrl = curentUrl.split("?")[0]; } if (h == 17 && m >= 10 && m <= 40) { $("#lottery_living_name").text("miền Trung"); if (curentUrl == curentOrg + "/" || curentUrl.indexOf("/xo-so-mien-trung/xsmt-p1.html") >= 0 || curentUrl.indexOf("/tuong-thuat-mien-trung/xsmt-tructiep.html") >= 0) { $("#curr_living_btn").attr("href", "#mt_" + ee); } else { $("#curr_living_btn").attr("href", "/xo-so-mien-trung/xsmt-p1.html"); } if (curentUrl.indexOf("/xo-so-mien-trung/xsmt-p1.html") < 0 && curentUrl.indexOf("/tuong-thuat-mien-trung/xsmt-tructiep.html") < 0) { $("#curr_living_neo").show(); } } else if (h == 16 && m >= 10 && m <= 40) { $("#lottery_living_name").text("miền Nam"); if (curentUrl == curentOrg + "/" || curentUrl.indexOf("/xo-so-mien-nam/xsmn-p1.html") >= 0 || curentUrl.indexOf("/tuong-thuat-mien-nam/xsmn-tructiep.html") >= 0) { $("#curr_living_btn").attr("href", "#mn_" + ee); } else { $("#curr_living_btn").attr("href", "/xo-so-mien-nam/xsmn-p1.html"); } if (curentUrl.indexOf("/xo-so-mien-nam/xsmn-p1.html") < 0 && curentUrl.indexOf("/tuong-thuat-mien-nam/xsmn-tructiep.html") < 0) { $("#curr_living_neo").show(); } } else if (h == 18 && m >= 10 && m <= 40) { $("#lottery_living_name").text("miền Bắc"); $("#curr_living_btn").attr("href", "/xo-so-mien-bac/xsmb-p1.html"); if (curentUrl != curentOrg + "/" && curentUrl.indexOf("/xo-so-mien-bac/xsmb-p1.html") < 0 && curentUrl.indexOf("/tuong-thuat-mien-bac/xsmb-tructiep.html") < 0) { $("#curr_living_neo").show(); } } else { $("#curr_living_neo").hide(); } } $('#number_detector_24f606').on('click', function (event) { event.preventDefault(); try { var numbers = $('#number_l4681z').val(), lotteryId = $('#province_w0c38u option:selected').val(), dateFrom = $('#dateRangeForm_g09f8w').val(), dateTo = $('#dateRangeTo_k98pru').val(); validateNumberDetector(numbers, dateFrom, dateTo, function (obj1, obj2) { var arrNumbers = numbers.split(','), numberFilter = arrNumbers.filter(function (elem, index, self) { return index === self.indexOf(elem) && elem !== ''; }); numbers = numberFilter.join(); setTimeout(function() { window.location = '/thong-ke-lo-' + numbers + '-tu-ngay-' + formatDate(obj1.Date, '-') + '-den-ngay-' + formatDate(obj2.Date, '-') + '-xs-' + lotteryId + '.html'; }, 300); }); } catch (e) { console.log(e); alert('Quý khách vui lòng thử lại sau.'); } }); $(function () { if ($('#lottery_living_name').length) { changCurrentLotteryLive(); setInterval("changCurrentLotteryLive()", 30000); } $('#number_l4681z').on('keypress keyup blur', function(event) { if (event.which != 44 && (event.which < 48 || event.which > 57)) { event.preventDefault(); } }); })