PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 1.4.6
Tutor LMS – eLearning and online course solution v1.4.6
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
1172 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 /**
141 * Resorting...
142 */
143 function enable_sorting_topic_lesson(){
144 if (jQuery().sortable) {
145 $(".course-contents").sortable({
146 handle: ".course-move-handle",
147 start: function (e, ui) {
148 ui.placeholder.css('visibility', 'visible');
149 },
150 stop: function (e, ui) {
151 tutor_sorting_topics_and_lesson();
152 },
153 });
154 $(".tutor-lessons:not(.drop-lessons)").sortable({
155 connectWith: ".tutor-lessons",
156 items: "div.course-content-item",
157 start: function (e, ui) {
158 ui.placeholder.css('visibility', 'visible');
159 },
160 stop: function (e, ui) {
161 tutor_sorting_topics_and_lesson();
162 },
163 });
164 }
165 }
166
167 function tutor_sorting_topics_and_lesson(){
168 var topics = {};
169 $('.tutor-topics-wrap').each(function(index, item){
170 var $topic = $(this);
171 var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10);
172 var lessons = {};
173
174 $topic.find('.course-content-item').each(function(lessonIndex, lessonItem){
175 var $lesson = $(this);
176 var lesson_id = parseInt($lesson.attr('id').match(/\d+/)[0], 10);
177
178 lessons[lessonIndex] = lesson_id;
179 });
180 topics[index] = { 'topic_id' : topics_id, 'lesson_ids' : lessons };
181 });
182 $('#tutor_topics_lessons_sorting').val(JSON.stringify(topics));
183 }
184
185 $(document).on('change keyup', '.course-edit-topic-title-input', function (e) {
186 e.preventDefault();
187 $(this).closest('.tutor-topics-top').find('.topic-inner-title').html($(this).val());
188 });
189
190 $(document).on('click', '.topic-edit-icon', function (e) {
191 e.preventDefault();
192 $(this).closest('.tutor-topics-top').find('.tutor-topics-edit-form').slideToggle();
193 });
194
195 $(document).on('click', '.tutor-topics-edit-button', function(e){
196 e.preventDefault();
197 var $button = $(this);
198 var $topic = $button.closest('.tutor-topics-wrap');
199 var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10);
200 var topic_title = $button.closest('.tutor-topics-wrap').find('[name="topic_title"]').val();
201 var topic_summery = $button.closest('.tutor-topics-wrap').find('[name="topic_summery"]').val();
202
203 var data = {topic_title: topic_title, topic_summery : topic_summery, topic_id : topics_id, action: 'tutor_update_topic'};
204 $.ajax({
205 url : ajaxurl,
206 type : 'POST',
207 data : data,
208 beforeSend: function () {
209 $button.addClass('tutor-updating-message');
210 },
211 success: function (data) {
212 if (data.success){
213 $button.closest('.tutor-topics-wrap').find('span.topic-inner-title').text(topic_title);
214 $button.closest('.tutor-topics-wrap').find('.tutor-topics-edit-form').slideUp();
215 }
216 },
217 complete: function () {
218 $button.removeClass('tutor-updating-message');
219 }
220 });
221 });
222
223 /**
224 * Update Lesson Modal
225 */
226 $(document).on('click', '.open-tutor-lesson-modal', function(e){
227 e.preventDefault();
228
229 var $that = $(this);
230 var lesson_id = $that.attr('data-lesson-id');
231 var topic_id = $that.attr('data-topic-id');
232 var course_id = $('#post_ID').val();
233
234 $.ajax({
235 url : ajaxurl,
236 type : 'POST',
237 data : {lesson_id : lesson_id, topic_id : topic_id, course_id : course_id, action: 'tutor_load_edit_lesson_modal'},
238 beforeSend: function () {
239 $that.addClass('tutor-updating-message');
240 },
241 success: function (data) {
242 $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output);
243 $('.tutor-lesson-modal-wrap').attr({'data-lesson-id' : lesson_id, 'data-topic-id':topic_id}).addClass('show');
244
245 var tinymceConfig = tinyMCEPreInit.mceInit.tutor_editor_config;
246 if ( ! tinymceConfig){
247 tinymceConfig = tinyMCEPreInit.mceInit.course_description;
248 }
249 tinymce.init(tinymceConfig);
250 tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_lesson_modal_editor' );
251 tinyMCE.execCommand('mceAddEditor', false, "tutor_lesson_modal_editor");
252
253 $(document).trigger('lesson_modal_loaded', {lesson_id : lesson_id, topic_id : topic_id, course_id : course_id});
254 },
255 complete: function () {
256 quicktags({id : "tutor_lesson_modal_editor"});
257 $that.removeClass('tutor-updating-message');
258 }
259 });
260 });
261
262 /**
263 * Lesson upload thumbnail
264 */
265 $(document).on( 'click', '.lesson_thumbnail_upload_btn', function( event ){
266 event.preventDefault();
267 var $that = $(this);
268 var frame;
269 if ( frame ) {
270 frame.open();
271 return;
272 }
273 frame = wp.media({
274 title: 'Select or Upload Media Of Your Chosen Persuasion',
275 button: {
276 text: 'Use this media'
277 },
278 multiple: false
279 });
280 frame.on( 'select', function() {
281 var attachment = frame.state().get('selection').first().toJSON();
282 $that.closest('.tutor-thumbnail-wrap').find('.thumbnail-img').html('<img src="'+attachment.url+'" alt="" />');
283 $that.closest('.tutor-thumbnail-wrap').find('input').val(attachment.id);
284 });
285 frame.open();
286 });
287
288 /**
289 * Delete Lesson from course builder
290 */
291 $(document).on('click', '.tutor-delete-lesson-btn', function(e){
292 e.preventDefault();
293
294 if( ! confirm('Are you sure?')){
295 return;
296 }
297
298 var $that = $(this);
299 var lesson_id = $that.attr('data-lesson-id');
300
301 $.ajax({
302 url : ajaxurl,
303 type : 'POST',
304 data : {lesson_id : lesson_id, action: 'tutor_delete_lesson_by_id'},
305 beforeSend: function () {
306 $that.addClass('tutor-updating-message');
307 },
308 success: function (data) {
309 if (data.success){
310 $that.closest('.course-content-item').remove();
311 }
312 },
313 complete: function () {
314 $that.removeClass('tutor-updating-message');
315 }
316 });
317 });
318
319 /**
320 * Confirmation for deleting Topic
321 */
322 $(document).on('click', '.topic-delete-btn a', function(e){
323 var topic_id = $(this).attr('data-topic-id');
324
325 if ( ! confirm('Are you sure to delete?')){
326 e.preventDefault();
327 }
328 });
329
330 $(document).on('click', '.tutor-expand-all-topic', function (e) {
331 e.preventDefault();
332 $('.tutor-topics-body').slideDown();
333 $('.expand-collapse-wrap i').removeClass('tutor-icon-light-down').addClass('tutor-icon-light-up');
334 });
335 $(document).on('click', '.tutor-collapse-all-topic', function (e) {
336 e.preventDefault();
337 $('.tutor-topics-body').slideUp();
338 $('.expand-collapse-wrap i').removeClass('tutor-icon-light-up').addClass('tutor-icon-light-down');
339 });
340 $(document).on('click', '.topic-inner-title, .expand-collapse-wrap', function (e) {
341 e.preventDefault();
342 var $that = $(this);
343 $that.closest('.tutor-topics-wrap').find('.tutor-topics-body').slideToggle();
344 $that.closest('.tutor-topics-wrap').find('.expand-collapse-wrap i').toggleClass('tutor-icon-light-down tutor-icon-light-up');
345 });
346
347 /**
348 * Create new quiz
349 */
350
351 $(document).on('click', '.quiz-modal-btn-first-step', function(e){
352 e.preventDefault();
353
354 var $that = $(this);
355 var $quizTitle = $('[name="quiz_title"]');
356 var quiz_title = $quizTitle.val();
357 var quiz_description = $('[name="quiz_description"]').val();
358
359 if ( ! quiz_title){
360 $quizTitle.closest('.tutor-quiz-builder-group').find('.quiz_form_msg').html('Please enter quiz title');
361 return;
362 }else{
363 $quizTitle.closest('.tutor-quiz-builder-group').find('.quiz_form_msg').html('');
364 }
365
366 var course_id = $('#post_ID').val();
367 var topic_id = $that.closest('.tutor-modal-wrap').attr('quiz-for-post-id');
368
369 if ($('#tutor_quiz_builder_quiz_id').length) {
370 /**
371 *
372 * @type {jQuery}
373 *
374 * if quiz id exists, we are sending it to update quiz
375 */
376
377 var quiz_id = $('#tutor_quiz_builder_quiz_id').val();
378 $.ajax({
379 url : ajaxurl,
380 type : 'POST',
381 data : {quiz_title:quiz_title, quiz_description: quiz_description, quiz_id : quiz_id, topic_id : topic_id, action: 'tutor_quiz_builder_quiz_update'},
382 beforeSend: function () {
383 $that.addClass('tutor-updating-message');
384 },
385 success: function (data) {
386 $('#tutor-quiz-'+quiz_id).html(data.data.output_quiz_row);
387 $('#tutor-quiz-modal-tab-items-wrap a[href="#quiz-builder-tab-questions"]').trigger('click');
388
389 tutor_slider_init();
390 },
391 complete: function () {
392 $that.removeClass('tutor-updating-message');
393 }
394 });
395
396 return;
397 }
398
399 $.ajax({
400 url : ajaxurl,
401 type : 'POST',
402 data : {quiz_title:quiz_title, quiz_description: quiz_description, course_id : course_id, topic_id : topic_id, action: 'tutor_create_quiz_and_load_modal'},
403 beforeSend: function () {
404 $that.addClass('tutor-updating-message');
405 },
406 success: function (data) {
407 $('.tutor-quiz-builder-modal-wrap .modal-container').html(data.data.output);
408 $('#tutor-topics-'+topic_id+' .tutor-lessons').append(data.data.output_quiz_row);
409 $('#tutor-quiz-modal-tab-items-wrap a[href="#quiz-builder-tab-questions"]').trigger('click');
410
411 tutor_slider_init();
412
413 $(document).trigger('quiz_modal_loaded', {topic_id : topic_id, course_id : course_id});
414 },
415 complete: function () {
416 $that.removeClass('tutor-updating-message');
417 }
418 });
419
420 });
421
422
423 /**
424 * Ope modal for edit quiz
425 */
426 $(document).on('click', '.open-tutor-quiz-modal', function(e){
427 e.preventDefault();
428
429 var $that = $(this);
430 var quiz_id = $that.attr('data-quiz-id');
431 var topic_id = $that.attr('data-topic-id');
432 var course_id = $('#post_ID').val();
433
434 $.ajax({
435 url : ajaxurl,
436 type : 'POST',
437 data : {quiz_id : quiz_id, topic_id : topic_id, course_id : course_id, action: 'tutor_load_edit_quiz_modal'},
438 beforeSend: function () {
439 $that.addClass('tutor-updating-message');
440 },
441 success: function (data) {
442 $('.tutor-quiz-builder-modal-wrap .modal-container').html(data.data.output);
443 $('.tutor-quiz-builder-modal-wrap').attr('data-quiz-id', quiz_id).addClass('show');
444
445 //Back to question Tab if exists
446 if ($that.attr('data-back-to-tab')){
447 var tabSelector = $that.attr('data-back-to-tab');
448 $('#tutor-quiz-modal-tab-items-wrap a[href="'+tabSelector+'"]').trigger('click');
449 }
450
451 $(document).trigger('quiz_modal_loaded', {quiz_id : quiz_id, topic_id : topic_id, course_id : course_id});
452
453 tutor_slider_init();
454 enable_quiz_questions_sorting();
455 },
456 complete: function () {
457 $that.removeClass('tutor-updating-message');
458 }
459 });
460 });
461
462 $(document).on('click', '.quiz-modal-settings-save-btn', function(e){
463 e.preventDefault();
464
465 var $that = $(this);
466 var quiz_id = $('.tutor-quiz-builder-modal-wrap').attr('data-quiz-id');
467
468 var $formInput = $('#quiz-builder-tab-settings :input, #quiz-builder-tab-advanced-options :input').serialize()+'&quiz_id='+quiz_id+'&action=tutor_quiz_modal_update_settings';
469
470 $.ajax({
471 url : ajaxurl,
472 type : 'POST',
473 data : $formInput,
474 beforeSend: function () {
475 $that.addClass('tutor-updating-message');
476 },
477 success: function (data) {
478 //
479 },
480 complete: function () {
481 $that.removeClass('tutor-updating-message');
482 if ($that.attr('data-action') === 'modal_close'){
483 $('.tutor-modal-wrap').removeClass('show');
484 }
485 }
486 });
487 });
488
489
490 /**
491 * Quiz Question edit save and continue
492 */
493 $(document).on('click', '.quiz-modal-question-save-btn', function(e){
494 e.preventDefault();
495
496 var $that = $(this);
497 var $formInput = $('.quiz_question_form :input').serialize()+'&action=tutor_quiz_modal_update_question';
498 $.ajax({
499 url : ajaxurl,
500 type : 'POST',
501 data : $formInput,
502 beforeSend: function () {
503 $that.addClass('tutor-updating-message');
504 },
505 success: function (data) {
506 if (data.success){
507 //ReOpen questions
508 $that.closest('.tutor-quiz-builder-modal-contents').find('.open-tutor-quiz-modal').trigger('click');
509 }else{
510 if (typeof data.data !== 'undefined') {
511 $('#quiz_validation_msg_wrap').html(data.data.validation_msg);
512 }
513 }
514 },
515 complete: function () {
516 $that.removeClass('tutor-updating-message');
517 }
518 });
519 });
520
521 /**
522 * Sort quiz questions
523 */
524 function enable_quiz_questions_sorting(){
525 if (jQuery().sortable) {
526 $(".quiz-builder-questions-wrap").sortable({
527 handle: ".question-sorting",
528 start: function (e, ui) {
529 ui.placeholder.css('visibility', 'visible');
530 },
531 stop: function (e, ui) {
532 tutor_save_sorting_quiz_questions_order();
533 },
534 });
535 }
536 }
537
538 function tutor_save_sorting_quiz_questions_order(){
539 var questions = {};
540 $('.quiz-builder-question-wrap').each(function(index, item){
541 var $question = $(this);
542 var question_id = parseInt($question.attr('data-question-id'), 10);
543 questions[index] = question_id;
544 });
545
546 $.ajax({url : ajaxurl, type : 'POST',
547 data : {sorted_question_ids : questions, action: 'tutor_quiz_question_sorting'},
548 });
549 }
550
551 /**
552 * Quiz Modal
553 */
554
555 $(document).on('click', '.modal-close-btn', function(e){
556 e.preventDefault();
557 $('.tutor-modal-wrap').removeClass('show');
558 });
559 $(document).on('keyup', function(e){
560 if (e.keyCode === 27){
561 $('.tutor-modal-wrap').removeClass('show');
562 }
563 });
564
565 $(document).on('click', '.tutor-add-quiz-btn', function(e){
566 e.preventDefault();
567
568 var $that = $(this);
569 var quiz_for_post_id = $(this).closest('.tutor_add_quiz_wrap').attr('data-add-quiz-under');
570 $.ajax({
571 url : ajaxurl,
572 type : 'POST',
573 data : {quiz_for_post_id : quiz_for_post_id, action: 'tutor_load_quiz_builder_modal'},
574 beforeSend: function () {
575 $that.addClass('tutor-updating-message');
576 },
577 success: function (data) {
578 $('.tutor-quiz-builder-modal-wrap .modal-container').html(data.data.output);
579 $('.tutor-quiz-builder-modal-wrap').attr('quiz-for-post-id', quiz_for_post_id).addClass('show');
580 },
581 complete: function () {
582 $that.removeClass('tutor-updating-message');
583 }
584 });
585 });
586
587
588 /**
589 * Quiz Builder Modal Tabs
590 */
591 $(document).on('click', '.tutor-quiz-modal-tab-item', function(e){
592 e.preventDefault();
593
594 var $that = $(this);
595
596 var $quizTitle = $('[name="quiz_title"]');
597 var quiz_title = $quizTitle.val();
598 if ( ! quiz_title){
599 $quizTitle.closest('.tutor-quiz-builder-form-row').find('.quiz_form_msg').html('<p class="quiz-form-warning">Please save the quiz' +
600 ' first</p>');
601 return;
602 }else{
603 $quizTitle.closest('.tutor-quiz-builder-form-row').find('.quiz_form_msg').html('');
604 }
605
606 var tabSelector = $that.attr('href');
607 $('.quiz-builder-tab-container').hide();
608 $(tabSelector).show();
609
610 $('a.tutor-quiz-modal-tab-item').removeClass('active');
611 $that.addClass('active');
612 });
613
614 //Next Prev Tab
615 $(document).on('click', '.quiz-modal-btn-next, .quiz-modal-btn-back', function(e){
616 e.preventDefault();
617
618 var tabSelector = $(this).attr('href');
619 $('#tutor-quiz-modal-tab-items-wrap a[href="'+tabSelector+'"]').trigger('click');
620 });
621
622 $(document).on('click', '.quiz-modal-tab-navigation-btn.quiz-modal-btn-cancel', function(e){
623 e.preventDefault();
624 $('.tutor-modal-wrap').removeClass('show');
625 });
626
627 /**
628 * Add Question to quiz modal
629 */
630 $(document).on('click', '.tutor-quiz-open-question-form', function(e){
631 e.preventDefault();
632
633 var $that = $(this);
634
635 var quiz_id = $('#tutor_quiz_builder_quiz_id').val();
636 var course_id = $('#post_ID').val();
637 var question_id = $that.attr('data-question-id');
638
639
640 var params = {quiz_id : quiz_id, course_id : course_id, action: 'tutor_quiz_builder_get_question_form'};
641
642 if (question_id) {
643 params.question_id = question_id;
644 }
645
646 $.ajax({
647 url : ajaxurl,
648 type : 'POST',
649 data : params,
650 beforeSend: function () {
651 $that.addClass('tutor-updating-message');
652 },
653 success: function (data) {
654 $('.tutor-quiz-builder-modal-contents').html(data.data.output);
655
656 //Initializing Tutor Select
657 tutor_select().reInit();
658 enable_quiz_answer_sorting();
659 },
660 complete: function () {
661 $that.removeClass('tutor-updating-message');
662 }
663 });
664
665 });
666
667 $(document).on('click', '.tutor-quiz-question-trash', function(e){
668 e.preventDefault();
669
670 var $that = $(this);
671 var question_id = $that.attr('data-question-id');
672
673 $.ajax({
674 url : ajaxurl,
675 type : 'POST',
676 data : {question_id : question_id, action: 'tutor_quiz_builder_question_delete'},
677 beforeSend: function () {
678 $that.closest('.quiz-builder-question-wrap').remove();
679 },
680 });
681 });
682
683 /**
684 * Get question answers option form to save multiple/single/true-false options
685 *
686 * @since v.1.0.0
687 */
688
689 $(document).on('click', '.add_question_answers_option', function(e){
690 e.preventDefault();
691
692 var $that = $(this);
693 var question_id = $that.attr('data-question-id');
694 var $formInput = $('.quiz_question_form :input').serialize()+'&question_id='+question_id+'&action=tutor_quiz_add_question_answers';
695
696 $.ajax({
697 url : ajaxurl,
698 type : 'POST',
699 data : $formInput,
700 beforeSend: function () {
701 $that.addClass('tutor-updating-message');
702 },
703 success: function (data) {
704 $('#tutor_quiz_question_answer_form').html(data.data.output);
705 },
706 complete: function () {
707 $that.removeClass('tutor-updating-message');
708 }
709 });
710 });
711
712 /**
713 * Get question answers option edit form
714 *
715 * @since v.1.0.0
716 */
717 $(document).on('click', '.tutor-quiz-answer-edit a', function(e){
718 e.preventDefault();
719
720 var $that = $(this);
721 var answer_id = $that.closest('.tutor-quiz-answer-wrap').attr('data-answer-id');
722
723 $.ajax({
724 url : ajaxurl,
725 type : 'POST',
726 data : {answer_id : answer_id, action : 'tutor_quiz_edit_question_answer'},
727 beforeSend: function () {
728 $that.addClass('tutor-updating-message');
729 },
730 success: function (data) {
731 $('#tutor_quiz_question_answer_form').html(data.data.output);
732 },
733 complete: function () {
734 $that.removeClass('tutor-updating-message');
735 }
736 });
737 });
738
739 /**
740 * Saving question answers options
741 * Student should select the right answer at quiz attempts
742 *
743 * @since v.1.0.0
744 */
745
746 $(document).on('click', '#quiz-answer-save-btn', function(e){
747 e.preventDefault();
748
749 var $that = $(this);
750 var $formInput = $('.quiz_question_form :input').serialize()+'&action=tutor_save_quiz_answer_options';
751
752 $.ajax({
753 url : ajaxurl,
754 type : 'POST',
755 data : $formInput,
756 beforeSend: function () {
757 $('#quiz_validation_msg_wrap').html("");
758 $that.addClass('tutor-updating-message');
759 },
760 success: function (data) {
761 $('#tutor_quiz_question_answers').trigger('refresh');
762 },
763 complete: function () {
764 $that.removeClass('tutor-updating-message');
765 }
766 });
767 });
768
769 /**
770 * Updating Answer
771 *
772 * @since v.1.0.0
773 */
774 $(document).on('click', '#quiz-answer-edit-btn', function(e){
775 e.preventDefault();
776
777 var $that = $(this);
778 var $formInput = $('.quiz_question_form :input').serialize()+'&action=tutor_update_quiz_answer_options';
779
780 $.ajax({
781 url : ajaxurl,
782 type : 'POST',
783 data : $formInput,
784 beforeSend: function () {
785 $that.addClass('tutor-updating-message');
786 },
787 success: function (data) {
788 $('#tutor_quiz_question_answers').trigger('refresh');
789 },
790 complete: function () {
791 $that.removeClass('tutor-updating-message');
792 }
793 });
794 });
795
796 $(document).on('change', '.tutor-quiz-answers-mark-correct-wrap input', function(e){
797 e.preventDefault();
798
799 var $that = $(this);
800
801 var answer_id = $that.val();
802 var inputValue = 1;
803 if ( ! $that.prop('checked')) {
804 inputValue = 0;
805 }
806
807 $.ajax({
808 url : ajaxurl,
809 type : 'POST',
810 data : {answer_id:answer_id, inputValue : inputValue, action : 'tutor_mark_answer_as_correct'},
811 });
812 });
813
814
815 $(document).on('refresh', '#tutor_quiz_question_answers', function(e){
816 e.preventDefault();
817
818 var $that = $(this);
819 var question_id = $that.attr('data-question-id');
820 var question_type = $('.tutor_select_value_holder').val();
821
822 $.ajax({
823 url : ajaxurl,
824 type : 'POST',
825 data : {question_id : question_id, question_type : question_type, action: 'tutor_quiz_builder_get_answers_by_question'},
826 beforeSend: function () {
827 $that.addClass('tutor-updating-message');
828 $('#tutor_quiz_question_answer_form').html('');
829 },
830 success: function (data) {
831 if (data.success){
832 $that.html(data.data.output);
833 }
834 },
835 complete: function () {
836 $that.removeClass('tutor-updating-message');
837 }
838 });
839 });
840
841
842
843 /**
844 * Delete answer for a question in quiz builder
845 *
846 * @since v.1.0.0
847 */
848
849 $(document).on('click', '.tutor-quiz-answer-trash-wrap a.answer-trash-btn', function(e){
850 e.preventDefault();
851
852 var $that = $(this);
853 var answer_id = $that.attr('data-answer-id');
854
855 $.ajax({
856 url : ajaxurl,
857 type : 'POST',
858 data : {answer_id : answer_id, action: 'tutor_quiz_builder_delete_answer'},
859 beforeSend: function () {
860 $that.closest('.tutor-quiz-answer-wrap').remove();
861 },
862 });
863 });
864
865
866 /**
867 * Delete Quiz
868 * @since v.1.0.0
869 */
870
871 $(document).on('click', '.tutor-delete-quiz-btn', function(e){
872 e.preventDefault();
873
874 if( ! confirm('Are you sure?')){
875 return;
876 }
877
878 var $that = $(this);
879 var quiz_id = $that.attr('data-quiz-id');
880
881 $.ajax({
882 url : ajaxurl,
883 type : 'POST',
884 data : {quiz_id : quiz_id, action: 'tutor_delete_quiz_by_id'},
885 beforeSend: function () {
886 $that.closest('.course-content-item').remove();
887 }
888 });
889 });
890
891 /**
892 * Save answer sorting placement
893 *
894 * @since v.1.0.0
895 */
896 function enable_quiz_answer_sorting(){
897 if (jQuery().sortable) {
898 $("#tutor_quiz_question_answers").sortable({
899 handle: ".tutor-quiz-answer-sort-icon",
900 start: function (e, ui) {
901 ui.placeholder.css('visibility', 'visible');
902 },
903 stop: function (e, ui) {
904 tutor_save_sorting_quiz_answer_order();
905 },
906 });
907 }
908 }
909 function tutor_save_sorting_quiz_answer_order(){
910 var answers = {};
911 $('.tutor-quiz-answer-wrap').each(function(index, item){
912 var $answer = $(this);
913 var answer_id = parseInt($answer.attr('data-answer-id'), 10);
914 answers[index] = answer_id;
915 });
916
917 $.ajax({url : ajaxurl, type : 'POST',
918 data : {sorted_answer_ids : answers, action: 'tutor_quiz_answer_sorting'},
919 });
920 }
921
922
923 /**
924 * Tutor Custom Select
925 */
926
927 function tutor_select(){
928 var obj = {
929 init : function(){
930 $(document).on('click', '.tutor-select .tutor-select-option', function(e){
931 e.preventDefault();
932
933 var $that = $(this);
934 if ($that.attr('data-is-pro') !== 'true') {
935 var $html = $that.html().trim();
936 $that.closest('.tutor-select').find('.select-header .lead-option').html($html);
937 $that.closest('.tutor-select').find('.select-header input.tutor_select_value_holder').val($that.attr('data-value')).trigger('change');
938 $that.closest('.tutor-select-options').hide();
939 }else{
940 alert('Tutor Pro version required');
941 }
942 });
943 $(document).on('click', '.tutor-select .select-header', function(e){
944 e.preventDefault();
945
946 var $that = $(this);
947 $that.closest('.tutor-select').find('.tutor-select-options').slideToggle();
948 });
949
950 this.setValue();
951 this.hideOnOutSideClick();
952 },
953 setValue : function(){
954 $('.tutor-select').each(function(){
955 var $that = $(this);
956 var $option = $that.find('.tutor-select-option');
957
958 if ($option.length){
959 $option.each(function(){
960 var $thisOption = $(this);
961
962 if ($thisOption.attr('data-selected') === 'selected'){
963 var $html = $thisOption.html().trim();
964 $thisOption.closest('.tutor-select').find('.select-header .lead-option').html($html);
965 $thisOption.closest('.tutor-select').find('.select-header input.tutor_select_value_holder').val($thisOption.attr('data-value'));
966 }
967 });
968 }
969 });
970 },
971 hideOnOutSideClick : function(){
972 $(document).mouseup(function(e) {
973 var $option_wrap = $(".tutor-select-options");
974 if ( ! $(e.target).closest('.select-header').length && !$option_wrap.is(e.target) && $option_wrap.has(e.target).length === 0) {
975 $option_wrap.hide();
976 }
977 });
978 },
979 reInit : function(){
980 this.setValue();
981 }
982 };
983
984 return obj;
985 }
986 tutor_select().init();
987
988
989 /**
990 * If change question type from quiz builder question
991 *
992 * @since v.1.0.0
993 */
994 $(document).on('change', 'input.tutor_select_value_holder', function(e) {
995 var $that = $(this);
996 //$('#tutor_quiz_question_answer_form').html('');
997 $('.add_question_answers_option').trigger('click');
998 $('#tutor_quiz_question_answers').trigger('refresh');
999 });
1000
1001 $(document).on('click', '.tutor-media-upload-btn', function(e){
1002 e.preventDefault();
1003
1004 var $that = $(this);
1005 var frame;
1006 if ( frame ) {
1007 frame.open();
1008 return;
1009 }
1010 frame = wp.media({
1011 title: 'Select or Upload Media Of Your Chosen Persuasion',
1012 button: {
1013 text: 'Use this media'
1014 },
1015 multiple: false
1016 });
1017 frame.on( 'select', function() {
1018 var attachment = frame.state().get('selection').first().toJSON();
1019 $that.html('<img src="'+attachment.url+'" alt="" />');
1020 $that.closest('.tutor-media-upload-wrap').find('input').val(attachment.id);
1021 });
1022 frame.open();
1023 });
1024 $(document).on('click', '.tutor-media-upload-trash', function(e){
1025 e.preventDefault();
1026
1027 var $that = $(this);
1028 $that.closest('.tutor-media-upload-wrap').find('.tutor-media-upload-btn').html('<i class="tutor-icon-image1"></i>');
1029 $that.closest('.tutor-media-upload-wrap').find('input').val('');
1030 });
1031
1032
1033 /**
1034 * Add instructor modal
1035 */
1036 $(document).on('click', '.tutor-add-instructor-btn', function(e){
1037 e.preventDefault();
1038
1039 var $that = $(this);
1040 var course_id = $('#post_ID').val();
1041
1042 $.ajax({
1043 url : ajaxurl,
1044 type : 'POST',
1045 data : {course_id : course_id, action: 'tutor_load_instructors_modal'},
1046 beforeSend: function () {
1047 $that.addClass('tutor-updating-message');
1048 },
1049 success: function (data) {
1050 if (data.success){
1051 $('.tutor-instructors-modal-wrap .modal-container').html(data.data.output);
1052 $('.tutor-instructors-modal-wrap').addClass('show');
1053 }
1054 },
1055 complete: function () {
1056 $that.removeClass('tutor-updating-message');
1057 }
1058 });
1059 });
1060
1061 $(document).on('change keyup', '.tutor-instructors-modal-wrap .tutor-modal-search-input', function(e){
1062 e.preventDefault();
1063
1064 var $that = $(this);
1065 var $modal = $('.tutor-modal-wrap');
1066
1067 tutor_delay(function(){
1068 var search_terms = $that.val();
1069 var course_id = $('#post_ID').val();
1070
1071 $.ajax({
1072 url : ajaxurl,
1073 type : 'POST',
1074 data : {course_id : course_id, search_terms : search_terms, action: 'tutor_load_instructors_modal'},
1075 beforeSend: function () {
1076 $modal.addClass('loading');
1077 },
1078 success: function (data) {
1079 if (data.success){
1080 $('.tutor-instructors-modal-wrap .modal-container').html(data.data.output);
1081 $('.tutor-instructors-modal-wrap').addClass('show');
1082 }
1083 },
1084 complete: function () {
1085 $modal.removeClass('loading');
1086 }
1087 });
1088
1089 }, 1000)
1090 });
1091 $(document).on('click', '.add_instructor_to_course_btn', function(e){
1092 e.preventDefault();
1093
1094 var $that = $(this);
1095 var $modal = $('.tutor-modal-wrap');
1096 var course_id = $('#post_ID').val();
1097 var data = $modal.find('input').serialize()+'&course_id='+course_id+'&action=tutor_add_instructors_to_course';
1098
1099 $.ajax({
1100 url : ajaxurl,
1101 type : 'POST',
1102 data : data,
1103 beforeSend: function () {
1104 $that.addClass('tutor-updating-message');
1105 },
1106 success: function (data) {
1107 if (data.success){
1108 $('.tutor-course-available-instructors').html(data.data.output);
1109 $('.tutor-modal-wrap').removeClass('show');
1110 }
1111 },
1112 complete: function () {
1113 $that.removeClass('tutor-updating-message');
1114 }
1115 });
1116 });
1117
1118 $(document).on('click', '.tutor-instructor-delete-btn', function(e){
1119 e.preventDefault();
1120
1121 var $that = $(this);
1122 var course_id = $('#post_ID').val();
1123 var instructor_id = $that.closest('.added-instructor-item').attr('data-instructor-id');
1124
1125 $.ajax({
1126 url : ajaxurl,
1127 type : 'POST',
1128 data : {course_id:course_id, instructor_id:instructor_id, action : 'detach_instructor_from_course'},
1129 success: function (data) {
1130 if (data.success){
1131 $that.closest('.added-instructor-item').remove();
1132 }
1133 }
1134 });
1135 });
1136
1137 $(document).on('click', '.settings-tabs-navs li', function(e){
1138 e.preventDefault();
1139
1140 var $that = $(this);
1141 var data_target = $that.find('a').attr('data-target');
1142 var url = $that.find('a').attr('href');
1143
1144 $that.addClass('active').siblings('li.active').removeClass('active');
1145 $('.settings-tab-wrap').removeClass('active').hide().siblings(data_target).addClass('active').show();
1146
1147 window.history.pushState({}, '', url);
1148 });
1149
1150 /**
1151 * Re init required
1152 * Modal Loaded...
1153 */
1154
1155 $(document).on('lesson_modal_loaded quiz_modal_loaded assignment_modal_loaded', function(e, obj){
1156 if (jQuery().select2){
1157 $('.select2_multiselect').select2({
1158 dropdownCssClass:'increasezindex'
1159 });
1160 }
1161 if (jQuery.datepicker){
1162 $( ".tutor_date_picker" ).datepicker({"dateFormat" : 'yy-mm-dd'});
1163 }
1164 });
1165 $(document).on('lesson_modal_loaded', function(e, obj){
1166 $('.tutor-lesson-modal-wrap .modal-title h1').html('Lesson');
1167 });
1168 $(document).on('assignment_modal_loaded', function(e, obj){
1169 $('.tutor-lesson-modal-wrap .modal-title h1').html('Assignment');
1170 });
1171
1172 });