window.history.forward(); $(document).ready(function () { updateProcess(); }); function updateProcess() { var total = parseInt($(".theory-data-list").attr('total')); var indexCur = parseInt($(".theory-data-list .theory-data-item.item-current").attr('index')); $(".theory-data-paginate .paginate-number.paginate-active").removeClass('paginate-active'); $(".theory-data-paginate .paginate-item.paginate-current .paginate-number[index='" + indexCur + "']").addClass('paginate-active'); $(".theory-data-list .theory-data-item.item-current").css('display', 'block'); $(".theory-data-paginate .paginate-item.paginate-current").css('display', 'block'); if (total > 0) { $(".theory-process .theory-process-bar").width((indexCur + 1) * 100 / total + '%'); } if ($(".theory-data-list .theory-data-item.item-current .icon-sound").length > 0) { setTimeout(function () { playSound($(".theory-data-list .theory-data-item.item-current .icon-sound")); }, 700); } } $(document).on('click', '.icon-sound', function () { playSound($(this), cache_fcComplete); }); var cache_fcComplete = function () { }; var checkLoadAudio; function playSound(element, fcComplete = function () { }) { // Set function callback to function temp cache_fcComplete = fcComplete; stopSound(); // Get link audio and element audio var src = $(element).attr('sound_url'); var speaker = $('.speaker-audio-1')[0]; if (src != undefined && src != "") { $(".exe-icon-sound").removeClass('sound-active'); // Load audio $(speaker).attr('src', src); speaker.load(); // Check audio load after 3s checkLoadAudio = setTimeout(function () { // Run callback fcComplete(); // Remove function callback temp cache_fcComplete = function () { }; }, 3000); // If audoo load success speaker.onloadeddata = function () { // Remove timeout clearTimeout(checkLoadAudio); // Play audio speaker.play(); element.addClass('sound-active'); // End audio speaker.onended = function () { element.removeClass('sound-active'); // Run callback fcComplete(); // Remove function callback temp cache_fcComplete = function () { }; }; }; } } function stopSound() { $('.icon-sound.sound-active').removeClass('sound-active'); ($('.speaker-audio-1')[0]).pause(); clearTimeout(checkLoadAudio); } var checkClickNext = 1; // Button NEXT $(document).on('click', '.theory-bottom .button.button-next', function () { stopSound(); if (checkClickNext == 1) { checkClickNext = 0; var divCurrent = $(".theory-data-item.item-current"); var indexCur = parseInt($(divCurrent).attr('index')); var indexNext = indexCur + 1; console.log(indexNext); changeQuestion(divCurrent, indexNext); } }); // Button PREV $(document).on('click', '.theory-bottom .button.button-prev', function () { stopSound(); if (checkClickNext == 1) { checkClickNext = 0; var divCurrent = $(".theory-data-item.item-current"); var indexCur = parseInt($(divCurrent).attr('index')); var indexPrev = indexCur - 1; changeQuestion(divCurrent, indexPrev); } }); function changeQuestion(divCurrent, indexNext) { var total = parseInt($(".theory-data-list").attr('total')); var indexCur = parseInt($(divCurrent).attr('index')); if (indexNext >= 0 && indexNext < total && indexNext != indexCur) { var divShow = $(".theory-data-item[index='" + indexNext + "']"); //if(divShow.length > 0){ $(divShow).addClass('item-current'); $(divCurrent).removeClass('item-current'); var isPrev = 0; if (indexNext < indexCur) { isPrev = 1; } if (isPrev == 0) { $(divShow).removeClass('theory-hide-question prev'); $(divCurrent).removeClass('theory-show-question prev'); $(divShow).addClass('theory-show-question'); $(divCurrent).addClass('theory-hide-question'); } else { $(divShow).removeClass('theory-hide-question prev'); $(divCurrent).removeClass('theory-show-question prev'); $(divCurrent).addClass('theory-hide-question prev'); $(divShow).addClass('theory-show-question prev'); } // Show number paginate var typeDataNext = parseInt($(divShow).attr('typeData')); var paginateItemNext = $('.theory-data-paginate .paginate-item[typeData="' + typeDataNext + '"]'); var paginateItemCur = $('.theory-data-paginate .paginate-item.paginate-current'); var typeDataCur = parseInt($(paginateItemCur).attr('typeData')); if (typeDataNext != typeDataCur) { $(paginateItemNext).addClass('paginate-current'); $(paginateItemCur).removeClass('paginate-current'); if (isPrev == 0) { $(paginateItemNext).find('.paginate-item-cover').removeClass('theory-hide-question prev'); $(paginateItemCur).find('.paginate-item-cover').removeClass('theory-show-question prev'); $(paginateItemNext).find('.paginate-item-cover').addClass('theory-show-question'); $(paginateItemCur).find('.paginate-item-cover').addClass('theory-hide-question'); } else { $(paginateItemNext).find('.paginate-item-cover').removeClass('theory-hide-question prev'); $(paginateItemCur).find('.paginate-item-cover').removeClass('theory-show-question prev'); $(paginateItemCur).find('.paginate-item-cover').addClass('theory-hide-question prev'); $(paginateItemNext).find('.paginate-item-cover').addClass('theory-show-question prev'); } } setTimeout(function () { $(divCurrent).hide(); if (typeDataNext != typeDataCur) { $(paginateItemCur).hide(); } checkClickNext = 1; }, 600); updateProcess(); //}else{ // getDataTheory(indexNext, function(result){ // if(result.length == 2){ // if(result[0] == 'true'){ // $(".theory-data-list").append(result[1]); // changeQuestion(divCurrent, indexNext); // }else if(result[0] == 'false'){ // window.location.href = result[1]; // } // } // }); //} } else if (indexNext >= total) { window.location.href = $("#learning-theory-complete").val(); } else { checkClickNext = 1; } } function getDataTheory(indexNext, fcGetdata) { $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') } }); $.ajax({ url: $("#learning-theory-data").val(), type: "POST", data: { index: indexNext }, success: function (result) { console.log(result); fcGetdata(result); } }); } $(document).on('click', '.theory-data-paginate .paginate-number,.bullet-item ', function () { stopSound(); if (checkClickNext == 1) { checkClickNext = 0; var divCurrent = $(".theory-data-item.item-current"); var indexNext = parseInt($(this).attr('index')); changeQuestion(divCurrent, indexNext); } }); $(document).ready(function () { //feedback //click feedback cancel button $('.cancel-fault').click(function () { $('.txt-fault').val(''); $('#feedback-fault').modal('hide'); }); var checkOption = 1; $('.slt-fault').click(function (e) { checkOption = 0; $('.slt-fault-option').slideToggle(); setTimeout(function () { checkOption = 1; }, 500); }); $('#feedback-fault .modal-body').click(function () { if (checkOption == 1) { $('.slt-fault-option').slideUp(); } }); $('.slt-item').click(function () { var val = $(this).attr('value'); $('.slt-fault span').attr('value', val); $('.slt-fault span').text($(this).text()); }); //feedback fault $('.send-fault').click(function () { var contentFault = $('.txt-fault').val(); var fault = $('.slt-fault span').attr('value'); var url = $(this).attr('link'); if (contentFault.trim() == "") { return; } $('.txt-fault').val(''); $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') } }); $.ajax({ url: url, type: "POST", data: { 'fault_id': fault, 'content': contentFault }, success: function (result) { if (result == 1) { $('.modal-content-feedback').css('display', 'none'); $('.modal-content-thanks').css('display', 'block'); $('.txt-fault').val(''); setTimeout(function () { $('#feedback-fault').modal('hide') $('.modal-content-thanks').css('display', 'none'); $('.modal-content-feedback').css('display', 'block'); }, 3000); } } }); }); }); // MORE SAMPLE //$(document).on('click', '.theory-data-content .data-button-more', function () { // var index = $(this).attr('index'); // var link = $('#learning-theory-more-sample').val(); // var modal = $("#more-sample-modal"); // var modalIndex = $(modal).attr('index'); // if (modalIndex == index) { // $("#more-sample-modal").modal(); // } else { // $(modal).attr('index', index); // $.ajaxSetup({ // headers: { // 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') // } // }); // $.ajax({ // url: link, // type: "POST", // data: { // 'index': index // }, // success: function (result) { // console.log(result); // if (result[0] == 'true') { // $(modal).html(result[1]); // modal.modal(); // } else if (result[0] == 'false') { // window.location.href = result[1]; // } // } // }); // } //});