learning-theory-test.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. $(document).ready(function () {
  2. window.history.forward();
  3. updateProcess();
  4. });
  5. function effectAnswerRight() {
  6. //Play sound right
  7. $("#audio-testing-answer-right")[0].load();
  8. $("#audio-testing-answer-right")[0].onloadeddata = function () {
  9. $("#audio-testing-answer-right")[0].play();
  10. };
  11. }
  12. function effectAnswerWrong() {
  13. //Play sound wrong
  14. $("#audio-testing-answer-wrong")[0].load();
  15. $("#audio-testing-answer-wrong")[0].onloadeddata = function () {
  16. $("#audio-testing-answer-wrong")[0].play();
  17. };
  18. }
  19. function playNormalTimeSound() {
  20. if ($("#normal-time-sound").length > 0) {
  21. $("#normal-time-sound")[0].load();
  22. $("#normal-time-sound")[0].onloadeddata = function () {
  23. $("#normal-time-sound")[0].play();
  24. };
  25. }
  26. }
  27. function playWarningTimeSound() {
  28. if ($("#warning-time-sound").length > 0) {
  29. $("#warning-time-sound")[0].load();
  30. $("#warning-time-sound")[0].onloadeddata = function () {
  31. $("#warning-time-sound")[0].play();
  32. };
  33. }
  34. }
  35. function updateProcess() {
  36. var total = parseInt($(".testing-theory-content").attr('total'));
  37. var indexCur = parseInt($(".testing-theory-content .testing-theory-item.item-current").attr('index'));
  38. $(".testing-theory-content .testing-theory-item.item-current").show();
  39. if (total > 0) {
  40. $(".testing-theory-process .testing-theory-process-bar").width((indexCur + 1) * 100 / total + '%');
  41. }
  42. $(".testing-theory-countdown svg circle.circle").css('stroke-dashoffset', '0px');
  43. $(".testing-theory-countdown-number").text(totalTime);
  44. var typeQuestionShow = $(".testing-theory-content .testing-theory-item.item-current").attr('typeQuestion');
  45. if (typeQuestionShow == 3) {
  46. if (!$('.testing-theory-content .testing-theory-item.item-current .testing-theory-pos-end').hasClass('ui-droppable')) {
  47. setDragAndDrop($(".testing-theory-content .testing-theory-item.item-current"));
  48. }
  49. }
  50. readyAnswer = 1;
  51. setTimeout(function () {
  52. runCountdown();
  53. }, 500);
  54. }
  55. var testData = new Array();
  56. var answerText = "";
  57. var answerTextTrue = "";
  58. var userAnswer = "";
  59. function nextQuestion(resultData, timeNext = 2000) {
  60. var answerTrue = $(".learning-theory-test-true").val();
  61. var qid = $(".learning-theory-test-true").attr('qid');
  62. var qtype = $(".learning-theory-test-true").attr('qtype');
  63. var ttype = $(".learning-theory-test-true").attr('ttype');
  64. testData.push({
  65. qid: qid,
  66. qtype: qtype,
  67. ttype: ttype,
  68. answerTrue: answerTrue,
  69. answer: userAnswer,
  70. answerText: answerText,
  71. answerTextTrue: answerTextTrue,
  72. time: Math.max(totalTime - second + 1, 1)
  73. });
  74. setTimeout(function () {
  75. questionNew = resultData['nextQuestion'];
  76. if (questionNew == "") {
  77. if (testData.length > 0) {
  78. /*$.blockUI(
  79. {
  80. message:'Vui lòng chờ trong giây lát',
  81. css: {
  82. border: 'none',
  83. padding: '15px',
  84. backgroundColor: '#000',
  85. '-webkit-border-radius': '2px',
  86. '-moz-border-radius': '2px',
  87. opacity: .5,
  88. color: '#fff'
  89. }}
  90. );*/
  91. $.ajaxSetup({
  92. headers: {
  93. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  94. }
  95. });
  96. $.ajax({
  97. url: $("#result-link").val(),
  98. type: "POST",
  99. data: {
  100. testData: testData
  101. },
  102. success: function (result) {
  103. console.log('link ' + $("#result-link").val());
  104. console.log('result ' + result);
  105. checkTest = 1;
  106. //if (result != 0) {
  107. // window.location.href = result;
  108. //} else {
  109. // window.location.href = location.protocol + "//" + location.host + '/';
  110. //}
  111. }
  112. });
  113. }
  114. }
  115. var divParent = $(".testing-theory-content");
  116. var divCurrent = $(".testing-theory-item.item-current");
  117. var divNext = $(divCurrent).next('.testing-theory-item');
  118. if (divNext.length == 0) {
  119. $(divParent).append(questionNew);
  120. divNext = $(divCurrent).next('.testing-theory-item');
  121. }
  122. if (divNext.length > 0) {
  123. $(divNext).addClass('item-current');
  124. $(divCurrent).removeClass('item-current');
  125. $(divCurrent).addClass('testing-theory-hide-question');
  126. $(divNext).addClass('testing-theory-show-question');
  127. updateProcess();
  128. setTimeout(function () {
  129. $(divCurrent).remove();
  130. }, 500);
  131. }
  132. }, timeNext);
  133. }
  134. // Time
  135. var t;
  136. var totalTime = 15;
  137. var second = totalTime;
  138. var readyRunCountdown = 1;
  139. var readyAnswer = 1;
  140. function runCountdown() {
  141. if (readyRunCountdown == 1 && readyAnswer == 1) {
  142. readyRunCountdown = 0;
  143. second = totalTime;
  144. var runCircle = 0;
  145. t = window.setInterval(function () {
  146. if (window.blurred) {
  147. } else {
  148. second = --second <= 0 ? 0 : second;
  149. if (runCircle == 0) {
  150. runCircle = 1;
  151. $(".testing-theory-countdown svg circle.circle").animate({
  152. "stroke-dashoffset": "-101px",
  153. }, (second) * 1000, "linear", function () {
  154. });
  155. }
  156. $(".testing-theory-countdown-number").text(second);
  157. if (second == 0) {
  158. window.clearInterval(t);
  159. endTime();
  160. return false;
  161. }
  162. if (second <= 5) {
  163. // $(".testing-theory-time-countdown").addClass("end-time");
  164. playWarningTimeSound();
  165. } else {
  166. playNormalTimeSound();
  167. }
  168. }
  169. }, 1000);
  170. }
  171. }
  172. function stopCountdown() {
  173. $(".testing-theory-countdown svg circle.circle").stop(true);
  174. window.clearInterval(t);
  175. readyRunCountdown = 1;
  176. readyAnswer = 0;
  177. }
  178. window.onblur = function () {
  179. window.blurred = true;
  180. $(".testing-theory-countdown svg circle.circle").stop(true);
  181. };
  182. window.onfocus = function () {
  183. window.blurred = false;
  184. if (readyRunCountdown == 0) {
  185. $(".testing-theory-countdown svg circle.circle").animate({ "stroke-dashoffset": "-101px" }, (second) * 1000, "linear");
  186. }
  187. };
  188. // END time
  189. function endTime() {
  190. // Get element
  191. //readyRunCountdown = 1;
  192. //var divParent = $('.testing-theory-content .testing-theory-item.item-current');
  193. // Check Show answer
  194. //if( !$(divParent).hasClass('show-answer') ){
  195. // Add class show answer
  196. //$(divParent).addClass('show-answer');
  197. // Get value for ajax
  198. //var token = $(divParent).attr('qToken');
  199. //var answer = '';
  200. //var typeQuestion = $(divParent).attr('typeQuestion');
  201. // Get answer true
  202. /*checkTestingAnswer(token, answer, function(answerTrue){
  203. effectAnswerWrong();
  204. // GUESSING
  205. if(typeQuestion == 2){
  206. // Effect answer
  207. $(divParent).find('.guessing-choice-item[val='+ answerTrue['answerTrue'] +']').addClass('choice-true');
  208. $(divParent).find(".guessing-choice-item.choice-true[hideAnswer] .guessing-text").text($(divParent).find(".guessing-choice-item.choice-true[hideAnswer]").attr('hideAnswer'));
  209. }
  210. nextQuestion(answerTrue);
  211. });*/
  212. //}
  213. }
  214. var answer = "";
  215. // CHECK ANSWER GUESSING
  216. $(document).on('click', '.testing-theory-item .guessing-choice-item', function () {
  217. // Get element
  218. var eleAnswer = $(this);
  219. var divParent = $(this).parents('.testing-theory-item');
  220. // Check Show answer
  221. if (!$(divParent).hasClass('show-answer')) {
  222. // Add class show answer
  223. $(divParent).addClass('show-answer');
  224. stopCountdown();
  225. // Get value for ajax
  226. var token = $(divParent).attr('qToken');
  227. userAnswer = $(eleAnswer).attr('val');
  228. answerText = $(eleAnswer).find('.guessing-text').text().trim();
  229. // Get answer true
  230. checkTestingAnswer(token, userAnswer, function (resultData) {
  231. divNextQuestion = resultData['nextQuestion'];
  232. //Check answer
  233. var checkAnswer = 0;
  234. if (userAnswer == resultData['answerTrue']) {
  235. checkAnswer = 1;
  236. }
  237. if (checkAnswer == 1) {
  238. effectAnswerRight();
  239. $(eleAnswer).addClass('choice-true');
  240. answerTextTrue = $(eleAnswer).find('.guessing-text').text().trim();
  241. if ($(eleAnswer).find(".guessing-choice-item").attr('mutilAnswer') != undefined) {
  242. answerText = $(eleAnswer).find(".guessing-choice-item").attr('mutilAnswer');
  243. answerTextTrue = $(eleAnswer).find(".guessing-choice-item").attr('mutilAnswer');
  244. }
  245. } else {
  246. effectAnswerWrong();
  247. $(eleAnswer).addClass('choice-false');
  248. $(divParent).find('.guessing-choice-item[val=' + resultData['answerTrue'] + ']').addClass('choice-true');
  249. var tEle = $(divParent).find('.guessing-choice-item[val=' + resultData['answerTrue'] + ']');
  250. answerTextTrue = $(tEle).find('.guessing-text').text().trim();
  251. if ($(tEle).find(".guessing-choice-item").attr('mutilAnswer') != undefined) {
  252. answerText = $(tEle).find(".guessing-choice-item").attr('mutilAnswer');
  253. answerTextTrue = $(tEle).find(".guessing-choice-item").attr('mutilAnswer');
  254. }
  255. }
  256. $(divParent).find(".guessing-choice-item.choice-true[hideAnswer] .guessing-text").text($(divParent).find(".guessing-choice-item.choice-true[hideAnswer]").attr('hideAnswer'));
  257. nextQuestion(resultData);
  258. });
  259. }
  260. });
  261. $(document).on('click', '.guessing-multi-choice-item', function () {
  262. $(this).toggleClass('choice-item-choose');
  263. var exeQuestion = $(this).parent('.guessing-exe-question');
  264. var check = 0;
  265. $(exeQuestion).children('.guessing-multi-choice-item').each(function () {
  266. if ($(this).hasClass('choice-item-choose')) {
  267. check = 1;
  268. }
  269. });
  270. if (check == 1) {
  271. $(exeQuestion).next('.exe-user-answer').find('.button-multi-check').addClass('button-active');
  272. } else {
  273. $(exeQuestion).next('.exe-user-answer').find('.button-multi-check').removeClass('button-active');
  274. }
  275. });
  276. // CHECH ANSWER ARRANGE
  277. $(document).on('click', '.testing-theory-item .exe-question-button-check.button-active, .button-multi-check.button-active', function () {
  278. $(this).removeClass('button-active');
  279. var button = $(this);
  280. var divParent = $('.testing-theory-item.item-current');
  281. var typeQuestion = $(divParent).attr('typeQuestion');
  282. if (!$(divParent).hasClass('show-answer')) {
  283. // Add class show answer
  284. $(divParent).addClass('show-answer');
  285. stopCountdown();
  286. var token = $(divParent).attr('qToken');
  287. if (typeQuestion == 3) {
  288. var answer = Array();
  289. answerTextTrue = '';
  290. $(divParent).find(".testing-theory-pos-end .pos-end-item").each(function (index, el) {
  291. answer.push($(divParent).find(".testing-theory-pos-begin .word-item.word-item-moved[pos='" + index + "']").text().toLowerCase().trim());
  292. });
  293. userAnswer = answer;
  294. // Get answer true
  295. checkTestingAnswer(token, answer, function (resultData) {
  296. var listGoal = $(divParent).find(".testing-theory-pos-end .pos-end-item");
  297. var listTrue = resultData['answerTrue'];
  298. if (listGoal.length == listTrue.length) {
  299. var checkAnswer = 1;
  300. answerText = "";
  301. listGoal.each(function (index, el) {
  302. if (index == 0) {
  303. answerText += $(divParent).find(".testing-theory-pos-begin .word-item.word-item-moved[pos='" + index + "']").text().toLowerCase().trim();
  304. } else {
  305. answerText += " + " + $(divParent).find(".testing-theory-pos-begin .word-item.word-item-moved[pos='" + index + "']").text().toLowerCase().trim();
  306. }
  307. if ($(divParent).find(".testing-theory-pos-begin .word-item.word-item-moved[pos='" + index + "']").text().toLowerCase().trim() != listTrue[index].toLowerCase().trim()) {
  308. $(divParent).find(".testing-theory-pos-begin .word-item.word-item-moved[pos='" + index + "']").addClass('sort-wrong');
  309. checkAnswer = 0;
  310. } else {
  311. $(divParent).find(".testing-theory-pos-begin .word-item.word-item-moved[pos='" + index + "']").addClass('sort-right');
  312. }
  313. });
  314. // Effect
  315. if (checkAnswer == 1) {
  316. effectAnswerRight();
  317. } else {
  318. effectAnswerWrong();
  319. }
  320. }
  321. nextQuestion(resultData);
  322. });
  323. } else if (typeQuestion == 4) {
  324. var exeQuestion = $(this).closest('.exe-user-answer').prev('.guessing-exe-question');
  325. var answer = "";
  326. $(exeQuestion).children('.guessing-multi-choice-item').each(function (index) {
  327. if ($(exeQuestion).children('.guessing-multi-choice-item[val="' + index + '"]').hasClass('choice-item-choose')) {
  328. answer += "1_";
  329. } else {
  330. answer += "0_";
  331. }
  332. });
  333. answer = answer.slice(0, -1);
  334. userAnswer = answer;
  335. // Get answer true
  336. checkTestingAnswer(token, answer, function (resultData) {
  337. //Check answer
  338. var checkAnswer = 0;
  339. if (userAnswer == resultData['answerTrue']) {
  340. checkAnswer = 1;
  341. }
  342. if (checkAnswer == 1) {
  343. effectAnswerRight();
  344. } else {
  345. effectAnswerWrong();
  346. }
  347. // Get answer
  348. var answerTrue = resultData['answerTrue'].split("_");
  349. var uAnswer = answer.split("_");
  350. for (var i = 0; i < answerTrue.length; i++) {
  351. if (parseInt(uAnswer[i]) === parseInt(answerTrue[i])) {
  352. if (parseInt(answerTrue[i]) == 1) {
  353. $(exeQuestion).children('.guessing-multi-choice-item[val="' + i + '"]').addClass('choice-answer-true');
  354. }
  355. } else {
  356. checkAnswer = 0;
  357. if (parseInt(answerTrue[i]) == 1) {
  358. $(exeQuestion).children('.guessing-multi-choice-item[val="' + i + '"]').addClass('item-answer-true');
  359. } else {
  360. $(exeQuestion).children('.guessing-multi-choice-item[val="' + i + '"]').addClass('choice-answer-false');
  361. }
  362. }
  363. }
  364. nextQuestion(resultData);
  365. });
  366. }
  367. }
  368. });
  369. // **********************************************
  370. //Sort word
  371. function setDragAndDrop(div) {
  372. var posCurrentTop = 0;
  373. var posCurrentLeft = 0;
  374. var checkClickItem = 0;
  375. //Check click and drag
  376. $(div).find(".testing-theory-pos-begin .word-item").draggable({
  377. start: function (event, ui) {
  378. $(this).css({ "transition": "none", "z-index": "2" });
  379. posCurrentTop = $(this).offset().top;
  380. posCurrentLeft = $(this).offset().left;
  381. checkClickItem = 1;
  382. setTimeout(function () {
  383. checkClickItem = 0;
  384. }, 200);
  385. },
  386. stop: function (event, ui) {
  387. $(this).css({ "transition": "all 0.5s ease", "z-index": "unset" });
  388. if ($(this).attr('pos') == undefined) {
  389. $(this).css({ "top": "0px", "left": "0px" });
  390. }
  391. if (Math.pow($(this).offset().left - posCurrentLeft, 2) + Math.pow($(this).offset().top - posCurrentTop, 2) < 400) { //if move < 20px
  392. if (checkClickItem == 1) {
  393. clickWord($(this));
  394. }
  395. }
  396. }
  397. });
  398. var checkDrop = 0;
  399. $(div).find(".testing-theory-pos-end .pos-end-item").droppable({
  400. drop: function (event, ui) {
  401. if ($(this).parents(".testing-theory-item").hasClass("item-current")) {
  402. checkDrop = 1;
  403. var element = ui.draggable;
  404. var divParent = $(element).parents(".testing-theory-item");
  405. var listgoal = divParent.find(".testing-theory-pos-end .pos-end-item");
  406. var listChildMoved = divParent.find(".testing-theory-pos-begin .word-item.word-item-moved");
  407. var pos = $(this).index();
  408. var box = listgoal[pos];
  409. var elementCurrent = divParent.find(".testing-theory-pos-begin .word-item.word-item-moved[pos='" + pos + "']");
  410. if (elementCurrent.length > 0 && !element.is(elementCurrent)) {
  411. var length = $(element).offset().left + $(element).width() / 2 - $(box).offset().left - $(box).width() / 2;
  412. if (length > 0) {
  413. pos++;
  414. box = listgoal[pos];
  415. }
  416. //check element next
  417. for (var i = listgoal.length - 1; i >= pos; i--) {
  418. if (listgoal[i + 1] != undefined && $(listgoal[i]).hasClass('word-div-haschild')) {
  419. var elCu = divParent.find(".testing-theory-pos-begin .word-item.word-item-moved[pos='" + i + "']");
  420. if (!$(listgoal[i + 1]).hasClass('word-div-haschild')) {
  421. $(listgoal[i + 1]).addClass('word-div-haschild');
  422. }
  423. $(listgoal[i]).removeClass('word-div-haschild');
  424. elCu.attr('pos', i + 1);
  425. $(listgoal[i + 1]).find(".word-div").width(elCu.width());
  426. }
  427. };
  428. }
  429. //add element to new box
  430. element.css("transition", "all 0.5s ease");
  431. if (!$(box).hasClass('word-div-haschild')) {
  432. $(box).addClass('word-div-haschild');
  433. }
  434. if (!element.hasClass('word-item-moved')) {
  435. element.addClass('word-item-moved');
  436. }
  437. element.attr("pos", pos);
  438. //edit position element
  439. adjustPositionWord(divParent);
  440. }
  441. },
  442. out: function (event, ui) {
  443. var element = ui.draggable;
  444. var pos = element.attr('pos');
  445. if (pos != undefined) {
  446. element.removeAttr("pos");
  447. element.removeClass('word-item-moved');
  448. var divParent = $(element).parents(".testing-theory-item");
  449. adjustPositionWord(divParent);
  450. }
  451. }
  452. });
  453. $(div).find(".testing-theory-pos-end").droppable({
  454. drop: function (event, ui) {
  455. if ($(this).parents(".testing-theory-item").hasClass("item-current")) {
  456. setTimeout(function () {
  457. if (checkDrop == 1) {
  458. checkDrop = 0;
  459. } else {
  460. var element = ui.draggable;
  461. var divParent = $(element).parents(".testing-theory-item");
  462. var listgoal = divParent.find(".testing-theory-pos-end .pos-end-item");
  463. listgoal.each(function (index) {
  464. if (!$(this).hasClass('word-div-haschild')) {
  465. element.addClass('word-item-moved');
  466. element.attr("pos", index);
  467. return false;
  468. }
  469. });
  470. //edit position element
  471. adjustPositionWord(divParent);
  472. }
  473. }, 50);
  474. }
  475. }
  476. });
  477. }
  478. $(document).on('click', '.testing-theory-pos-begin .pos-begin-item .word-item', function () {
  479. var element = $(this);
  480. clickWord(element);
  481. });
  482. function clickWord(element) {
  483. var divParent = $(element).parents(".testing-theory-item");
  484. var listgoal = divParent.find(".testing-theory-pos-end .pos-end-item");
  485. //Back
  486. if (element.hasClass("word-item-moved")) {
  487. element.removeAttr("pos");
  488. element.removeClass('word-item-moved');
  489. $(element).css({ "top": "0px", "left": "0px" });
  490. var divParent = $(element).parents(".testing-theory-item");
  491. adjustPositionWord(divParent);
  492. // Go
  493. } else {
  494. listgoal.each(function (index) {
  495. if (!$(this).hasClass('word-div-haschild')) {
  496. element.addClass('word-item-moved');
  497. element.attr("pos", index);
  498. return false;
  499. }
  500. });
  501. //edit position element
  502. adjustPositionWord(divParent);
  503. }
  504. }
  505. function adjustPositionWord(divParent) {
  506. var listChildMoved = $(divParent).find(".testing-theory-pos-begin .word-item.word-item-moved");
  507. $(divParent).find(".testing-theory-pos-begin .pos-begin-item .word-item.sort-wrong").removeClass("sort-wrong");
  508. if (listChildMoved.length > 0) {
  509. //edit position of element moved
  510. var listgoal = $(divParent).find(".testing-theory-pos-end .pos-end-item");
  511. $(listgoal).removeClass('word-div-haschild');
  512. for (var i = 0; i < listgoal.length; i++) {
  513. if ($(divParent).find(".testing-theory-pos-begin .word-item.word-item-moved[pos='" + i + "']").length > 0) {
  514. for (var j = 0; j < i; j++) {
  515. if ($(divParent).find(".testing-theory-pos-begin .word-item.word-item-moved[pos='" + j + "']").length <= 0) {
  516. $(divParent).find(".testing-theory-pos-begin .word-item.word-item-moved[pos='" + i + "']").attr('pos', j);
  517. break;
  518. }
  519. }
  520. }
  521. }
  522. // Set width before set top, left
  523. listgoal.each(function (index, el) {
  524. var destination = $(el).find(".word-div");
  525. var current = divParent.find(".testing-theory-pos-begin .word-item.word-item-moved[pos='" + index + "']");
  526. if (current.length > 0) {
  527. $(destination).parent().addClass('word-div-haschild');
  528. $(destination).width($(current).width());
  529. } else {
  530. $(destination).width(0);
  531. }
  532. });
  533. listChildMoved.each(function (index, el) {
  534. var destination = divParent.find(".testing-theory-pos-end .pos-end-item:nth-of-type(" + (parseInt($(el).attr('pos')) + 1) + ") .word-div");
  535. var current = $(el).parent();
  536. var h = destination.offset().top - current.offset().top;
  537. var w = destination.offset().left - current.offset().left;
  538. $(el).css({ "top": h, "left": w });
  539. });
  540. //active button
  541. var button = $(divParent).find(".exe-question-button-check");
  542. if (listgoal.length == listChildMoved.length) {
  543. button.addClass("button-active");
  544. } else {
  545. button.removeClass("button-active");
  546. }
  547. // $(divParent).find(".testing-theory-question .button-reset").addClass('button-active');
  548. } else {
  549. // $(divParent).find(".testing-theory-question .button-reset").removeClass('button-active');
  550. }
  551. }
  552. function checkTestingAnswer(token, answer, getData) {
  553. $.ajaxSetup({
  554. headers: {
  555. 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  556. }
  557. });
  558. var link = $('#answer-link').val();
  559. $.ajax({
  560. url: link,
  561. type: "POST",
  562. data: {
  563. 'token': token,
  564. 'user_answer': answer,
  565. 'time': Math.max(totalTime - second + 1, 1)
  566. },
  567. success: function (data) {
  568. if (data.length == 2) {
  569. if (data[0] == 'true') {
  570. getData(data[1]);
  571. } else if (data[0] == 'false') {
  572. window.location.href = data[1];
  573. }
  574. }
  575. },
  576. error: function (result) {
  577. }
  578. });
  579. }