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