'; $('.pcCalcSection').append(html); }else if($('#calc2').val() != ''){ var date = new Date($('#calc2').val()); date.setDate(date.getDate() + 266); var dd = date.getDate(); var mm = date.getMonth() + 1; var y = date.getFullYear(); var someFormattedDate = dd + '/'+ mm + '/'+ y; var html = '
Pregnancy Date: ' + someFormattedDate + '
'; $('.pcCalcSection').append(html); } }) $(document).on('click', '.pcMedia__brands-img img', function(){ clearInterval(mediaSlideTimer); var index = $('.pcMedia__brands-img img').index($(this)); var slide = index + 1; var oldSlideIndex = $(this).closest('.pcMedia__wrap').attr('data-slide'); $(this).closest('.pcMedia__wrap').attr('data-slide', slide); var newSlideIndex = $(this).closest('.pcMedia__wrap').attr('data-slide'); jumpSlider('.pcMedia .sliderWrapper', oldSlideIndex, newSlideIndex); setMediaSliding('.pcMedia .sliderWrapper') }); $(document).on('click', '.pcDidYouKnow__dot', function(){ clearInterval(triviaSlideTimer); var index = $('.pcDidYouKnow__dot').index($(this)); var slide = index + 1; var oldSlideIndex = $(this).closest('.pcDidYouKnow__wrap').attr('data-slide'); $(this).closest('.pcDidYouKnow__wrap').attr('data-slide', slide); var newSlideIndex = $(this).closest('.pcDidYouKnow__wrap').attr('data-slide'); jumpSlider('.pcDidYouKnow .sliderWrapper', oldSlideIndex, newSlideIndex); setTriviaSliding('.pcDidYouKnow .sliderWrapper') }); $(document).on('click', '.showMore__toggle', function(){ toggleShowMoreBut(showMoreEl,openHeight,shutHeight); }); $(document).on('click', '.showMore__toggle2', function(){ toggleShowMoreBut2(showMoreEl2,openHeight2,shutHeight); });})function setupSliders(){ for(var i=0;i<$('.sliderWrapper').length;i++){ var ele = $('.sliderWrapper')[i]; $(ele).attr('data-slidesAmount',$(ele).find('.slider-item').length); cloneSlides(ele); } setMediaSliding('.pcMedia .sliderWrapper'); setTriviaSliding('.pcDidYouKnow .sliderWrapper');}function cloneSlides(slides){for (var i=1;i <= $(slides).attr('data-slidesAmount'); i++) { if($(slides).find("[data-pos='" + $(slides).attr('data-slidesAmount') + "']" ).length == 0){ var cloneA = $(slides).find("[data-pos='0'").clone(); $(cloneA).attr('data-pos',$(slides).attr('data-slidesAmount')); $(slides).append(cloneA); } if($(slides).find("[data-pos='-" + i + "']" ).length == 0){ var cloneA = $(slides).find("[data-item='" + ($(slides).attr('data-slidesAmount') - i) + "']" ).clone(); $(cloneA).attr('data-pos','-' + i); $(slides).append(cloneA); }}}function removeItems(element){ $(element).find("[data-pos='-" + $(element).attr('data-slidesAmount') + "']" ).remove(); $(element).find("[data-pos='" + ($(element).attr('data-slidesAmount') + 1) + "']" ).remove();}function moveSlider(element, direction){ var slideEle = $(element).find('.slider-item'); for (var i = 0; i < (slideEle.length); i++) { var b = $(slideEle[i]); var dataPos = $(b).attr('data-pos'); var dataPoss = (parseInt(dataPos) + direction); $(b).attr('data-pos',dataPoss); } removeItems(element); cloneSlides(element);}function jumpSlider(element, oldIndex, newIndex){ var slideEle = $(element).find('.slider-item'); var sum = oldIndex - newIndex;var direction; if(sum < 0){ direction = -1; }else if(sum > 0){ direction = 1; } for (var i = 0; i < Math.abs(sum); i++) { console.log('here') moveSlider(element, direction); }}function setMediaSliding(element){ mediaSlideTimer = setInterval(function(){setTimeout(function(){ moveSlider(element,-1); var dataVal = $('.pcMedia .slider-item[data-pos="0"]').attr('data-item'); $('.pcMedia__wrap').attr('data-slide', dataVal);},10)},4000);}function setTriviaSliding(element){ triviaSlideTimer = setInterval(function(){setTimeout(function(){ moveSlider(element,-1); var dataVal = $('.pcDidYouKnow .slider-item[data-pos="0"]').attr('data-item'); $('.pcDidYouKnow__wrap').attr('data-slide', dataVal);},10)},4000);}function setupShowMore(ele,open,close){ ele.style.maxHeight = close + 'px'; $($('.pcInfoSlides__copy-desc')[0]).css('height',open +'px');}function setupShowMore2(ele,open,close){ ele.style.maxHeight = close + 'px'; $($('.pcInfoSlides__copy-desc')[1]).css('height',open +'px');}function toggleShowMoreBut(ele,open,close){ if(ele.classList.contains('copy-open')){ ele.classList.remove("copy-open"); ele.style.maxHeight = close + 'px'; document.querySelector('.showMore__toggle p').innerHTML = 'Show More'; }else{ ele.classList.add("copy-open"); ele.style.maxHeight = open + 'px'; document.querySelector('.showMore__toggle p').innerHTML = 'Show Less'; } }function toggleShowMoreBut2(ele,open,close){ if(ele.classList.contains('copy-open')){ ele.classList.remove("copy-open"); ele.style.maxHeight = close + 'px'; document.querySelector('.showMore__toggle2 p').innerHTML = 'Show More'; }else{ ele.classList.add("copy-open"); ele.style.maxHeight = open + 'px'; document.querySelector('.showMore__toggle2 p').innerHTML = 'Show Less'; } }function swipedetect(el, callback){ var touchsurface = el, swipedir, startX, startY, distX, distY, threshold = 50, restraint = 100, allowedTime = 500, elapsedTime, startTime, handleswipe = callback || function(swipedir){} touchsurface.addEventListener('touchstart', function(e){ var touchobj = e.changedTouches[0] swipedir = 'none' dist = 0 startX = touchobj.pageX startY = touchobj.pageY startTime = new Date().getTime() }, false) touchsurface.addEventListener('touchmove', function(e){ }, false) touchsurface.addEventListener('touchend', function(e){ var touchobj = e.changedTouches[0] distX = touchobj.pageX - startX distY = touchobj.pageY - startY elapsedTime = new Date().getTime() - startTime if (elapsedTime <= allowedTime){ if (Math.abs(distX) >= threshold && Math.abs(distY) <= restraint){ swipedir = (distX < 0)? 'left' : 'right' } } handleswipe(swipedir) }, false)}