Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var utils = window.optimizely.get('utils');
- var $ = window.optimizely.get('jquery');
- var html = '<aside id="v2-662744473353739-timer"><div class="countdown-wrapper"><p class="title"></p><span class="time-label"></span></div></div></aside>';
- var css = '#v2-662744473353739-timer{background-color:#189cac;padding:.4em 0 .4em 0;height:3.7em;text-align:center;position:fixed;top:0;width:100%;z-index:999}#v2-662744473353739-timer p{font-size:1.1em;color:#fff;float:left;text-align:right;margin:.5em 0}.countdown-wrapper{display:inline-block}#v2-662744473353739-timer .time-label{color:#fff;font-size:1.7em;float:left;padding-left:.6em}.navbar{position:fixed;top:0;width:100%;z-index:999}';
- utils.waitForElement('su-cart-summary').then(function(element) {
- $('head').append('<style>' + css + '</style>');
- var main = $('.main-nav');
- //add new html
- main.after (html);
- var navBar = $("#navbar-top-collapse");
- var timerElem = $("#v2-662744473353739-timer");
- var marginTop = navBar.height() + timerElem.height ();
- $('body').css ({"margin-top" : marginTop});
- timerElem.css ({"margin-top" : navBar.height()});
- var labelText = "This deal is being reserved for you for:";
- if (angular.element(document.getElementsByTagName("BODY")[0]).scope().currentLang == "zh_CN")
- labelText = '锁定此特价剩余时间:';
- timerElem.find (".title").text (labelText);
- var timerLabel = $("#v2-662744473353739-timer .time-label");
- var minutes = 20;
- timerLabel.text (minutes + ":00");
- var timer = setInterval(function () {
- var presentTime = timerLabel.text ();
- var timeArray = presentTime.split(/[:]+/);
- var m = timeArray[0];
- var s = checkSecond((timeArray[1] - 1));
- if(s==59)
- m=m-1;
- if(m == 0 && s == 0)
- clearInterval(timer);
- timerLabel.text (m + ":" + s);
- }, 1000);
- function checkSecond(sec) {
- if (sec < 10 && sec >= 0) {sec = "0" + sec}; // add zero in front of numbers < 10
- if (sec < 0) {sec = "59"};
- return sec;
- }
- });
Add Comment
Please, Sign In to add comment