| 1 |
<?php |
| 2 |
/** |
| 3 |
* Admin Quiz Editor: Question item. |
| 4 |
* |
| 5 |
* @since 3.0.0 |
| 6 |
*/ |
| 7 |
|
| 8 |
learn_press_admin_view( 'quiz/question-actions' ); |
| 9 |
learn_press_admin_view( 'quiz/question-settings' ); |
| 10 |
?> |
| 11 |
|
| 12 |
<script type="text/x-template" id="tmpl-lp-quiz-question-item"> |
| 13 |
<div :class="['question-item',question.type.key, isNew() ? 'empty-question' : '']" :data-item-id="question.id" :data-question-order="index"> |
| 14 |
<lp-quiz-question-actions :question="question" :index="index" @nav="navItem"></lp-quiz-question-actions> |
| 15 |
<lp-quiz-question-settings :question="question" :index="index"></lp-quiz-question-settings> |
| 16 |
</div> |
| 17 |
</script> |
| 18 |
|
| 19 |
<script type="text/javascript"> |
| 20 |
jQuery(function ($) { |
| 21 |
var $Vue = window.$Vue || Vue; |
| 22 |
var $store = window.LP_Quiz_Store; |
| 23 |
|
| 24 |
$Vue.component('lp-quiz-question-item', { |
| 25 |
template: '#tmpl-lp-quiz-question-item', |
| 26 |
props: ['question', 'index'], |
| 27 |
computed: { |
| 28 |
numberQuestions: function () { |
| 29 |
return ($store.getters['lqs/listQuestions']).length; |
| 30 |
} |
| 31 |
}, |
| 32 |
methods: { |
| 33 |
// navigation questions in quiz |
| 34 |
navItem: function (payload) { |
| 35 |
|
| 36 |
var keyCode = payload.key, |
| 37 |
order = payload.order; |
| 38 |
|
| 39 |
if (keyCode === 38 && order !== 0) { |
| 40 |
this.nav(order - 1); |
| 41 |
} |
| 42 |
if ((keyCode === 40 || keyCode === 13) && this.numberQuestions !== order) { |
| 43 |
this.nav(order + 1); |
| 44 |
} |
| 45 |
|
| 46 |
}, |
| 47 |
// focus item |
| 48 |
nav: function (position) { |
| 49 |
var element = 'div[data-question-order=' + position + ']'; |
| 50 |
($(element).find('.name input')).focus(); |
| 51 |
}, |
| 52 |
isNew: function () { |
| 53 |
return isNaN(this.question.id); |
| 54 |
} |
| 55 |
} |
| 56 |
}); |
| 57 |
|
| 58 |
}) |
| 59 |
</script> |
| 60 |
|