      /* timer.js */
      $(document).ready(function () { const data = {}; window.timerInit = (selector, seconds = null) => { data[`${selector}`] = { started: false, inteval: null }; $(`#${selector}.timer_container`).children('ul').length <= 0 && $(`#${selector}.timer_container`).append('<ul class="flip minutePlay"> <li class="before"> <a href="#"> <div class="up"> <div class="shadow"></div> <div class="inn"></div> </div> <div class="down"> <div class="shadow"></div> <div class="inn"></div> </div> </a> </li> <li class="active"> <a href="#"> <div class="up"> <div class="shadow"></div> <div class="inn"></div> </div> <div class="down"> <div class="shadow"></div> <div class="inn"></div> </div> </a> </li> </ul> <ul class="flip secondPlay"> <li class="before"> <a href="#"> <div class="up"> <div class="shadow"></div> <div class="inn"></div> </div> <div class="down"> <div class="shadow"></div> <div class="inn"></div> </div> </a> </li> <li class="active"> <a href="#"> <div class="up"> <div class="shadow"></div> <div class="inn"></div> </div> <div class="down"> <div class="shadow"></div> <div class="inn"></div> </div> </a> </li> </ul>'); if (seconds != null) { let timer = [...(seconds + '')]; timer.length == 1 && timer.unshift('0'); $(`#${selector}.timer_container`).attr('tens', timer[0]); $(`#${selector}.timer_container`).attr('ones', timer[1]); } data[`${selector}`].tens = parseInt($(`#${selector}.timer_container`).attr('tens')); data[`${selector}`].ones = parseInt($(`#${selector}.timer_container`).attr('ones')); $(`#${selector} .minutePlay .before .inn, #${selector} .minutePlay .active .inn`).text(data[`${selector}`].tens); $(`#${selector} .secondPlay .before .inn, #${selector} .secondPlay .active .inn`).text(data[`${selector}`].ones); $(`#${selector}.timer_container`).addClass('play'); }; window.timerStart = (selector, setting = { unit: 1000, count: 'down', limit: [0, 0], continuous: false, autoplay: false }, timeUp = () => {}) => { const { unit, count, limit, continuous, autoplay } = setting; if (data[`${selector}`].started == false) { autoplay && onesPlay(); data[`${selector}`].inteval = setInterval(onesPlay, unit); data[`${selector}`].started = true; } function onesPlay() { if (count == 'down') { if (!continuous && data[`${selector}`].tens <= limit[0] && data[`${selector}`].ones <= limit[1]) { timerStop(selector); timeUp(); } else { data[`${selector}`].ones == 0 && tensPlay(); data[`${selector}`].ones = data[`${selector}`].ones > 0 ? (data[`${selector}`].ones - 1) % 10 : 9; $(`#${selector} .secondPlay li`).toggleClass('active before'); } } else { if (!continuous && data[`${selector}`].tens >= limit[0] && data[`${selector}`].ones >= limit[1]) { timerStop(selector); timeUp(); } else { data[`${selector}`].ones == 9 && tensPlay(); data[`${selector}`].ones = (data[`${selector}`].ones + 1) % 10; $(`#${selector} .secondPlay li`).toggleClass('active before'); } } $(`#${selector} .secondPlay .active .inn`).text(data[`${selector}`].ones); } function tensPlay() { if (count == 'down') { data[`${selector}`].tens = data[`${selector}`].tens > 0 ? (data[`${selector}`].tens - 1) % 10 : limit[0]; } else { data[`${selector}`].tens = data[`${selector}`].tens >= limit[0] ? 0 : (data[`${selector}`].tens + 1) % 10; } $(`#${selector} .minutePlay li`).toggleClass('active before'); $(`#${selector} .minutePlay .active .inn`).text(data[`${selector}`].tens); } }; window.timerReset = (selector) => { timerStop(selector); timerInit(selector); data[`${selector}`].started = false; if (data[`${selector}`].inteval != null) clearInterval(data[`${selector}`].inteval); }; window.timerStop = (selector) => { data[`${selector}`].started = false; if (data[`${selector}`].inteval != null) clearInterval(data[`${selector}`].inteval); }; window.timerCheck = (selector) => parseInt(`${data[`${selector}`].tens}${data[`${selector}`].ones}`); });
  