PageRenderTime 168ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/learnpress/assets/js/frontend/single-quiz.js

https://gitlab.com/gregtyka/lfmawordpress
JavaScript | 731 lines | 697 code | 24 blank | 10 comment | 124 complexity | 43734d99c09c6cb311df49ce942473fa MD5 | raw file
  1. if (typeof LearnPress == 'undefined') var LearnPress = {};
  2. (function ($) {
  3. "use strict";
  4. var LearnPress_Model_Quiz = window.LearnPress_Model_Quiz = Backbone.Model.extend({
  5. defaults : {
  6. //question_id: 0
  7. },
  8. data : null,
  9. view : false,
  10. url : function () {
  11. },
  12. urlRoot : '',
  13. questions : null,
  14. initialize : function () {
  15. this.createQuestionsList();
  16. },
  17. createQuestionsList: function () {
  18. this.questions = new LearnPress_Collection_Questions();
  19. _.each(this.get('questions'), function (args, i) {
  20. var $model = new LearnPress_Model_Question($.extend({
  21. quiz_id: this.get('id'),
  22. user_id: this.get('user_id'),
  23. }, args));
  24. $model.urlRoot = this.get('ajaxurl');
  25. $model.view = this.view;
  26. this.questions.add($model);
  27. }, this);
  28. },
  29. next : function (callback) {
  30. if (!this.isLast()) {
  31. var next_id = this.findNext(),
  32. question = this.questions.findWhere({id: next_id}),
  33. that = this;
  34. question.submit({
  35. data : {
  36. save_id : that.get('question_id'),
  37. question_answer: this.view.$('form').serialize(),
  38. time_remaining : that.get('time_remaining')
  39. },
  40. complete: function () {
  41. that.set('question_id', next_id);
  42. $.isFunction(callback) && callback.apply(that);
  43. LearnPress.Hook.doAction('learn_press_next_question', next_id, that);
  44. }
  45. });
  46. }
  47. },
  48. prev : function (callback) {
  49. if (!this.isFirst()) {
  50. var prev_id = this.findPrev(),
  51. question = this.questions.findWhere({id: prev_id}),
  52. that = this;
  53. //if (!question.get('content')) {
  54. question.submit({
  55. data : {
  56. save_id : that.get('question_id'),
  57. question_answer: this.view.$('form').serialize(),
  58. time_remaining : that.get('time_remaining')
  59. },
  60. complete: function () {
  61. that.set('question_id', prev_id);
  62. $.isFunction(callback) && callback.apply(that);
  63. LearnPress.Hook.doAction('learn_press_previous_question', prev_id, that);
  64. }
  65. });
  66. }
  67. },
  68. select : function (id, callback) {
  69. var question = this.questions.findWhere({id: id}),
  70. that = this;
  71. question && question.submit({
  72. data : {
  73. save_id : that.get('question_id'),
  74. question_answer: this.view.$('form').serialize(), //$('input, select, textarea', this.view.$('form')).toJSON(),
  75. time_remaining : that.get('time_remaining')
  76. },
  77. complete: function (response) {
  78. that.set('question_id', id);
  79. $.isFunction(callback) && callback.apply(that, [response])
  80. }
  81. });
  82. },
  83. getQuestionPosition: function (question_id) {
  84. question_id = question_id || this.get('question_id');
  85. return _.indexOf(this.getIds(), question_id);
  86. },
  87. countQuestions : function () {
  88. return this.questions.length;
  89. },
  90. isLast : function (question_id) {
  91. question_id = question_id || this.get('question_id');
  92. return this.getQuestionPosition(question_id) == (this.countQuestions() - 1);
  93. },
  94. isFirst : function (question_id) {
  95. question_id = question_id || this.get('question_id');
  96. return this.getQuestionPosition(question_id) == 0;
  97. },
  98. findNext : function (question_id) {
  99. question_id = question_id || this.get('question_id');
  100. var ids = this.getIds(),
  101. pos = this.getQuestionPosition(question_id);
  102. pos++;
  103. if (typeof ids[pos] == 'undefined') return false;
  104. return ids[pos];
  105. },
  106. findPrev : function (question_id) {
  107. question_id = question_id || this.get('question_id');
  108. var ids = this.getIds(),
  109. pos = this.getQuestionPosition(question_id);
  110. pos--;
  111. if (typeof ids[pos] == 'undefined') return false;
  112. return ids[pos];
  113. },
  114. current : function () {
  115. return this.questions.findWhere({id: parseInt(this.get('question_id'))});
  116. },
  117. getIds : function () {
  118. return $.map(this.get('questions'), function (i, v) {
  119. return parseInt(i.id)
  120. });
  121. }
  122. });
  123. var LearnPress_Model_Question = window.LearnPress_Model_Question = Backbone.Model.extend({
  124. defaults : {
  125. //question_id: 0
  126. },
  127. data : null,
  128. view : false,
  129. url : function () {
  130. return this.urlRoot;
  131. },
  132. urlRoot : '',
  133. initialize: function () {
  134. },
  135. element : function () {
  136. return $(this.get('content'));
  137. },
  138. submit : function (args) {
  139. var that = this;
  140. args = $.extend({
  141. complete: null,
  142. data : {}
  143. }, args || {});
  144. this.fetch({
  145. data : $.extend({
  146. action : 'learnpress_load_quiz_question',
  147. user_id : this.get('user_id'),
  148. quiz_id : this.get('quiz_id'),
  149. question_id: this.get('id')
  150. }, args.data || {}),
  151. complete: (function (e) {
  152. var response = LearnPress.parseJSON(e.responseText);
  153. if (response.result == 'success') {
  154. //if (!that.get('content')) {
  155. that.set(response.question);
  156. if (response.permalink) {
  157. LearnPress.setUrl(response.permalink);
  158. }
  159. //}
  160. $.isFunction(args.complete) && args.complete.call(that, response);
  161. }
  162. })
  163. });
  164. },
  165. check : function (args) {
  166. var that = this;
  167. if ($.isFunction(args)) {
  168. args = {
  169. complete: args
  170. }
  171. } else {
  172. args = $.extend({
  173. complete: null,
  174. data : {}
  175. }, args || {});
  176. }
  177. LearnPress.doAjax({
  178. data : $.extend({
  179. 'lp-ajax' : 'check-question',
  180. user_id : this.get('user_id'),
  181. quiz_id : this.get('quiz_id'),
  182. question_id : this.get('id'),
  183. save_id : this.get('id'),
  184. question_answer: $('form#learn-press-quiz-question').serialize()
  185. }, args.data || {}),
  186. success: function (response, raw) {
  187. that.set('checked', response.checked);
  188. $.isFunction(args.complete) && args.complete.call(that, response)
  189. }
  190. })
  191. }
  192. });
  193. var LearnPress_Collection_Questions = window.LearnPress_Collection_Questions = Backbone.Collection.extend({
  194. url : 'admin-ajax.php',
  195. model: LearnPress_Model_Question
  196. });
  197. var LearnPress_View_Quiz = window.LearnPress_View_Quiz = Backbone.View.extend({
  198. model : {},
  199. events : {
  200. 'click .button-start-quiz' : '_startQuiz',
  201. 'click .button-finish-quiz' : '_finishQuiz',
  202. 'click .button-retake-quiz' : '_retakeQuiz',
  203. 'click .next-question' : '_nextQuestion',
  204. 'click .prev-question' : '_prevQuestion',
  205. 'click .check-question' : '_checkQuestion',
  206. 'click .quiz-questions-list li a': '_selectQuestion',
  207. 'click .hint-question' : '_hintQuestion',
  208. 'click .explain-question' : '_explainQuestion'
  209. },
  210. el : '.single-quiz',
  211. isRendered : false,
  212. $buttons : {},
  213. initialize : function (model) {
  214. this.model = model;
  215. this.model.view = this;
  216. this.listenTo(this.model, 'change:question_id', this.changeQuestion);
  217. this.listenTo(this.model, 'change', this.render);
  218. this.listenTo(this.model, 'change', this.updateCountdown);
  219. LearnPress.Hook
  220. .addAction('learn_press_check_question', function (response, that) {
  221. that.updateAnswer.apply(that, [response]);
  222. })
  223. .addAction('learn_press_update_question_content', function ($newQuestion, $oldQuestion, that) {
  224. var $current = that.model.current();
  225. setTimeout(function () {
  226. if ($current.get('checked')) {
  227. that.updateAnswer.apply(that, [{checked: $current.get('checked'), result: 'success'}]);
  228. }
  229. }, 100)
  230. });
  231. _.bindAll(this, 'render', '_timeOver', '_checkQuestion', '_hintQuestion', 'updateAnswer', 'updateCountdown');
  232. this._create();
  233. this.render();
  234. this.updateCountdown(true);
  235. },
  236. _create : function () {
  237. this.$buttons = {
  238. start : this.$('.button-start-quiz'),
  239. finish : this.$('.button-finish-quiz'),
  240. retake : this.$('.button-retake-quiz'),
  241. next : this.$('.next-question'),
  242. prev : this.$('.prev-question'),
  243. check : this.$('.check-question'),
  244. hint : this.$('.hint-question'),
  245. explain: this.$('.explain-question'),
  246. };
  247. if (this.model.get('status') == 'started') {
  248. this.initCountdown();
  249. var $current = this.model.current();
  250. if ($current) {
  251. $current.set({
  252. content: $('#learn-press-quiz-question .question-' + $current.get('id'))
  253. });
  254. this._updateQuestion($current.element());
  255. }
  256. }
  257. var that = this;
  258. this.setButtonsState();
  259. },
  260. changeQuestion : function () {
  261. var $current = this.model.current();
  262. if ($current) {
  263. this._updateQuestion($current.element());
  264. }
  265. },
  266. updateCountdown : function (force) {
  267. if (!this.model.hasChanged('status') && !force) {
  268. return;
  269. }
  270. if (this.model.get('status') == 'started') {
  271. if (!this.$countdown) {
  272. this.initCountdown();
  273. }
  274. this.$countdown.backward_timer('start');
  275. }
  276. },
  277. render : function () {
  278. if (!this.model.hasChanged('question_id') && !this.model.hasChanged('status')) {
  279. //return;
  280. }
  281. var $question = this.model.current();
  282. this.setButtonsState();
  283. switch (this.model.get('status')) {
  284. case 'started':
  285. this.$('.quiz-intro').remove();
  286. this.$('.quiz-countdown').removeClass('hide-if-js');
  287. }
  288. if ($question && this.model.get('status') == 'started') {
  289. this.$('form[name="learn-press-quiz-question"]').html($question.get('content'));
  290. this.$('#learn-press-quiz-questions li[data-id="' + $question.get('id') + '"]')
  291. .addClass('current')
  292. .siblings('.current').removeClass('current');
  293. }
  294. this.isRendered = true;
  295. this.$el.css('visibility', 'visible');
  296. },
  297. setButtonsState : function () {
  298. var hidden = 'hide-if-js',
  299. current = this.model.current();
  300. switch (this.model.get('status').toLowerCase()) {
  301. case 'completed':
  302. this.$buttons.start.addClass(hidden);
  303. this.$buttons.finish.addClass(hidden);
  304. this.$buttons.check.addClass(hidden);
  305. this.$buttons.retake.removeClass(hidden);
  306. break;
  307. case 'started':
  308. this.$buttons.start.addClass(hidden);
  309. this.$buttons.finish.removeClass(hidden);
  310. this.$buttons.retake.addClass(hidden);
  311. if (this.model.countQuestions() <= 1) {
  312. this.$buttons.next.addClass(hidden);
  313. this.$buttons.prev.addClass(hidden);
  314. } else {
  315. this.$buttons.next.removeClass(hidden);
  316. this.$buttons.prev.removeClass(hidden);
  317. if (this.model.isLast()) {
  318. this.$buttons.next.addClass(hidden);
  319. this.$buttons.finish.filter('[data-area="nav"]').removeClass(hidden);
  320. } else {
  321. this.$buttons.finish.filter('[data-area="nav"]').addClass(hidden);
  322. }
  323. if (this.model.isFirst()) {
  324. this.$buttons.prev.addClass(hidden);
  325. }
  326. }
  327. if (current && current.get('check_answer')) {
  328. this.$buttons.check.removeClass(hidden);
  329. } else {
  330. this.$buttons.check.addClass(hidden);
  331. }
  332. if (current && current.get('hint')) {
  333. this.$buttons.hint.removeClass(hidden);
  334. } else {
  335. this.$buttons.hint.addClass(hidden);
  336. }
  337. if (current && current.get('explanation')) {
  338. this.$buttons.explain.removeClass(hidden);
  339. } else {
  340. this.$buttons.explain.addClass(hidden);
  341. }
  342. break;
  343. default:
  344. this.$buttons.next.addClass(hidden);
  345. this.$buttons.prev.addClass(hidden);
  346. this.$buttons.start.removeClass(hidden);
  347. this.$buttons.finish.addClass(hidden);
  348. this.$buttons.retake.addClass(hidden);
  349. this.$('.quiz-questions .qq.current').removeClass('current');
  350. }
  351. },
  352. startQuiz : function (args) {
  353. this.block_page();
  354. args = $.extend({
  355. complete: false
  356. }, args || {});
  357. var that = this,
  358. data = $.extend({
  359. 'lp-ajax': 'start-quiz',
  360. quiz_id : this.model.get('id'),
  361. nonce : this.model.get('nonce')
  362. }, args.data || {});
  363. LearnPress.doAjax({
  364. url : window.location.href,
  365. data : data,
  366. success: function (response, raw) {
  367. LearnPress.MessageBox.hide();
  368. var response = LearnPress.Hook.applyFilters('learn_press_start_quiz_results', response, that);
  369. if (response.result == 'success') {
  370. that.model.current().set(response.question);
  371. that.model.set({status: response.data.status, question_id: response.question.id});
  372. LearnPress.setUrl(response.question.permalink);
  373. }
  374. $.isFunction(args.complete) && args.complete.call(that, response)
  375. }
  376. });
  377. },
  378. finishQuiz : function (args) {
  379. this.pause();
  380. this.block_page();
  381. args = $.extend({
  382. complete: false
  383. }, args || {});
  384. var that = this,
  385. data = $.extend({
  386. 'lp-ajax': 'finish-quiz',
  387. quiz_id : this.model.get('id'),
  388. nonce : this.model.get('nonce')
  389. }, args.data || {});
  390. LearnPress.doAjax({
  391. data : data,
  392. success: function (response) {
  393. var callbackReturn = undefined;
  394. $.isFunction(args.complete) && ( callbackReturn = args.complete.call(LearnPress.Quiz, response) );
  395. LearnPress.Hook.doAction('learn_press_finish_quiz', that.model.get('id'), that);
  396. LearnPress.MessageBox.show(single_quiz_localize.finished_quiz, {
  397. autohide: 2000,
  398. onHide : function () {
  399. if (callbackReturn && callbackReturn.redirect) {
  400. LearnPress.reload(callbackReturn.redirect);
  401. } else if (callbackReturn == undefined && response.redirect) {
  402. LearnPress.reload(response.redirect);
  403. }
  404. }
  405. });
  406. }
  407. });
  408. },
  409. retakeQuiz : function (args) {
  410. this.block_page();
  411. args = $.extend({
  412. complete: false
  413. }, args || {});
  414. var that = this,
  415. data = $.extend({
  416. 'lp-ajax': 'retake-quiz',
  417. quiz_id : this.model.get('id'),
  418. nonce : this.model.get('nonce')
  419. }, args.data || {});
  420. LearnPress.doAjax({
  421. data : data,
  422. success: function (response, raw) {
  423. LearnPress.MessageBox.hide();
  424. if (response.result == 'success') {
  425. $.isFunction(args.complete) && args.complete.call(LearnPress.Quiz, response);
  426. LearnPress.MessageBox.show(single_quiz_localize.retaken_quiz, {
  427. autohide: 2000,
  428. onHide : function () {
  429. LearnPress.reload(response.redirect);
  430. }
  431. });
  432. } else {
  433. LearnPress.alert(response.message);
  434. }
  435. }
  436. });
  437. },
  438. updateAnswer : function (response) {
  439. if (!response || response.result != 'success') {
  440. return;
  441. }
  442. var $current = this.model.current(),
  443. $content = $($current.get('content'));
  444. switch ($current.get('type')) {
  445. case 'true_or_false':
  446. case 'single_choice':
  447. case 'multi_choice':
  448. $.each(response.checked, function (k, v) {
  449. var $input = $content.find('input[value="' + v.value + '"]'),
  450. $li = $input.closest('li').removeClass('answer-true user-answer-false');
  451. if (v.is_true == 'yes') {
  452. $li.addClass('answer-true')
  453. }
  454. if (response.answered) {
  455. if (typeof response.answered == 'string') {
  456. if (response.answered == v.value) {
  457. $input.prop('checked', true);
  458. }
  459. } else if ($.inArray(v.value, response.answered) != -1) {
  460. $input.prop('checked', true);
  461. }
  462. }
  463. if ($input.is(':checked') && v.is_true == 'yes') {
  464. } else {
  465. $li.addClass('user-answer-false');
  466. }
  467. });
  468. $content.addClass('checked').find('input, select, textarea').prop('disabled', true);
  469. $current.set({
  470. content: $content
  471. });
  472. }
  473. //LearnPress.Hook.doAction('learn_press_check_question', response, $current);
  474. this.render();
  475. },
  476. _checkQuestion : function () {
  477. if (LearnPress.Hook.applyFilters('learn_press_before_check_question', true, this) !== false) {
  478. var that = this;
  479. this.$buttons.next.prop('disabled', true);
  480. this.$buttons.prev.prop('disabled', true);
  481. this.$buttons.finish.prop('disabled', true);
  482. this.$buttons.check.prop('disabled', true);
  483. this.pause();
  484. this.block_page();
  485. this.model.current().check({
  486. complete: function (response) {
  487. that.$buttons.next.prop('disabled', false);
  488. that.$buttons.prev.prop('disabled', false);
  489. that.$buttons.finish.prop('disabled', false);
  490. that.$buttons.check.prop('disabled', false);
  491. LearnPress.Hook.doAction('learn_press_check_question', response, that);
  492. that.resume();
  493. },
  494. data : {nonce: this.model.get('nonce')}
  495. });
  496. }
  497. },
  498. _hintQuestion : function (e) {
  499. e.preventDefault();
  500. var current = this.model.current();
  501. if (current && current.get('hint')) {
  502. $('#learn-press-question-hint-' + current.get('id')).toggleClass('hide-if-js')
  503. }
  504. },
  505. _explainQuestion: function (e) {
  506. e.preventDefault();
  507. var current = this.model.current();
  508. if (current && current.get('explanation')) {
  509. $('#learn-press-question-explanation-' + current.get('id')).toggleClass('hide-if-js')
  510. }
  511. },
  512. _nextQuestion : function () {
  513. if (LearnPress.Hook.applyFilters('learn_press_before_next_question', true, this) !== false) {
  514. var that = this;
  515. this.$buttons.next.prop('disabled', true);
  516. this.$buttons.prev.prop('disabled', true);
  517. this.$buttons.finish.prop('disabled', true);
  518. this.pause();
  519. this.block_page();
  520. this.model.next(function () {
  521. that.$buttons.next.prop('disabled', false);
  522. that.$buttons.prev.prop('disabled', false);
  523. that.$buttons.finish.prop('disabled', false);
  524. });
  525. }
  526. },
  527. _prevQuestion : function () {
  528. if (LearnPress.Hook.applyFilters('learn_press_before_prev_question', true, this) !== false) {
  529. var that = this;
  530. this.$buttons.next.prop('disabled', true);
  531. this.$buttons.prev.prop('disabled', true);
  532. this.$buttons.finish.prop('disabled', true);
  533. this.pause();
  534. this.block_page();
  535. this.model.prev(function () {
  536. that.$buttons.next.prop('disabled', false);
  537. that.$buttons.prev.prop('disabled', false);
  538. that.$buttons.finish.prop('disabled', false);
  539. });
  540. }
  541. },
  542. _selectQuestion : function (e) {
  543. e.preventDefault();
  544. var that = this,
  545. id = $(e.target).closest('.learn-press-question-wrap').data('id');
  546. if (this.model.get('status') != 'started') {
  547. return false;
  548. }
  549. if (LearnPress.Hook.applyFilters('learn_press_before_select_question', true, that) !== false) {
  550. this.pause();
  551. this.$buttons.next.prop('disabled', true);
  552. this.$buttons.prev.prop('disabled', true);
  553. this.$buttons.finish.prop('disabled', true);
  554. this.pause();
  555. this.model.select(id, function (response) {
  556. LearnPress.Hook.doAction('learn_press_selected_question', id, that);
  557. that.$buttons.next.prop('disabled', false);
  558. that.$buttons.prev.prop('disabled', false);
  559. that.$buttons.finish.prop('disabled', false);
  560. });
  561. }
  562. },
  563. _getNonce : function (field) {
  564. return this.$('input#' + field + '-nonce').val();
  565. },
  566. _startQuiz : function () {
  567. var that = this;
  568. if (LearnPress.Hook.applyFilters('learn_press_before_start_quiz', true, that) !== false) {
  569. that.$buttons.next.prop('disabled', true);
  570. that.$buttons.prev.prop('disabled', true);
  571. that.$buttons.finish.prop('disabled', true);
  572. LearnPress.MessageBox.blockUI();
  573. that.startQuiz({
  574. complete: function (response) {
  575. LearnPress.MessageBox.hide();
  576. if (response.message) {
  577. LearnPress.alert(response.message, function () {
  578. if (response.redirect) {
  579. LearnPress.reload(response.redirect)
  580. }
  581. });
  582. } else {
  583. if (response.redirect) {
  584. LearnPress.reload(response.redirect)
  585. }
  586. }
  587. that.$buttons.next.prop('disabled', false);
  588. that.$buttons.prev.prop('disabled', false);
  589. that.$buttons.finish.prop('disabled', false);
  590. LearnPress.Hook.doAction('learn_press_start_quiz', response, that);
  591. }
  592. });
  593. }
  594. },
  595. _retakeQuiz : function () {
  596. var that = this;
  597. if (LearnPress.Hook.applyFilters('learn_press_before_retake_quiz', true, that) !== false) {
  598. LearnPress.confirm(single_quiz_localize.confirm_retake_quiz, function (confirm) {
  599. if (!confirm) {
  600. return;
  601. }
  602. that.$buttons.retake.prop('disabled', true);
  603. LearnPress.MessageBox.blockUI();
  604. that.retakeQuiz({
  605. complete: function (response) {
  606. LearnPress.MessageBox.hide();
  607. LearnPress.Hook.doAction('learn_press_user_retaken_quiz', response, that);
  608. }
  609. });
  610. })
  611. }
  612. },
  613. _finishQuiz : function () {
  614. var that = this;
  615. if (LearnPress.Hook.applyFilters('learn_press_before_finish_quiz', true, that) !== false) {
  616. LearnPress.confirm(single_quiz_localize.confirm_finish_quiz, function (confirm) {
  617. if (!confirm) {
  618. return;
  619. }
  620. that.$buttons.next.prop('disabled', true);
  621. that.$buttons.prev.prop('disabled', true);
  622. that.$buttons.finish.prop('disabled', true);
  623. LearnPress.MessageBox.blockUI();
  624. that.finishQuiz({
  625. data : {
  626. save_id : that.model.get('question_id'),
  627. question_answer: that.$('form').serialize(),
  628. time_remaining : that.model.get('time_remaining')
  629. },
  630. complete: function (response) {
  631. LearnPress.MessageBox.hide();
  632. LearnPress.Hook.doAction('learn_press_user_finished_quiz', response, that);
  633. }
  634. });
  635. });
  636. }
  637. },
  638. _updateQuestion : function ($newQuestion) {
  639. var $container = this.$('.quiz-question-content form'),
  640. $oldQuestion = $container.find('.learn-press-question-wrap');
  641. if ($oldQuestion.length) {
  642. $oldQuestion.replaceWith($newQuestion);
  643. } else {
  644. $container.append($newQuestion);
  645. }
  646. LearnPress.Hook.doAction('learn_press_update_question_content', $newQuestion, $oldQuestion, this);
  647. LearnPress.setUrl($newQuestion.find('input[name="learn-press-question-permalink"]').val());
  648. },
  649. initCountdown : function () {
  650. var that = this,
  651. $countdown = this.$countdown;
  652. if (!$countdown) {
  653. this.$countdown = $("#quiz-countdown-value");
  654. this.$countdown.backward_timer({
  655. seconds : parseInt(this.model.get('time_remaining')),
  656. format : that.model.get('time_format'),
  657. on_exhausted: function (timer) {
  658. that._timeOver(timer)
  659. },
  660. on_tick : function (timer) {
  661. var color = (timer.seconds_left <= 5) ? "#F00" : "";
  662. if (color) timer.target.css('color', color);
  663. //that.model.set('time_remaining', timer.seconds_left);
  664. }
  665. });
  666. }
  667. },
  668. pause : function () {
  669. this.$countdown.backward_timer('cancel');
  670. },
  671. resume : function () {
  672. this.$countdown.backward_timer('start');
  673. },
  674. loadPage : function (url) {
  675. url = url || window.location.href;
  676. window.location.href = url;
  677. },
  678. _timeOver : function (timer) {
  679. timer.target.css('color', '#F00');
  680. LearnPress.MessageBox.blockUI(single_quiz_localize.quiz_time_is_over_message);
  681. this.finishQuiz({
  682. complete: function (response) {
  683. LearnPress.MessageBox.hide();
  684. if (response.redirect) {
  685. LearnPress.reload(response.redirect);
  686. }
  687. }
  688. });
  689. },
  690. block_page : function () {
  691. //this.$el.block_ui();
  692. },
  693. unblock_page : function () {
  694. //this.$el.unblock_ui();
  695. }
  696. });
  697. LearnPress.Quiz = {
  698. init: function (data) {
  699. var model = new LearnPress_Model_Quiz(data);
  700. new LearnPress_View_Quiz(model);
  701. }
  702. }
  703. $(document).ready(function () {
  704. var json = JSON.stringify(single_quiz_params);
  705. LearnPress.Quiz.init(single_quiz_params);
  706. })
  707. })(jQuery);