PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 1.9.8
Tutor LMS – eLearning and online course solution v1.9.8
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 4 years ago gutenberg_blocks.js 5 years ago mce-button.js 4 years ago tutor-admin.js 4 years ago tutor-front.js 4 years ago tutor-setup.js 5 years ago tutor.js 4 years ago
tutor.js
1896 lines
1 function tutor_get_nonce_data(send_key_value) {
2
3 var nonce_data = window._tutorobject || {};
4 var nonce_key = nonce_data.nonce_key || '';
5 var nonce_value = nonce_data[nonce_key] || '';
6
7 if(send_key_value) {
8 return {key:nonce_key, value:nonce_value};
9 }
10
11 return {[nonce_key]:nonce_value};
12 }
13
14 window.tutor_popup = function($, icon, padding) {
15
16 var $this = this;
17 var element;
18
19 this.popup_wrapper = function(wrapper_tag) {
20 var img_tag = icon === '' ? '' : '<img class="tutor-pop-icon" src="'+window._tutorobject.tutor_url+'assets/images/'+icon+'.svg"/>';
21
22 return '<'+wrapper_tag+' class="tutor-component-popup-container">\
23 <div class="tutor-component-popup-'+padding+'">\
24 <div class="tutor-component-content-container">'+img_tag+'</div>\
25 <div class="tutor-component-button-container"></div>\
26 </div>\
27 </'+wrapper_tag+'>';
28 }
29
30 this.popup = function(data) {
31
32 var title = data.title ? '<h3>'+data.title+'</h3>' : '';
33 var description = data.description ? '<p>'+data.description+'</p>' : '';
34
35 var buttons = Object.keys(data.buttons || {}).map(function(key) {
36 var button = data.buttons[key];
37 var button_id = button.id ? 'tutor-popup-'+button.id : '';
38 return $('<button id="'+button_id+'" class="tutor-button tutor-button-'+button.class+'">'+button.title+'</button>').click(button.callback);
39 });
40
41 element = $($this.popup_wrapper(data.wrapper_tag || 'div'));
42 var content_wrapper = element.find('.tutor-component-content-container');
43
44 content_wrapper.append(title);
45 data.after_title ? content_wrapper.append(data.after_title) : 0;
46
47 content_wrapper.append(description);
48 data.after_description ? content_wrapper.append(data.after_description) : 0;
49
50 // Assign close event on click black overlay
51 element.click(function() {
52 $(this).remove();
53 }).children().click(function(e) {
54 e.stopPropagation();
55 });
56
57 // Append action button
58 for(var i=0; i<buttons.length; i++) {
59 element.find('.tutor-component-button-container').append(buttons[i]);
60 }
61
62 $('body').append(element);
63
64 return element;
65 }
66
67 return {popup: this.popup};
68 }
69 window.tutorDotLoader = (loaderType) => {
70 return `
71 <div class="tutor-dot-loader ${loaderType ? loaderType: ''}">
72 <span class="dot dot-1"></span>
73 <span class="dot dot-2"></span>
74 <span class="dot dot-3"></span>
75 <span class="dot dot-4"></span>
76 </div>`;
77 }
78
79 window.tutor_date_picker = () => {
80 if (jQuery.datepicker){
81 var format = _tutorobject.wp_date_format;
82 if ( !format ) {
83 format = "yy-mm-dd";
84 }
85 $( ".tutor_date_picker" ).datepicker({"dateFormat" : format});
86 }
87 }
88
89 jQuery(document).ready(function($){
90 'use strict';
91
92 const { __, _x, _n, _nx } = wp.i18n;
93 /**
94 * Global date_picker selector
95 *
96 * @since 1.9.7
97 */
98 function load_date_picker() {
99 if (jQuery.datepicker){
100 var format = _tutorobject.wp_date_format;
101 if ( !format ) {
102 format = "yy-mm-dd";
103 }
104 $( ".tutor_date_picker" ).datepicker({"dateFormat" : format});
105 }
106 };
107 load_date_picker();
108 /**
109 * Slider bar
110 */
111 function tutor_slider_init(){
112 $('.tutor-field-slider').each(function(){
113 var $slider = $(this);
114 var $input = $slider.closest('.tutor-field-type-slider').find('input[type="hidden"]');
115 var $showVal = $slider.closest('.tutor-field-type-slider').find('.tutor-field-type-slider-value');
116 var min = parseFloat($slider.closest('.tutor-field-type-slider').attr('data-min'));
117 var max = parseFloat($slider.closest('.tutor-field-type-slider').attr('data-max'));
118
119 $slider.slider({
120 range: "max",
121 min: min,
122 max: max,
123 value: $input.val(),
124 slide: function( event, ui ) {
125 $showVal.text(ui.value);
126 $input.val(ui.value);
127 }
128 });
129 });
130 }
131 tutor_slider_init();
132
133
134 /**
135 * Video source tabs
136 */
137
138 if (jQuery().select2){
139 $('.videosource_select2').select2({
140 width: "100%",
141 templateSelection: iformat,
142 templateResult: iformat,
143 allowHtml: true
144 });
145 }
146 //videosource_select2
147
148 function iformat(icon) {
149 var originalOption = icon.element;
150 return $('<span><i class="tutor-icon-' + $(originalOption).data('icon') + '"></i> ' + icon.text + '</span>');
151 }
152
153 $(document).on('change', '.tutor_lesson_video_source', function(e){
154 var $that = $(this);
155 var selector = $(this).val();
156
157 if (selector){
158 $('.video-metabox-source-input-wrap').show();
159 }else{
160 $('.video-metabox-source-input-wrap').hide();
161 }
162 $that.closest('.tutor-option-field').find('.video-metabox-source-item').hide();
163 $that.closest('.tutor-option-field').find('.video_source_wrap_'+selector).show();
164 });
165
166 /**
167 * Course Builder
168 *
169 * @since v.1.3.4
170 */
171
172 $(document).on( 'click', '.tutor-course-thumbnail-upload-btn', function( event ){
173 event.preventDefault();
174 var $that = $(this);
175 var frame;
176 if ( frame ) {
177 frame.open();
178 return;
179 }
180 frame = wp.media({
181 title: __( 'Select or Upload Media Of Your Chosen Persuasion', 'tutor' ),
182 button: {
183 text: __( 'Use this media', 'tutor' )
184 },
185 multiple: false
186 });
187 frame.on( 'select', function() {
188 var attachment = frame.state().get('selection').first().toJSON();
189 $that.closest('.tutor-thumbnail-wrap').find('.thumbnail-img').attr('src', attachment.url);
190 $that.closest('.tutor-thumbnail-wrap').find('input').val(attachment.id);
191 $('.tutor-course-thumbnail-delete-btn').show();
192 });
193 frame.open();
194 });
195
196 //Delete Thumbnail
197 $(document).on( 'click', '.tutor-course-thumbnail-delete-btn', function( event ){
198 event.preventDefault();
199 var $that = $(this);
200
201 var placeholder_src = $that.closest('.tutor-thumbnail-wrap').find('.thumbnail-img').attr('data-placeholder-src');
202 $that.closest('.tutor-thumbnail-wrap').find('.thumbnail-img').attr('src', placeholder_src);
203 $that.closest('.tutor-thumbnail-wrap').find('input').val('');
204 $('.tutor-course-thumbnail-delete-btn').hide();
205 });
206
207 /**
208 * Quiz Builder
209 */
210
211 $(document).on('click', '.create_new_topic_btn', function (e) {
212 e.preventDefault();
213 $('.tutor-metabox-add-topics').slideToggle();
214 });
215
216 $(document).on('click', '#tutor-add-topic-btn', function (e) {
217 e.preventDefault();
218 var $that = $(this);
219 var form_data = $that.closest('.tutor-metabox-add-topics').find('input, textarea').serializeObject();
220 form_data.action = 'tutor_add_course_topic';
221
222 $.ajax({
223 url : window._tutorobject.ajaxurl,
224 type : 'POST',
225 data : form_data,
226 beforeSend: function () {
227 $that.addClass('tutor-updating-message');
228 },
229 success: function (data) {
230 if (data.success){
231 $('#tutor-course-content-wrap').html(data.data.course_contents);
232 $that.closest('.tutor-metabox-add-topics').find('input[type!="hidden"], textarea').each(function () {
233 $(this).val('');
234 });
235 $that.closest('.tutor-metabox-add-topics').slideUp();
236 enable_sorting_topic_lesson();
237 }
238 },
239 complete: function () {
240 $that.removeClass('tutor-updating-message');
241 }
242 });
243 });
244
245 /**
246 * Zoom Meeting js
247 * here for support enable_sorting_topic_lesson function
248 * @since 1.7.1
249 */
250 $('.tutor-zoom-meeting-modal-wrap').on('submit', '.tutor-meeting-modal-form', function (e) {
251 e.preventDefault();
252 var $form = $(this);
253 var data = $form.serializeObject();
254 var timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
255 data.timezone = timezone;
256 var $btn = $form.find('button[type="submit"]');
257
258 $.ajax({
259 url: window._tutorobject.ajaxurl,
260 type: 'POST',
261 data: data,
262 beforeSend: function () {
263 $btn.addClass('tutor-updating-message');
264 },
265 success: function (data) {
266
267 data.success ?
268 tutor_toast(__('Success', 'tutor'), $btn.data('toast_success_message'), 'success'):
269 tutor_toast(__('Update Error', 'tutor'), __('Meeting Update Failed', 'tutor'), 'error');
270
271 if(data.course_contents) {
272 $(data.selector).html(data.course_contents);
273 if ( data.selector == '#tutor-course-content-wrap') {
274 enable_sorting_topic_lesson();
275 }
276 //Close the modal
277 $('.tutor-zoom-meeting-modal-wrap').removeClass('show');
278 } else {
279 location.reload();
280 }
281 },
282 complete: function () {
283 $btn.removeClass('tutor-updating-message');
284 }
285 });
286 });
287
288 /**
289 * Resorting...
290 */
291 function enable_sorting_topic_lesson(){
292 if (jQuery().sortable) {
293 $(".course-contents").sortable({
294 handle: ".course-move-handle",
295 start: function (e, ui) {
296 ui.placeholder.css('visibility', 'visible');
297 },
298 stop: function (e, ui) {
299 tutor_sorting_topics_and_lesson();
300 },
301 });
302 $(".tutor-lessons:not(.drop-lessons)").sortable({
303 connectWith: ".tutor-lessons",
304 items: "div.course-content-item",
305 start: function (e, ui) {
306 ui.placeholder.css('visibility', 'visible');
307 },
308 stop: function (e, ui) {
309 tutor_sorting_topics_and_lesson();
310 },
311 });
312 }
313 }
314
315 function tutor_sorting_topics_and_lesson(){
316 var topics = {};
317 $('.tutor-topics-wrap').each(function(index, item){
318 var $topic = $(this);
319 var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10);
320 var lessons = {};
321
322 $topic.find('.course-content-item').each(function(lessonIndex, lessonItem){
323 var $lesson = $(this);
324 var lesson_id = parseInt($lesson.attr('id').match(/\d+/)[0], 10);
325
326 lessons[lessonIndex] = lesson_id;
327 });
328 topics[index] = { 'topic_id' : topics_id, 'lesson_ids' : lessons };
329 });
330 $('#tutor_topics_lessons_sorting').val(JSON.stringify(topics));
331 }
332
333 $(document).on('change keyup', '.course-edit-topic-title-input', function (e) {
334 e.preventDefault();
335 $(this).closest('.tutor-topics-top').find('.topic-inner-title').html($(this).val());
336 });
337
338 $(document).on('click', '.topic-edit-icon', function (e) {
339 e.preventDefault();
340 $(this).closest('.tutor-topics-top').find('.tutor-topics-edit-form').slideToggle();
341 });
342
343 $(document).on('click', '.tutor-topics-edit-button', function(e){
344 e.preventDefault();
345 var $button = $(this);
346 var $topic = $button.closest('.tutor-topics-wrap');
347 var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10);
348 var topic_title = $button.closest('.tutor-topics-wrap').find('[name="topic_title"]').val();
349 var topic_summery = $button.closest('.tutor-topics-wrap').find('[name="topic_summery"]').val();
350
351 var data = {topic_title: topic_title, topic_summery : topic_summery, topic_id : topics_id, action: 'tutor_update_topic'};
352 $.ajax({
353 url : window._tutorobject.ajaxurl,
354 type : 'POST',
355 data : data,
356 beforeSend: function () {
357 $button.addClass('tutor-updating-message');
358 },
359 success: function (data) {
360 if (data.success){
361 $button.closest('.tutor-topics-wrap').find('span.topic-inner-title').text(topic_title);
362 $button.closest('.tutor-topics-wrap').find('.tutor-topics-edit-form').slideUp();
363 }
364 },
365 complete: function () {
366 $button.removeClass('tutor-updating-message');
367 }
368 });
369 });
370
371 /**
372 * Update Lesson Modal
373 */
374 $(document).on('click', '.open-tutor-lesson-modal', function(e){
375 e.preventDefault();
376
377 var $that = $(this);
378 var lesson_id = $that.attr('data-lesson-id');
379 var topic_id = $that.attr('data-topic-id');
380 var course_id = $('#post_ID').val();
381
382 $.ajax({
383 url : window._tutorobject.ajaxurl,
384 type : 'POST',
385 data : {lesson_id : lesson_id, topic_id : topic_id, course_id : course_id, action: 'tutor_load_edit_lesson_modal'},
386 beforeSend: function () {
387 $that.addClass('tutor-updating-message');
388 },
389 success: function (data) {
390 $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output);
391 $('.tutor-lesson-modal-wrap').attr({'data-lesson-id' : lesson_id, 'data-topic-id':topic_id}).addClass('show');
392
393 var tinymceConfig = tinyMCEPreInit.mceInit.tutor_editor_config;
394 if ( ! tinymceConfig){
395 tinymceConfig = tinyMCEPreInit.mceInit.course_description;
396 }
397 tinymce.init(tinymceConfig);
398 tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_lesson_modal_editor' );
399 tinyMCE.execCommand('mceAddEditor', false, "tutor_lesson_modal_editor");
400
401 $(document).trigger('lesson_modal_loaded', {lesson_id : lesson_id, topic_id : topic_id, course_id : course_id});
402 },
403 complete: function () {
404 quicktags({id : "tutor_lesson_modal_editor"});
405 $that.removeClass('tutor-updating-message');
406 }
407 });
408 });
409
410 /**
411 * Lesson upload thumbnail
412 */
413 $(document).on( 'click', '.lesson_thumbnail_upload_btn', function( event ){
414 event.preventDefault();
415 var $that = $(this);
416 var frame;
417 if ( frame ) {
418 frame.open();
419 return;
420 }
421 frame = wp.media({
422 title: __( 'Select or Upload Media Of Your Chosen Persuasion', 'tutor' ),
423 button: {
424 text: __( 'Use this media', 'tutor' )
425 },
426 multiple: false
427 });
428 frame.on( 'select', function() {
429 var attachment = frame.state().get('selection').first().toJSON();
430 $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>');
431 $that.closest('.tutor-thumbnail-wrap').find('input').val(attachment.id);
432 $('.tutor-lesson-thumbnail-delete-btn').show();
433 });
434 frame.open();
435 });
436
437 /**
438 * Lesson Feature Image Delete
439 * @since v.1.5.6
440 */
441 $(document).on('click', '.tutor-lesson-thumbnail-delete-btn', function(e){
442 e.preventDefault();
443
444 var $that = $(this);
445
446 $that.closest('.tutor-thumbnail-wrap').find('._lesson_thumbnail_id').val('');
447 $that.closest('.tutor-thumbnail-wrap').find('.thumbnail-img').html('');
448 $that.hide();
449
450 });
451
452 /**
453 * Delete Lesson from course builder
454 */
455 $(document).on('click', '.tutor-delete-lesson-btn', function(e){
456 e.preventDefault();
457
458 if( ! confirm( __( 'Are you sure?', 'tutor' ) )){
459 return;
460 }
461
462 var $that = $(this);
463 var lesson_id = $that.attr('data-lesson-id');
464
465 $.ajax({
466 url : window._tutorobject.ajaxurl,
467 type : 'POST',
468 data : {lesson_id : lesson_id, action: 'tutor_delete_lesson_by_id'},
469 beforeSend: function () {
470 $that.addClass('tutor-updating-message');
471 },
472 success: function (data) {
473 if (data.success){
474 $that.closest('.course-content-item').remove();
475 }
476 },
477 complete: function () {
478 $that.removeClass('tutor-updating-message');
479 }
480 });
481 });
482
483 /**
484 * Confirmation for deleting Topic
485 */
486 $(document).on('click', '.topic-delete-btn a', function(e){
487 var topic_id = $(this).attr('data-topic-id');
488
489 if ( ! confirm( __( 'Are you sure to delete?', 'tutor' ) )){
490 e.preventDefault();
491 }
492 });
493
494 $(document).on('click', '.tutor-expand-all-topic', function (e) {
495 e.preventDefault();
496 $('.tutor-topics-body').slideDown();
497 $('.expand-collapse-wrap i').removeClass('tutor-icon-light-down').addClass('tutor-icon-light-up');
498 });
499 $(document).on('click', '.tutor-collapse-all-topic', function (e) {
500 e.preventDefault();
501 $('.tutor-topics-body').slideUp();
502 $('.expand-collapse-wrap i').removeClass('tutor-icon-light-up').addClass('tutor-icon-light-down');
503 });
504 $(document).on('click', '.topic-inner-title, .expand-collapse-wrap', function (e) {
505 e.preventDefault();
506 var $that = $(this);
507 $that.closest('.tutor-topics-wrap').find('.tutor-topics-body').slideToggle();
508 $that.closest('.tutor-topics-wrap').find('.expand-collapse-wrap i').toggleClass('tutor-icon-light-down tutor-icon-light-up');
509 });
510
511 /**
512 * Create new quiz
513 */
514
515 $(document).on('click', '.quiz-modal-btn-first-step', function(e){
516 e.preventDefault();
517
518 var $that = $(this);
519 var $quizTitle = $('[name="quiz_title"]');
520 var quiz_title = $quizTitle.val();
521 var quiz_description = $('[name="quiz_description"]').val();
522
523 if ( ! quiz_title){
524 $quizTitle.closest('.tutor-quiz-builder-group').find('.quiz_form_msg').html('Please enter quiz title');
525 return;
526 }else{
527 $quizTitle.closest('.tutor-quiz-builder-group').find('.quiz_form_msg').html('');
528 }
529
530 var course_id = $('#post_ID').val();
531 var topic_id = $that.closest('.tutor-modal-wrap').attr('quiz-for-post-id');
532
533 if ($('#tutor_quiz_builder_quiz_id').length) {
534 /**
535 *
536 * @type {jQuery}
537 *
538 * if quiz id exists, we are sending it to update quiz
539 */
540
541 var quiz_id = $('#tutor_quiz_builder_quiz_id').val();
542 $.ajax({
543 url : window._tutorobject.ajaxurl,
544 type : 'POST',
545 data : {quiz_title:quiz_title, quiz_description: quiz_description, quiz_id : quiz_id, topic_id : topic_id, action: 'tutor_quiz_builder_quiz_update'},
546 beforeSend: function () {
547 $that.addClass('tutor-updating-message');
548 },
549 success: function (data) {
550 $('#tutor-quiz-'+quiz_id).html(data.data.output_quiz_row);
551 $('#tutor-quiz-modal-tab-items-wrap a[href="#quiz-builder-tab-questions"]').trigger('click');
552
553 tutor_slider_init();
554 },
555 complete: function () {
556 $that.removeClass('tutor-updating-message');
557 }
558 });
559
560 return;
561 }
562
563 $.ajax({
564 url : window._tutorobject.ajaxurl,
565 type : 'POST',
566 data : {quiz_title:quiz_title, quiz_description: quiz_description, course_id : course_id, topic_id : topic_id, action: 'tutor_create_quiz_and_load_modal'},
567 beforeSend: function () {
568 $that.addClass('tutor-updating-message');
569 },
570 success: function (data) {
571 $('.tutor-quiz-builder-modal-wrap .modal-container').html(data.data.output);
572 $('#tutor-topics-'+topic_id+' .tutor-lessons').append(data.data.output_quiz_row);
573 $('#tutor-quiz-modal-tab-items-wrap a[href="#quiz-builder-tab-questions"]').trigger('click');
574
575 tutor_slider_init();
576
577 $(document).trigger('quiz_modal_loaded', {topic_id : topic_id, course_id : course_id});
578 },
579 complete: function () {
580 $that.removeClass('tutor-updating-message');
581 }
582 });
583
584 });
585
586
587 /**
588 * Ope modal for edit quiz
589 */
590 $(document).on('click', '.open-tutor-quiz-modal', function(e){
591 e.preventDefault();
592
593 var $that = $(this);
594 var quiz_id = $that.attr('data-quiz-id');
595 var topic_id = $that.attr('data-topic-id');
596 if ( topic_id == undefined ) {
597 topic_id = $that.closest('.tutor-modal-wrap').attr('quiz-for-post-id');
598 }
599
600
601 var course_id = $('#post_ID').val();
602
603 $.ajax({
604 url : window._tutorobject.ajaxurl,
605 type : 'POST',
606 data : {quiz_id : quiz_id, topic_id : topic_id, course_id : course_id, action: 'tutor_load_edit_quiz_modal'},
607 beforeSend: function () {
608 $that.addClass('tutor-updating-message');
609 },
610 success: function (data) {
611 $('.tutor-quiz-builder-modal-wrap .modal-container').html(data.data.output);
612 $('.tutor-quiz-builder-modal-wrap').attr('data-quiz-id', quiz_id).attr('quiz-for-post-id', topic_id).addClass('show');
613
614 //Back to question Tab if exists
615 if ($that.attr('data-back-to-tab')){
616 var tabSelector = $that.attr('data-back-to-tab');
617 $('#tutor-quiz-modal-tab-items-wrap a[href="'+tabSelector+'"]').trigger('click');
618 }
619
620 $(document).trigger('quiz_modal_loaded', {quiz_id : quiz_id, topic_id : topic_id, course_id : course_id});
621
622 tutor_slider_init();
623 enable_quiz_questions_sorting();
624 },
625 complete: function () {
626 $that.removeClass('tutor-updating-message');
627 }
628 });
629 });
630
631 $(document).on('click', '.quiz-modal-settings-save-btn', function(e){
632 e.preventDefault();
633
634 var $that = $(this);
635 var quiz_id = $('.tutor-quiz-builder-modal-wrap').attr('data-quiz-id');
636 var current_topic_id = $("#current_topic_id_for_quiz").val();
637
638 var $formInput = $('#quiz-builder-tab-settings :input, #quiz-builder-tab-advanced-options :input').serializeObject();
639 $formInput.topic_id = current_topic_id;
640 $formInput.quiz_id = quiz_id;
641 $formInput.action = 'tutor_quiz_modal_update_settings';
642
643 $.ajax({
644 url : window._tutorobject.ajaxurl,
645 type : 'POST',
646 data : $formInput,
647 beforeSend: function () {
648 $that.addClass('tutor-updating-message');
649 },
650 success: function (data) {
651 if ( data.success ) {
652 $('#tutor-course-content-wrap').html(data.data.course_contents);
653 }
654 data.success ?
655 tutor_toast(__('Success', 'tutor'), $that.data('toast_success_message'), 'success') :
656 tutor_toast(__('Update Error', 'tutor'), __('Quiz Update Failed', 'tutor'), 'error');
657 },
658 complete: function () {
659 $that.removeClass('tutor-updating-message');
660 if ($that.attr('data-action') === 'modal_close'){
661 $('.tutor-modal-wrap').removeClass('show');
662 }
663 }
664 });
665 });
666
667
668 /**
669 * Quiz Question edit save and continue
670 */
671 $(document).on('click', '.quiz-modal-question-save-btn', function(e){
672 e.preventDefault();
673
674 var $that = $(this);
675 var $formInput = $('.quiz_question_form :input').serializeObject();
676 $formInput.action = 'tutor_quiz_modal_update_question';
677 var topic_id = $that.closest('.tutor-modal-wrap').attr('quiz-for-post-id');
678 $formInput.topic_id = topic_id;
679
680 $.ajax({
681 url : window._tutorobject.ajaxurl,
682 type : 'POST',
683 data : $formInput,
684 beforeSend: function () {
685 $that.addClass('tutor-updating-message');
686 },
687 success: function (data) {
688 if (data.success){
689 //ReOpen questions
690 $that.closest('.tutor-quiz-builder-modal-contents').find('.open-tutor-quiz-modal').trigger('click');
691 }else{
692 if (typeof data.data !== 'undefined') {
693 $('#quiz_validation_msg_wrap').html(data.data.validation_msg);
694 }
695 }
696 },
697 complete: function () {
698 $that.removeClass('tutor-updating-message');
699 }
700 });
701 });
702
703 /**
704 * Sort quiz questions
705 */
706 function enable_quiz_questions_sorting(){
707 if (jQuery().sortable) {
708 $(".quiz-builder-questions-wrap").sortable({
709 handle: ".question-sorting",
710 start: function (e, ui) {
711 ui.placeholder.css('visibility', 'visible');
712 },
713 stop: function (e, ui) {
714 tutor_save_sorting_quiz_questions_order();
715 },
716 });
717 }
718 }
719
720 function tutor_save_sorting_quiz_questions_order(){
721 var questions = {};
722 $('.quiz-builder-question-wrap').each(function(index, item){
723 var $question = $(this);
724 var question_id = parseInt($question.attr('data-question-id'), 10);
725 questions[index] = question_id;
726 });
727
728 $.ajax({url : window._tutorobject.ajaxurl, type : 'POST',
729 data : {sorted_question_ids : questions, action: 'tutor_quiz_question_sorting'},
730 });
731 }
732
733 /**
734 * Quiz Modal
735 */
736
737 $(document).on('click', '.modal-close-btn', function(e){
738 e.preventDefault();
739 $('.tutor-modal-wrap').removeClass('show');
740 });
741 $(document).on('keyup', function(e){
742 if (e.keyCode === 27){
743 $('.tutor-modal-wrap').removeClass('show');
744 }
745 });
746
747 $(document).on('click', '.tutor-add-quiz-btn', function(e){
748 e.preventDefault();
749
750 var $that = $(this);
751 var quiz_for_post_id = $(this).closest('.tutor_add_quiz_wrap').attr('data-add-quiz-under');
752 var current_topic_id = $(this).data('topic-id');
753 $.ajax({
754 url : window._tutorobject.ajaxurl,
755 type : 'POST',
756 data : {
757 quiz_for_post_id : quiz_for_post_id,
758 current_topic_id : current_topic_id,
759 action: 'tutor_load_quiz_builder_modal'
760 },
761 beforeSend: function () {
762 $that.addClass('tutor-updating-message');
763 },
764 success: function (data) {
765 $('.tutor-quiz-builder-modal-wrap .modal-container').html(data.data.output);
766 $('.tutor-quiz-builder-modal-wrap').attr('quiz-for-post-id', quiz_for_post_id).addClass('show');
767 },
768 complete: function () {
769 $that.removeClass('tutor-updating-message');
770 }
771 });
772 });
773
774
775 /**
776 * Quiz Builder Modal Tabs
777 */
778 $(document).on('click', '.tutor-quiz-modal-tab-item', function(e){
779 e.preventDefault();
780
781 var $that = $(this);
782
783 var $quizTitle = $('[name="quiz_title"]');
784 var quiz_title = $quizTitle.val();
785 if ( ! quiz_title){
786 $quizTitle.closest('.tutor-quiz-builder-form-row').find('.quiz_form_msg').html('<p class="quiz-form-warning">Please save the quiz' +
787 ' first</p>');
788 return;
789 }else{
790 $quizTitle.closest('.tutor-quiz-builder-form-row').find('.quiz_form_msg').html('');
791 }
792
793 var tabSelector = $that.attr('href');
794 $('.quiz-builder-tab-container').hide();
795 $(tabSelector).show();
796
797 $('a.tutor-quiz-modal-tab-item').removeClass('active');
798 $that.addClass('active');
799 });
800
801 //Next Prev Tab
802 $(document).on('click', '.quiz-modal-btn-next, .quiz-modal-btn-back', function(e){
803 e.preventDefault();
804
805 var tabSelector = $(this).attr('href');
806 $('#tutor-quiz-modal-tab-items-wrap a[href="'+tabSelector+'"]').trigger('click');
807 });
808
809 $(document).on('click', '.quiz-modal-tab-navigation-btn.quiz-modal-btn-cancel', function(e){
810 e.preventDefault();
811 $('.tutor-modal-wrap').removeClass('show');
812 });
813
814 /**
815 * Add Question to quiz modal
816 */
817 $(document).on('click', '.tutor-quiz-open-question-form', function(e){
818 e.preventDefault();
819
820 var $that = $(this);
821
822 var quiz_id = $('#tutor_quiz_builder_quiz_id').val();
823 var course_id = $('#post_ID').val();
824 var question_id = $that.attr('data-question-id');
825
826
827 var params = {quiz_id : quiz_id, course_id : course_id, action: 'tutor_quiz_builder_get_question_form'};
828
829 if (question_id) {
830 params.question_id = question_id;
831 }
832
833 $.ajax({
834 url : window._tutorobject.ajaxurl,
835 type : 'POST',
836 data : params,
837 beforeSend: function () {
838 $that.addClass('tutor-updating-message');
839 },
840 success: function (data) {
841 $('.tutor-quiz-builder-modal-contents').html(data.data.output);
842
843 //Initializing Tutor Select
844 tutor_select().reInit();
845 enable_quiz_answer_sorting();
846 disableAddoption();
847 },
848 complete: function () {
849 $that.removeClass('tutor-updating-message');
850 }
851 });
852
853 });
854
855 $(document).on('click', '.tutor-quiz-question-trash', function(e){
856 e.preventDefault();
857
858 var $that = $(this);
859 var question_id = $that.attr('data-question-id');
860
861 $.ajax({
862 url : window._tutorobject.ajaxurl,
863 type : 'POST',
864 data : {question_id : question_id, action: 'tutor_quiz_builder_question_delete'},
865 beforeSend: function () {
866 $that.closest('.quiz-builder-question-wrap').remove();
867 },
868 });
869 });
870
871 /**
872 * Get question answers option form to save multiple/single/true-false options
873 *
874 * @since v.1.0.0
875 */
876
877 $(document).on('click', '.add_question_answers_option:not(.disabled)', function(e){
878 e.preventDefault();
879
880 var $that = $(this);
881 var question_id = $that.attr('data-question-id');
882
883 var $formInput = $('.quiz_question_form :input').serializeObject();
884
885 $formInput.question_id = question_id;
886 $formInput.action = 'tutor_quiz_add_question_answers';
887 $.ajax({
888 url : window._tutorobject.ajaxurl,
889 type : 'POST',
890 data : $formInput,
891 beforeSend: function () {
892 $that.addClass('tutor-updating-message');
893 },
894 success: function (data) {
895 $('#tutor_quiz_question_answer_form').html(data.data.output);
896 disableAddoption();
897 },
898 complete: function () {
899 $that.removeClass('tutor-updating-message');
900 }
901 });
902 });
903
904 /**
905 * Get question answers option edit form
906 *
907 * @since v.1.0.0
908 */
909 $(document).on('click', '.tutor-quiz-answer-edit a', function(e){
910 e.preventDefault();
911
912 var $that = $(this);
913 var answer_id = $that.closest('.tutor-quiz-answer-wrap').attr('data-answer-id');
914
915 $.ajax({
916 url : window._tutorobject.ajaxurl,
917 type : 'POST',
918 data : {answer_id : answer_id, action : 'tutor_quiz_edit_question_answer'},
919 beforeSend: function () {
920 $that.addClass('tutor-updating-message');
921 },
922 success: function (data) {
923 $('#tutor_quiz_question_answer_form').html(data.data.output);
924 },
925 complete: function () {
926 $that.removeClass('tutor-updating-message');
927 }
928 });
929 });
930
931 /**
932 * Saving question answers options
933 * Student should select the right answer at quiz attempts
934 *
935 * @since v.1.0.0
936 */
937
938 $(document).on('click', '#quiz-answer-save-btn', function(e){
939 e.preventDefault();
940
941 var $that = $(this);
942 var $formInput = $('.quiz_question_form :input').serializeObject();
943 $formInput.action = 'tutor_save_quiz_answer_options';
944
945 $.ajax({
946 url : window._tutorobject.ajaxurl,
947 type : 'POST',
948 data : $formInput,
949 beforeSend: function () {
950 $('#quiz_validation_msg_wrap').html("");
951 $that.addClass('tutor-updating-message');
952 },
953 success: function (data) {
954 $('#tutor_quiz_question_answers').trigger('refresh');
955 },
956 complete: function () {
957 $that.removeClass('tutor-updating-message');
958 }
959 });
960 });
961
962 /**
963 * Updating Answer
964 *
965 * @since v.1.0.0
966 */
967 $(document).on('click', '#quiz-answer-edit-btn', function(e){
968 e.preventDefault();
969
970 var $that = $(this);
971 var $formInput = $('.quiz_question_form :input').serializeObject();
972 $formInput.action = 'tutor_update_quiz_answer_options';
973
974 $.ajax({
975 url : window._tutorobject.ajaxurl,
976 type : 'POST',
977 data : $formInput,
978 beforeSend: function () {
979 $that.addClass('tutor-updating-message');
980 },
981 success: function (data) {
982 $('#tutor_quiz_question_answers').trigger('refresh');
983 },
984 complete: function () {
985 $that.removeClass('tutor-updating-message');
986 }
987 });
988 });
989
990 $(document).on('change', '.tutor-quiz-answers-mark-correct-wrap input', function(e){
991 e.preventDefault();
992
993 var $that = $(this);
994
995 var answer_id = $that.val();
996 var inputValue = 1;
997 if ( ! $that.prop('checked')) {
998 inputValue = 0;
999 }
1000
1001 $.ajax({
1002 url : window._tutorobject.ajaxurl,
1003 type : 'POST',
1004 data : {answer_id:answer_id, inputValue : inputValue, action : 'tutor_mark_answer_as_correct'},
1005 });
1006 });
1007
1008
1009 $(document).on('refresh', '#tutor_quiz_question_answers', function(e){
1010 e.preventDefault();
1011
1012 var $that = $(this);
1013 var question_id = $that.attr('data-question-id');
1014 var question_type = $('.tutor_select_value_holder').val();
1015
1016 $.ajax({
1017 url : window._tutorobject.ajaxurl,
1018 type : 'POST',
1019 data : {question_id : question_id, question_type : question_type, action: 'tutor_quiz_builder_get_answers_by_question'},
1020 beforeSend: function () {
1021 $that.addClass('tutor-updating-message');
1022 $('#tutor_quiz_question_answer_form').html('');
1023 },
1024 success: function (data) {
1025 if (data.success){
1026 $that.html(data.data.output);
1027 }
1028 },
1029 complete: function () {
1030 $that.removeClass('tutor-updating-message');
1031 }
1032 });
1033 });
1034
1035
1036
1037 /**
1038 * Delete answer for a question in quiz builder
1039 *
1040 * @since v.1.0.0
1041 */
1042
1043 $(document).on('click', '.tutor-quiz-answer-trash-wrap a.answer-trash-btn', function(e){
1044 e.preventDefault();
1045
1046 var $that = $(this);
1047 var answer_id = $that.attr('data-answer-id');
1048
1049 $.ajax({
1050 url : window._tutorobject.ajaxurl,
1051 type : 'POST',
1052 data : {answer_id : answer_id, action: 'tutor_quiz_builder_delete_answer'},
1053 beforeSend: function () {
1054 $that.closest('.tutor-quiz-answer-wrap').remove();
1055 },
1056 });
1057 });
1058
1059
1060 /**
1061 * Delete Quiz
1062 * @since v.1.0.0
1063 */
1064
1065 $(document).on('click', '.tutor-delete-quiz-btn', function(e){
1066 e.preventDefault();
1067
1068 if( ! confirm( __( 'Are you sure?', 'tutor' ) )){
1069 return;
1070 }
1071
1072 var $that = $(this);
1073 var quiz_id = $that.attr('data-quiz-id');
1074
1075 $.ajax({
1076 url : window._tutorobject.ajaxurl,
1077 type : 'POST',
1078 data : {quiz_id : quiz_id, action: 'tutor_delete_quiz_by_id'},
1079 beforeSend: function () {
1080 $that.closest('.course-content-item').remove();
1081 }
1082 });
1083 });
1084
1085 /**
1086 * Save answer sorting placement
1087 *
1088 * @since v.1.0.0
1089 */
1090 function enable_quiz_answer_sorting(){
1091 if (jQuery().sortable) {
1092 $("#tutor_quiz_question_answers").sortable({
1093 handle: ".tutor-quiz-answer-sort-icon",
1094 start: function (e, ui) {
1095 ui.placeholder.css('visibility', 'visible');
1096 },
1097 stop: function (e, ui) {
1098 tutor_save_sorting_quiz_answer_order();
1099 },
1100 });
1101 }
1102 }
1103 function tutor_save_sorting_quiz_answer_order(){
1104 var answers = {};
1105 $('.tutor-quiz-answer-wrap').each(function(index, item){
1106 var $answer = $(this);
1107 var answer_id = parseInt($answer.attr('data-answer-id'), 10);
1108 answers[index] = answer_id;
1109 });
1110
1111 $.ajax({url : window._tutorobject.ajaxurl, type : 'POST',
1112 data : {sorted_answer_ids : answers, action: 'tutor_quiz_answer_sorting'},
1113 });
1114 }
1115
1116
1117 /**
1118 * Tutor Custom Select
1119 */
1120
1121 function tutor_select(){
1122 var obj = {
1123 init : function(){
1124 $(document).on('click', '.tutor-select .tutor-select-option', function(e){
1125 e.preventDefault();
1126
1127 var $that = $(this);
1128 if ($that.attr('data-is-pro') !== 'true') {
1129 var $html = $that.html().trim();
1130 $that.closest('.tutor-select').find('.select-header .lead-option').html($html);
1131 $that.closest('.tutor-select').find('.select-header input.tutor_select_value_holder').val($that.attr('data-value')).trigger('change');
1132 $that.closest('.tutor-select-options').hide();
1133
1134 disableAddoption();
1135 }else{
1136 alert('Tutor Pro version required');
1137 }
1138 });
1139 $(document).on('click', '.tutor-select .select-header', function(e){
1140 e.preventDefault();
1141
1142 var $that = $(this);
1143 $that.closest('.tutor-select').find('.tutor-select-options').slideToggle();
1144 });
1145
1146 this.setValue();
1147 this.hideOnOutSideClick();
1148 },
1149 setValue : function(){
1150 $('.tutor-select').each(function(){
1151 var $that = $(this);
1152 var $option = $that.find('.tutor-select-option');
1153
1154 if ($option.length){
1155 $option.each(function(){
1156 var $thisOption = $(this);
1157
1158 if ($thisOption.attr('data-selected') === 'selected'){
1159 var $html = $thisOption.html().trim();
1160 $thisOption.closest('.tutor-select').find('.select-header .lead-option').html($html);
1161 $thisOption.closest('.tutor-select').find('.select-header input.tutor_select_value_holder').val($thisOption.attr('data-value'));
1162 }
1163 });
1164 }
1165 });
1166 },
1167 hideOnOutSideClick : function(){
1168 $(document).mouseup(function(e) {
1169 var $option_wrap = $(".tutor-select-options");
1170 if ( ! $(e.target).closest('.select-header').length && !$option_wrap.is(e.target) && $option_wrap.has(e.target).length === 0) {
1171 $option_wrap.hide();
1172 }
1173 });
1174 },
1175 reInit : function(){
1176 this.setValue();
1177 }
1178 };
1179
1180 return obj;
1181 }
1182 tutor_select().init();
1183
1184
1185 /**
1186 * If change question type from quiz builder question
1187 *
1188 * @since v.1.0.0
1189 */
1190 $(document).on('change', 'input.tutor_select_value_holder', function(e) {
1191 var $that = $(this);
1192 //$('#tutor_quiz_question_answer_form').html('');
1193 $('.add_question_answers_option').trigger('click');
1194 $('#tutor_quiz_question_answers').trigger('refresh');
1195 });
1196
1197 $(document).on('click', '.tutor-media-upload-btn', function(e){
1198 e.preventDefault();
1199
1200 var $that = $(this);
1201 var frame;
1202 if ( frame ) {
1203 frame.open();
1204 return;
1205 }
1206 frame = wp.media({
1207 title: __( 'Select or Upload Media Of Your Chosen Persuasion', 'tutor' ),
1208 button: {
1209 text: __( 'Use this media', 'tutor' )
1210 },
1211 multiple: false
1212 });
1213 frame.on( 'select', function() {
1214 var attachment = frame.state().get('selection').first().toJSON();
1215 $that.html('<img src="'+attachment.url+'" alt="" />');
1216 $that.closest('.tutor-media-upload-wrap').find('input').val(attachment.id);
1217 });
1218 frame.open();
1219 });
1220 $(document).on('click', '.tutor-media-upload-trash', function(e){
1221 e.preventDefault();
1222
1223 var $that = $(this);
1224 $that.closest('.tutor-media-upload-wrap').find('.tutor-media-upload-btn').html('<i class="tutor-icon-image1"></i>');
1225 $that.closest('.tutor-media-upload-wrap').find('input').val('');
1226 });
1227
1228 /**
1229 * Delay Function
1230 */
1231
1232 var tutor_delay = (function(){
1233 var timer = 0;
1234 return function(callback, ms){
1235 clearTimeout (timer);
1236 timer = setTimeout(callback, ms);
1237 };
1238 })();
1239
1240 /**
1241 * Add instructor modal
1242 */
1243 $(document).on('click', '.tutor-add-instructor-btn', function(e){
1244 e.preventDefault();
1245
1246 var $that = $(this);
1247 var course_id = $('#post_ID').val();
1248
1249 $.ajax({
1250 url : window._tutorobject.ajaxurl,
1251 type : 'POST',
1252 data : {course_id : course_id, action: 'tutor_load_instructors_modal'},
1253 beforeSend: function () {
1254 $that.addClass('tutor-updating-message');
1255 },
1256 success: function (data) {
1257 if (data.success){
1258 $('.tutor-instructors-modal-wrap .modal-container').html(data.data.output);
1259 $('.tutor-instructors-modal-wrap').addClass('show');
1260 }
1261 },
1262 complete: function () {
1263 $that.removeClass('tutor-updating-message');
1264 }
1265 });
1266 });
1267
1268 $(document).on('change keyup', '.tutor-instructors-modal-wrap .tutor-modal-search-input', function(e){
1269 e.preventDefault();
1270
1271 var $that = $(this);
1272 var $modal = $('.tutor-modal-wrap');
1273
1274 tutor_delay(function(){
1275 var search_terms = $that.val();
1276 var course_id = $('#post_ID').val();
1277
1278 $.ajax({
1279 url : window._tutorobject.ajaxurl,
1280 type : 'POST',
1281 data : {course_id : course_id, search_terms : search_terms, action: 'tutor_load_instructors_modal'},
1282 beforeSend: function () {
1283 $modal.addClass('loading');
1284 },
1285 success: function (data) {
1286 if (data.success){
1287 $('.tutor-instructors-modal-wrap .modal-container').html(data.data.output);
1288 $('.tutor-instructors-modal-wrap').addClass('show');
1289 }
1290 },
1291 complete: function () {
1292 $modal.removeClass('loading');
1293 }
1294 });
1295
1296 }, 1000)
1297 });
1298 $(document).on('click', '.add_instructor_to_course_btn', function(e){
1299 e.preventDefault();
1300
1301 var $that = $(this);
1302 var $modal = $('.tutor-modal-wrap');
1303 var course_id = $('#post_ID').val();
1304
1305 var data = $modal.find('input').serializeObject();
1306 data.course_id = course_id;
1307 data.action = 'tutor_add_instructors_to_course';
1308
1309 $.ajax({
1310 url : window._tutorobject.ajaxurl,
1311 type : 'POST',
1312 data : data,
1313 beforeSend: function () {
1314 $that.addClass('tutor-updating-message');
1315 },
1316 success: function (data) {
1317 if (data.success){
1318 $('.tutor-course-available-instructors').html(data.data.output);
1319 $('.tutor-modal-wrap').removeClass('show');
1320 }
1321 },
1322 complete: function () {
1323 $that.removeClass('tutor-updating-message');
1324 }
1325 });
1326 });
1327
1328 $(document).on('click', '.tutor-instructor-delete-btn', function(e){
1329 e.preventDefault();
1330
1331 var $that = $(this);
1332 var course_id = $('#post_ID').val();
1333 var instructor_id = $that.closest('.added-instructor-item').attr('data-instructor-id');
1334
1335 $.ajax({
1336 url : window._tutorobject.ajaxurl,
1337 type : 'POST',
1338 data : {course_id:course_id, instructor_id:instructor_id, action : 'detach_instructor_from_course'},
1339 success: function (data) {
1340 if (data.success){
1341 $that.closest('.added-instructor-item').remove();
1342 }
1343 }
1344 });
1345 });
1346
1347 $(document).on('click', '.settings-tabs-navs li', function(e){
1348 e.preventDefault();
1349
1350 var $that = $(this);
1351 var data_target = $that.find('a').attr('data-target');
1352 var url = $that.find('a').attr('href');
1353
1354 $that.addClass('active').siblings('li.active').removeClass('active');
1355 $('.settings-tab-wrap').removeClass('active').hide();
1356 $(data_target).addClass('active').show();
1357
1358 window.history.pushState({}, '', url);
1359 });
1360
1361 /**
1362 * Re init required
1363 * Modal Loaded...
1364 */
1365
1366 $(document).on('lesson_modal_loaded quiz_modal_loaded assignment_modal_loaded', function(e, obj){
1367 if (jQuery().select2){
1368 $('.select2_multiselect').select2({
1369 dropdownCssClass:'increasezindex'
1370 });
1371 }
1372 load_date_picker();
1373 });
1374 $(document).on('lesson_modal_loaded', function(e, obj){
1375 $('.tutor-lesson-modal-wrap .modal-title h1').html(__( 'Lesson', 'tutor' ));
1376 });
1377 $(document).on('assignment_modal_loaded', function(e, obj){
1378 $('.tutor-lesson-modal-wrap .modal-title h1').html(__( 'Assignment', 'tutor' ));
1379 });
1380
1381 /**
1382 * Tutor number validation
1383 *
1384 * @since v.1.6.3
1385 */
1386 $(document).on('keyup change', '.tutor-number-validation', function(e) {
1387 var input = $(this);
1388 var val = parseInt(input.val());
1389 var min = parseInt(input.attr('data-min'));
1390 var max = parseInt(input.attr('data-max'));
1391 if ( val < min ) {
1392 input.val(min);
1393 } else if ( val > max ) {
1394 input.val(max);
1395 }
1396 });
1397
1398 /*
1399 * @since v.1.6.4
1400 * Quiz Attempts Instructor Feedback
1401 */
1402 $(document).on('click', '.tutor-instructor-feedback', function(e) {
1403
1404 e.preventDefault();
1405 var $that = $(this);
1406
1407 $.ajax({
1408 url : (window.ajaxurl || _tutorobject.ajaxurl),
1409 type : 'POST',
1410 data : {attempts_id: $that.data('attemptid'), feedback: $('.tutor-instructor-feedback-content').val() , action: 'tutor_instructor_feedback'},
1411 beforeSend: function () {
1412 $that.addClass('tutor-updating-message');
1413 },
1414 success: function (data) {
1415 if (data.success){
1416 $that.closest('.course-content-item').remove();
1417 tutor_toast(__('Success', 'tutor'), $that.data('toast_success_message'), 'success');
1418 }
1419 },
1420 complete: function () {
1421 $that.removeClass('tutor-updating-message');
1422 }
1423 });
1424 });
1425
1426 /**
1427 * Since 1.7.9
1428 * Announcements scripts
1429 */
1430 var add_new_button = $(".tutor-announcement-add-new");
1431 var update_button = $(".tutor-announcement-edit");
1432 var delete_button = $(".tutor-announcement-delete");
1433 var details_button = $(".tutor-announcement-details");
1434 var close_button = $(".tutor-announcement-close-btn");
1435 var create_modal = $(".tutor-accouncement-create-modal");
1436 var update_modal = $(".tutor-accouncement-update-modal");
1437 var details_modal = $(".tutor-accouncement-details-modal");
1438 //open create modal
1439 $(add_new_button).click(function(){
1440 create_modal.addClass("show");
1441 $("#tutor-annoucement-backend-create-modal").addClass('show');
1442 })
1443
1444 $(details_button).click(function(){
1445 var announcement_date = $(this).attr('announcement-date');
1446 var announcement_id = $(this).attr('announcement-id');
1447 var course_id = $(this).attr('course-id');
1448 var course_name = $(this).attr('course-name');
1449 var announcement_title = $(this).attr('announcement-title');
1450 var announcement_summary = $(this).attr('announcement-summary');
1451
1452 $(".tutor-announcement-detail-content").html(`<h3>${announcement_title}</h3><p>${announcement_summary}</p>`);
1453 $(".tutor-announcement-detail-course-info p").html(`${course_name}`);
1454 $(".tutor-announcement-detail-date-info p").html(`${announcement_date}`);
1455 //set attr on edit button
1456 $("#tutor-announcement-edit-from-detail").attr('announcement-id',announcement_id);
1457 $("#tutor-announcement-edit-from-detail").attr('course-id',course_id);
1458 $("#tutor-announcement-edit-from-detail").attr('announcement-title',announcement_title);
1459 $("#tutor-announcement-edit-from-detail").attr('announcement-summary',announcement_summary);
1460 $("#tutor-announcement-delete-from-detail").attr('announcement-id',announcement_id);
1461 details_modal.addClass("show");
1462 })
1463
1464 //open update modal
1465 $(update_button).click(function(){
1466 if(details_modal){
1467 details_modal.removeClass('show');
1468 }
1469 var announcement_id = $(this).attr('announcement-id');
1470 var course_id = $(this).attr('course-id');
1471 var announcement_title = $(this).attr('announcement-title');
1472 var announcement_summary = $(this).attr('announcement-summary');
1473
1474 $("#tutor-announcement-course-id").val(course_id);
1475 $("#announcement_id").val(announcement_id);
1476 $("#tutor-announcement-title").val(announcement_title);
1477 $("#tutor-announcement-summary").val(announcement_summary);
1478
1479 update_modal.addClass("show");
1480 })
1481
1482 //close create and update modal
1483 $(close_button).click(function(){
1484 create_modal.removeClass("show");
1485 update_modal.removeClass("show");
1486 details_modal.removeClass("show");
1487 $("#tutor-annoucement-backend-create-modal").removeClass('show');
1488 })
1489
1490 //create announcement
1491 $(".tutor-announcements-form").on('submit',function(e){
1492 e.preventDefault();
1493 var $btn = $(this).find('button[type="submit"]');
1494 var formData = $(".tutor-announcements-form").serialize() + '&action=tutor_announcement_create' + '&action_type=create';
1495
1496 $.ajax({
1497 url : window._tutorobject.ajaxurl,
1498 type : 'POST',
1499 data : formData,
1500 beforeSend: function() {
1501 $btn.addClass('tutor-updating-message');
1502 },
1503 success: function(data) {
1504
1505 $(".tutor-alert").remove();
1506
1507 if(data.status=="success") {
1508 location.reload();
1509 }
1510
1511 if(data.status=="validation_error"){
1512 $(".tutor-announcements-create-alert").append(`<div class="tutor-alert alert-warning"></div>`);
1513 for(let [key,value] of Object.entries(data.message)){
1514
1515 $(".tutor-announcements-create-alert .tutor-alert").append(`<li>${value}</li>`);
1516 }
1517 }
1518 if(data.status=="fail"){
1519
1520 $(".tutor-announcements-create-alert").html(`<li>${data.message}</li>`);
1521
1522 }
1523 },
1524 error: function(data){
1525 console.log(data);
1526 }
1527 })
1528 })
1529 //update announcement
1530 $(".tutor-announcements-update-form").on('submit',function(e){
1531 e.preventDefault();
1532 var $btn = $(this).find('button[type="submit"]');
1533 var formData = $(".tutor-announcements-update-form").serialize() + '&action=tutor_announcement_create' + '&action_type=update';
1534
1535 $.ajax({
1536 url : window._tutorobject.ajaxurl,
1537 type : 'POST',
1538 data : formData,
1539 beforeSend: function() {
1540 $btn.addClass('tutor-updating-message');
1541 },
1542 success: function(data) {
1543
1544 $(".tutor-alert").remove();
1545 if(data.status=="success"){
1546 location.reload();
1547 }
1548 if(data.status=="validation_error"){
1549 $(".tutor-announcements-update-alert").append(`<div class="tutor-alert alert-warning"></div>`);
1550 for(let [key,value] of Object.entries(data.message)){
1551 $(".tutor-announcements-update-alert > .tutor-alert").append(`<li>${value}</li>`);
1552 }
1553 }
1554 if(data.status=="fail"){
1555
1556 $(".tutor-announcements-create-alert").html(`<li>${data.message}</li>`);
1557
1558 }
1559 },
1560 error: function(){
1561
1562 }
1563 })
1564 });
1565
1566 $(delete_button).click(function(){
1567 var announcement_id = $(this).attr('announcement-id');
1568 var whichtr = $("#tutor-announcement-tr-"+announcement_id);
1569 if(confirm("Do you want to delete?")){
1570 $.ajax({
1571 url : window._tutorobject.ajaxurl,
1572 type : 'POST',
1573 data : {action:'tutor_announcement_delete',announcement_id:announcement_id},
1574 beforeSend: function() {
1575
1576 },
1577 success: function(data) {
1578
1579 whichtr.remove();
1580 if(details_modal.length){
1581 details_modal.removeClass('show');
1582 }
1583 if(data.status == "fail"){
1584 console.log(data.message);
1585 }
1586 },
1587 error: function(){
1588
1589 }
1590 })
1591 }
1592 })
1593 //sorting
1594 // if (jQuery.datepicker){
1595 // $( "#tutor-announcement-datepicker" ).datepicker({"dateFormat" : 'yy-mm-dd'});
1596 // }
1597 function urlPrams(type, val){
1598 var url = new URL(window.location.href);
1599 var search_params = url.searchParams;
1600 search_params.set(type, val);
1601
1602 url.search = search_params.toString();
1603
1604 search_params.set('paged', 1);
1605 url.search = search_params.toString();
1606
1607 return url.toString();
1608 }
1609 $('.tutor-announcement-course-sorting').on('change', function(e){
1610 window.location = urlPrams( 'course-id', $(this).val() );
1611 });
1612 $('.tutor-announcement-order-sorting').on('change', function(e){
1613 window.location = urlPrams( 'order', $(this).val() );
1614 });
1615 $('.tutor-announcement-date-sorting').on('change', function(e){
1616 window.location = urlPrams( 'date', $(this).val() );
1617 });
1618 $('.tutor-announcement-search-sorting').on('click', function(e){
1619 window.location = urlPrams( 'search', $(".tutor-announcement-search-field").val() );
1620 });
1621 //dropdown toggle
1622 $(document).click(function(){
1623 $(".tutor-dropdown").removeClass('show');
1624 });
1625
1626 $(".tutor-dropdown").click(function(e){
1627 e.stopPropagation();
1628 if ( $('.tutor-dropdown').hasClass('show') ) {
1629 $('.tutor-dropdown').removeClass('show')
1630 }
1631 $(this).addClass('show');
1632 });
1633
1634 //announcement end
1635
1636
1637
1638 /**
1639 * @since v.1.9.0
1640 * Parse and show video duration on link paste in lesson video
1641 */
1642 var video_url_input = '.video_source_wrap_external_url input, .video_source_wrap_vimeo input, .video_source_wrap_youtube input, .video_source_wrap_html5, .video_source_upload_wrap_html5';
1643 var autofill_url_timeout;
1644 $('body').on('paste', video_url_input, function(e) {
1645 e.stopImmediatePropagation();
1646
1647 var root = $(this).closest('.lesson-modal-form-wrap').find('.tutor-option-field-video-duration');
1648 var duration_label = root.find('label');
1649 var is_wp_media = $(this).hasClass('video_source_wrap_html5') || $(this).hasClass('video_source_upload_wrap_html5');
1650 var autofill_url = $(this).data('autofill_url');
1651 $(this).data('autofill_url', null);
1652
1653 var video_url = is_wp_media ? $(this).find('span').data('video_url') : (autofill_url || e.originalEvent.clipboardData.getData('text'));
1654
1655 var toggle_loading = function(show) {
1656
1657 if(!show) {
1658 duration_label.find('img').remove();
1659 return;
1660 }
1661
1662 // Show loading icon
1663 if(duration_label.find('img').length==0) {
1664 duration_label.append(' <img src="'+window._tutorobject.loading_icon_url+'" style="display:inline-block"/>');
1665 }
1666 }
1667
1668 var set_duration = function(sec_num) {
1669 var hours = Math.floor(sec_num / 3600);
1670 var minutes = Math.floor((sec_num - (hours * 3600)) / 60);
1671 var seconds = Math.round( sec_num - (hours * 3600) - (minutes * 60) );
1672
1673 if (hours < 10) {hours = "0"+hours;}
1674 if (minutes < 10) {minutes = "0"+minutes;}
1675 if (seconds < 10) {seconds = "0"+seconds;}
1676
1677 var fragments = [hours, minutes, seconds];
1678 var time_fields = root.find('input');
1679 for(var i=0; i<3; i++) {
1680 time_fields.eq(i).val(fragments[i]);
1681 }
1682 }
1683
1684 var yt_to_seconds = function (duration) {
1685 var match = duration.match(/PT(\d+H)?(\d+M)?(\d+S)?/);
1686
1687 match = match.slice(1).map(function(x) {
1688 if (x != null) {
1689 return x.replace(/\D/, '');
1690 }
1691 });
1692
1693 var hours = (parseInt(match[0]) || 0);
1694 var minutes = (parseInt(match[1]) || 0);
1695 var seconds = (parseInt(match[2]) || 0);
1696
1697 return hours * 3600 + minutes * 60 + seconds;
1698 }
1699
1700 if(is_wp_media || $(this).parent().hasClass('video_source_wrap_external_url')) {
1701 var player = document.createElement('video');
1702 player.addEventListener('loadedmetadata', function() {
1703 set_duration( player.duration );
1704 toggle_loading(false);
1705 });
1706
1707 toggle_loading(true);
1708 player.src = video_url;
1709
1710 } else if($(this).parent().hasClass('video_source_wrap_vimeo')) {
1711
1712 var regExp = /^.*(vimeo\.com\/)((channels\/[A-z]+\/)|(groups\/[A-z]+\/videos\/))?([0-9]+)/;
1713 var match = video_url.match(regExp);
1714 var video_id = match ? match[5] : null;
1715
1716 if(video_id) {
1717 toggle_loading(true);
1718
1719 $.getJSON('http://vimeo.com/api/v2/video/'+video_id+'/json', function(data) {
1720 if(Array.isArray(data) && data[0] && data[0].duration!==undefined) {
1721 set_duration(data[0].duration);
1722 }
1723
1724 toggle_loading(false);
1725 });
1726 }
1727 } else if($(this).parent().hasClass('video_source_wrap_youtube')) {
1728 var regExp = /^.*((youtu.be\/)|(v\/)|(\/u\/\w\/)|(embed\/)|(watch\?))\??v?=?([^#&?]*).*/;
1729 var match = video_url.match(regExp);
1730 var video_id = (match && match[7].length==11) ? match[7] : false;
1731 var api_key = $(this).data('youtube_api_key');
1732
1733 if(video_id && api_key) {
1734
1735 var result_url = 'https://www.googleapis.com/youtube/v3/videos?id='+video_id+'&key='+api_key+'&part=contentDetails';
1736 toggle_loading(true);
1737
1738 $.getJSON(result_url, function(data) {
1739 if(typeof data=='object' && data.items && data.items[0] && data.items[0].contentDetails && data.items[0].contentDetails.duration) {
1740 set_duration( yt_to_seconds(data.items[0].contentDetails.duration) );
1741 }
1742
1743 toggle_loading(false);
1744 });
1745 }
1746 }
1747 }).on('input', video_url_input, function() {
1748
1749 if(autofill_url_timeout) {
1750 clearTimeout(autofill_url_timeout);
1751 }
1752
1753 var $this = $(this);
1754 autofill_url_timeout = setTimeout(function() {
1755 var val = $this.val();
1756 val = val ? val.trim() : '';
1757 console.log('Trigger', val);
1758 val ? $this.data('autofill_url', val).trigger('paste') : 0;
1759 }, 700);
1760 });
1761
1762 /**
1763 * @since v.1.8.6
1764 * SUbmit form through ajax
1765 */
1766 $('.tutor-form-submit-through-ajax').submit(function(e) {
1767 e.preventDefault();
1768
1769 var $that = $(this);
1770 var url = $(this).attr('action') || window.location.href;
1771 var type = $(this).attr('method') || 'GET';
1772 var data = $(this).serializeObject();
1773
1774 $that.find('button').addClass('tutor-updating-message');
1775
1776 $.ajax({
1777 url: url,
1778 type: type,
1779 data: data,
1780 success: function() {
1781 tutor_toast(__('Success', 'tutor'), $that.data('toast_success_message'), 'success');
1782 },
1783 complete: function () {
1784 $that.find('button').removeClass('tutor-updating-message');
1785 }
1786 });
1787 });
1788
1789 /*
1790 * @since v.1.7.9
1791 * Send wp nonce to every ajax request
1792 */
1793 $.ajaxSetup({data : tutor_get_nonce_data()});
1794 });
1795
1796 jQuery.fn.serializeObject = function()
1797 {
1798 var values = {};
1799 var array = this.serializeArray();
1800
1801 jQuery.each(array, function() {
1802 if (values[this.name]) {
1803 if (!values[this.name].push) {
1804 values[this.name] = [values[this.name]];
1805 }
1806 values[this.name].push(this.value || '');
1807 } else {
1808 values[this.name] = this.value || '';
1809 }
1810 });
1811
1812 return values;
1813 };
1814
1815 function tutor_toast(title, description, type) {
1816 var tutor_ob = window._tutorobject || {};
1817 var asset = (tutor_ob.tutor_url || '') + 'assets/images/';
1818
1819 if(!jQuery('.tutor-toast-parent').length) {
1820 jQuery('body').append('<div class="tutor-toast-parent"></div>');
1821 }
1822
1823 var icons = {
1824 success : asset+'icon-check.svg',
1825 error: asset+'icon-cross.svg'
1826 }
1827
1828 var content = jQuery('\
1829 <div>\
1830 <div>\
1831 <img src="'+icons[type]+'"/>\
1832 </div>\
1833 <div>\
1834 <div>\
1835 <b>'+title+'</b>\
1836 <span>'+description+'</span>\
1837 </div>\
1838 </div>\
1839 <div>\
1840 <i class="tutor-toast-close tutor-icon-line-cross"></i>\
1841 </div>\
1842 </div>');
1843
1844 content.find('.tutor-toast-close').click(function() {
1845 content.remove();
1846 });
1847
1848 jQuery('.tutor-toast-parent').append(content);
1849
1850 setTimeout(function() {
1851 if(content) {
1852 content.fadeOut('fast', function() {
1853 jQuery(this).remove();
1854 });
1855 }
1856 }, 5000);
1857 }
1858
1859 /**
1860 * Add option disable when don't need to add an option
1861 *
1862 * @since 1.9.7
1863 */
1864 function disableAddoption() {
1865 const selected_question_type = document.querySelector(".tutor_select_value_holder").value;
1866 const question_answers = document.getElementById("tutor_quiz_question_answers");
1867 const question_answer_form = document.getElementById("tutor_quiz_question_answer_form");
1868 const add_question_answer_option = document.querySelector(".add_question_answers_option");
1869
1870 const addDisabledClass = (elem) => {
1871 if ( !elem.classList.contains("disabled") ) {
1872 elem.classList.add('disabled');
1873 }
1874 }
1875
1876 const removeDisabledClass = (elem) => {
1877 if ( elem.classList.contains("disabled") ) {
1878 elem.classList.remove('disabled');
1879 }
1880 }
1881
1882 //dont need add option for open_ended & short_answer
1883 if ( selected_question_type === 'open_ended' || selected_question_type === 'short_answer' ) {
1884 addDisabledClass(add_question_answer_option);
1885 } else if ( selected_question_type === 'true_false' || selected_question_type === 'fill_in_the_blank' ) {
1886 //if already have options then dont need to show add option
1887 if ( question_answer_form.hasChildNodes() || question_answers.hasChildNodes() ) {
1888 addDisabledClass(add_question_answer_option);
1889 } else {
1890 removeDisabledClass(add_question_answer_option);
1891 }
1892 } else {
1893 //if other question type then remove disabled
1894 removeDisabledClass(add_question_answer_option);
1895 }
1896 }