jQuery.fn.extend({ quizload: function(){ var $this = $(this), $quizid = $this.data('quiz'); $.ajax({ type: "POST", url: $this.data('load'), data: {q: $quizid}, dataType: 'JSON', success: function($response){ switch($response.status){ case 'success': $this.empty().html($response.message); break; case 'login': $('#loginModal').modal('show'); break; } }, }); }, }); $(document).ready(function(){ var $autoPlayTimeoutID; $('body').on('click', '#retest, .qq-play-scorm', function(){ if ($autoPlayTimeoutID) { clearTimeout($autoPlayTimeoutID); } }); //$('form[data-toggle="quicktest"]').quizload(); $('#quizform, form[data-toggle="quicktest"]').submit(function(){ var $thisForm = $(this); var $url = $thisForm.attr('action'); if($thisForm.hasClass('waitting')){ return false; } $thisForm.addClass('waitting'); $.ajax({ type: "POST", url: $url, data: $thisForm.serialize(), dataType: 'JSON', success: function($response){ switch($response.status){ case 'success': $thisForm.empty().html($response.message); $thisForm.find(".dadm-ans-list, .dads-ans-list").sortable({ stop: function( event, ui ) { ui.item.addClass('dad-moved'); var $this = $(this), $questions = $($this.data('target')).find('input.dadhide'); $this.children().each(function($index){ $questions.eq($index).val($(this).data('value')); }); } }); $thisForm.find(".qq-select-one").selectable({ selected: function(event, ui){ $(ui.selected).addClass('ui-selected').siblings().removeClass('ui-selected'); }, stop: function( event, ui ) { $( ".ui-selected", this ).each(function() { $(this).find('input[type="radio"]').prop('checked', true); }); } }); $thisForm.find(".qq-select-multi").selectable({ unselected: function(event, ui ) { $(ui.unselected).find('input[type="checkbox"]').prop('checked', false); }, stop: function( event, ui ) { $( ".ui-selected", this ).each(function() { $(this).find('input[type="checkbox"]').prop('checked', true); }); } }); MathJax.Hub.Queue(["Typeset",MathJax.Hub,"quizform"]); if($response.finish == 'finish'){ $autoPlayTimeoutID = setTimeout(function(){ var $learnpage = $('#learn-page'); hideLearnPanel(); if($learnpage.data('videoloaded')){ showLearnPanel('video'); if($response.ishtml5 == 'ishtml5'){ //player.playlist.currentItem(idx+1); player.play(); }else{ //player.play(idx+1); player.play(); } }else{ $('.with-play-scorm').trigger('click'); } }, 10000); } break; case 'login': $('#loginModal').modal('show'); break; case 'fail': var $mModal = $('#messageModal'); $mModal.find('.warning-des').html($response.message); $mModal.find('.modal-title').html('Thông báo'); $mModal.find('.modal-footer').html(''); $mModal.modal('show'); break; } $thisForm.removeClass('waitting'); }, error: function(){ $thisForm.removeClass('waitting'); } }); return false; }); });