/*! /app/webroot/js/main.js !*/ var questions = false; var questionItems = false; var submitAnswerNow = true; function updateQuestionAnswer(answerItem, questionNumber) { $answer = $(answerItem); $question = $('#question' + questionNumber); $('.answers li', $question).removeClass('selected'); $('.answer-input', $question).val($answer.attr('answer')); $answer.addClass('selected'); $question.addClass('done'); $('#index .qindex' + questionNumber ).addClass('done'); } // function updateQuestionAnswerProgressBar(answeredQuestionId) { // $('#test-footer-bar-box li[data-question=' + answeredQuestionId + ']').addClass('done'); // $('#total-answered').text($('#test-footer-bar-box li[data-question].done').length); // } function nextQuestion(questionNumber, nextQuestionNumber, total) { $('.progress .count').html(nextQuestionNumber); $('#question' + questionNumber ).fadeOut(300, function() { //$('#index .qindex' + questionNumber ).addClass('done'); $('#question' + nextQuestionNumber ).fadeIn(); done = $('.questions div.question.done').length; //console.log(done); $('#testprogress .graph').attr('data-number', (done / total) * 100); updateProgress(); }); } function updateProgress() { $('#testprogress .graph').each(function() { $this = $(this); $('.bar', $this).animate({ width: $this.attr('data-number')+"%" }, 1500, 'swing'); }); } function unanswered(submit) { if(submit) { $('#processing').show(); $('#TestSaveForm').submit(); } $('#unanswered').hide(); } function setQuestionFocus(questionItem, noScroll) { if (! questionItem) { questionItem = $('#content .test .questions .question.focus'); } else if (! isNaN(questionItem)) { questionItem = $('#question' + questionItem); } else { questionItem = $(questionItem); } var questionOptions = questions[questionItem.attr('data-question')]; //console.log(questionOptions); $('.questions .question:visible').fadeOut(300, function() { $(questionItem).fadeIn(); }); } function allQuestionAnswered() { var success = $('.questions div.question').length === $('.questions div.question.done').length; if (success) { $('#processing').show(); return true; } $('#unanswered').show(); return false; } // function initQuestionItemPosition() // { // questions = {}; // if (questionItems.length) { // questionItems.each(function(index, item){ // item = $(item); // var details = item.offset(); // details.id = item.attr('id'); // details.height = item.height(); // questions[item.attr('data-question')] = details; // }); // } // } // function loadQuestions() { // if (! questions) { // var items = $('#content .test .questions .question'); // if (items.length) { // questionItems = items; // initQuestionItemPosition(); // $(document).keyup(function(event){ // if (event.keyCode == 13) { // if(allQuestionAnswered()) $('#TestViewForm').submit(); // } // if (event.keyCode >= 65 && event.keyCode <= 90) { // var item = $('#content .test .questions .question.focus li[answerkey=' + event.keyCode + ']'); // if (item.length) item.click(); // } // }); // $(window).scroll(calcCurrentQuestion); // $('body').bind('touchmove', calcCurrentQuestion); // function calcCurrentQuestion() { // var scrollTop = $(window).scrollTop(); // var screenHeight = $(window).height(); // var screenWidth = $(window).width() // if(screenWidth > 800) { // var middleLine = (scrollTop + (screenHeight / 3)); // } else { // var middleLine = (scrollTop + (screenHeight / 10)); // } // var first = false; // for (var i in questions) { // if (questions[i].top < scrollTop && questions[i].top + questions[i].height > scrollTop) // first = i; // if (questions[i].top >= scrollTop && questions[i].top + questions[i].height <= scrollTop + screenHeight) { // if (questions[i].top < middleLine && questions[i].top + questions[i].height > middleLine) // return setQuestionFocus(i, true); // else if (questions[i].top > middleLine && questions[i].top + questions[i].height > middleLine) // return setQuestionFocus(i, true); // first = i; // } // } // if (first) return setQuestionFocus(first, true); // } // } // } // } function fixedFooter(nav_id, container_id){ $footer = $(nav_id); $container = $(container_id); $(window).scroll(function(){calcPos();}); $('body').bind('touchmove', function(){calcPos();}); function calcPos(){ if (($(window).height() < $(document).height()) && ($(window).scrollTop() < $container.offset().top - $(window).height())) { $footer.addClass('fixed'); } else { $footer.removeClass('fixed'); } } } $(document).ready(function() { $('body').addClass('js'); var ua = detect.parse(navigator.userAgent); $('html').addClass(ua.browser.family.toLowerCase()); $('html').addClass('v' + ua.browser.major); $('html').addClass(ua.device.family.toLowerCase()); //responsive menu $menuLink = $('#header.body #mobiletrigger'); $menu = $('#header.body .mobile-navigation'); // $footerLink = $('#footer #footertrigger'); // $footermenu = $('#footer #footermenu'); // $menuLink = $('header#main .mobile-menu-toggle'); // $menu = $('header#main .menu-header-menu-container'); $accountLink = $('#mobile-account'); $account = $('header#main .account-menu'); $backendMenuTrigger = $('.navigation #mobiletrigger'); $backendMenu = $('.navigation #courses'); $menuLink.on('click', function(e) { e.preventDefault(); //$menuLink.stop().toggleClass('open'); $menu.stop().slideToggle(); }); // $footerLink.on('click', function(e) { // e.preventDefault(); // $footerLink.stop().toggleClass('open'); // $footermenu.stop().slideToggle(); // }); $accountLink.on('click', function(e) { e.preventDefault(); $account.slideToggle(); }); $backendMenuTrigger.on('click', function(e) { e.preventDefault(); $backendMenu.stop().slideToggle(); }); $(window).resize(function(){ var w = $(window).width(); if(w > 1100) { $backendMenu.removeAttr('style'); } if(w > 920) { $menu.removeAttr('style'); } }); if($('#courses .flyouts .flyout').html()) { $('#courses .menu li').hoverIntent(function(){ //Hover In var id = $(this).attr('data-course'); console.log(id); if(id != undefined) { $('#courses .flyouts .flyout').hide(); $('#'+id).show(); } },function(){}); } if($('.test.entry-content').html() || $('.modules.view').html()) { $(document).on('click', '.test-navigation ul li', function(){ num = $(this).attr('data-question'); $('html, body').stop().animate({ scrollTop: $("#question" + num).offset().top - $('.test-navigation').outerHeight(true) - 10 }, 1000); }); $(document).on('click', '.questions .question input', function(){ num = $(this).closest('.question').attr('data-question'); $("#num" + num).addClass('answered'); }); //$('.test.entry-content .questions').css('marginTop', $('.test.entry-content .test-navigation').height() + 'px'); } if($('.modules-widget').html()) { $('.modules-widget .category.closed ul').hide(); $('.modules-widget').on('click', '.category.closed h4', function(){ $this = $(this); $widget = $this.closest('.modules-widget'); if($('.category ul:visible').html()) { $('.category ul:visible', $widget).slideUp(400, function(){ $('.category', $widget).addClass('closed').removeClass('open'); $this.closest('.category').removeClass('closed').addClass('open'); $this.siblings('ul').slideDown(400, function(){}); }); } else { $('.category', $widget).addClass('closed').removeClass('open'); $this.closest('.category').removeClass('closed').addClass('open'); $this.siblings('ul').slideDown(400, function(){}); } }); $('.modules-widget').on('click', '.category.open h4', function(){ $this = $(this); $widget = $this.closest('.modules-widget'); $('.category ul:visible', $widget).slideUp(400, function(){ $('.category', $widget).addClass('closed').removeClass('open'); }); }); } if($('ul.star-rating').html()) { $('ul.star-rating li').hover(function(){ $(this).prevAll().addClass('active'); },function(){ $(this).prevAll().removeClass('active'); }); $('ul.star-rating li').click(function(e){ $('ul.star-rating li').removeClass('set'); $(this).addClass('set'); $(this).prevAll().addClass('set'); $('#ReviewRating').val($(this).attr('data-rating')); }); } function fixedNav(nav_id, container_id){ $header = $(nav_id); $container = $(container_id); origin = $header.offset().top; $(window).scroll(function(){calcPos();}); $('body').bind('touchmove', function(){calcPos();}); function calcPos(){ if ($(window).scrollTop() > origin) { $container.css('marginTop', $header.outerHeight(true) + 20); $header.css({top:0}).addClass('fixed'); } else { $header.removeClass('fixed').css({top: origin}); $container.css('marginTop', 0); } } } if($('.test.entry-content .test-navigation').html()) { //fixedNav('.test.entry-content .test-navigation', '.test.entry-content #TestViewForm' ); } function fixedFooter(nav_id, container_id){ $footer = $(nav_id); $container = $(container_id); $(window).scroll(function(){calcPos();}); $('body').bind('touchmove', function(){calcPos();}); function calcPos(){ if (($(window).height() < $(document).height()) && ($(window).scrollTop() < $container.offset().top - $(window).height())) { $footer.addClass('fixed'); } else { $footer.removeClass('fixed'); } } } if ($('#test-footer-bar-box').html()) { fixedFooter('.test-footer-bar', '#test-footer-bar-box'); } $('#OrderSameAsShipping').click(function() { if($(this).is(':checked')) { $('div#billing').stop().slideUp(); } else { $('div#billing').stop().slideDown(); } }); if($("#copy-billing").html()) { var $to = {}; var values = {}; $("#copy-billing").click(function(e){ e.preventDefault(); var x = 0; $('.col.shipping :input:visible').each(function() { $to[x] = $(this); x++; }); var y = 0; $('.col.billing :input:visible').each(function() { $to[y].val($(this).val()); y++; }); }); } $( '#content table' ).wrap( '
' ); } );