(function($) { $.fn.emc = function(options) { var defaults = { key: [], scoring: "normal", progress: true }, settings = $.extend(defaults,options), $quizItems = $('[data-quiz-item]'), $choices = $('[data-choices]'), itemCount = $quizItems.length, chosen = [], $option = null, $label = null; emcInit(); if (settings.progress) { var $bar = $('#emc-progress'), $inner = $('
'), $perc = $('0/'+itemCount+''); $bar.append($inner).prepend($perc); } function emcInit() { $quizItems.each( function(index,value) { var $this = $(this), $choiceEl = $this.find('.choices'), choices = $choiceEl.data('choices'); for (var i = 0; i < choices.length; i++) { $option = $(''); $label = $(''); $choiceEl.append($option).append($label); $option.on( 'change', function() { $this.addClass('item-correct'); if ($('.dontUsed').length == 1) { $this.attr('id', 'focus-quest'); } else { $this.removeAttr('id'); }; if (!($('section').hasClass('start-quizz'))) { // $('a').css('pointer-events', 'none'); // $('img:not(.cross)').unwrap('a'); // $('img:not(.cross)').attr('data-scroll', '#next-quest'); // $('.btn').css('pointer-events', 'auto'); $('footer').css('display', 'block'); setTimeout(function () { $('footer').css('opacity', '1'); }, 100); $('footer').fadeIn('slow', 'linear'); $('#ssbutton').html('Get your Free Trial'); $('#ssbutton').attr('id', 'ssbutton'); }; $('section').addClass('start-quizz'); $this.removeClass('dontUsed'); return getChosen(); }); } }); } function getChosen() { chosen = []; $choices.each( function() { var $inputs = $(this).find('input[type="radio"]'); $inputs.each( function(index,value) { if($(this).is(':checked')) { chosen.push(index + 1); } }); }); getProgress(); } function getProgress() { var prog = (chosen.length / itemCount) * 100 + "%", $submit = $('#emc-submit'); if (settings.progress) { $perc.text(chosen.length * 20 + '% on to getting free bottle'); //footer progress bar text $inner.css({width: prog}); } if (chosen.length === itemCount) { $submit.addClass('ready-show'); $('.question').css('display', 'none'); $('.question-num').css('display', 'none'); $('.choices').css('display', 'none'); setTimeout(function () { $('#emc-progress').css('opacity', '0'); $('#next-min').css('opacity', '0'); setTimeout(function () { $('#emc-progress').css('display', 'none'); $('#next-min').css('display', 'none'); $('#progress-button').css('display', 'block'); setTimeout(function () { $('#progress-button').css('opacity', '1'); }, 100); }, 150); }, 1000); $('.stock').css('display', 'block'); // $('a').css('pointer-events', 'auto'); $('#quest-box section:not(#focus-quest)').css('display', 'block'); // $('img:not(.cross)').wrap(''); $('section').removeClass('item-correct'); if (!($('#quest-box').is(':empty'))) { $('#ssbutton').css('display', 'block'); } else { $('#ssbutton').attr('id', 'ssbutton'); $('#ssbutton').html('Get your Free Trial'); }; $('html, body').animate({ scrollTop: $('#focus-quest').offset().top }, 500); } } } }(jQuery)); $(document).emc({ }); setTimeout(function () { var target = $('#quest-box'); var targetPos = target.offset().top; var winHeight = $(window).height(); var scrollToElem = targetPos - winHeight; var oneTimeScroll = false; $(window).scroll(function () { var winScrollTop = $(this).scrollTop(); if (winScrollTop > scrollToElem) { if ($('.dontUsed').length != 0) { $('.next-min').css('display', 'flex'); }; $('#emc-progress_ind').css('width', 'calc(61% - 55px)'); $('#emc-progress').css('width', 'calc(61% - 55px)'); if ($('section').hasClass('start-quizz')) { $('#description-quest').css('display', 'none'); $('#quest-box').append($('#wrapper>.dontUsed')); }; if (!oneTimeScroll && $('section').hasClass('start-quizz') && $('.dontUsed').length != 0) { $('html, body').animate({ scrollTop: $('#ssbutton').offset().top }, 500); oneTimeScroll = true; }; }; }); }, 2000); $('.next-min').click(function () { var scrollName = $(this).attr('data-scroll'), scrollElem = $(scrollName), scrollTop = scrollElem.offset().top; $('html, body').animate({ scrollTop: scrollTop }, 500); }); $('img').click(function () { var scrollName = $(this).attr('data-scroll'), scrollElem = $(scrollName), scrollTop = scrollElem.offset().top; $('html, body').animate({ scrollTop: scrollTop }, 500); });