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