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-front.js
2095 lines
| 1 | jQuery(document).ready(function ($) { |
| 2 | 'use strict'; |
| 3 | |
| 4 | /** |
| 5 | * Initiate Select2 |
| 6 | * @since v.1.3.4 |
| 7 | */ |
| 8 | if (jQuery().select2) { |
| 9 | $('.tutor_select2').select2({ |
| 10 | escapeMarkup: function (markup) { |
| 11 | return markup; |
| 12 | } |
| 13 | }); |
| 14 | } |
| 15 | //END: select2 |
| 16 | |
| 17 | |
| 18 | /*! |
| 19 | * jQuery UI Touch Punch 0.2.3 |
| 20 | * |
| 21 | * Copyright 2011–2014, Dave Furfero |
| 22 | * Dual licensed under the MIT or GPL Version 2 licenses. |
| 23 | * |
| 24 | * Depends: |
| 25 | * jquery.ui.widget.js |
| 26 | * jquery.ui.mouse.js |
| 27 | */ |
| 28 | !function (a) { function f(a, b) { if (!(a.originalEvent.touches.length > 1)) { a.preventDefault(); var c = a.originalEvent.changedTouches[0], d = document.createEvent("MouseEvents"); d.initMouseEvent(b, !0, !0, window, 1, c.screenX, c.screenY, c.clientX, c.clientY, !1, !1, !1, !1, 0, null), a.target.dispatchEvent(d) } } if (a.support.touch = "ontouchend" in document, a.support.touch) { var e, b = a.ui.mouse.prototype, c = b._mouseInit, d = b._mouseDestroy; b._touchStart = function (a) { var b = this; !e && b._mouseCapture(a.originalEvent.changedTouches[0]) && (e = !0, b._touchMoved = !1, f(a, "mouseover"), f(a, "mousemove"), f(a, "mousedown")) }, b._touchMove = function (a) { e && (this._touchMoved = !0, f(a, "mousemove")) }, b._touchEnd = function (a) { e && (f(a, "mouseup"), f(a, "mouseout"), this._touchMoved || f(a, "click"), e = !1) }, b._mouseInit = function () { var b = this; b.element.bind({ touchstart: a.proxy(b, "_touchStart"), touchmove: a.proxy(b, "_touchMove"), touchend: a.proxy(b, "_touchEnd") }), c.call(b) }, b._mouseDestroy = function () { var b = this; b.element.unbind({ touchstart: a.proxy(b, "_touchStart"), touchmove: a.proxy(b, "_touchMove"), touchend: a.proxy(b, "_touchEnd") }), d.call(b) } } }(jQuery); |
| 29 | |
| 30 | /** |
| 31 | * END jQuery UI Touch Punch |
| 32 | */ |
| 33 | |
| 34 | |
| 35 | /* $(document).on('change', '.tutor-course-filter-form', function (e) { |
| 36 | e.preventDefault(); |
| 37 | $(this).closest('form').submit(); |
| 38 | }); */ |
| 39 | |
| 40 | const videoPlayer = { |
| 41 | ajaxurl: _tutorobject.ajaxurl, |
| 42 | nonce_key: _tutorobject.nonce_key, |
| 43 | video_data: function () { |
| 44 | const video_track_data = $('#tutor_video_tracking_information').val(); |
| 45 | return video_track_data ? JSON.parse(video_track_data) : {}; |
| 46 | }, |
| 47 | track_player: function () { |
| 48 | const that = this; |
| 49 | if (typeof Plyr !== 'undefined') { |
| 50 | const player = new Plyr('#tutorPlayer'); |
| 51 | const video_data = that.video_data(); |
| 52 | player.on('ready', function (event) { |
| 53 | const instance = event.detail.plyr; |
| 54 | const { best_watch_time } = video_data; |
| 55 | if (best_watch_time > 0 && instance.duration > Math.round(best_watch_time)) { |
| 56 | instance.media.currentTime = best_watch_time; |
| 57 | } |
| 58 | that.sync_time(instance); |
| 59 | }); |
| 60 | |
| 61 | let tempTimeNow = 0; |
| 62 | let intervalSeconds = 30; //Send to tutor backend about video playing time in this interval |
| 63 | player.on('timeupdate', function (event) { |
| 64 | const instance = event.detail.plyr; |
| 65 | const tempTimeNowInSec = (tempTimeNow / 4); //timeupdate firing 250ms interval |
| 66 | if (tempTimeNowInSec >= intervalSeconds) { |
| 67 | that.sync_time(instance); |
| 68 | tempTimeNow = 0; |
| 69 | } |
| 70 | tempTimeNow++; |
| 71 | }); |
| 72 | |
| 73 | player.on('ended', function (event) { |
| 74 | const video_data = that.video_data(); |
| 75 | const instance = event.detail.plyr; |
| 76 | const data = { is_ended: true }; |
| 77 | that.sync_time(instance, data); |
| 78 | if (video_data.autoload_next_course_content) { |
| 79 | that.autoload_content(); |
| 80 | } |
| 81 | }); |
| 82 | } |
| 83 | }, |
| 84 | sync_time: function (instance, options) { |
| 85 | const post_id = this.video_data().post_id; |
| 86 | //TUTOR is sending about video playback information to server. |
| 87 | let data = { action: 'sync_video_playback', currentTime: instance.currentTime, duration: instance.duration, post_id }; |
| 88 | data[this.nonce_key] = _tutorobject[this.nonce_key]; |
| 89 | let data_send = data; |
| 90 | if (options) { |
| 91 | data_send = Object.assign(data, options); |
| 92 | } |
| 93 | $.post(this.ajaxurl, data_send); |
| 94 | }, |
| 95 | autoload_content: function () { |
| 96 | const post_id = this.video_data().post_id; |
| 97 | const data = { action: 'autoload_next_course_content', post_id }; |
| 98 | data[this.nonce_key] = _tutorobject[this.nonce_key]; |
| 99 | $.post(this.ajaxurl, data).done(function (response) { |
| 100 | if (response.success && response.data.next_url) { |
| 101 | location.href = response.data.next_url; |
| 102 | } |
| 103 | }); |
| 104 | }, |
| 105 | init: function () { |
| 106 | this.track_player(); |
| 107 | } |
| 108 | }; |
| 109 | |
| 110 | /** |
| 111 | * Fire TUTOR video |
| 112 | * @since v.1.0.0 |
| 113 | */ |
| 114 | if ($('#tutorPlayer').length) { |
| 115 | videoPlayer.init(); |
| 116 | } |
| 117 | |
| 118 | $(document).on('change keyup paste', '.tutor_user_name', function () { |
| 119 | $(this).val(tutor_slugify($(this).val())); |
| 120 | }); |
| 121 | |
| 122 | function tutor_slugify(text) { |
| 123 | return text.toString().toLowerCase() |
| 124 | .replace(/\s+/g, '-') // Replace spaces with - |
| 125 | .replace(/[^\w\-]+/g, '') // Remove all non-word chars |
| 126 | .replace(/\-\-+/g, '-') // Replace multiple - with single - |
| 127 | .replace(/^-+/, '') // Trim - from start of text |
| 128 | .replace(/-+$/, ''); // Trim - from end of text |
| 129 | } |
| 130 | |
| 131 | function toggle_star_(star){ |
| 132 | star.add(star.prevAll()).filter('i').addClass('tutor-icon-star-full').removeClass('tutor-icon-star-line'); |
| 133 | star.nextAll().filter('i').removeClass('tutor-icon-star-full').addClass('tutor-icon-star-line'); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Hover tutor rating and set value |
| 138 | */ |
| 139 | $(document).on('mouseover', '.tutor-write-review-box .tutor-star-rating-group i', function () { |
| 140 | toggle_star_($(this)); |
| 141 | }); |
| 142 | |
| 143 | $(document).on('click', '.tutor-write-review-box .tutor-star-rating-group i', function () { |
| 144 | var rating = $(this).attr('data-rating-value'); |
| 145 | $(this).closest('.tutor-star-rating-group').find('input[name="tutor_rating_gen_input"]').val(rating); |
| 146 | |
| 147 | toggle_star_($(this)); |
| 148 | }); |
| 149 | |
| 150 | $(document).on('mouseout', '.tutor-write-review-box .tutor-star-rating-group', function(){ |
| 151 | var value = $(this).find('input[name="tutor_rating_gen_input"]').val(); |
| 152 | var rating = parseInt(value); |
| 153 | |
| 154 | var selected = $(this).find('[data-rating-value="'+rating+'"]'); |
| 155 | (rating && selected && selected.length>0) ? toggle_star_(selected) : $(this).find('i').removeClass('tutor-icon-star-full').addClass('tutor-icon-star-line'); |
| 156 | }); |
| 157 | |
| 158 | $(document).on('click', '.tutor_submit_review_btn', function (e) { |
| 159 | e.preventDefault(); |
| 160 | var $that = $(this); |
| 161 | var rating = $that.closest('form').find('input[name="tutor_rating_gen_input"]').val(); |
| 162 | var review = $that.closest('form').find('textarea[name="review"]').val(); |
| 163 | review = review.trim(); |
| 164 | |
| 165 | var course_id = $('input[name="tutor_course_id"]').val(); |
| 166 | var data = { course_id: course_id, rating: rating, review: review, action: 'tutor_place_rating' }; |
| 167 | |
| 168 | if (review) { |
| 169 | $.ajax({ |
| 170 | url: _tutorobject.ajaxurl, |
| 171 | type: 'POST', |
| 172 | data: data, |
| 173 | beforeSend: function () { |
| 174 | $that.addClass('updating-icon'); |
| 175 | }, |
| 176 | success: function (data) { |
| 177 | var review_id = data.data.review_id; |
| 178 | var review = data.data.review; |
| 179 | $('.tutor-review-' + review_id + ' .review-content').html(review); |
| 180 | location.reload(); |
| 181 | } |
| 182 | }); |
| 183 | } |
| 184 | }); |
| 185 | |
| 186 | $(document).on('click', '.write-course-review-link-btn', function (e) { |
| 187 | e.preventDefault(); |
| 188 | $(this).siblings('.tutor-write-review-form').slideToggle(); |
| 189 | }); |
| 190 | |
| 191 | $(document).on('click', '.tutor-ask-question-btn', function (e) { |
| 192 | e.preventDefault(); |
| 193 | $('.tutor-add-question-wrap').slideToggle(); |
| 194 | }); |
| 195 | $(document).on('click', '.tutor_question_cancel', function (e) { |
| 196 | e.preventDefault(); |
| 197 | $('.tutor-add-question-wrap').toggle(); |
| 198 | }); |
| 199 | |
| 200 | $(document).on('submit', '#tutor-ask-question-form', function (e) { |
| 201 | e.preventDefault(); |
| 202 | |
| 203 | var $form = $(this); |
| 204 | var data = $(this).serialize() + '&action=tutor_ask_question'; |
| 205 | |
| 206 | $.ajax({ |
| 207 | url: _tutorobject.ajaxurl, |
| 208 | type: 'POST', |
| 209 | data: data, |
| 210 | beforeSend: function () { |
| 211 | $form.find('.tutor_ask_question_btn').addClass('updating-icon'); |
| 212 | }, |
| 213 | success: function (data) { |
| 214 | if (data.success) { |
| 215 | $('.tutor-add-question-wrap').hide(); |
| 216 | window.location.reload(); |
| 217 | } |
| 218 | }, |
| 219 | complete: function () { |
| 220 | $form.find('.tutor_ask_question_btn').removeClass('updating-icon'); |
| 221 | } |
| 222 | }); |
| 223 | }); |
| 224 | |
| 225 | $(document).on('submit', '.tutor-add-answer-form', function (e) { |
| 226 | e.preventDefault(); |
| 227 | |
| 228 | var $form = $(this); |
| 229 | var data = $(this).serialize() + '&action=tutor_add_answer'; |
| 230 | |
| 231 | $.ajax({ |
| 232 | url: _tutorobject.ajaxurl, |
| 233 | type: 'POST', |
| 234 | data: data, |
| 235 | beforeSend: function () { |
| 236 | $form.find('.tutor_add_answer_btn').addClass('updating-icon'); |
| 237 | }, |
| 238 | success: function (data) { |
| 239 | if (data.success) { |
| 240 | window.location.reload(); |
| 241 | } |
| 242 | }, |
| 243 | complete: function () { |
| 244 | $form.find('.tutor_add_answer_btn').removeClass('updating-icon'); |
| 245 | } |
| 246 | }); |
| 247 | }); |
| 248 | |
| 249 | $(document).on('focus', '.tutor_add_answer_textarea', function (e) { |
| 250 | e.preventDefault(); |
| 251 | |
| 252 | var question_id = $(this).closest('.tutor_add_answer_wrap').attr('data-question-id'); |
| 253 | var conf = { |
| 254 | tinymce: { |
| 255 | wpautop: true, |
| 256 | //plugins : 'charmap colorpicker compat3x directionality fullscreen hr image lists media paste tabfocus textcolor wordpress wpautoresize wpdialogs wpeditimage wpemoji wpgallery wplink wptextpattern wpview', |
| 257 | toolbar1: 'bold italic underline bullist strikethrough numlist blockquote alignleft aligncenter alignright undo redo link unlink spellchecker fullscreen' |
| 258 | }, |
| 259 | }; |
| 260 | wp.editor.initialize('tutor_answer_' + question_id, conf); |
| 261 | }); |
| 262 | |
| 263 | $(document).on('click', '.tutor_cancel_wp_editor', function (e) { |
| 264 | e.preventDefault(); |
| 265 | $(this).closest('.tutor_wp_editor_wrap').toggle(); |
| 266 | $(this).closest('.tutor_add_answer_wrap').find('.tutor_wp_editor_show_btn_wrap').toggle(); |
| 267 | var question_id = $(this).closest('.tutor_add_answer_wrap').attr('data-question-id'); |
| 268 | wp.editor.remove('tutor_answer_' + question_id); |
| 269 | }); |
| 270 | |
| 271 | $(document).on('click', '.tutor_wp_editor_show_btn', function (e) { |
| 272 | e.preventDefault(); |
| 273 | $(this).closest('.tutor_add_answer_wrap').find('.tutor_wp_editor_wrap').toggle(); |
| 274 | $(this).closest('.tutor_wp_editor_show_btn_wrap').toggle(); |
| 275 | }); |
| 276 | |
| 277 | /** |
| 278 | * Quiz attempt |
| 279 | */ |
| 280 | var $tutor_quiz_time_update = $('#tutor-quiz-time-update'); |
| 281 | var attempt_settings = null; |
| 282 | if ($tutor_quiz_time_update.length) { |
| 283 | attempt_settings = JSON.parse($tutor_quiz_time_update.attr('data-attempt-settings')); |
| 284 | var attempt_meta = JSON.parse($tutor_quiz_time_update.attr('data-attempt-meta')); |
| 285 | |
| 286 | if (attempt_meta.time_limit.time_limit_seconds > 0) { |
| 287 | //No time Zero limit for |
| 288 | var countDownDate = new Date(attempt_settings.attempt_started_at).getTime() + (attempt_meta.time_limit.time_limit_seconds * 1000); |
| 289 | var time_now = new Date(attempt_meta.date_time_now).getTime(); |
| 290 | |
| 291 | var tutor_quiz_interval = setInterval(function () { |
| 292 | var distance = countDownDate - time_now; |
| 293 | |
| 294 | var days = Math.floor(distance / (1000 * 60 * 60 * 24)); |
| 295 | var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); |
| 296 | var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); |
| 297 | var seconds = Math.floor((distance % (1000 * 60)) / 1000); |
| 298 | |
| 299 | var countdown_human = ''; |
| 300 | |
| 301 | if (days) { |
| 302 | countdown_human += days + "d "; |
| 303 | } |
| 304 | if (hours) { |
| 305 | countdown_human += hours + "h "; |
| 306 | } |
| 307 | if (minutes) { |
| 308 | countdown_human += minutes + "m "; |
| 309 | } |
| 310 | if (seconds) { |
| 311 | countdown_human += seconds + "s "; |
| 312 | } |
| 313 | |
| 314 | if (distance < 0) { |
| 315 | clearInterval(tutor_quiz_interval); |
| 316 | countdown_human = "EXPIRED"; |
| 317 | //Set the quiz attempt to timeout in ajax |
| 318 | |
| 319 | if (_tutorobject.quiz_options.quiz_when_time_expires === 'autosubmit') { |
| 320 | /** |
| 321 | * Auto Submit |
| 322 | */ |
| 323 | $('form#tutor-answering-quiz').submit(); |
| 324 | |
| 325 | } else if (_tutorobject.quiz_options.quiz_when_time_expires === 'autoabandon') { |
| 326 | /** |
| 327 | * |
| 328 | * @type {jQuery} |
| 329 | * |
| 330 | * Current attempt will be cancel with attempt status attempt_timeout |
| 331 | */ |
| 332 | |
| 333 | var quiz_id = $('#tutor_quiz_id').val(); |
| 334 | var tutor_quiz_remaining_time_secs = $('#tutor_quiz_remaining_time_secs').val(); |
| 335 | var quiz_timeout_data = { quiz_id: quiz_id, action: 'tutor_quiz_timeout' }; |
| 336 | |
| 337 | $.ajax({ |
| 338 | url: _tutorobject.ajaxurl, |
| 339 | type: 'POST', |
| 340 | data: quiz_timeout_data, |
| 341 | success: function (data) { |
| 342 | if (data.success) { |
| 343 | window.location.reload(true); |
| 344 | } |
| 345 | }, |
| 346 | complete: function () { |
| 347 | $('#tutor-quiz-body').html(''); |
| 348 | window.location.reload(true); |
| 349 | } |
| 350 | }); |
| 351 | } |
| 352 | |
| 353 | } |
| 354 | time_now = time_now + 1000; |
| 355 | $tutor_quiz_time_update.html(countdown_human); |
| 356 | }, 1000); |
| 357 | } else { |
| 358 | $tutor_quiz_time_update.closest('.time-remaining').remove(); |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | var $quiz_start_form = $('#tutor-quiz-body form#tutor-start-quiz'); |
| 363 | if ($quiz_start_form.length) { |
| 364 | if (_tutorobject.quiz_options.quiz_auto_start === '1') { |
| 365 | $quiz_start_form.submit(); |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | /** |
| 370 | * Quiz Frontend Review Action |
| 371 | * @since 1.4.0 |
| 372 | */ |
| 373 | $(document).on('click', '.quiz-manual-review-action', function (e) { |
| 374 | e.preventDefault(); |
| 375 | var $that = $(this), |
| 376 | attempt_id = $that.attr('data-attempt-id'), |
| 377 | attempt_answer_id = $that.attr('data-attempt-answer-id'), |
| 378 | mark_as = $that.attr('data-mark-as'); |
| 379 | |
| 380 | $.ajax({ |
| 381 | url: _tutorobject.ajaxurl, |
| 382 | type: 'GET', |
| 383 | data: { action: 'review_quiz_answer', attempt_id: attempt_id, attempt_answer_id: attempt_answer_id, mark_as: mark_as }, |
| 384 | beforeSend: function () { |
| 385 | $that.find('i').addClass('updating-icon'); |
| 386 | }, |
| 387 | success: function (data) { |
| 388 | location.reload(); |
| 389 | }, |
| 390 | complete: function () { |
| 391 | $that.find('i').removeClass('updating-icon'); |
| 392 | } |
| 393 | }); |
| 394 | }); |
| 395 | |
| 396 | // Quiz Review : Tooltip |
| 397 | $(".tooltip-btn").on("hover", function (e) { |
| 398 | $(this).toggleClass("active"); |
| 399 | }); |
| 400 | |
| 401 | // tutor course content accordion |
| 402 | |
| 403 | /** |
| 404 | * Toggle topic summery |
| 405 | * @since v.1.6.9 |
| 406 | */ |
| 407 | $('.tutor-course-title h4 .toogle-informaiton-icon').on('click', function (e) { |
| 408 | $(this).closest('.tutor-topics-in-single-lesson').find('.tutor-topics-summery').slideToggle(); |
| 409 | e.stopPropagation(); |
| 410 | }); |
| 411 | |
| 412 | $('.tutor-course-topic.tutor-active').find('.tutor-course-lessons').slideDown(); |
| 413 | $('.tutor-course-title').on('click', function () { |
| 414 | var lesson = $(this).siblings('.tutor-course-lessons'); |
| 415 | $(this).closest('.tutor-course-topic').toggleClass('tutor-active'); |
| 416 | lesson.slideToggle(); |
| 417 | }); |
| 418 | |
| 419 | $(document).on('click', '.tutor-topics-title h3 .toogle-informaiton-icon', function (e) { |
| 420 | $(this).closest('.tutor-topics-in-single-lesson').find('.tutor-topics-summery').slideToggle(); |
| 421 | e.stopPropagation(); |
| 422 | }); |
| 423 | |
| 424 | $(document).on('click', '.tutor-course-wishlist-btn', function (e) { |
| 425 | e.preventDefault(); |
| 426 | |
| 427 | var $that = $(this); |
| 428 | var course_id = $that.attr('data-course-id'); |
| 429 | |
| 430 | $.ajax({ |
| 431 | url: _tutorobject.ajaxurl, |
| 432 | type: 'POST', |
| 433 | data: { course_id: course_id, 'action': 'tutor_course_add_to_wishlist' }, |
| 434 | beforeSend: function () { |
| 435 | $that.addClass('updating-icon'); |
| 436 | }, |
| 437 | success: function (data) { |
| 438 | if (data.success) { |
| 439 | if (data.data.status === 'added') { |
| 440 | $that.addClass('has-wish-listed'); |
| 441 | } else { |
| 442 | $that.removeClass('has-wish-listed'); |
| 443 | } |
| 444 | } else { |
| 445 | window.location = data.data.redirect_to; |
| 446 | } |
| 447 | }, |
| 448 | complete: function () { |
| 449 | $that.removeClass('updating-icon'); |
| 450 | } |
| 451 | }); |
| 452 | }); |
| 453 | |
| 454 | /** |
| 455 | * Check if lesson has classic editor support |
| 456 | * If classic editor support, stop ajax load on the lesson page. |
| 457 | * |
| 458 | * @since v.1.0.0 |
| 459 | * |
| 460 | * @updated v.1.4.0 |
| 461 | */ |
| 462 | if (!_tutorobject.enable_lesson_classic_editor) { |
| 463 | |
| 464 | $(document).on('click', '.tutor-single-lesson-a', function (e) { |
| 465 | e.preventDefault(); |
| 466 | |
| 467 | var $that = $(this); |
| 468 | var lesson_id = $that.attr('data-lesson-id'); |
| 469 | var $wrap = $('#tutor-single-entry-content'); |
| 470 | |
| 471 | $.ajax({ |
| 472 | url: _tutorobject.ajaxurl, |
| 473 | type: 'POST', |
| 474 | data: { lesson_id: lesson_id, 'action': 'tutor_render_lesson_content' }, |
| 475 | beforeSend: function () { |
| 476 | var page_title = $that.find('.lesson_title').text(); |
| 477 | $('head title').text(page_title); |
| 478 | window.history.pushState('obj', page_title, $that.attr('href')); |
| 479 | $wrap.addClass('loading-lesson'); |
| 480 | $('.tutor-single-lesson-items').removeClass('active'); |
| 481 | $that.closest('.tutor-single-lesson-items').addClass('active'); |
| 482 | }, |
| 483 | success: function (data) { |
| 484 | $wrap.html(data.data.html); |
| 485 | videoPlayer.init(); |
| 486 | $('.tutor-lesson-sidebar').css('display', ''); |
| 487 | }, |
| 488 | complete: function () { |
| 489 | $wrap.removeClass('loading-lesson'); |
| 490 | } |
| 491 | }); |
| 492 | }); |
| 493 | |
| 494 | $(document).on('click', '.sidebar-single-quiz-a', function (e) { |
| 495 | e.preventDefault(); |
| 496 | |
| 497 | var $that = $(this); |
| 498 | var quiz_id = $that.attr('data-quiz-id'); |
| 499 | var page_title = $that.find('.lesson_title').text(); |
| 500 | var $wrap = $('#tutor-single-entry-content'); |
| 501 | |
| 502 | $.ajax({ |
| 503 | url: _tutorobject.ajaxurl, |
| 504 | type: 'POST', |
| 505 | data: { quiz_id: quiz_id, 'action': 'tutor_render_quiz_content' }, |
| 506 | beforeSend: function () { |
| 507 | $('head title').text(page_title); |
| 508 | window.history.pushState('obj', page_title, $that.attr('href')); |
| 509 | $wrap.addClass('loading-lesson'); |
| 510 | $('.tutor-single-lesson-items').removeClass('active'); |
| 511 | $that.closest('.tutor-single-lesson-items').addClass('active'); |
| 512 | }, |
| 513 | success: function (data) { |
| 514 | $wrap.html(data.data.html); |
| 515 | init_quiz_builder(); |
| 516 | $('.tutor-lesson-sidebar').css('display', ''); |
| 517 | }, |
| 518 | complete: function () { |
| 519 | $wrap.removeClass('loading-lesson'); |
| 520 | } |
| 521 | }); |
| 522 | }); |
| 523 | } |
| 524 | |
| 525 | /** |
| 526 | * @date 05 Feb, 2019 |
| 527 | */ |
| 528 | |
| 529 | $(document).on('click', '.tutor-lesson-sidebar-hide-bar', function (e) { |
| 530 | e.preventDefault(); |
| 531 | $('.tutor-lesson-sidebar').toggle(); |
| 532 | $('#tutor-single-entry-content').toggleClass("sidebar-hidden"); |
| 533 | |
| 534 | }); |
| 535 | |
| 536 | $(".tutor-tabs-btn-group a").on('click touchstart', function (e) { |
| 537 | e.preventDefault(); |
| 538 | var $that = $(this); |
| 539 | var tabSelector = $that.attr('href'); |
| 540 | $('.tutor-lesson-sidebar-tab-item').hide(); |
| 541 | $(tabSelector).show(); |
| 542 | |
| 543 | $('.tutor-tabs-btn-group a').removeClass('active'); |
| 544 | $that.addClass('active'); |
| 545 | }); |
| 546 | /** |
| 547 | * @date 18 Feb, 2019 |
| 548 | * @since v.1.0.0 |
| 549 | */ |
| 550 | |
| 551 | function init_quiz_builder() { |
| 552 | if (jQuery().sortable) { |
| 553 | $(".tutor-quiz-answers-wrap").sortable({ |
| 554 | handle: ".answer-sorting-bar", |
| 555 | start: function (e, ui) { |
| 556 | ui.placeholder.css('visibility', 'visible'); |
| 557 | }, |
| 558 | stop: function (e, ui) { |
| 559 | //Sorting Stopped... |
| 560 | }, |
| 561 | }).disableSelection(); |
| 562 | |
| 563 | $(".quiz-draggable-rand-answers, .quiz-answer-matching-droppable").sortable({ |
| 564 | connectWith: ".quiz-answer-matching-droppable", |
| 565 | placeholder: "drop-hover", |
| 566 | }).disableSelection(); |
| 567 | } |
| 568 | } |
| 569 | init_quiz_builder(); |
| 570 | /** |
| 571 | * Quiz view |
| 572 | * @date 22 Feb, 2019 |
| 573 | * @since v.1.0.0 |
| 574 | */ |
| 575 | |
| 576 | $(document).on('click', '.tutor-quiz-answer-next-btn', function (e) { |
| 577 | e.preventDefault(); |
| 578 | |
| 579 | var $that = $(this); |
| 580 | var $question_wrap = $that.closest('.quiz-attempt-single-question'); |
| 581 | /** |
| 582 | * Validating required answer |
| 583 | * @type {jQuery} |
| 584 | * |
| 585 | * @since v.1.6.1 |
| 586 | */ |
| 587 | |
| 588 | var validated = tutor_quiz_validation($question_wrap); |
| 589 | if (!validated) { |
| 590 | return; |
| 591 | } |
| 592 | |
| 593 | var feedBackNext = feedback_response($question_wrap); |
| 594 | if (!feedBackNext) { |
| 595 | return; |
| 596 | } |
| 597 | |
| 598 | var question_id = parseInt($that.closest('.quiz-attempt-single-question').attr('id').match(/\d+/)[0], 10); |
| 599 | |
| 600 | var next_question_id = $that.closest('.quiz-attempt-single-question').attr('data-next-question-id'); |
| 601 | |
| 602 | if (next_question_id) { |
| 603 | var $nextQuestion = $(next_question_id); |
| 604 | if ($nextQuestion && $nextQuestion.length) { |
| 605 | $('.quiz-attempt-single-question').hide(); |
| 606 | $nextQuestion.show(); |
| 607 | |
| 608 | /** |
| 609 | * If pagination exists, set active class |
| 610 | */ |
| 611 | |
| 612 | if ($('.tutor-quiz-questions-pagination').length) { |
| 613 | $('.tutor-quiz-question-paginate-item').removeClass('active'); |
| 614 | $('.tutor-quiz-questions-pagination a[href="' + next_question_id + '"]').addClass('active'); |
| 615 | } |
| 616 | |
| 617 | } |
| 618 | } |
| 619 | }); |
| 620 | |
| 621 | |
| 622 | $(document).on('click', '.tutor-quiz-answer-next-btn', function (e) { |
| 623 | e.preventDefault(); |
| 624 | |
| 625 | }); |
| 626 | |
| 627 | |
| 628 | $(document).on('submit', '#tutor-answering-quiz', function (e) { |
| 629 | var $questions_wrap = $('.quiz-attempt-single-question'); |
| 630 | var validated = true; |
| 631 | if ($questions_wrap.length) { |
| 632 | $questions_wrap.each(function (index, question) { |
| 633 | validated = tutor_quiz_validation($(question)); |
| 634 | validated = feedback_response($(question)); |
| 635 | }); |
| 636 | } |
| 637 | |
| 638 | if (!validated) { |
| 639 | e.preventDefault(); |
| 640 | } |
| 641 | |
| 642 | }); |
| 643 | |
| 644 | |
| 645 | $(document).on('click', '.tutor-quiz-question-paginate-item', function (e) { |
| 646 | e.preventDefault(); |
| 647 | var $that = $(this); |
| 648 | var $question = $($that.attr('href')); |
| 649 | $('.quiz-attempt-single-question').hide(); |
| 650 | $question.show(); |
| 651 | |
| 652 | //Active Class |
| 653 | $('.tutor-quiz-question-paginate-item').removeClass('active'); |
| 654 | $that.addClass('active'); |
| 655 | }); |
| 656 | |
| 657 | /** |
| 658 | * Limit Short Answer Question Type |
| 659 | */ |
| 660 | $(document).on('keyup', 'textarea.question_type_short_answer, textarea.question_type_open_ended', function (e) { |
| 661 | var $that = $(this); |
| 662 | var value = $that.val(); |
| 663 | var limit = $that.hasClass('question_type_short_answer') ? _tutorobject.quiz_options.short_answer_characters_limit : _tutorobject.quiz_options.open_ended_answer_characters_limit; |
| 664 | var remaining = limit - value.length; |
| 665 | |
| 666 | if (remaining < 1) { |
| 667 | $that.val(value.substr(0, limit)); |
| 668 | remaining = 0; |
| 669 | } |
| 670 | $that.closest('.tutor-quiz-answers-wrap').find('.characters_remaining').html(remaining); |
| 671 | }); |
| 672 | |
| 673 | /** |
| 674 | * |
| 675 | * @type {jQuery} |
| 676 | * |
| 677 | * Improved Quiz draggable answers drop accessibility |
| 678 | * Answers draggable wrap will be now same height. |
| 679 | * |
| 680 | * @since v.1.4.4 |
| 681 | */ |
| 682 | var countDraggableAnswers = $('.quiz-draggable-rand-answers').length; |
| 683 | if (countDraggableAnswers) { |
| 684 | $('.quiz-draggable-rand-answers').each(function () { |
| 685 | var $that = $(this); |
| 686 | var draggableDivHeight = $that.height(); |
| 687 | |
| 688 | $that.css({ "height": draggableDivHeight }); |
| 689 | }); |
| 690 | } |
| 691 | |
| 692 | |
| 693 | /** |
| 694 | * Quiz Validation Helper |
| 695 | * |
| 696 | * @since v.1.6.1 |
| 697 | */ |
| 698 | |
| 699 | function tutor_quiz_validation($question_wrap) { |
| 700 | var validated = true; |
| 701 | |
| 702 | var $required_answer_wrap = $question_wrap.find('.quiz-answer-required'); |
| 703 | |
| 704 | if ($required_answer_wrap.length) { |
| 705 | /** |
| 706 | * Radio field validation |
| 707 | * |
| 708 | * @type {jQuery} |
| 709 | * |
| 710 | * @since v.1.6.1 |
| 711 | */ |
| 712 | var $inputs = $required_answer_wrap.find('input'); |
| 713 | if ($inputs.length) { |
| 714 | var $type = $inputs.attr('type'); |
| 715 | if ($type === 'radio') { |
| 716 | if ($required_answer_wrap.find('input[type="radio"]:checked').length == 0) { |
| 717 | $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">Please select an option to answer</p>'); |
| 718 | validated = false; |
| 719 | } |
| 720 | } else if ($type === 'checkbox') { |
| 721 | if ($required_answer_wrap.find('input[type="checkbox"]:checked').length == 0) { |
| 722 | $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">Please select at least one option to answer.</p>'); |
| 723 | validated = false; |
| 724 | } |
| 725 | } else if ($type === 'text') { |
| 726 | //Fill in the gaps if many, validation all |
| 727 | $inputs.each(function (index, input) { |
| 728 | if (!$(input).val().trim().length) { |
| 729 | $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">The answer for this question is required</p>'); |
| 730 | validated = false; |
| 731 | } |
| 732 | }); |
| 733 | } |
| 734 | |
| 735 | } |
| 736 | if ($required_answer_wrap.find('textarea').length) { |
| 737 | if ($required_answer_wrap.find('textarea').val().trim().length < 1) { |
| 738 | $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">The answer for this question is required</p>'); |
| 739 | validated = false; |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | /** |
| 744 | * Matching Question |
| 745 | */ |
| 746 | var $matchingDropable = $required_answer_wrap.find('.quiz-answer-matching-droppable'); |
| 747 | if ($matchingDropable.length) { |
| 748 | |
| 749 | $matchingDropable.each(function (index, matching) { |
| 750 | if (!$(matching).find('.quiz-draggable-answer-item').length) { |
| 751 | $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">Please match all the items</p>'); |
| 752 | validated = false; |
| 753 | } |
| 754 | }); |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | return validated; |
| 759 | } |
| 760 | |
| 761 | function feedback_response($question_wrap) { |
| 762 | var goNext = false; |
| 763 | |
| 764 | var feedBackMode = $question_wrap.attr('data-quiz-feedback-mode'); |
| 765 | $('.wrong-right-text').remove(); |
| 766 | $('.quiz-answer-input-bottom').removeClass('wrong-answer right-answer'); |
| 767 | |
| 768 | var validatedTrue = true; |
| 769 | var $inputs = $question_wrap.find('input'); |
| 770 | var $checkedInputs = $question_wrap.find('input[type="radio"]:checked, input[type="checkbox"]:checked'); |
| 771 | |
| 772 | if (feedBackMode === 'retry') { |
| 773 | $checkedInputs.each(function () { |
| 774 | var $input = $(this); |
| 775 | |
| 776 | var $type = $input.attr('type'); |
| 777 | if ($type === 'radio' || $type === 'checkbox') { |
| 778 | var isTrue = $input.attr('data-is-correct') == '1'; |
| 779 | if ( !isTrue) { |
| 780 | if ($input.prop("checked")) { |
| 781 | $input.closest('.quiz-answer-input-bottom').addClass('wrong-answer').append('<span class="wrong-right-text"><i class="tutor-icon-line-cross"></i> Incorrect, Please try again</span>'); |
| 782 | } |
| 783 | validatedTrue = false; |
| 784 | } |
| 785 | } |
| 786 | }); |
| 787 | |
| 788 | $inputs.each(function () { |
| 789 | var $input = $(this); |
| 790 | var $type = $input.attr('type'); |
| 791 | if ($type === 'checkbox') { |
| 792 | var isTrue = $input.attr('data-is-correct') == '1'; |
| 793 | var checked = $input.is(':checked'); |
| 794 | |
| 795 | if (isTrue && !checked) { |
| 796 | $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">More answer for this question is required</p>'); |
| 797 | validatedTrue = false; |
| 798 | } |
| 799 | } |
| 800 | }); |
| 801 | |
| 802 | } else if (feedBackMode === 'reveal') { |
| 803 | $checkedInputs.each(function () { |
| 804 | var $input = $(this); |
| 805 | var isTrue = $input.attr('data-is-correct') == '1'; |
| 806 | if (!isTrue) { |
| 807 | validatedTrue = false; |
| 808 | } |
| 809 | }); |
| 810 | |
| 811 | $inputs.each(function () { |
| 812 | var $input = $(this); |
| 813 | |
| 814 | var $type = $input.attr('type'); |
| 815 | if ($type === 'radio' || $type === 'checkbox') { |
| 816 | var isTrue = $input.attr('data-is-correct') == '1'; |
| 817 | var checked = $input.is(':checked'); |
| 818 | |
| 819 | if (isTrue) { |
| 820 | $input.closest('.quiz-answer-input-bottom').addClass('right-answer').append('<span class="wrong-right-text"><i class="tutor-icon-checkbox-pen-outline"></i> Correct Answer</span>'); |
| 821 | } else { |
| 822 | if ($input.prop("checked")) { |
| 823 | $input.closest('.quiz-answer-input-bottom').addClass('wrong-answer'); |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | if (isTrue && !checked) { |
| 828 | validatedTrue = false; |
| 829 | } |
| 830 | } |
| 831 | }); |
| 832 | } |
| 833 | |
| 834 | if (validatedTrue) { |
| 835 | goNext = true; |
| 836 | } |
| 837 | |
| 838 | return goNext; |
| 839 | } |
| 840 | |
| 841 | |
| 842 | /** |
| 843 | * Add to cart in guest mode, show login form |
| 844 | * |
| 845 | * @since v.1.0.4 |
| 846 | */ |
| 847 | |
| 848 | $(document).on('submit click', '.cart-required-login, .cart-required-login a, .cart-required-login form', function (e) { |
| 849 | e.preventDefault(); |
| 850 | |
| 851 | var login_url = $(this).data('login_page_url'); |
| 852 | login_url ? window.location.assign(login_url) : $('.tutor-cart-box-login-form').fadeIn(100); |
| 853 | }); |
| 854 | |
| 855 | $('.tutor-popup-form-close, .login-overlay-close').on('click', function () { |
| 856 | $('.tutor-cart-box-login-form').fadeOut(100); |
| 857 | }); |
| 858 | |
| 859 | $(document).on('keyup', function (e) { |
| 860 | if (e.keyCode === 27) { |
| 861 | $('.tutor-frontend-modal').hide(); |
| 862 | $('.tutor-cart-box-login-form').fadeOut(100); |
| 863 | } |
| 864 | }); |
| 865 | /** |
| 866 | * Share Link enable |
| 867 | * |
| 868 | * @since v.1.0.4 |
| 869 | */ |
| 870 | if ($.fn.ShareLink) { |
| 871 | var $social_share_wrap = $('.tutor-social-share-wrap'); |
| 872 | if ($social_share_wrap.length) { |
| 873 | var share_config = JSON.parse($social_share_wrap.attr('data-social-share-config')); |
| 874 | |
| 875 | $('.tutor_share').ShareLink({ |
| 876 | title: share_config.title, |
| 877 | text: share_config.text, |
| 878 | image: share_config.image, |
| 879 | class_prefix: 's_', |
| 880 | width: 640, |
| 881 | height: 480, |
| 882 | }); |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | /** |
| 887 | * Datepicker initiate |
| 888 | * |
| 889 | * @since v.1.1.2 |
| 890 | */ |
| 891 | if (jQuery.datepicker) { |
| 892 | $(".tutor_report_datepicker").datepicker({ "dateFormat": 'yy-mm-dd' }); |
| 893 | } |
| 894 | |
| 895 | |
| 896 | /** |
| 897 | * Withdraw Form Tab/Toggle |
| 898 | * |
| 899 | * @since v.1.1.2 |
| 900 | */ |
| 901 | |
| 902 | $(".withdraw-method-select-input").on('change', function (e) { |
| 903 | var $that = $(this); |
| 904 | $('.withdraw-method-form').hide(); |
| 905 | $('#withdraw-method-form-' + $that.closest('.withdraw-method-select').attr('data-withdraw-method')).show(); |
| 906 | }); |
| 907 | |
| 908 | $('.withdraw-method-select-input').each(function () { |
| 909 | var $that = $(this); |
| 910 | if ($that.is(":checked")) { |
| 911 | $('.withdraw-method-form').hide(); |
| 912 | $('#withdraw-method-form-' + $that.closest('.withdraw-method-select').attr('data-withdraw-method')).show(); |
| 913 | } |
| 914 | }); |
| 915 | |
| 916 | |
| 917 | |
| 918 | /** |
| 919 | * Setting account for withdraw earning |
| 920 | * |
| 921 | * @since v.1.2.0 |
| 922 | */ |
| 923 | $(document).on('submit', '#tutor-withdraw-account-set-form', function (e) { |
| 924 | e.preventDefault(); |
| 925 | |
| 926 | var $form = $(this); |
| 927 | var $btn = $form.find('.tutor_set_withdraw_account_btn'); |
| 928 | var data = $form.serialize(); |
| 929 | |
| 930 | $.ajax({ |
| 931 | url: _tutorobject.ajaxurl, |
| 932 | type: 'POST', |
| 933 | data: data, |
| 934 | beforeSend: function () { |
| 935 | $form.find('.tutor-success-msg').remove(); |
| 936 | $btn.addClass('updating-icon'); |
| 937 | }, |
| 938 | success: function (data) { |
| 939 | if (data.success) { |
| 940 | var successMsg = '<div class="tutor-success-msg" style="display: none;"><i class="tutor-icon-mark"></i> ' + data.data.msg + ' </div>'; |
| 941 | $btn.closest('.withdraw-account-save-btn-wrap').append(successMsg); |
| 942 | if ($form.find('.tutor-success-msg').length) { |
| 943 | $form.find('.tutor-success-msg').slideDown(); |
| 944 | } |
| 945 | setTimeout(function () { |
| 946 | $form.find('.tutor-success-msg').slideUp(); |
| 947 | }, 5000) |
| 948 | } |
| 949 | }, |
| 950 | complete: function () { |
| 951 | $btn.removeClass('updating-icon'); |
| 952 | } |
| 953 | }); |
| 954 | }); |
| 955 | |
| 956 | /** |
| 957 | * Make Withdraw Form |
| 958 | * |
| 959 | * @since v.1.2.0 |
| 960 | */ |
| 961 | |
| 962 | $(document).on('click', 'a.open-withdraw-form-btn, .close-withdraw-form-btn', function (e) { |
| 963 | e.preventDefault(); |
| 964 | |
| 965 | if($(this).data('reload')=='yes'){ |
| 966 | window.location.reload(); |
| 967 | return; |
| 968 | } |
| 969 | |
| 970 | $('.tutor-earning-withdraw-form-wrap').toggle().find('[name="tutor_withdraw_amount"]').val(''); |
| 971 | $('.tutor-withdrawal-pop-up-success').hide().next().show(); |
| 972 | $('html, body').css('overflow', ($('.tutor-earning-withdraw-form-wrap').is(':visible') ? 'hidden' : 'auto')); |
| 973 | }); |
| 974 | |
| 975 | $(document).on('submit', '#tutor-earning-withdraw-form', function (e) { |
| 976 | e.preventDefault(); |
| 977 | |
| 978 | var $form = $(this); |
| 979 | var $btn = $('#tutor-earning-withdraw-btn'); |
| 980 | var $responseDiv = $('.tutor-withdraw-form-response'); |
| 981 | var data = $form.serialize(); |
| 982 | |
| 983 | $.ajax({ |
| 984 | url: _tutorobject.ajaxurl, |
| 985 | type: 'POST', |
| 986 | data: data, |
| 987 | beforeSend: function () { |
| 988 | $form.find('.tutor-success-msg').remove(); |
| 989 | $btn.addClass('updating-icon'); |
| 990 | }, |
| 991 | success: function (data) { |
| 992 | var Msg; |
| 993 | if (data.success) { |
| 994 | |
| 995 | if (data.data.available_balance !== 'undefined') { |
| 996 | $('.withdraw-balance-col .available_balance').html(data.data.available_balance); |
| 997 | } |
| 998 | |
| 999 | $('.tutor-withdrawal-pop-up-success').show().next().hide(); |
| 1000 | |
| 1001 | } else { |
| 1002 | Msg = '<div class="tutor-error-msg inline-image-text is-inline-block">\ |
| 1003 | <img src="'+window.tutor_url_base+'assets/images/icon-cross.svg"/> \ |
| 1004 | <div>\ |
| 1005 | <b>Error</b><br/>\ |
| 1006 | <span>'+ data.data.msg + '</span>\ |
| 1007 | </div>\ |
| 1008 | </div>'; |
| 1009 | |
| 1010 | $responseDiv.html(Msg); |
| 1011 | setTimeout(function () { |
| 1012 | $responseDiv.html(''); |
| 1013 | }, 5000) |
| 1014 | } |
| 1015 | }, |
| 1016 | complete: function () { |
| 1017 | $btn.removeClass('updating-icon'); |
| 1018 | } |
| 1019 | }); |
| 1020 | }); |
| 1021 | |
| 1022 | var frontEndModal = $('.tutor-frontend-modal'); |
| 1023 | frontEndModal.each(function () { |
| 1024 | var modal = $(this), |
| 1025 | action = $(this).data('popup-rel'); |
| 1026 | $('[href="' + action + '"]').on('click', function (e) { |
| 1027 | modal.fadeIn(); |
| 1028 | e.preventDefault(); |
| 1029 | }); |
| 1030 | }); |
| 1031 | $(document).on('click', '.tm-close, .tutor-frontend-modal-overlay, .tutor-modal-btn-cancel', function () { |
| 1032 | frontEndModal.fadeOut(); |
| 1033 | }); |
| 1034 | |
| 1035 | /** |
| 1036 | * Delete Course |
| 1037 | */ |
| 1038 | $(document).on('click', '.tutor-dashboard-element-delete-btn', function (e) { |
| 1039 | e.preventDefault(); |
| 1040 | var element_id = $(this).attr('data-id'); |
| 1041 | $('#tutor-dashboard-delete-element-id').val(element_id); |
| 1042 | }); |
| 1043 | $(document).on('submit', '#tutor-dashboard-delete-element-form', function (e) { |
| 1044 | e.preventDefault(); |
| 1045 | |
| 1046 | var element_id = $('#tutor-dashboard-delete-element-id').val(); |
| 1047 | var $btn = $('.tutor-modal-element-delete-btn'); |
| 1048 | var data = $(this).serialize(); |
| 1049 | |
| 1050 | $.ajax({ |
| 1051 | url: _tutorobject.ajaxurl, |
| 1052 | type: 'POST', |
| 1053 | data: data, |
| 1054 | beforeSend: function () { |
| 1055 | $btn.addClass('updating-icon'); |
| 1056 | }, |
| 1057 | success: function (res) { |
| 1058 | if (res.success) { |
| 1059 | $('#tutor-dashboard-' + res.data.element + '-' + element_id).remove(); |
| 1060 | } |
| 1061 | }, |
| 1062 | complete: function () { |
| 1063 | $btn.removeClass('updating-icon'); |
| 1064 | $('.tutor-frontend-modal').hide(); |
| 1065 | } |
| 1066 | }); |
| 1067 | }); |
| 1068 | |
| 1069 | /** |
| 1070 | * Frontend Profile |
| 1071 | */ |
| 1072 | |
| 1073 | if (!$('#tutor_profile_photo_id').val()) { |
| 1074 | $('.tutor-profile-photo-delete-btn').hide(); |
| 1075 | } |
| 1076 | |
| 1077 | $(document).on('click', '.tutor-profile-photo-delete-btn', function () { |
| 1078 | $('.tutor-profile-photo-upload-wrap').find('img').attr('src', _tutorobject.placeholder_img_src); |
| 1079 | $('#tutor_profile_photo_id').val(''); |
| 1080 | $('.tutor-profile-photo-delete-btn').hide(); |
| 1081 | |
| 1082 | $.ajax({ |
| 1083 | url: _tutorobject.ajaxurl, |
| 1084 | type: 'POST', |
| 1085 | data: { 'action': 'tutor_profile_photo_remove' }, |
| 1086 | }); |
| 1087 | |
| 1088 | return false; |
| 1089 | }); |
| 1090 | |
| 1091 | /** |
| 1092 | * Assignment |
| 1093 | * |
| 1094 | * @since v.1.3.3 |
| 1095 | */ |
| 1096 | $(document).on('submit', '#tutor_assignment_start_form', function (e) { |
| 1097 | e.preventDefault(); |
| 1098 | |
| 1099 | var $that = $(this); |
| 1100 | var form_data = $that.serialize() + '&action=tutor_start_assignment'; |
| 1101 | |
| 1102 | $.ajax({ |
| 1103 | url: _tutorobject.ajaxurl, |
| 1104 | type: 'POST', |
| 1105 | data: form_data, |
| 1106 | beforeSend: function () { |
| 1107 | $('#tutor_assignment_start_btn').addClass('updating-icon'); |
| 1108 | }, |
| 1109 | success: function (data) { |
| 1110 | if (data.success) { |
| 1111 | location.reload(); |
| 1112 | } |
| 1113 | }, |
| 1114 | complete: function () { |
| 1115 | $('#tutor_assignment_start_btn').removeClass('updating-icon'); |
| 1116 | } |
| 1117 | }); |
| 1118 | }); |
| 1119 | |
| 1120 | /** |
| 1121 | * Assignment answer validation |
| 1122 | */ |
| 1123 | $(document).on('submit', '#tutor_assignment_submit_form', function (e) { |
| 1124 | var assignment_answer = $('textarea[name="assignment_answer"]').val(); |
| 1125 | if (assignment_answer.trim().length < 1) { |
| 1126 | $('#form_validation_response').html('<div class="tutor-error-msg">' + _tutorobject.text.assignment_text_validation_msg + '</div>'); |
| 1127 | e.preventDefault(); |
| 1128 | } |
| 1129 | }); |
| 1130 | |
| 1131 | /** |
| 1132 | * Course builder video |
| 1133 | * @since v.1.3.4 |
| 1134 | */ |
| 1135 | |
| 1136 | |
| 1137 | $(document).on('click', '.video_source_upload_wrap_html5 .video_upload_btn', function (event) { |
| 1138 | event.preventDefault(); |
| 1139 | |
| 1140 | var $that = $(this); |
| 1141 | var frame; |
| 1142 | // If the media frame already exists, reopen it. |
| 1143 | if (frame) { |
| 1144 | frame.open(); |
| 1145 | return; |
| 1146 | } |
| 1147 | frame = wp.media({ |
| 1148 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 1149 | button: { |
| 1150 | text: 'Use this media' |
| 1151 | }, |
| 1152 | library: { type: 'video' }, |
| 1153 | multiple: false // Set to true to allow multiple files to be selected |
| 1154 | }); |
| 1155 | frame.on('select', function () { |
| 1156 | // Get media attachment details from the frame state |
| 1157 | var attachment = frame.state().get('selection').first().toJSON(); |
| 1158 | $that.closest('.video_source_upload_wrap_html5').find('span.video_media_id').text(attachment.id).closest('p').show(); |
| 1159 | $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id); |
| 1160 | }); |
| 1161 | frame.open(); |
| 1162 | }); |
| 1163 | |
| 1164 | |
| 1165 | /** |
| 1166 | * Course and lesson sorting |
| 1167 | */ |
| 1168 | |
| 1169 | function enable_sorting_topic_lesson() { |
| 1170 | if (jQuery().sortable) { |
| 1171 | $(".course-contents").sortable({ |
| 1172 | handle: ".course-move-handle", |
| 1173 | start: function (e, ui) { |
| 1174 | ui.placeholder.css('visibility', 'visible'); |
| 1175 | }, |
| 1176 | stop: function (e, ui) { |
| 1177 | tutor_sorting_topics_and_lesson(); |
| 1178 | }, |
| 1179 | }); |
| 1180 | $(".tutor-lessons:not(.drop-lessons)").sortable({ |
| 1181 | connectWith: ".tutor-lessons", |
| 1182 | items: "div.course-content-item", |
| 1183 | start: function (e, ui) { |
| 1184 | ui.placeholder.css('visibility', 'visible'); |
| 1185 | }, |
| 1186 | stop: function (e, ui) { |
| 1187 | tutor_sorting_topics_and_lesson(); |
| 1188 | }, |
| 1189 | }); |
| 1190 | } |
| 1191 | } |
| 1192 | enable_sorting_topic_lesson(); |
| 1193 | function tutor_sorting_topics_and_lesson() { |
| 1194 | var topics = {}; |
| 1195 | $('.tutor-topics-wrap').each(function (index, item) { |
| 1196 | var $topic = $(this); |
| 1197 | var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10); |
| 1198 | var lessons = {}; |
| 1199 | |
| 1200 | $topic.find('.course-content-item').each(function (lessonIndex, lessonItem) { |
| 1201 | var $lesson = $(this); |
| 1202 | var lesson_id = parseInt($lesson.attr('id').match(/\d+/)[0], 10); |
| 1203 | |
| 1204 | lessons[lessonIndex] = lesson_id; |
| 1205 | }); |
| 1206 | topics[index] = { 'topic_id': topics_id, 'lesson_ids': lessons }; |
| 1207 | }); |
| 1208 | $('#tutor_topics_lessons_sorting').val(JSON.stringify(topics)); |
| 1209 | } |
| 1210 | |
| 1211 | /** |
| 1212 | * Lesson Update or Create Modal |
| 1213 | */ |
| 1214 | $(document).on('click', '.update_lesson_modal_btn', function (event) { |
| 1215 | event.preventDefault(); |
| 1216 | |
| 1217 | var $that = $(this); |
| 1218 | var content; |
| 1219 | var editor = tinyMCE.get('tutor_lesson_modal_editor'); |
| 1220 | if (editor) { |
| 1221 | content = editor.getContent(); |
| 1222 | } else { |
| 1223 | content = $('#' + inputid).val(); |
| 1224 | } |
| 1225 | |
| 1226 | var form_data = $(this).closest('form').serialize(); |
| 1227 | form_data += '&lesson_content=' + encodeURIComponent(content); |
| 1228 | |
| 1229 | $.ajax({ |
| 1230 | url: ajaxurl, |
| 1231 | type: 'POST', |
| 1232 | data: form_data, |
| 1233 | beforeSend: function () { |
| 1234 | $that.addClass('tutor-updating-message'); |
| 1235 | }, |
| 1236 | success: function (data) { |
| 1237 | if (data.success) { |
| 1238 | $('#tutor-course-content-wrap').html(data.data.course_contents); |
| 1239 | enable_sorting_topic_lesson(); |
| 1240 | |
| 1241 | //Close the modal |
| 1242 | $('.tutor-lesson-modal-wrap').removeClass('show'); |
| 1243 | } |
| 1244 | }, |
| 1245 | complete: function () { |
| 1246 | $that.removeClass('tutor-updating-message'); |
| 1247 | } |
| 1248 | }); |
| 1249 | }); |
| 1250 | |
| 1251 | /** |
| 1252 | * END: Tutor Course builder JS |
| 1253 | */ |
| 1254 | |
| 1255 | /** |
| 1256 | * Attachment in forntend course builder |
| 1257 | * @since v.1.3.4 |
| 1258 | */ |
| 1259 | $(document).on('click', 'a.tutor-delete-attachment', function (e) { |
| 1260 | e.preventDefault(); |
| 1261 | $(this).closest('.tutor-added-attachment').remove(); |
| 1262 | }); |
| 1263 | $(document).on('click', '.tutorUploadAttachmentBtn', function (e) { |
| 1264 | e.preventDefault(); |
| 1265 | |
| 1266 | var $that = $(this); |
| 1267 | var frame; |
| 1268 | if (frame) { |
| 1269 | frame.open(); |
| 1270 | return; |
| 1271 | } |
| 1272 | frame = wp.media({ |
| 1273 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 1274 | button: { |
| 1275 | text: 'Use this media' |
| 1276 | }, |
| 1277 | multiple: true // Set to true to allow multiple files to be selected |
| 1278 | }); |
| 1279 | frame.on('select', function () { |
| 1280 | var attachments = frame.state().get('selection').toJSON(); |
| 1281 | if (attachments.length) { |
| 1282 | for (var i = 0; i < attachments.length; i++) { |
| 1283 | var attachment = attachments[i]; |
| 1284 | |
| 1285 | var inputHtml = '<div class="tutor-added-attachment"><i class="tutor-icon-archive"></i><a href="javascript:;" class="tutor-delete-attachment tutor-icon-line-cross"></a> <span> <a href="' + attachment.url + '">' + attachment.filename + '</a> </span> <input type="hidden" name="tutor_attachments[]" value="' + attachment.id + '"></div>'; |
| 1286 | $that.closest('.tutor-lesson-attachments-metabox').find('.tutor-added-attachments-wrap').append(inputHtml); |
| 1287 | } |
| 1288 | } |
| 1289 | }); |
| 1290 | frame.open(); |
| 1291 | }); |
| 1292 | |
| 1293 | |
| 1294 | /** |
| 1295 | * Single Assignment Upload Button |
| 1296 | * @since v.1.3.4 |
| 1297 | */ |
| 1298 | $('form').on('change', '.tutor-assignment-file-upload', function () { |
| 1299 | $(this).siblings("label").find('span').html($(this).val().replace(/.*(\/|\\)/, '')); |
| 1300 | }); |
| 1301 | |
| 1302 | /** |
| 1303 | * Lesson Sidebar Topic Toggle |
| 1304 | * @since v.1.3.4 |
| 1305 | */ |
| 1306 | |
| 1307 | $(document).on('click', '.tutor-topics-in-single-lesson .tutor-topics-title h3, .tutor-single-lesson-topic-toggle', function (e) { |
| 1308 | var $that = $(this); |
| 1309 | var $parent = $that.closest('.tutor-topics-in-single-lesson'); |
| 1310 | $parent.toggleClass('tutor-topic-active'); |
| 1311 | $parent.find('.tutor-lessons-under-topic').slideToggle(); |
| 1312 | }); |
| 1313 | |
| 1314 | $('.tutor-single-lesson-items.active').closest('.tutor-lessons-under-topic').show(); |
| 1315 | $('.tutor-single-lesson-items.active').closest('.tutor-topics-in-single-lesson').addClass('tutor-topic-active'); |
| 1316 | $('.tutor-course-lesson.active').closest('.tutor-lessons-under-topic').show(); |
| 1317 | |
| 1318 | |
| 1319 | /** |
| 1320 | * Assignments Addons |
| 1321 | * @backend Support |
| 1322 | * |
| 1323 | */ |
| 1324 | |
| 1325 | |
| 1326 | /** |
| 1327 | * Tutor Assignments JS |
| 1328 | * @since v.1.3.3 |
| 1329 | */ |
| 1330 | $(document).on('click', '.tutor-create-assignments-btn', function (e) { |
| 1331 | e.preventDefault(); |
| 1332 | |
| 1333 | var $that = $(this); |
| 1334 | var topic_id = $(this).attr('data-topic-id'); |
| 1335 | var course_id = $('#post_ID').val(); |
| 1336 | |
| 1337 | $.ajax({ |
| 1338 | url: ajaxurl, |
| 1339 | type: 'POST', |
| 1340 | data: { topic_id: topic_id, course_id: course_id, action: 'tutor_load_assignments_builder_modal' }, |
| 1341 | beforeSend: function () { |
| 1342 | $that.addClass('tutor-updating-message'); |
| 1343 | }, |
| 1344 | success: function (data) { |
| 1345 | $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output); |
| 1346 | $('.tutor-lesson-modal-wrap').attr('data-topic-id', topic_id).addClass('show'); |
| 1347 | |
| 1348 | $(document).trigger('assignment_modal_loaded', { topic_id: topic_id, course_id: course_id }); |
| 1349 | |
| 1350 | tinymce.init(tinyMCEPreInit.mceInit.course_description); |
| 1351 | tinymce.execCommand('mceRemoveEditor', false, 'tutor_assignments_modal_editor'); |
| 1352 | tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor"); |
| 1353 | }, |
| 1354 | complete: function () { |
| 1355 | quicktags({ id: "tutor_assignments_modal_editor" }); |
| 1356 | $that.removeClass('tutor-updating-message'); |
| 1357 | } |
| 1358 | }); |
| 1359 | }); |
| 1360 | |
| 1361 | $(document).on('click', '.open-tutor-assignment-modal', function (e) { |
| 1362 | e.preventDefault(); |
| 1363 | |
| 1364 | var $that = $(this); |
| 1365 | var assignment_id = $that.attr('data-assignment-id'); |
| 1366 | var topic_id = $that.attr('data-topic-id'); |
| 1367 | var course_id = $('#post_ID').val(); |
| 1368 | |
| 1369 | $.ajax({ |
| 1370 | url: ajaxurl, |
| 1371 | type: 'POST', |
| 1372 | data: { assignment_id: assignment_id, topic_id: topic_id, course_id: course_id, action: 'tutor_load_assignments_builder_modal' }, |
| 1373 | beforeSend: function () { |
| 1374 | $that.addClass('tutor-updating-message'); |
| 1375 | }, |
| 1376 | success: function (data) { |
| 1377 | $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output); |
| 1378 | $('.tutor-lesson-modal-wrap').attr({ 'data-assignment-id': assignment_id, 'data-topic-id': topic_id }).addClass('show'); |
| 1379 | |
| 1380 | $(document).trigger('assignment_modal_loaded', { assignment_id: assignment_id, topic_id: topic_id, course_id: course_id }); |
| 1381 | |
| 1382 | tinymce.init(tinyMCEPreInit.mceInit.course_description); |
| 1383 | tinymce.execCommand('mceRemoveEditor', false, 'tutor_assignments_modal_editor'); |
| 1384 | tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor"); |
| 1385 | }, |
| 1386 | complete: function () { |
| 1387 | quicktags({ id: "tutor_assignments_modal_editor" }); |
| 1388 | $that.removeClass('tutor-updating-message'); |
| 1389 | } |
| 1390 | }); |
| 1391 | }); |
| 1392 | |
| 1393 | /** |
| 1394 | * Update Assignment Data |
| 1395 | */ |
| 1396 | $(document).on('click', '.update_assignment_modal_btn', function (event) { |
| 1397 | event.preventDefault(); |
| 1398 | |
| 1399 | var $that = $(this); |
| 1400 | var content; |
| 1401 | var editor = tinyMCE.get('tutor_assignments_modal_editor'); |
| 1402 | if (editor) { |
| 1403 | content = editor.getContent(); |
| 1404 | } else { |
| 1405 | content = $('#' + inputid).val(); |
| 1406 | } |
| 1407 | |
| 1408 | var form_data = $(this).closest('form').serialize(); |
| 1409 | form_data += '&assignment_content=' + content; |
| 1410 | |
| 1411 | $.ajax({ |
| 1412 | url: ajaxurl, |
| 1413 | type: 'POST', |
| 1414 | data: form_data, |
| 1415 | beforeSend: function () { |
| 1416 | $that.addClass('tutor-updating-message'); |
| 1417 | }, |
| 1418 | success: function (data) { |
| 1419 | if (data.success) { |
| 1420 | $('#tutor-course-content-wrap').html(data.data.course_contents); |
| 1421 | enable_sorting_topic_lesson(); |
| 1422 | |
| 1423 | //Close the modal |
| 1424 | $('.tutor-lesson-modal-wrap').removeClass('show'); |
| 1425 | } |
| 1426 | }, |
| 1427 | complete: function () { |
| 1428 | $that.removeClass('tutor-updating-message'); |
| 1429 | } |
| 1430 | }); |
| 1431 | }); |
| 1432 | |
| 1433 | /** |
| 1434 | * Add Assignment |
| 1435 | */ |
| 1436 | $(document).on('click', '.add-assignment-attachments', function (event) { |
| 1437 | event.preventDefault(); |
| 1438 | |
| 1439 | var $that = $(this); |
| 1440 | var frame; |
| 1441 | // If the media frame already exists, reopen it. |
| 1442 | if (frame) { |
| 1443 | frame.open(); |
| 1444 | return; |
| 1445 | } |
| 1446 | |
| 1447 | // Create a new media frame |
| 1448 | frame = wp.media({ |
| 1449 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 1450 | button: { |
| 1451 | text: 'Use this media' |
| 1452 | }, |
| 1453 | multiple: false // Set to true to allow multiple files to be selected |
| 1454 | }); |
| 1455 | |
| 1456 | // When an image is selected in the media frame... |
| 1457 | frame.on('select', function () { |
| 1458 | // Get media attachment details from the frame state |
| 1459 | var attachment = frame.state().get('selection').first().toJSON(); |
| 1460 | |
| 1461 | var field_markup = '<div class="tutor-individual-attachment-file"><p class="attachment-file-name">' + attachment.filename + '</p><input type="hidden" name="tutor_assignment_attachments[]" value="' + attachment.id + '"><a href="javascript:;" class="remove-assignment-attachment-a text-muted"> × Remove</a></div>'; |
| 1462 | |
| 1463 | $('#assignment-attached-file').append(field_markup); |
| 1464 | $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id); |
| 1465 | }); |
| 1466 | // Finally, open the modal on click |
| 1467 | frame.open(); |
| 1468 | }); |
| 1469 | |
| 1470 | $(document).on('click', '.remove-assignment-attachment-a', function (event) { |
| 1471 | event.preventDefault(); |
| 1472 | $(this).closest('.tutor-individual-attachment-file').remove(); |
| 1473 | }); |
| 1474 | |
| 1475 | |
| 1476 | /** |
| 1477 | * |
| 1478 | * @type {jQuery} |
| 1479 | * |
| 1480 | * Course builder auto draft save |
| 1481 | * |
| 1482 | * @since v.1.3.4 |
| 1483 | */ |
| 1484 | var tutor_course_builder = $('input[name="tutor_action"]').val(); |
| 1485 | if (tutor_course_builder === 'tutor_add_course_builder') { |
| 1486 | setInterval(auto_draft_save_course_builder, 30000); |
| 1487 | } |
| 1488 | |
| 1489 | function auto_draft_save_course_builder() { |
| 1490 | var form_data = $('form#tutor-frontend-course-builder').serialize(); |
| 1491 | $.ajax({ |
| 1492 | //url : _tutorobject.ajaxurl, |
| 1493 | type: 'POST', |
| 1494 | data: form_data + '&tutor_ajax_action=tutor_course_builder_draft_save', |
| 1495 | beforeSend: function () { |
| 1496 | $('.tutor-dashboard-builder-draft-btn span').text('Saving...'); |
| 1497 | }, |
| 1498 | success: function (data) { |
| 1499 | |
| 1500 | }, |
| 1501 | complete: function () { |
| 1502 | $('.tutor-dashboard-builder-draft-btn span').text('Save'); |
| 1503 | } |
| 1504 | }); |
| 1505 | } |
| 1506 | |
| 1507 | /** |
| 1508 | * |
| 1509 | * @type {jQuery} |
| 1510 | * |
| 1511 | * Course builder section toggle |
| 1512 | * |
| 1513 | * @since v.1.3.5 |
| 1514 | */ |
| 1515 | |
| 1516 | $('.tutor-course-builder-section-title').on('click', function () { |
| 1517 | if ($(this).find('i').hasClass("tutor-icon-up")) { |
| 1518 | $(this).find('i').removeClass('tutor-icon-up').addClass('tutor-icon-down'); |
| 1519 | } else { |
| 1520 | $(this).find('i').removeClass('tutor-icon-down').addClass('tutor-icon-up'); |
| 1521 | } |
| 1522 | $(this).next('div').slideToggle(); |
| 1523 | }); |
| 1524 | |
| 1525 | /** |
| 1526 | * Open Tutor Modal to edit review |
| 1527 | * @since v.1.4.0 |
| 1528 | */ |
| 1529 | $(document).on('click', '.open-tutor-edit-review-modal', function (e) { |
| 1530 | e.preventDefault(); |
| 1531 | |
| 1532 | var $that = $(this); |
| 1533 | var review_id = $that.attr('data-review-id'); |
| 1534 | |
| 1535 | var nonce_key = _tutorobject.nonce_key; |
| 1536 | |
| 1537 | var json_data = { review_id: review_id, action: 'tutor_load_edit_review_modal' }; |
| 1538 | json_data[nonce_key] = _tutorobject[nonce_key]; |
| 1539 | |
| 1540 | $.ajax({ |
| 1541 | url: _tutorobject.ajaxurl, |
| 1542 | type: 'POST', |
| 1543 | data: json_data, |
| 1544 | beforeSend: function () { |
| 1545 | $that.addClass('tutor-updating-message'); |
| 1546 | }, |
| 1547 | success: function (data) { |
| 1548 | if (typeof data.data !== 'undefined') { |
| 1549 | $('.tutor-edit-review-modal-wrap .modal-container').html(data.data.output); |
| 1550 | $('.tutor-edit-review-modal-wrap').attr('data-review-id', review_id).addClass('show'); |
| 1551 | } |
| 1552 | }, |
| 1553 | complete: function () { |
| 1554 | $that.removeClass('tutor-updating-message'); |
| 1555 | } |
| 1556 | }); |
| 1557 | }); |
| 1558 | |
| 1559 | /** |
| 1560 | * Update the rating |
| 1561 | * @since v.1.4.0 |
| 1562 | */ |
| 1563 | $(document).on('submit', '#tutor_update_review_form', function (e) { |
| 1564 | e.preventDefault(); |
| 1565 | |
| 1566 | var $that = $(this); |
| 1567 | var review_id = $that.closest('.tutor-edit-review-modal-wrap ').attr('data-review-id'); |
| 1568 | |
| 1569 | var nonce_key = _tutorobject.nonce_key; |
| 1570 | |
| 1571 | var rating = $that.find('input[name="tutor_rating_gen_input"]').val(); |
| 1572 | var review = $that.find('textarea[name="review"]').val(); |
| 1573 | review = review.trim(); |
| 1574 | |
| 1575 | var json_data = { review_id: review_id, rating: rating, review: review, action: 'tutor_update_review_modal' }; |
| 1576 | json_data[nonce_key] = _tutorobject[nonce_key]; |
| 1577 | |
| 1578 | $.ajax({ |
| 1579 | url: _tutorobject.ajaxurl, |
| 1580 | type: 'POST', |
| 1581 | data: json_data, |
| 1582 | beforeSend: function () { |
| 1583 | $that.find('button[type="submit"]').addClass('tutor-updating-message'); |
| 1584 | }, |
| 1585 | success: function (data) { |
| 1586 | if (data.success) { |
| 1587 | //Close the modal |
| 1588 | $('.tutor-edit-review-modal-wrap').removeClass('show'); |
| 1589 | location.reload(true); |
| 1590 | } |
| 1591 | }, |
| 1592 | complete: function () { |
| 1593 | $that.find('button[type="submit"]').removeClass('tutor-updating-message'); |
| 1594 | } |
| 1595 | }); |
| 1596 | }); |
| 1597 | |
| 1598 | /** |
| 1599 | * Profile photo upload |
| 1600 | * @since v.1.4.5 |
| 1601 | */ |
| 1602 | |
| 1603 | $(document).on('click', '#tutor_profile_photo_button', function (e) { |
| 1604 | e.preventDefault(); |
| 1605 | |
| 1606 | $('#tutor_profile_photo_file').trigger('click'); |
| 1607 | }); |
| 1608 | |
| 1609 | $(document).on('change', '#tutor_profile_photo_file', function (event) { |
| 1610 | event.preventDefault(); |
| 1611 | |
| 1612 | var $file = this; |
| 1613 | if ($file.files && $file.files[0]) { |
| 1614 | var reader = new FileReader(); |
| 1615 | reader.onload = function (e) { |
| 1616 | $('.tutor-profile-photo-upload-wrap').find('img').attr('src', e.target.result); |
| 1617 | } |
| 1618 | reader.readAsDataURL($file.files[0]); |
| 1619 | } |
| 1620 | }); |
| 1621 | |
| 1622 | /** |
| 1623 | * Addon, Tutor BuddyPress |
| 1624 | * Retrieve MetaInformation on BuddyPress message system |
| 1625 | * @for TutorLMS Pro |
| 1626 | * @since v.1.4.8 |
| 1627 | */ |
| 1628 | |
| 1629 | $(document).on('click', '.thread-content .subject', function (e) { |
| 1630 | var $btn = $(this); |
| 1631 | |
| 1632 | var thread_id = parseInt($btn.closest('.thread-content').attr('data-thread-id')); |
| 1633 | |
| 1634 | var nonce_key = _tutorobject.nonce_key; |
| 1635 | var json_data = { thread_id: thread_id, action: 'tutor_bp_retrieve_user_records_for_thread' }; |
| 1636 | json_data[nonce_key] = _tutorobject[nonce_key]; |
| 1637 | |
| 1638 | $.ajax({ |
| 1639 | type: 'POST', |
| 1640 | url: ajaxurl, |
| 1641 | data: json_data, |
| 1642 | beforeSend: function () { |
| 1643 | $('#tutor-bp-thread-wrap').html(''); |
| 1644 | }, |
| 1645 | success: function (data) { |
| 1646 | if (data.success) { |
| 1647 | $('#tutor-bp-thread-wrap').html(data.data.thread_head_html); |
| 1648 | tutor_bp_setting_enrolled_courses_list(); |
| 1649 | } |
| 1650 | } |
| 1651 | }); |
| 1652 | |
| 1653 | }); |
| 1654 | |
| 1655 | |
| 1656 | function tutor_bp_setting_enrolled_courses_list() { |
| 1657 | $('ul.tutor-bp-enrolled-course-list').each(function () { |
| 1658 | var $that = $(this); |
| 1659 | var $li = $that.find(' > li'); |
| 1660 | var itemShow = 3; |
| 1661 | |
| 1662 | if ($li.length > itemShow) { |
| 1663 | var plusCourseCount = $li.length - itemShow; |
| 1664 | $li.each(function (liIndex, liItem) { |
| 1665 | var $liItem = $(this); |
| 1666 | |
| 1667 | if (liIndex >= itemShow) { |
| 1668 | $liItem.hide(); |
| 1669 | } |
| 1670 | }); |
| 1671 | |
| 1672 | var infoHtml = '<a href="javascript:;" class="tutor_bp_plus_courses"><strong>+' + plusCourseCount + ' More </strong></a> Courses'; |
| 1673 | $that.closest('.tutor-bp-enrolled-courses-wrap').find('.thread-participant-enrolled-info').html(infoHtml); |
| 1674 | } |
| 1675 | |
| 1676 | $that.show(); |
| 1677 | }); |
| 1678 | } |
| 1679 | tutor_bp_setting_enrolled_courses_list(); |
| 1680 | |
| 1681 | $(document).on('click', 'a.tutor_bp_plus_courses', function (e) { |
| 1682 | e.preventDefault(); |
| 1683 | |
| 1684 | var $btn = $(this); |
| 1685 | $btn.closest('.tutor-bp-enrolled-courses-wrap').find('.tutor-bp-enrolled-course-list li').show(); |
| 1686 | $btn.closest('.thread-participant-enrolled-info').html(''); |
| 1687 | }); |
| 1688 | |
| 1689 | |
| 1690 | /** |
| 1691 | * Addon, Tutor Certificate |
| 1692 | * Certificate dropdown content and copy link |
| 1693 | * @for TutorLMS Pro |
| 1694 | * @since v.1.5.1 |
| 1695 | */ |
| 1696 | $(document).on('click', '.tutor-dropbtn', function (e) { |
| 1697 | var $content = $(this).parent().find(".tutor-dropdown-content"); |
| 1698 | $content.slideToggle(100); |
| 1699 | }); |
| 1700 | $(document).on('click', '.tutor-copy-link', function (e) { |
| 1701 | var $btn = $(this); |
| 1702 | var copy = '<i class="tutor-icon-copy"></i> Copy Link'; |
| 1703 | var copied = '<i class="tutor-icon-mark"></i> Copied'; |
| 1704 | var dummy = document.createElement('input'), |
| 1705 | text = window.location.href; |
| 1706 | document.body.appendChild(dummy); |
| 1707 | dummy.value = text; |
| 1708 | dummy.select(); |
| 1709 | document.execCommand('copy'); |
| 1710 | document.body.removeChild(dummy); |
| 1711 | $btn.html(copied); |
| 1712 | setTimeout(function () { |
| 1713 | $btn.html(copy); |
| 1714 | }, 2500); |
| 1715 | }); |
| 1716 | $(document).on('click', function (e) { |
| 1717 | var container = $(".tutor-dropdown"); |
| 1718 | var $content = container.find('.tutor-dropdown-content'); |
| 1719 | // if the target of the click isn't the container nor a descendant of the container |
| 1720 | if (!container.is(e.target) && container.has(e.target).length === 0) { |
| 1721 | $content.slideUp(100); |
| 1722 | } |
| 1723 | }); |
| 1724 | |
| 1725 | |
| 1726 | /** |
| 1727 | * Tutor ajax login |
| 1728 | * |
| 1729 | * @since v.1.6.3 |
| 1730 | */ |
| 1731 | $(document).on('submit', '.tutor-login-form-wrap #loginform', function (e) { |
| 1732 | e.preventDefault(); |
| 1733 | |
| 1734 | var $that = $(this); |
| 1735 | var $form_wrapper = $('.tutor-login-form-wrap'); |
| 1736 | var form_data = $that.serialize() + '&action=tutor_user_login'; |
| 1737 | |
| 1738 | $.ajax({ |
| 1739 | url: _tutorobject.ajaxurl, |
| 1740 | type: 'POST', |
| 1741 | data: form_data, |
| 1742 | success: function (response) { |
| 1743 | if (response.success) { |
| 1744 | location.assign(response.data.redirect); |
| 1745 | location.reload(); |
| 1746 | } else { |
| 1747 | if ($form_wrapper.find('.tutor-alert').length) { |
| 1748 | $form_wrapper.find('.tutor-alert').html(response.data); |
| 1749 | } else { |
| 1750 | $form_wrapper.prepend('<div class="tutor-alert tutor-alert-warning">' + response.data + '</div>'); |
| 1751 | } |
| 1752 | } |
| 1753 | }, |
| 1754 | }); |
| 1755 | }); |
| 1756 | |
| 1757 | /** |
| 1758 | * Show hide is course public checkbox (frontend dashboard editor) |
| 1759 | * |
| 1760 | * @since v.1.7.2 |
| 1761 | */ |
| 1762 | var price_type = $('.tutor-frontend-builder-course-price [name="tutor_course_price_type"]'); |
| 1763 | if(price_type.length==0){ |
| 1764 | $('#_tutor_is_course_public_meta_checkbox').show(); |
| 1765 | } |
| 1766 | else{ |
| 1767 | price_type.change(function(){ |
| 1768 | if($(this).prop('checked')){ |
| 1769 | var method = $(this).val()=='paid' ? 'hide' : 'show'; |
| 1770 | $('#_tutor_is_course_public_meta_checkbox')[method](); |
| 1771 | } |
| 1772 | }).trigger('change'); |
| 1773 | } |
| 1774 | |
| 1775 | /** |
| 1776 | * Withdrawal page tooltip |
| 1777 | * |
| 1778 | * @since v.1.7.4 |
| 1779 | */ |
| 1780 | // Fully accessible tooltip jQuery plugin with delegation. |
| 1781 | // Ideal for view containers that may re-render content. |
| 1782 | (function ($) { |
| 1783 | $.fn.tutor_tooltip = function () { |
| 1784 | this |
| 1785 | |
| 1786 | // Delegate to tooltip, Hide if tooltip receives mouse or is clicked (tooltip may stick if parent has focus) |
| 1787 | .on('mouseenter click', '.tooltip', function (e) { |
| 1788 | e.stopPropagation(); |
| 1789 | $(this).removeClass('isVisible'); |
| 1790 | }) |
| 1791 | // Delegate to parent of tooltip, Show tooltip if parent receives mouse or focus |
| 1792 | .on('mouseenter focus', ':has(>.tooltip)', function (e) { |
| 1793 | if (!$(this).prop('disabled')) { // IE 8 fix to prevent tooltip on `disabled` elements |
| 1794 | $(this) |
| 1795 | .find('.tooltip') |
| 1796 | .addClass('isVisible'); |
| 1797 | } |
| 1798 | }) |
| 1799 | // Delegate to parent of tooltip, Hide tooltip if parent loses mouse or focus |
| 1800 | .on('mouseleave blur keydown', ':has(>.tooltip)', function (e) { |
| 1801 | if (e.type === 'keydown') { |
| 1802 | if(e.which === 27) { |
| 1803 | $(this) |
| 1804 | .find('.tooltip') |
| 1805 | .removeClass('isVisible'); |
| 1806 | } |
| 1807 | } else { |
| 1808 | $(this) |
| 1809 | .find('.tooltip') |
| 1810 | .removeClass('isVisible'); |
| 1811 | } |
| 1812 | }); |
| 1813 | return this; |
| 1814 | }; |
| 1815 | }(jQuery)); |
| 1816 | |
| 1817 | // Bind event listener to container element |
| 1818 | $('.tutor-tooltip-inside').tutor_tooltip(); |
| 1819 | |
| 1820 | |
| 1821 | |
| 1822 | /** |
| 1823 | * Manage course filter |
| 1824 | * |
| 1825 | * @since v.1.7.2 |
| 1826 | */ |
| 1827 | var filter_criteria = {action:'tutor_course_filter_ajax'}; |
| 1828 | var filter_container = $('.tutor-course-filter-container'); |
| 1829 | var loop_container = $('.tutor-course-filter-loop-container'); |
| 1830 | var toggle_criteria = function(name, value, is_checked){ |
| 1831 | |
| 1832 | if(is_checked===undefined){ |
| 1833 | |
| 1834 | if(!value){ |
| 1835 | delete filter_criteria[name]; |
| 1836 | } |
| 1837 | else{ |
| 1838 | filter_criteria[name]=value; |
| 1839 | } |
| 1840 | } |
| 1841 | else{ |
| 1842 | !filter_criteria[name] ? filter_criteria[name]=[] : 0; |
| 1843 | var index = filter_criteria[name].indexOf(value); |
| 1844 | |
| 1845 | if(is_checked){ |
| 1846 | index==-1 ? filter_criteria[name].push(value) : 0; |
| 1847 | } |
| 1848 | else{ |
| 1849 | filter_criteria[name].splice(index, 1); |
| 1850 | } |
| 1851 | } |
| 1852 | |
| 1853 | push_state(); |
| 1854 | } |
| 1855 | |
| 1856 | var push_state=function(){ |
| 1857 | var exclude = ['column_per_row', 'course_per_page']; |
| 1858 | |
| 1859 | var str = Object.keys(filter_criteria).map(function(key){ |
| 1860 | var val = filter_criteria[key]; |
| 1861 | var str = Array.isArray(val) ? val.join(',') : val; |
| 1862 | |
| 1863 | return (key=='action' || !str || exclude.indexOf(key)>-1) ? null : key+'='+str; |
| 1864 | |
| 1865 | }).filter(q=>q!==null).join('&'); |
| 1866 | |
| 1867 | window.history.replaceState({'id':'tutor_courses'}, 'Courses', (str ? '?'+str : '')); |
| 1868 | } |
| 1869 | |
| 1870 | // Sidebar checkbox value change |
| 1871 | filter_container.find('[type=checkbox]').change(function(e){ |
| 1872 | |
| 1873 | e.originalEvent ? toggle_criteria($(this).attr('name'), $(this).val(), $(this).prop('checked')) : 0; |
| 1874 | filter_criteria.column_per_row = loop_container.data('column_per_row'); |
| 1875 | filter_criteria.course_per_page = loop_container.data('course_per_page'); |
| 1876 | loop_container.html('<div style="text-align:center"><img src="'+window.tutor_loading_icon_url+'"/></div>').show(); |
| 1877 | |
| 1878 | $.ajax({ |
| 1879 | url:window._tutorobject.ajaxurl+(filter_criteria.page ? '?paged='+filter_criteria.page : ''), |
| 1880 | type:'POST', |
| 1881 | data:filter_criteria, |
| 1882 | success:function(r){ |
| 1883 | loop_container.html(r).find('.tutor-pagination-wrap a').each(function(){ |
| 1884 | $(this).attr('data-href', $(this).attr('href')).attr('href', '#'); |
| 1885 | }); |
| 1886 | }, |
| 1887 | error:function(){ |
| 1888 | alert('Request Failed!'); |
| 1889 | } |
| 1890 | }) |
| 1891 | }); |
| 1892 | |
| 1893 | // Search field |
| 1894 | var time_out; |
| 1895 | filter_container.on('input', '[name="tutor-course-filter-keyword"]', function(){ |
| 1896 | window.clearTimeout(time_out); |
| 1897 | |
| 1898 | var value = $(this).val(); |
| 1899 | value = value.trim(); |
| 1900 | |
| 1901 | time_out=window.setTimeout(function(){ |
| 1902 | |
| 1903 | toggle_criteria('keyword', value); |
| 1904 | |
| 1905 | filter_container.find('[type="checkbox"]:first').trigger('change'); |
| 1906 | }, 500); |
| 1907 | }); |
| 1908 | |
| 1909 | // Alter pagination |
| 1910 | loop_container.on('click', '.tutor-pagination-wrap a', function(e){ |
| 1911 | var url = $(this).data('href') || $(this).attr('href'); |
| 1912 | |
| 1913 | if(url){ |
| 1914 | url = new URL(url); |
| 1915 | var page = url.searchParams.get("paged"); |
| 1916 | |
| 1917 | if(page){ |
| 1918 | e.preventDefault(); |
| 1919 | toggle_criteria('page', page); |
| 1920 | |
| 1921 | filter_container.find('[type="checkbox"]:first').trigger('change'); |
| 1922 | } |
| 1923 | } |
| 1924 | }); |
| 1925 | |
| 1926 | // Alter sort filter |
| 1927 | loop_container.on('change', 'select[name="tutor_course_filter"]', function(){ |
| 1928 | toggle_criteria('tutor_course_filter', $(this).val()); |
| 1929 | filter_container.find('[type="checkbox"]:first').trigger('change'); |
| 1930 | }); |
| 1931 | |
| 1932 | // Parse filter from URL |
| 1933 | var url = new URL(window.location.href); |
| 1934 | var trigger_load=false; |
| 1935 | filter_container.find('[type="checkbox"]').each(function(){ |
| 1936 | var name = $(this).attr('name'); |
| 1937 | var value = $(this).val(); |
| 1938 | var checked = $(this).prop('checked'); |
| 1939 | |
| 1940 | var arg = url.searchParams.get(name); |
| 1941 | arg = arg ? arg.split(',') : []; |
| 1942 | |
| 1943 | |
| 1944 | if(arg.indexOf(value)>-1 || checked){ |
| 1945 | $(this).prop('checked', true); |
| 1946 | toggle_criteria(name, value, true, false); |
| 1947 | } |
| 1948 | }); |
| 1949 | |
| 1950 | ['page', 'keyword', 'tutor_course_filter'].forEach(function(name){ |
| 1951 | var value = url.searchParams.get(name); |
| 1952 | |
| 1953 | if(value){ |
| 1954 | toggle_criteria(name, value, undefined, false); |
| 1955 | name=='keyword' ? filter_container.find('[name="tutor-course-filter-keyword"]').val(value) : 0; |
| 1956 | name=='tutor_course_filter' ? loop_container.find('select[name="tutor_course_filter"]').val(value) : 0; |
| 1957 | trigger_load=true; |
| 1958 | } |
| 1959 | }); |
| 1960 | |
| 1961 | if(trigger_load || filter_container.find('input:checked').length>0){ |
| 1962 | filter_container.find('[type="checkbox"]:first').trigger('change'); |
| 1963 | } |
| 1964 | else{ |
| 1965 | loop_container.show(); |
| 1966 | } |
| 1967 | |
| 1968 | // Refresh page after coming back to course archive page from cart |
| 1969 | var archive_loop = $('.tutor-course-loop'); |
| 1970 | if(archive_loop.length>0){ |
| 1971 | window.sessionStorage.getItem('tutor_refresh_archive')==='yes' ? window.location.reload() : 0; |
| 1972 | window.sessionStorage.removeItem('tutor_refresh_archive'); |
| 1973 | archive_loop.on('click', '.tutor-loop-cart-btn-wrap', function(){ |
| 1974 | window.sessionStorage.setItem('tutor_refresh_archive', 'yes'); |
| 1975 | }); |
| 1976 | } |
| 1977 | |
| 1978 | /** |
| 1979 | * Profile Photo and Cover Photo editor |
| 1980 | * |
| 1981 | * @since v.1.7.5 |
| 1982 | */ |
| 1983 | var PhotoEditor=function(photo_editor){ |
| 1984 | |
| 1985 | this.dialogue_box = photo_editor.find('#tutor_photo_dialogue_box'); |
| 1986 | |
| 1987 | |
| 1988 | this.open_dialogue_box = function(name){ |
| 1989 | this.dialogue_box.attr('name', name); |
| 1990 | this.dialogue_box.trigger('click'); |
| 1991 | } |
| 1992 | |
| 1993 | this.validate_image = function(file){ |
| 1994 | return true; |
| 1995 | } |
| 1996 | |
| 1997 | this.upload_selected_image = function(name, file){ |
| 1998 | if(!file || !this.validate_image(file)){ |
| 1999 | return; |
| 2000 | } |
| 2001 | |
| 2002 | var context = this; |
| 2003 | context.toggle_loader(name, true); |
| 2004 | |
| 2005 | // Prepare payload to upload |
| 2006 | var form_data = new FormData(); |
| 2007 | form_data.append('action', 'tutor_user_photo_upload'); |
| 2008 | form_data.append('photo_type', name); |
| 2009 | form_data.append('photo_file', file, file.name); |
| 2010 | |
| 2011 | $.ajax({ |
| 2012 | url:window._tutorobject.ajaxurl, |
| 2013 | data:form_data, |
| 2014 | type:'POST', |
| 2015 | processData: false, |
| 2016 | contentType: false, |
| 2017 | error:context.error_alert, |
| 2018 | complete:function(){ |
| 2019 | context.toggle_loader(name, false); |
| 2020 | } |
| 2021 | }) |
| 2022 | } |
| 2023 | |
| 2024 | this.accept_upload_image=function(context, e){ |
| 2025 | var file = e.currentTarget.files[0] || null; |
| 2026 | context.update_preview(e.currentTarget.name, file); |
| 2027 | context.upload_selected_image(e.currentTarget.name, file); |
| 2028 | $(e.currentTarget).val(''); |
| 2029 | } |
| 2030 | |
| 2031 | this.delete_image=function(name){ |
| 2032 | var context = this; |
| 2033 | context.toggle_loader(name, true); |
| 2034 | |
| 2035 | $.ajax({ |
| 2036 | url:window._tutorobject.ajaxurl, |
| 2037 | data:{action:'tutor_user_photo_remove', photo_type:name}, |
| 2038 | type:'POST', |
| 2039 | error:context.error_alert, |
| 2040 | complete:function(){ |
| 2041 | context.toggle_loader(name, false); |
| 2042 | } |
| 2043 | }); |
| 2044 | } |
| 2045 | |
| 2046 | this.update_preview=function(name, file){ |
| 2047 | var renderer = photo_editor.find(name=='cover_photo' ? '#tutor_cover_area' : '#tutor_profile_area'); |
| 2048 | |
| 2049 | if(!file){ |
| 2050 | renderer.css('background-image', 'url('+renderer.data('fallback')+')'); |
| 2051 | this.delete_image(name); |
| 2052 | return; |
| 2053 | } |
| 2054 | |
| 2055 | var reader = new FileReader(); |
| 2056 | reader.onload = function(e) { |
| 2057 | renderer.css('background-image', 'url('+e.target.result+')'); |
| 2058 | } |
| 2059 | |
| 2060 | reader.readAsDataURL(file); |
| 2061 | } |
| 2062 | |
| 2063 | this.toggle_profile_pic_action=function(show){ |
| 2064 | var method = show===undefined ? 'toggleClass' : (show ? 'addClass' : 'removeClass'); |
| 2065 | photo_editor[method]('pop-up-opened'); |
| 2066 | } |
| 2067 | |
| 2068 | this.error_alert=function(){ |
| 2069 | alert('Something Went Wrong.'); |
| 2070 | } |
| 2071 | |
| 2072 | this.toggle_loader = function(name, show){ |
| 2073 | photo_editor.find('#tutor_photo_meta_area .loader-area').css('display', (show ? 'block' : 'none')); |
| 2074 | } |
| 2075 | |
| 2076 | this.initialize = function(){ |
| 2077 | var context = this; |
| 2078 | |
| 2079 | this.dialogue_box.change(function(e){context.accept_upload_image(context, e)}); |
| 2080 | |
| 2081 | photo_editor.find('#tutor_profile_area .tutor_overlay, #tutor_pp_option>div:last-child').click(function(){context.toggle_profile_pic_action()}); |
| 2082 | |
| 2083 | // Upload new |
| 2084 | photo_editor.find('.tutor_cover_uploader').click(function(){context.open_dialogue_box('cover_photo')}); |
| 2085 | photo_editor.find('.tutor_pp_uploader').click(function(){context.open_dialogue_box('profile_photo')}); |
| 2086 | |
| 2087 | // Delete existing |
| 2088 | photo_editor.find('.tutor_cover_deleter').click(function(){context.update_preview('cover_photo', null)}); |
| 2089 | photo_editor.find('.tutor_pp_deleter').click(function(){context.update_preview('profile_photo', null)}); |
| 2090 | } |
| 2091 | } |
| 2092 | |
| 2093 | var photo_editor = $('#tutor_profile_cover_photo_editor'); |
| 2094 | photo_editor.length>0 ? new PhotoEditor(photo_editor).initialize() : 0; |
| 2095 | }); |