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