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