PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 1.4.0
Tutor LMS – eLearning and online course solution v1.4.0
4.0.1 4.0.0 3.9.15 3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.11 1.2.12 1.2.13 1.2.20 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.15 1.9.16 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.4.0 2.5.0 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.1.0 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / assets / js / tutor.js
tutor / assets / js Last commit date
Chart.bundle.min.js 6 years ago gutenberg_blocks.js 6 years ago mce-button.js 6 years ago tutor-admin.js 6 years ago tutor-front.js 6 years ago tutor.js 6 years ago
tutor.js
1086 lines
1 jQuery(document).ready(function($){
2 'use strict';
3
4 /**
5 * Slider bar
6 */
7 function tutor_slider_init(){
8 $('.tutor-field-slider').each(function(){
9 var $slider = $(this);
10 var $input = $slider.closest('.tutor-field-type-slider').find('input[type="hidden"]');
11 var $showVal = $slider.closest('.tutor-field-type-slider').find('.tutor-field-type-slider-value');
12 var min = parseFloat($slider.closest('.tutor-field-type-slider').attr('data-min'));
13 var max = parseFloat($slider.closest('.tutor-field-type-slider').attr('data-max'));
14
15 $slider.slider({
16 range: "max",
17 min: min,
18 max: max,
19 value: $input.val(),
20 slide: function( event, ui ) {
21 $showVal.text(ui.value);
22 $input.val(ui.value);
23 }
24 });
25 });
26 }
27 tutor_slider_init();
28
29
30 /**
31 * Video source tabs
32 */
33
34 if (jQuery().select2){
35 $('.videosource_select2').select2({
36 width: "100%",
37 templateSelection: iformat,
38 templateResult: iformat,
39 allowHtml: true
40 });
41 }
42 //videosource_select2
43
44 function iformat(icon) {
45 var originalOption = icon.element;
46 return $('<span><i class="tutor-icon-' + $(originalOption).data('icon') + '"></i> ' + icon.text + '</span>');
47 }
48
49 $(document).on('change', '.tutor_lesson_video_source', function(e){
50 var $that = $(this);
51 var selector = $(this).val();
52
53 if (selector){
54 $('.video-metabox-source-input-wrap').show();
55 }else{
56 $('.video-metabox-source-input-wrap').hide();
57 }
58 $that.closest('.tutor-option-field').find('.video-metabox-source-item').hide();
59 $that.closest('.tutor-option-field').find('.video_source_wrap_'+selector).show();
60 });
61
62 /**
63 * Course Builder
64 *
65 * @since v.1.3.4
66 */
67
68 $(document).on( 'click', '.tutor-course-thumbnail-upload-btn', function( event ){
69 event.preventDefault();
70 var $that = $(this);
71 var frame;
72 if ( frame ) {
73 frame.open();
74 return;
75 }
76 frame = wp.media({
77 title: 'Select or Upload Media Of Your Chosen Persuasion',
78 button: {
79 text: 'Use this media'
80 },
81 multiple: false
82 });
83 frame.on( 'select', function() {
84 var attachment = frame.state().get('selection').first().toJSON();
85 $that.closest('.tutor-thumbnail-wrap').find('.thumbnail-img').attr('src', attachment.url);
86 $that.closest('.tutor-thumbnail-wrap').find('input').val(attachment.id);
87 $('.tutor-course-thumbnail-delete-btn').show();
88 });
89 frame.open();
90 });
91
92 //Delete Thumbnail
93 $(document).on( 'click', '.tutor-course-thumbnail-delete-btn', function( event ){
94 event.preventDefault();
95 var $that = $(this);
96
97 var placeholder_src = $that.closest('.tutor-thumbnail-wrap').find('.thumbnail-img').attr('data-placeholder-src');
98 $that.closest('.tutor-thumbnail-wrap').find('.thumbnail-img').attr('src', placeholder_src);
99 $that.closest('.tutor-thumbnail-wrap').find('input').val('');
100 $('.tutor-course-thumbnail-delete-btn').hide();
101 });
102
103 /**
104 * Quiz Builder
105 */
106
107 $(document).on('click', '.create_new_topic_btn', function (e) {
108 e.preventDefault();
109 $('.tutor-metabox-add-topics').slideToggle();
110 });
111
112 $(document).on('click', '#tutor-add-topic-btn', function (e) {
113 e.preventDefault();
114 var $that = $(this);
115 var form_data = $that.closest('.tutor-metabox-add-topics').find('input, textarea').serialize()+'&action=tutor_add_course_topic';
116
117 $.ajax({
118 url : ajaxurl,
119 type : 'POST',
120 data : form_data,
121 beforeSend: function () {
122 $that.addClass('tutor-updating-message');
123 },
124 success: function (data) {
125 if (data.success){
126 $('#tutor-course-content-wrap').html(data.data.course_contents);
127 $that.closest('.tutor-metabox-add-topics').find('input[type!="hidden"], textarea').each(function () {
128 $(this).val('');
129 });
130 $that.closest('.tutor-metabox-add-topics').slideUp();
131 enable_sorting_topic_lesson();
132 }
133 },
134 complete: function () {
135 $that.removeClass('tutor-updating-message');
136 }
137 });
138 });
139
140 $(document).on('change keyup', '.course-edit-topic-title-input', function (e) {
141 e.preventDefault();
142 $(this).closest('.tutor-topics-top').find('.topic-inner-title').html($(this).val());
143 });
144
145 $(document).on('click', '.topic-edit-icon', function (e) {
146 e.preventDefault();
147 $(this).closest('.tutor-topics-top').find('.tutor-topics-edit-form').slideToggle();
148 });
149
150 $(document).on('click', '.tutor-topics-edit-button', function(e){
151 e.preventDefault();
152 var $button = $(this);
153 var $topic = $button.closest('.tutor-topics-wrap');
154 var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10);
155 var topic_title = $button.closest('.tutor-topics-wrap').find('[name="topic_title"]').val();
156 var topic_summery = $button.closest('.tutor-topics-wrap').find('[name="topic_summery"]').val();
157
158 var data = {topic_title: topic_title, topic_summery : topic_summery, topic_id : topics_id, action: 'tutor_update_topic'};
159 $.ajax({
160 url : ajaxurl,
161 type : 'POST',
162 data : data,
163 beforeSend: function () {
164 $button.addClass('tutor-updating-message');
165 },
166 success: function (data) {
167 if (data.success){
168 $button.closest('.tutor-topics-wrap').find('span.topic-inner-title').text(topic_title);
169 $button.closest('.tutor-topics-wrap').find('.tutor-topics-edit-form').slideUp();
170 }
171 },
172 complete: function () {
173 $button.removeClass('tutor-updating-message');
174 }
175 });
176 });
177
178 /**
179 * Update Lesson Modal
180 */
181 $(document).on('click', '.open-tutor-lesson-modal', function(e){
182 e.preventDefault();
183
184 var $that = $(this);
185 var lesson_id = $that.attr('data-lesson-id');
186 var topic_id = $that.attr('data-topic-id');
187 var course_id = $('#post_ID').val();
188
189 $.ajax({
190 url : ajaxurl,
191 type : 'POST',
192 data : {lesson_id : lesson_id, topic_id : topic_id, course_id : course_id, action: 'tutor_load_edit_lesson_modal'},
193 beforeSend: function () {
194 $that.addClass('tutor-updating-message');
195 },
196 success: function (data) {
197 $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output);
198 $('.tutor-lesson-modal-wrap').attr({'data-lesson-id' : lesson_id, 'data-topic-id':topic_id}).addClass('show');
199
200 var tinymceConfig = tinyMCEPreInit.mceInit.tutor_editor_config;
201 if ( ! tinymceConfig){
202 tinymceConfig = tinyMCEPreInit.mceInit.course_description;
203 }
204 tinymce.init(tinymceConfig);
205 tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_lesson_modal_editor' );
206 tinyMCE.execCommand('mceAddEditor', false, "tutor_lesson_modal_editor");
207 },
208 complete: function () {
209 quicktags({id : "tutor_lesson_modal_editor"});
210 $that.removeClass('tutor-updating-message');
211 }
212 });
213 });
214
215 /**
216 * Lesson upload thumbnail
217 */
218 $(document).on( 'click', '.lesson_thumbnail_upload_btn', function( event ){
219 event.preventDefault();
220 var $that = $(this);
221 var frame;
222 if ( frame ) {
223 frame.open();
224 return;
225 }
226 frame = wp.media({
227 title: 'Select or Upload Media Of Your Chosen Persuasion',
228 button: {
229 text: 'Use this media'
230 },
231 multiple: false
232 });
233 frame.on( 'select', function() {
234 var attachment = frame.state().get('selection').first().toJSON();
235 $that.closest('.tutor-thumbnail-wrap').find('.thumbnail-img').html('<img src="'+attachment.url+'" alt="" />');
236 $that.closest('.tutor-thumbnail-wrap').find('input').val(attachment.id);
237 });
238 frame.open();
239 });
240
241 /**
242 * Delete Lesson from course builder
243 */
244 $(document).on('click', '.tutor-delete-lesson-btn', function(e){
245 e.preventDefault();
246
247 if( ! confirm('Are you sure?')){
248 return;
249 }
250
251 var $that = $(this);
252 var lesson_id = $that.attr('data-lesson-id');
253
254 $.ajax({
255 url : ajaxurl,
256 type : 'POST',
257 data : {lesson_id : lesson_id, action: 'tutor_delete_lesson_by_id'},
258 beforeSend: function () {
259 $that.addClass('tutor-updating-message');
260 },
261 success: function (data) {
262 if (data.success){
263 $that.closest('.course-content-item').remove();
264 }
265 },
266 complete: function () {
267 $that.removeClass('tutor-updating-message');
268 }
269 });
270 });
271
272 /**
273 * Confirmation for deleting Topic
274 */
275 $(document).on('click', '.topic-delete-btn a', function(e){
276 var topic_id = $(this).attr('data-topic-id');
277
278 if ( ! confirm('Are you sure to delete?')){
279 e.preventDefault();
280 }
281 });
282
283 $(document).on('click', '.tutor-expand-all-topic', function (e) {
284 e.preventDefault();
285 $('.tutor-topics-body').slideDown();
286 $('.expand-collapse-wrap i').removeClass('tutor-icon-light-down').addClass('tutor-icon-light-up');
287 });
288 $(document).on('click', '.tutor-collapse-all-topic', function (e) {
289 e.preventDefault();
290 $('.tutor-topics-body').slideUp();
291 $('.expand-collapse-wrap i').removeClass('tutor-icon-light-up').addClass('tutor-icon-light-down');
292 });
293 $(document).on('click', '.topic-inner-title, .expand-collapse-wrap', function (e) {
294 e.preventDefault();
295 var $that = $(this);
296 $that.closest('.tutor-topics-wrap').find('.tutor-topics-body').slideToggle();
297 $that.closest('.tutor-topics-wrap').find('.expand-collapse-wrap i').toggleClass('tutor-icon-light-down tutor-icon-light-up');
298 });
299
300 /**
301 * Create new quiz
302 */
303
304 $(document).on('click', '.quiz-modal-btn-first-step', function(e){
305 e.preventDefault();
306
307 var $that = $(this);
308 var $quizTitle = $('[name="quiz_title"]');
309 var quiz_title = $quizTitle.val();
310 var quiz_description = $('[name="quiz_description"]').val();
311
312 if ( ! quiz_title){
313 $quizTitle.closest('.tutor-quiz-builder-group').find('.quiz_form_msg').html('Please enter quiz title');
314 return;
315 }else{
316 $quizTitle.closest('.tutor-quiz-builder-group').find('.quiz_form_msg').html('');
317 }
318
319 var course_id = $('#post_ID').val();
320 var topic_id = $that.closest('.tutor-modal-wrap').attr('quiz-for-post-id');
321
322 if ($('#tutor_quiz_builder_quiz_id').length) {
323 /**
324 *
325 * @type {jQuery}
326 *
327 * if quiz id exists, we are sending it to update quiz
328 */
329
330 var quiz_id = $('#tutor_quiz_builder_quiz_id').val();
331 $.ajax({
332 url : ajaxurl,
333 type : 'POST',
334 data : {quiz_title:quiz_title, quiz_description: quiz_description, quiz_id : quiz_id, topic_id : topic_id, action: 'tutor_quiz_builder_quiz_update'},
335 beforeSend: function () {
336 $that.addClass('tutor-updating-message');
337 },
338 success: function (data) {
339 $('#tutor-quiz-'+quiz_id).html(data.data.output_quiz_row);
340 $('#tutor-quiz-modal-tab-items-wrap a[href="#quiz-builder-tab-questions"]').trigger('click');
341
342 tutor_slider_init();
343 },
344 complete: function () {
345 $that.removeClass('tutor-updating-message');
346 }
347 });
348
349 return;
350 }
351
352 $.ajax({
353 url : ajaxurl,
354 type : 'POST',
355 data : {quiz_title:quiz_title, quiz_description: quiz_description, course_id : course_id, topic_id : topic_id, action: 'tutor_create_quiz_and_load_modal'},
356 beforeSend: function () {
357 $that.addClass('tutor-updating-message');
358 },
359 success: function (data) {
360 $('.tutor-quiz-builder-modal-wrap .modal-container').html(data.data.output);
361 $('#tutor-topics-'+topic_id+' .tutor-lessons').append(data.data.output_quiz_row);
362 $('#tutor-quiz-modal-tab-items-wrap a[href="#quiz-builder-tab-questions"]').trigger('click');
363
364 tutor_slider_init();
365 },
366 complete: function () {
367 $that.removeClass('tutor-updating-message');
368 }
369 });
370
371 });
372
373
374 /**
375 * Ope modal for edit quiz
376 */
377 $(document).on('click', '.open-tutor-quiz-modal', function(e){
378 e.preventDefault();
379
380 var $that = $(this);
381 var quiz_id = $that.attr('data-quiz-id');
382 var topic_id = $that.attr('data-topic-id');
383 var course_id = $('#post_ID').val();
384
385 $.ajax({
386 url : ajaxurl,
387 type : 'POST',
388 data : {quiz_id : quiz_id, topic_id : topic_id, course_id : course_id, action: 'tutor_load_edit_quiz_modal'},
389 beforeSend: function () {
390 $that.addClass('tutor-updating-message');
391 },
392 success: function (data) {
393 $('.tutor-quiz-builder-modal-wrap .modal-container').html(data.data.output);
394 $('.tutor-quiz-builder-modal-wrap').attr('data-quiz-id', quiz_id).addClass('show');
395
396 //Back to question Tab if exists
397 if ($that.attr('data-back-to-tab')){
398 var tabSelector = $that.attr('data-back-to-tab');
399 $('#tutor-quiz-modal-tab-items-wrap a[href="'+tabSelector+'"]').trigger('click');
400 }
401 tutor_slider_init();
402 enable_quiz_questions_sorting();
403 },
404 complete: function () {
405 $that.removeClass('tutor-updating-message');
406 }
407 });
408 });
409
410 $(document).on('click', '.quiz-modal-settings-save-btn', function(e){
411 e.preventDefault();
412
413 var $that = $(this);
414 var quiz_id = $('.tutor-quiz-builder-modal-wrap').attr('data-quiz-id');
415
416 var $formInput = $('#quiz-builder-tab-settings :input, #quiz-builder-tab-advanced-options :input').serialize()+'&quiz_id='+quiz_id+'&action=tutor_quiz_modal_update_settings';
417
418 $.ajax({
419 url : ajaxurl,
420 type : 'POST',
421 data : $formInput,
422 beforeSend: function () {
423 $that.addClass('tutor-updating-message');
424 },
425 success: function (data) {
426 //
427 },
428 complete: function () {
429 $that.removeClass('tutor-updating-message');
430 if ($that.attr('data-action') === 'modal_close'){
431 $('.tutor-modal-wrap').removeClass('show');
432 }
433 }
434 });
435 });
436
437
438 /**
439 * Quiz Question edit save and continue
440 */
441 $(document).on('click', '.quiz-modal-question-save-btn', function(e){
442 e.preventDefault();
443
444 var $that = $(this);
445 var $formInput = $('.quiz_question_form :input').serialize()+'&action=tutor_quiz_modal_update_question';
446 $.ajax({
447 url : ajaxurl,
448 type : 'POST',
449 data : $formInput,
450 beforeSend: function () {
451 $that.addClass('tutor-updating-message');
452 },
453 success: function (data) {
454 if (data.success){
455 //ReOpen questions
456 $that.closest('.tutor-quiz-builder-modal-contents').find('.open-tutor-quiz-modal').trigger('click');
457 }else{
458 if (typeof data.data !== 'undefined') {
459 $('#quiz_validation_msg_wrap').html(data.data.validation_msg);
460 }
461 }
462 },
463 complete: function () {
464 $that.removeClass('tutor-updating-message');
465 }
466 });
467 });
468
469 /**
470 * Sort quiz questions
471 */
472 function enable_quiz_questions_sorting(){
473 if (jQuery().sortable) {
474 $(".quiz-builder-questions-wrap").sortable({
475 handle: ".question-sorting",
476 start: function (e, ui) {
477 ui.placeholder.css('visibility', 'visible');
478 },
479 stop: function (e, ui) {
480 tutor_save_sorting_quiz_questions_order();
481 },
482 });
483 }
484 }
485
486 function tutor_save_sorting_quiz_questions_order(){
487 var questions = {};
488 $('.quiz-builder-question-wrap').each(function(index, item){
489 var $question = $(this);
490 var question_id = parseInt($question.attr('data-question-id'), 10);
491 questions[index] = question_id;
492 });
493
494 $.ajax({url : ajaxurl, type : 'POST',
495 data : {sorted_question_ids : questions, action: 'tutor_quiz_question_sorting'},
496 });
497 }
498
499 /**
500 * Quiz Modal
501 */
502
503 $(document).on('click', '.modal-close-btn', function(e){
504 e.preventDefault();
505 $('.tutor-modal-wrap').removeClass('show');
506 });
507 $(document).on('keyup', function(e){
508 if (e.keyCode === 27){
509 $('.tutor-modal-wrap').removeClass('show');
510 }
511 });
512
513 $(document).on('click', '.tutor-add-quiz-btn', function(e){
514 e.preventDefault();
515
516 var $that = $(this);
517 var quiz_for_post_id = $(this).closest('.tutor_add_quiz_wrap').attr('data-add-quiz-under');
518 $.ajax({
519 url : ajaxurl,
520 type : 'POST',
521 data : {quiz_for_post_id : quiz_for_post_id, action: 'tutor_load_quiz_builder_modal'},
522 beforeSend: function () {
523 $that.addClass('tutor-updating-message');
524 },
525 success: function (data) {
526 $('.tutor-quiz-builder-modal-wrap .modal-container').html(data.data.output);
527 $('.tutor-quiz-builder-modal-wrap').attr('quiz-for-post-id', quiz_for_post_id).addClass('show');
528 },
529 complete: function () {
530 $that.removeClass('tutor-updating-message');
531 }
532 });
533 });
534
535
536 /**
537 * Quiz Builder Modal Tabs
538 */
539 $(document).on('click', '.tutor-quiz-modal-tab-item', function(e){
540 e.preventDefault();
541
542 var $that = $(this);
543
544 var $quizTitle = $('[name="quiz_title"]');
545 var quiz_title = $quizTitle.val();
546 if ( ! quiz_title){
547 $quizTitle.closest('.tutor-quiz-builder-form-row').find('.quiz_form_msg').html('<p class="quiz-form-warning">Please save the quiz' +
548 ' first</p>');
549 return;
550 }else{
551 $quizTitle.closest('.tutor-quiz-builder-form-row').find('.quiz_form_msg').html('');
552 }
553
554 var tabSelector = $that.attr('href');
555 $('.quiz-builder-tab-container').hide();
556 $(tabSelector).show();
557
558 $('a.tutor-quiz-modal-tab-item').removeClass('active');
559 $that.addClass('active');
560 });
561
562 //Next Prev Tab
563 $(document).on('click', '.quiz-modal-btn-next, .quiz-modal-btn-back', function(e){
564 e.preventDefault();
565
566 var tabSelector = $(this).attr('href');
567 $('#tutor-quiz-modal-tab-items-wrap a[href="'+tabSelector+'"]').trigger('click');
568 });
569
570 $(document).on('click', '.quiz-modal-tab-navigation-btn.quiz-modal-btn-cancel', function(e){
571 e.preventDefault();
572 $('.tutor-modal-wrap').removeClass('show');
573 });
574
575 /**
576 * Add Question to quiz modal
577 */
578 $(document).on('click', '.tutor-quiz-open-question-form', function(e){
579 e.preventDefault();
580
581 var $that = $(this);
582
583 var quiz_id = $('#tutor_quiz_builder_quiz_id').val();
584 var course_id = $('#post_ID').val();
585 var question_id = $that.attr('data-question-id');
586
587
588 var params = {quiz_id : quiz_id, course_id : course_id, action: 'tutor_quiz_builder_get_question_form'};
589
590 if (question_id) {
591 params.question_id = question_id;
592 }
593
594 $.ajax({
595 url : ajaxurl,
596 type : 'POST',
597 data : params,
598 beforeSend: function () {
599 $that.addClass('tutor-updating-message');
600 },
601 success: function (data) {
602 $('.tutor-quiz-builder-modal-contents').html(data.data.output);
603
604 //Initializing Tutor Select
605 tutor_select().reInit();
606 enable_quiz_answer_sorting();
607 },
608 complete: function () {
609 $that.removeClass('tutor-updating-message');
610 }
611 });
612
613 });
614
615 $(document).on('click', '.tutor-quiz-question-trash', function(e){
616 e.preventDefault();
617
618 var $that = $(this);
619 var question_id = $that.attr('data-question-id');
620
621 $.ajax({
622 url : ajaxurl,
623 type : 'POST',
624 data : {question_id : question_id, action: 'tutor_quiz_builder_question_delete'},
625 beforeSend: function () {
626 $that.closest('.quiz-builder-question-wrap').remove();
627 },
628 });
629 });
630
631 /**
632 * Get question answers option form to save multiple/single/true-false options
633 *
634 * @since v.1.0.0
635 */
636
637 $(document).on('click', '.add_question_answers_option', function(e){
638 e.preventDefault();
639
640 var $that = $(this);
641 var question_id = $that.attr('data-question-id');
642 var $formInput = $('.quiz_question_form :input').serialize()+'&question_id='+question_id+'&action=tutor_quiz_add_question_answers';
643
644 $.ajax({
645 url : ajaxurl,
646 type : 'POST',
647 data : $formInput,
648 beforeSend: function () {
649 $that.addClass('tutor-updating-message');
650 },
651 success: function (data) {
652 $('#tutor_quiz_question_answer_form').html(data.data.output);
653 },
654 complete: function () {
655 $that.removeClass('tutor-updating-message');
656 }
657 });
658 });
659
660 /**
661 * Get question answers option edit form
662 *
663 * @since v.1.0.0
664 */
665 $(document).on('click', '.tutor-quiz-answer-edit a', function(e){
666 e.preventDefault();
667
668 var $that = $(this);
669 var answer_id = $that.closest('.tutor-quiz-answer-wrap').attr('data-answer-id');
670
671 $.ajax({
672 url : ajaxurl,
673 type : 'POST',
674 data : {answer_id : answer_id, action : 'tutor_quiz_edit_question_answer'},
675 beforeSend: function () {
676 $that.addClass('tutor-updating-message');
677 },
678 success: function (data) {
679 $('#tutor_quiz_question_answer_form').html(data.data.output);
680 },
681 complete: function () {
682 $that.removeClass('tutor-updating-message');
683 }
684 });
685 });
686
687 /**
688 * Saving question answers options
689 * Student should select the right answer at quiz attempts
690 *
691 * @since v.1.0.0
692 */
693
694 $(document).on('click', '#quiz-answer-save-btn', function(e){
695 e.preventDefault();
696
697 var $that = $(this);
698 var $formInput = $('.quiz_question_form :input').serialize()+'&action=tutor_save_quiz_answer_options';
699
700 $.ajax({
701 url : ajaxurl,
702 type : 'POST',
703 data : $formInput,
704 beforeSend: function () {
705 $('#quiz_validation_msg_wrap').html("");
706 $that.addClass('tutor-updating-message');
707 },
708 success: function (data) {
709 $('#tutor_quiz_question_answers').trigger('refresh');
710 },
711 complete: function () {
712 $that.removeClass('tutor-updating-message');
713 }
714 });
715 });
716
717 /**
718 * Updating Answer
719 *
720 * @since v.1.0.0
721 */
722 $(document).on('click', '#quiz-answer-edit-btn', function(e){
723 e.preventDefault();
724
725 var $that = $(this);
726 var $formInput = $('.quiz_question_form :input').serialize()+'&action=tutor_update_quiz_answer_options';
727
728 $.ajax({
729 url : ajaxurl,
730 type : 'POST',
731 data : $formInput,
732 beforeSend: function () {
733 $that.addClass('tutor-updating-message');
734 },
735 success: function (data) {
736 $('#tutor_quiz_question_answers').trigger('refresh');
737 },
738 complete: function () {
739 $that.removeClass('tutor-updating-message');
740 }
741 });
742 });
743
744 $(document).on('change', '.tutor-quiz-answers-mark-correct-wrap input', function(e){
745 e.preventDefault();
746
747 var $that = $(this);
748
749 var answer_id = $that.val();
750 var inputValue = 1;
751 if ( ! $that.prop('checked')) {
752 inputValue = 0;
753 }
754
755 $.ajax({
756 url : ajaxurl,
757 type : 'POST',
758 data : {answer_id:answer_id, inputValue : inputValue, action : 'tutor_mark_answer_as_correct'},
759 });
760 });
761
762
763 $(document).on('refresh', '#tutor_quiz_question_answers', function(e){
764 e.preventDefault();
765
766 var $that = $(this);
767 var question_id = $that.attr('data-question-id');
768 var question_type = $('.tutor_select_value_holder').val();
769
770 $.ajax({
771 url : ajaxurl,
772 type : 'POST',
773 data : {question_id : question_id, question_type : question_type, action: 'tutor_quiz_builder_get_answers_by_question'},
774 beforeSend: function () {
775 $that.addClass('tutor-updating-message');
776 $('#tutor_quiz_question_answer_form').html('');
777 },
778 success: function (data) {
779 if (data.success){
780 $that.html(data.data.output);
781 }
782 },
783 complete: function () {
784 $that.removeClass('tutor-updating-message');
785 }
786 });
787 });
788
789
790
791 /**
792 * Delete answer for a question in quiz builder
793 *
794 * @since v.1.0.0
795 */
796
797 $(document).on('click', '.tutor-quiz-answer-trash-wrap a.answer-trash-btn', function(e){
798 e.preventDefault();
799
800 var $that = $(this);
801 var answer_id = $that.attr('data-answer-id');
802
803 $.ajax({
804 url : ajaxurl,
805 type : 'POST',
806 data : {answer_id : answer_id, action: 'tutor_quiz_builder_delete_answer'},
807 beforeSend: function () {
808 $that.closest('.tutor-quiz-answer-wrap').remove();
809 },
810 });
811 });
812
813
814 /**
815 * Delete Quiz
816 * @since v.1.0.0
817 */
818
819 $(document).on('click', '.tutor-delete-quiz-btn', function(e){
820 e.preventDefault();
821
822 if( ! confirm('Are you sure?')){
823 return;
824 }
825
826 var $that = $(this);
827 var quiz_id = $that.attr('data-quiz-id');
828
829 $.ajax({
830 url : ajaxurl,
831 type : 'POST',
832 data : {quiz_id : quiz_id, action: 'tutor_delete_quiz_by_id'},
833 beforeSend: function () {
834 $that.closest('.course-content-item').remove();
835 }
836 });
837 });
838
839 /**
840 * Save answer sorting placement
841 *
842 * @since v.1.0.0
843 */
844 function enable_quiz_answer_sorting(){
845 if (jQuery().sortable) {
846 $("#tutor_quiz_question_answers").sortable({
847 handle: ".tutor-quiz-answer-sort-icon",
848 start: function (e, ui) {
849 ui.placeholder.css('visibility', 'visible');
850 },
851 stop: function (e, ui) {
852 tutor_save_sorting_quiz_answer_order();
853 },
854 });
855 }
856 }
857 function tutor_save_sorting_quiz_answer_order(){
858 var answers = {};
859 $('.tutor-quiz-answer-wrap').each(function(index, item){
860 var $answer = $(this);
861 var answer_id = parseInt($answer.attr('data-answer-id'), 10);
862 answers[index] = answer_id;
863 });
864
865 $.ajax({url : ajaxurl, type : 'POST',
866 data : {sorted_answer_ids : answers, action: 'tutor_quiz_answer_sorting'},
867 });
868 }
869
870
871 /**
872 * Tutor Custom Select
873 */
874
875 function tutor_select(){
876 var obj = {
877 init : function(){
878 $(document).on('click', '.tutor-select .tutor-select-option', function(e){
879 e.preventDefault();
880
881 var $that = $(this);
882 if ($that.attr('data-is-pro') !== 'true') {
883 var $html = $that.html().trim();
884 $that.closest('.tutor-select').find('.select-header .lead-option').html($html);
885 $that.closest('.tutor-select').find('.select-header input.tutor_select_value_holder').val($that.attr('data-value')).trigger('change');
886 $that.closest('.tutor-select-options').hide();
887 }else{
888 alert('Tutor Pro version required');
889 }
890 });
891 $(document).on('click', '.tutor-select .select-header', function(e){
892 e.preventDefault();
893
894 var $that = $(this);
895 $that.closest('.tutor-select').find('.tutor-select-options').slideToggle();
896 });
897
898 this.setValue();
899 this.hideOnOutSideClick();
900 },
901 setValue : function(){
902 $('.tutor-select').each(function(){
903 var $that = $(this);
904 var $option = $that.find('.tutor-select-option');
905
906 if ($option.length){
907 $option.each(function(){
908 var $thisOption = $(this);
909
910 if ($thisOption.attr('data-selected') === 'selected'){
911 var $html = $thisOption.html().trim();
912 $thisOption.closest('.tutor-select').find('.select-header .lead-option').html($html);
913 $thisOption.closest('.tutor-select').find('.select-header input.tutor_select_value_holder').val($thisOption.attr('data-value'));
914 }
915 });
916 }
917 });
918 },
919 hideOnOutSideClick : function(){
920 $(document).mouseup(function(e) {
921 var $option_wrap = $(".tutor-select-options");
922 if ( ! $(e.target).closest('.select-header').length && !$option_wrap.is(e.target) && $option_wrap.has(e.target).length === 0) {
923 $option_wrap.hide();
924 }
925 });
926 },
927 reInit : function(){
928 this.setValue();
929 }
930 };
931
932 return obj;
933 }
934 tutor_select().init();
935
936
937 /**
938 * If change question type from quiz builder question
939 *
940 * @since v.1.0.0
941 */
942 $(document).on('change', 'input.tutor_select_value_holder', function(e) {
943 var $that = $(this);
944 //$('#tutor_quiz_question_answer_form').html('');
945 $('.add_question_answers_option').trigger('click');
946 $('#tutor_quiz_question_answers').trigger('refresh');
947 });
948
949 $(document).on('click', '.tutor-media-upload-btn', function(e){
950 e.preventDefault();
951
952 var $that = $(this);
953 var frame;
954 if ( frame ) {
955 frame.open();
956 return;
957 }
958 frame = wp.media({
959 title: 'Select or Upload Media Of Your Chosen Persuasion',
960 button: {
961 text: 'Use this media'
962 },
963 multiple: false
964 });
965 frame.on( 'select', function() {
966 var attachment = frame.state().get('selection').first().toJSON();
967 $that.html('<img src="'+attachment.url+'" alt="" />');
968 $that.closest('.tutor-media-upload-wrap').find('input').val(attachment.id);
969 });
970 frame.open();
971 });
972 $(document).on('click', '.tutor-media-upload-trash', function(e){
973 e.preventDefault();
974
975 var $that = $(this);
976 $that.closest('.tutor-media-upload-wrap').find('.tutor-media-upload-btn').html('<i class="tutor-icon-image1"></i>');
977 $that.closest('.tutor-media-upload-wrap').find('input').val('');
978 });
979
980
981 /**
982 * Add instructor modal
983 */
984 $(document).on('click', '.tutor-add-instructor-btn', function(e){
985 e.preventDefault();
986
987 var $that = $(this);
988 var course_id = $('#post_ID').val();
989
990 $.ajax({
991 url : ajaxurl,
992 type : 'POST',
993 data : {course_id : course_id, action: 'tutor_load_instructors_modal'},
994 beforeSend: function () {
995 $that.addClass('tutor-updating-message');
996 },
997 success: function (data) {
998 if (data.success){
999 $('.tutor-instructors-modal-wrap .modal-container').html(data.data.output);
1000 $('.tutor-instructors-modal-wrap').addClass('show');
1001 }
1002 },
1003 complete: function () {
1004 $that.removeClass('tutor-updating-message');
1005 }
1006 });
1007 });
1008
1009 $(document).on('change keyup', '.tutor-instructors-modal-wrap .tutor-modal-search-input', function(e){
1010 e.preventDefault();
1011
1012 var $that = $(this);
1013 var $modal = $('.tutor-modal-wrap');
1014
1015 tutor_delay(function(){
1016 var search_terms = $that.val();
1017 var course_id = $('#post_ID').val();
1018
1019 $.ajax({
1020 url : ajaxurl,
1021 type : 'POST',
1022 data : {course_id : course_id, search_terms : search_terms, action: 'tutor_load_instructors_modal'},
1023 beforeSend: function () {
1024 $modal.addClass('loading');
1025 },
1026 success: function (data) {
1027 if (data.success){
1028 $('.tutor-instructors-modal-wrap .modal-container').html(data.data.output);
1029 $('.tutor-instructors-modal-wrap').addClass('show');
1030 }
1031 },
1032 complete: function () {
1033 $modal.removeClass('loading');
1034 }
1035 });
1036
1037 }, 1000)
1038 });
1039 $(document).on('click', '.add_instructor_to_course_btn', function(e){
1040 e.preventDefault();
1041
1042 var $that = $(this);
1043 var $modal = $('.tutor-modal-wrap');
1044 var course_id = $('#post_ID').val();
1045 var data = $modal.find('input').serialize()+'&course_id='+course_id+'&action=tutor_add_instructors_to_course';
1046
1047 $.ajax({
1048 url : ajaxurl,
1049 type : 'POST',
1050 data : data,
1051 beforeSend: function () {
1052 $that.addClass('tutor-updating-message');
1053 },
1054 success: function (data) {
1055 if (data.success){
1056 $('.tutor-course-available-instructors').html(data.data.output);
1057 $('.tutor-modal-wrap').removeClass('show');
1058 }
1059 },
1060 complete: function () {
1061 $that.removeClass('tutor-updating-message');
1062 }
1063 });
1064 });
1065
1066 $(document).on('click', '.tutor-instructor-delete-btn', function(e){
1067 e.preventDefault();
1068
1069 var $that = $(this);
1070 var course_id = $('#post_ID').val();
1071 var instructor_id = $that.closest('.added-instructor-item').attr('data-instructor-id');
1072
1073 $.ajax({
1074 url : ajaxurl,
1075 type : 'POST',
1076 data : {course_id:course_id, instructor_id:instructor_id, action : 'detach_instructor_from_course'},
1077 success: function (data) {
1078 if (data.success){
1079 $that.closest('.added-instructor-item').remove();
1080 }
1081 }
1082 });
1083 });
1084
1085
1086 });