PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.10.4
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.10.4
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
merchant / assets / js / modules / countdown-timer / countdown-timer.min.js

countdown-timer.min.js in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 1.10.4, at assets/js/modules/countdown-timer/countdown-timer.min.js

1 lines 19.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";function _slicedToArray(e,t){return _arrayWithHoles(e)||_iterableToArrayLimit(e,t)||_unsupportedIterableToArray(e,t)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _iterableToArrayLimit(e,t){var i=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=i){var n,a,r,s,o=[],c=!0,l=!1;try{if(r=(i=i.call(e)).next,0===t){if(Object(i)!==i)return;c=!1}else for(;!(c=(n=r.call(i)).done)&&(o.push(n.value),o.length!==t);c=!0);}catch(e){l=!0,a=e}finally{try{if(!c&&null!=i.return&&(s=i.return(),Object(s)!==s))return}finally{if(l)throw a}}return o}}function _arrayWithHoles(e){if(Array.isArray(e))return e}function _createForOfIteratorHelper(e,t){var i,n,a,r,s="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(s)return n=!(i=!0),{s:function(){s=s.call(e)},n:function(){var e=s.next();return i=e.done,e},e:function(e){n=!0,a=e},f:function(){try{i||null==s.return||s.return()}finally{if(n)throw a}}};if(Array.isArray(e)||(s=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length)return s&&(e=s),r=0,{s:t=function(){},n:function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}},e:function(e){throw e},f:t};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){var i;if(e)return"string"==typeof e?_arrayLikeToArray(e,t):"Map"===(i="Object"===(i=Object.prototype.toString.call(e).slice(8,-1))&&e.constructor?e.constructor.name:i)||"Set"===i?Array.from(e):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?_arrayLikeToArray(e,t):void 0}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var i=0,n=new Array(t);i<t;i++)n[i]=e[i];return n}function _typeof(e){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,_toPropertyKey(n.key),n)}}function _createClass(e,t,i){return t&&_defineProperties(e.prototype,t),i&&_defineProperties(e,i),Object.defineProperty(e,"prototype",{writable:!1}),e}function _toPropertyKey(e){e=_toPrimitive(e,"string");return"symbol"===_typeof(e)?e:String(e)}function _toPrimitive(e,t){if("object"!==_typeof(e)||null===e)return e;var i=e[Symbol.toPrimitive];if(void 0===i)return("string"===t?String:Number)(e);i=i.call(e,t||"default");if("object"!==_typeof(i))return i;throw new TypeError("@@toPrimitive must return a primitive value.")}!function(e){e(document).ready(function(e){new CountDownTimer(e)})}(jQuery,window);var defaultStyles={classic:{labelsColor:"",digitsColor:"#444444",digitsBackground:"",borderColor:"",fontSizeDigits:16,fontSizeLabels:16},progress:{labelsColor:"",digitsColor:"#3858E9",digitsBackground:"#3858E9",borderColor:"",progressColor:"#3858E9",fontSizeDigits:16,fontSizeLabels:16},circles:{labelsColor:"#7C7C7C",digitsColor:"#000",digitsBackground:"#fff",borderColor:"#444444",progressColor:"#3858E9",fontSizeDigits:22,fontSizeLabels:10,width:80,height:80},squares:{labelsColor:"#180B40",digitsColor:"#000",digitsBackground:"#fff",borderColor:"#000000",fontSizeDigits:28,fontSizeLabels:12,width:65,height:65},minimalist:{labelsColor:"#7C7C7C",digitsColor:"#000000",digitsBackground:"#F6F7F7",borderColor:"",fontSizeDigits:40,fontSizeLabels:12,width:80,height:80},cards:{labelsColor:"#3858E9",digitsColor:"#3858E9",digitsBackground:"#E0E2EC",borderColor:"#000000",fontSizeDigits:40,fontSizeLabels:12,width:80,height:80},modern:{labelsColor:"#180B40",digitsColor:"#fff",digitsBackground:"#180B40",borderColor:"",fontSizeDigits:36,fontSizeLabels:12,width:80,height:95}},CountDownTimer=function(){function t(e){_classCallCheck(this,t),this.countDownWrapper=e(".merchant-countdown-timer"),this.countDownTimer=this.countDownWrapper.find(".merchant-countdown-timer-countdown"),this.countDownTimer.length&&(this.total,this.days,this.hours,this.minutes,this.seconds,this.currentTimeInitial=this.getCurrentTime(),this.theme=this.countDownWrapper.attr("data-theme"),this.timerType=this.countDownWrapper.attr("data-countdown-type"),this.startDate=new Date(this.countDownWrapper.attr("data-start-date")||null),this.endDate=new Date(this.countDownWrapper.attr("data-end-date")||null),this.startTime=this.startDate.getTime(),this.endTime=this.endDate.getTime(),this.minExpiration=parseInt(this.countDownWrapper.attr("data-min-expiration")),this.maxExpiration=parseInt(this.countDownWrapper.attr("data-max-expiration")),this.offPeriod=parseInt(this.countDownWrapper.attr("data-off-period")),this.timerCookie="merchant_countdown_timer",this.timerOffPeriodCookie="merchant_countdown_timer_off_period",this.variationsDates=this.countDownWrapper.attr("data-variations-dates"),this.variationsDates=this.variationsDates?JSON.parse(this.variationsDates):[],this.flipTimerKeys={days:{value:"",currentValue:""},hours:{value:"",currentValue:""},minutes:{value:"",currentValue:""},seconds:{value:"",currentValue:""}},null!=(e=merchant)&&e.is_admin&&(this.deleteCookie(this.timerCookie),this.deleteCookie(this.timerOffPeriodCookie)),this.init())}return _createClass(t,[{key:"init",value:function(){this.buildTimerMarkup(),this.setTimerData(),this.startTimer(),this.events()}},{key:"events",value:function(){this.updateVariationTimer(),this.updateAdminPreview()}},{key:"buildTimerMarkup",value:function(){var e=["classic","progress"].includes(this.theme)?"<span></span>":"circles"===this.theme?'\n <div class="cd-days">\n <svg class="cd-svg">\n <circle class="circle-static" r="47%" cx="50%" cy="50%"></circle>\n <circle class="circle-dynamic" r="47%" cx="50%" cy="50%"></circle>\n </svg>\n <div>\n <span class="cd-value">00</span>\n <span class="cd-label">Days</span>\n </div>\n </div>\n <div class="cd-hours">\n <svg class="cd-svg">\n <circle class="circle-static" r="47%" cx="50%" cy="50%"></circle>\n <circle class="circle-dynamic" r="47%" cx="50%" cy="50%"></circle>\n </svg>\n <div>\n <span class="cd-value">00</span>\n <span class="cd-label">Hours</span>\n </div>\n </div>\n <div class="cd-minutes">\n <svg class="cd-svg">\n <circle class="circle-static" r="47%" cx="50%" cy="50%"></circle>\n <circle class="circle-dynamic" r="47%" cx="50%" cy="50%"></circle>\n </svg>\n <div>\n <span class="cd-value">00</span>\n <span class="cd-label">Minutes</span>\n </div>\n </div>\n <div class="cd-seconds">\n <svg class="cd-svg">\n <circle class="circle-static" r="47%" cx="50%" cy="50%"></circle>\n <circle class="circle-dynamic" r="47%" cx="50%" cy="50%"></circle>\n </svg>\n <div>\n <span class="cd-value">00</span>\n <span class="cd-label">Seconds</span>\n </div>\n </div>\n ':"modern"===this.theme?'\n <div class="cd-flip">\n <div class="cd-flip-card cd-days">\n <div class="cd-flip-card-wrapper">\n <div class="cd-flip-card-inner">\n <span class="cd-flip-card-top cd-value">00</span>\n <span class="cd-flip-card-back" data-time="00">\n <span class="cd-flip-card-bottom" data-time="00"></span>\n </span>\n </div>\n </div>\n <span class="cd-flip-clock-label cd-label">Days</span>\n </div>\n\n <div class="cd-flip-card cd-hours">\n <div class="cd-flip-card-wrapper">\n <div class="cd-flip-card-inner">\n <span class="cd-flip-card-top cd-value">00</span>\n <span class="cd-flip-card-back" data-time="00">\n <span class="cd-flip-card-bottom" data-time="00"></span>\n </span>\n </div>\n </div>\n <span class="cd-flip-clock-label cd-label">Hours</span>\n </div>\n\n <div class="cd-flip-card cd-minutes">\n <div class="cd-flip-card-wrapper">\n <div class="cd-flip-card-inner">\n <span class="cd-flip-card-top cd-value">00</span>\n <span class="cd-flip-card-back" data-time="00">\n <span class="cd-flip-card-bottom" data-time="00"></span>\n </span>\n </div>\n </div>\n <span class="cd-flip-clock-label cd-label">Minutes</span>\n </div>\n \n <div class="cd-flip-card cd-seconds">\n <div class="cd-flip-card-wrapper">\n <div class="cd-flip-card-inner">\n <span class="cd-flip-card-top cd-value">00</span>\n <span class="cd-flip-card-back" data-time="00">\n <span class="cd-flip-card-bottom" data-time="00"></span>\n </span>\n </div>\n </div>\n <span class="cd-flip-clock-label cd-label">Seconds</span>\n </div>\n\n </div>\n ':'\n <div class="cd-days">\n <span class="cd-value" data-time="00">00</span>\n <span class="cd-label">Days</span>\n </div>\n <div class="cd-hours">\n <span class="cd-value" data-time="00">00</span>\n <span class="cd-label" data-time="">Hours</span>\n </div>\n <div class="cd-minutes">\n <span class="cd-value" data-time="00">00</span>\n <span class="cd-label">Minutes</span>\n </div>\n <div class="cd-seconds">\n <span class="cd-value" data-time="00">00</span>\n <span class="cd-label">Seconds</span>\n </div>\n ';this.countDownWrapper.find(".cd-progress").remove(),this.countDownTimer.html(e),"progress"===this.theme&&jQuery('<progress class="cd-progress" value="0" max="100"></progress>').insertBefore(this.countDownTimer)}},{key:"setTimerData",value:function(){var e,t,i,n,a;"sale-dates"===this.timerType?this.endTime=this.endDate.getTime():"evergreen"===this.timerType&&(e=this.getCookie(this.timerCookie),t=this.getCookie(this.timerOffPeriodCookie),i=1e3*this.getRandomValueForCountDown(this.minExpiration,this.maxExpiration),i=this.getCurrentTime()+i,n=new Date(i),a=i+1e3*this.offPeriod,!(!e&&t)?e?(this.endTime=new Date(e).getTime(),t||this.setCookie(this.timerOffPeriodCookie,this.offPeriod,a)):(this.setCookie(this.timerCookie,n,i),this.setCookie(this.timerOffPeriodCookie,this.offPeriod,a),this.endTime=n.getTime()):(this.endTime=0,this.displayTimer(0)))}},{key:"startTimer",value:function(){var e=this.getRemainingTime();e?this.displayTimer(e,this.timerEnd):this.timerEnd(),"circles"===this.theme?this.progressCircles():"progress"===this.theme&&this.progressBar()}},{key:"displayTimer",value:function(e,t){t=t||function(){};var i=["classic","progress"].includes(this.theme);this.days=Math.floor(e/864e5),this.days=i?this.days:this.days.toString().padStart(2,"0"),this.hours=Math.floor(e%864e5/36e5).toString().padStart(2,"0"),this.minutes=Math.floor(e%36e5/6e4).toString().padStart(2,"0"),this.seconds=Math.floor(e%6e4/1e3).toString().padStart(2,"0"),i?this.countDownTimer.find("span").html("".concat(this.days," <span>days ").concat("progress"===this.theme?" : ":""," </span> ").concat(this.hours,":").concat(this.minutes,":").concat(this.seconds)):"modern"===this.theme?this.flipTimer():(this.countDownTimer.find(".cd-days .cd-value").html(this.days).attr("data-time",this.days),this.countDownTimer.find(".cd-hours .cd-value").html(this.hours).attr("data-time",this.hours),this.countDownTimer.find(".cd-minutes .cd-value").html(this.minutes).attr("data-time",this.minutes),this.countDownTimer.find(".cd-seconds .cd-value").html(this.seconds).attr("data-time",this.seconds)),e<=0?t.call(this):(this.countDownWrapper.show(),setTimeout(this.startTimer.bind(this),1e3))}},{key:"timerEnd",value:function(){var e;null!=(e=merchant)&&e.is_admin?this.countDownWrapper.show():this.countDownWrapper.hide(),this.displayTimer(0),this.deleteCookie(this.timerCookie)}},{key:"updateVariationTimer",value:function(){var n,a;"sale-dates"===this.timerType&&(n=jQuery,a=this,n('input[name="variation_id"]').on("change",function(){var e,t,i=parseInt(n(this).val());i&&a.variationsDates.length&&(e=(t=a.variationsDates.find(function(e){return parseInt(null==e?void 0:e.id)===i})||{}).start,t=t.end,e="object"===_typeof(e)?null==e?void 0:e.date:e,t="object"===_typeof(t)?null==t?void 0:t.date:t,a.startTime=e?new Date(e).getTime():0,a.endTime=t?new Date(t).getTime():0,a.displayTimer(0),a.startTimer())}))}},{key:"flipTimer",value:function(){var o=this;this.countDownTimer.find(".cd-flip-card").each(function(){var e,t,i,n=jQuery(this),a="",r=(Object.keys(o.flipTimerKeys).forEach(function(e){if(n.hasClass("cd-"+e))return a=e,!1}),o.flipTimerKeys[a].currentValue),s=o[a];s!==r&&(e=n.find(".cd-flip-card-top"),t=n.find(".cd-flip-card-back"),i=n.find(".cd-flip-card-back .cd-flip-card-bottom"),0<=r&&t.attr("data-time",r),o.flipTimerKeys[a].currentValue=s,e.html(s),i.attr("data-time",s),n.removeClass("cd-flipped"),n[0].offsetWidth,n.addClass("cd-flipped"))})}},{key:"getCurrentTime",value:function(){var e=!(0<arguments.length&&void 0!==arguments[0])||arguments[0],t=new Date;return e?t.getTime():t}},{key:"getRemainingTime",value:function(){var e=this.getCurrentTime();return this.startTime>e||this.endTime<e?0:Math.max(this.endTime-e,0)}},{key:"progressBar",value:function(){var e=this.getCurrentTime();this.startTime=this.startTime||this.currentTimeInitial,this.total=this.endTime-this.startTime;var e=100-(e-this.startTime)/this.total*100,t=this.countDownWrapper.find(".cd-progress");t.length&&t.attr("value",Math.floor(e))}},{key:"progressCircles",value:function(){function e(e){var t=s/60;return(r-parseInt(e))*t}var t,i,n,a=parseInt(this.countDownWrapper.find(".merchant-countdown-timer-countdown").css("--merchant-digits-width")),r=60,s=3*parseInt(a),o=(this.countDownTimer.find(".circle-dynamic").css("stroke-dasharray",s),{days:{$el:this.countDownTimer.find(".cd-days .circle-dynamic"),offset:e(this.days)},hours:{$el:this.countDownTimer.find(".cd-hours .circle-dynamic"),offset:e(this.hours)},minutes:{$el:this.countDownTimer.find(".cd-minutes .circle-dynamic"),offset:e(this.minutes)},seconds:{$el:this.countDownTimer.find(".cd-seconds .circle-dynamic"),offset:e(this.seconds)}});for(t in o)Object.hasOwnProperty.call(o,t)&&(i=(n=o[t]||{}).$el,n=n.offset,i.length)&&i.css("stroke-dashoffset",n)}},{key:"setCookie",value:function(e,t,i){i=new Date(i),i="expires=".concat(i.toUTCString());document.cookie="".concat(e,"=").concat(t,";").concat(i,";path=/")}},{key:"getCookie",value:function(e){var t,i=_createForOfIteratorHelper(document.cookie.split(";"));try{for(i.s();!(t=i.n()).done;){var n=_slicedToArray(t.value.trim().split("="),2),a=n[0],r=n[1];if(a===e)return decodeURIComponent(r)}}catch(e){i.e(e)}finally{i.f()}return null}},{key:"deleteCookie",value:function(e){document.cookie="".concat(e,"=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;")}},{key:"getRandomValueForCountDown",value:function(e,t){return Math.floor(Math.random()*(t-e+1))+e}},{key:"updateAdminPreview",value:function(){var c=this,l=jQuery,e=(l(document).on("save.merchant",function(e,t){"countdown-timer"===t&&c.deleteCookie(c.timerOffPeriodCookie)}),l(document).on("change",".merchant-field-end_date select",function(){c.timerType=l(this).val(),c.deleteCookie(c.timerCookie),c.deleteCookie(c.timerOffPeriodCookie),c.init()}),l(document).on("change",".merchant-field-theme input",function(){c.theme=l(".merchant-field-theme input:checked").val(),l(".merchant-field-theme input").each(function(){c.countDownWrapper.removeClass("merchant-countdown-timer-"+l(this).val())}),c.countDownWrapper.attr("data-theme",c.theme).addClass("merchant-countdown-timer-"+c.theme),c.buildTimerMarkup(),c.updateStyles()}),l(document).on("change.merchant-datepicker",function(e,t,i){i&&(c.displayTimer(0),"merchant[sale_start_date]"===(i=null==i?void 0:i.attr("name"))&&(c.startTime=new Date(t)),"merchant[sale_end_date]"===i&&(c.endTime=new Date(t)),c.countDownTimer.hide(),c.startTimer(),setTimeout(function(){return c.countDownTimer.show()},500))}),null);l(document).on("input",".merchant-countdown-evergreen-field input",function(){c.displayTimer(0),clearTimeout(e),e=setTimeout(function(){var i=0,n=0,a=2,r=26,s=0,o=0;c.deleteCookie(c.timerCookie),c.deleteCookie(c.timerOffPeriodCookie),l(".merchant-countdown-evergreen-field input").each(function(){var e=l(this).attr("name"),t=+l(this).val();switch(e){case"merchant[min_expiration_deadline_days]":i=t;break;case"merchant[max_expiration_deadline_days]":n=t;break;case"merchant[min_expiration_deadline]":a=t;break;case"merchant[max_expiration_deadline]":r=t;break;case"merchant[min_expiration_deadline_minutes]":s=t;break;case"merchant[max_expiration_deadline_minutes]":o=t}}),c.minExpiration=24*i*60*60+60*a*60+60*s,c.maxExpiration=24*n*60*60+60*r*60+60*o,c.setTimerData(),c.startTimer()},500)}),l(document).on("input",".merchant-field-cool_off_period input",function(){c.clearOffPeriodCookie=!0}),l(document).on("change",".merchant-field-sale_ending_alignment select",function(){l(this).find("option").each(function(){c.countDownWrapper.removeClass("merchant-countdown-timer--"+l(this).val())}),c.countDownWrapper.addClass("merchant-countdown-timer--"+l(this).val())})}},{key:"updateStyles",value:function(){for(var e=jQuery,t=0,i=Object.entries({digits_font_size:"fontSizeDigits",labels_font_size:"fontSizeLabels",labels_color:"labelsColor",digits_color:"digitsColor",digits_background:"digitsBackground",progress_color:"progressColor",digits_border:"borderColor",digits_width:"width",digits_height:"height"});t<i.length;t++){var n=_slicedToArray(i[t],2),a=n[0],n=n[1],r=null==(r=defaultStyles[this.theme])?void 0:r[n];r&&e('input[name="merchant['.concat(a,']"]')).val(r).attr("value",r).trigger("input").trigger("change")}}}]),t}();