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
1730 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 | /** |
| 132 | * Hover tutor rating and set value |
| 133 | */ |
| 134 | $(document).on('hover', '.tutor-write-review-box .tutor-star-rating-group i', function () { |
| 135 | $(this).closest('.tutor-star-rating-group').find('i').removeClass('tutor-icon-star-full').addClass('tutor-icon-star-line'); |
| 136 | var currentRateValue = $(this).attr('data-rating-value'); |
| 137 | for (var i = 1; i <= currentRateValue; i++) { |
| 138 | $(this).closest('.tutor-star-rating-group').find('i[data-rating-value="' + i + '"]').removeClass('tutor-icon-star-line').addClass('tutor-icon-star-full'); |
| 139 | } |
| 140 | $(this).closest('.tutor-star-rating-group').find('input[name="tutor_rating_gen_input"]').val(currentRateValue); |
| 141 | }); |
| 142 | |
| 143 | $(document).on('click', '.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 | |
| 148 | $(document).on('click', '.tutor_submit_review_btn', function (e) { |
| 149 | e.preventDefault(); |
| 150 | var $that = $(this); |
| 151 | var rating = $that.closest('form').find('input[name="tutor_rating_gen_input"]').val(); |
| 152 | var review = $that.closest('form').find('textarea[name="review"]').val(); |
| 153 | review = review.trim(); |
| 154 | |
| 155 | var course_id = $('input[name="tutor_course_id"]').val(); |
| 156 | var data = { course_id: course_id, rating: rating, review: review, action: 'tutor_place_rating' }; |
| 157 | |
| 158 | if (review) { |
| 159 | $.ajax({ |
| 160 | url: _tutorobject.ajaxurl, |
| 161 | type: 'POST', |
| 162 | data: data, |
| 163 | beforeSend: function () { |
| 164 | $that.addClass('updating-icon'); |
| 165 | }, |
| 166 | success: function (data) { |
| 167 | var review_id = data.data.review_id; |
| 168 | var review = data.data.review; |
| 169 | $('.tutor-review-' + review_id + ' .review-content').html(review); |
| 170 | location.reload(); |
| 171 | } |
| 172 | }); |
| 173 | } |
| 174 | }); |
| 175 | |
| 176 | $(document).on('click', '.write-course-review-link-btn', function (e) { |
| 177 | e.preventDefault(); |
| 178 | $(this).siblings('.tutor-write-review-form').slideToggle(); |
| 179 | }); |
| 180 | |
| 181 | $(document).on('click', '.tutor-ask-question-btn', function (e) { |
| 182 | e.preventDefault(); |
| 183 | $('.tutor-add-question-wrap').slideToggle(); |
| 184 | }); |
| 185 | $(document).on('click', '.tutor_question_cancel', function (e) { |
| 186 | e.preventDefault(); |
| 187 | $('.tutor-add-question-wrap').toggle(); |
| 188 | }); |
| 189 | |
| 190 | $(document).on('submit', '#tutor-ask-question-form', function (e) { |
| 191 | e.preventDefault(); |
| 192 | |
| 193 | var $form = $(this); |
| 194 | var data = $(this).serialize() + '&action=tutor_ask_question'; |
| 195 | |
| 196 | $.ajax({ |
| 197 | url: _tutorobject.ajaxurl, |
| 198 | type: 'POST', |
| 199 | data: data, |
| 200 | beforeSend: function () { |
| 201 | $form.find('.tutor_ask_question_btn').addClass('updating-icon'); |
| 202 | }, |
| 203 | success: function (data) { |
| 204 | if (data.success) { |
| 205 | $('.tutor-add-question-wrap').hide(); |
| 206 | window.location.reload(); |
| 207 | } |
| 208 | }, |
| 209 | complete: function () { |
| 210 | $form.find('.tutor_ask_question_btn').removeClass('updating-icon'); |
| 211 | } |
| 212 | }); |
| 213 | }); |
| 214 | |
| 215 | $(document).on('submit', '.tutor-add-answer-form', function (e) { |
| 216 | e.preventDefault(); |
| 217 | |
| 218 | var $form = $(this); |
| 219 | var data = $(this).serialize() + '&action=tutor_add_answer'; |
| 220 | |
| 221 | $.ajax({ |
| 222 | url: _tutorobject.ajaxurl, |
| 223 | type: 'POST', |
| 224 | data: data, |
| 225 | beforeSend: function () { |
| 226 | $form.find('.tutor_add_answer_btn').addClass('updating-icon'); |
| 227 | }, |
| 228 | success: function (data) { |
| 229 | if (data.success) { |
| 230 | window.location.reload(); |
| 231 | } |
| 232 | }, |
| 233 | complete: function () { |
| 234 | $form.find('.tutor_add_answer_btn').removeClass('updating-icon'); |
| 235 | } |
| 236 | }); |
| 237 | }); |
| 238 | |
| 239 | $(document).on('focus', '.tutor_add_answer_textarea', function (e) { |
| 240 | e.preventDefault(); |
| 241 | |
| 242 | var question_id = $(this).closest('.tutor_add_answer_wrap').attr('data-question-id'); |
| 243 | var conf = { |
| 244 | tinymce: { |
| 245 | wpautop: true, |
| 246 | //plugins : 'charmap colorpicker compat3x directionality fullscreen hr image lists media paste tabfocus textcolor wordpress wpautoresize wpdialogs wpeditimage wpemoji wpgallery wplink wptextpattern wpview', |
| 247 | toolbar1: 'bold italic underline bullist strikethrough numlist blockquote alignleft aligncenter alignright undo redo link unlink spellchecker fullscreen' |
| 248 | }, |
| 249 | }; |
| 250 | wp.editor.initialize('tutor_answer_' + question_id, conf); |
| 251 | }); |
| 252 | |
| 253 | $(document).on('click', '.tutor_cancel_wp_editor', function (e) { |
| 254 | e.preventDefault(); |
| 255 | $(this).closest('.tutor_wp_editor_wrap').toggle(); |
| 256 | $(this).closest('.tutor_add_answer_wrap').find('.tutor_wp_editor_show_btn_wrap').toggle(); |
| 257 | var question_id = $(this).closest('.tutor_add_answer_wrap').attr('data-question-id'); |
| 258 | wp.editor.remove('tutor_answer_' + question_id); |
| 259 | }); |
| 260 | |
| 261 | $(document).on('click', '.tutor_wp_editor_show_btn', function (e) { |
| 262 | e.preventDefault(); |
| 263 | $(this).closest('.tutor_add_answer_wrap').find('.tutor_wp_editor_wrap').toggle(); |
| 264 | $(this).closest('.tutor_wp_editor_show_btn_wrap').toggle(); |
| 265 | }); |
| 266 | |
| 267 | /** |
| 268 | * Quiz attempt |
| 269 | */ |
| 270 | var $tutor_quiz_time_update = $('#tutor-quiz-time-update'); |
| 271 | var attempt_settings = null; |
| 272 | if ($tutor_quiz_time_update.length) { |
| 273 | attempt_settings = JSON.parse($tutor_quiz_time_update.attr('data-attempt-settings')); |
| 274 | var attempt_meta = JSON.parse($tutor_quiz_time_update.attr('data-attempt-meta')); |
| 275 | |
| 276 | if (attempt_meta.time_limit.time_limit_seconds > 0) { |
| 277 | //No time Zero limit for |
| 278 | var countDownDate = new Date(attempt_settings.attempt_started_at).getTime() + (attempt_meta.time_limit.time_limit_seconds * 1000); |
| 279 | var time_now = new Date(attempt_meta.date_time_now).getTime(); |
| 280 | |
| 281 | var tutor_quiz_interval = setInterval(function () { |
| 282 | var distance = countDownDate - time_now; |
| 283 | |
| 284 | var days = Math.floor(distance / (1000 * 60 * 60 * 24)); |
| 285 | var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); |
| 286 | var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); |
| 287 | var seconds = Math.floor((distance % (1000 * 60)) / 1000); |
| 288 | |
| 289 | var countdown_human = ''; |
| 290 | |
| 291 | if (days) { |
| 292 | countdown_human += days + "d "; |
| 293 | } |
| 294 | if (hours) { |
| 295 | countdown_human += hours + "h "; |
| 296 | } |
| 297 | if (minutes) { |
| 298 | countdown_human += minutes + "m "; |
| 299 | } |
| 300 | if (seconds) { |
| 301 | countdown_human += seconds + "s "; |
| 302 | } |
| 303 | |
| 304 | if (distance < 0) { |
| 305 | clearInterval(tutor_quiz_interval); |
| 306 | countdown_human = "EXPIRED"; |
| 307 | //Set the quiz attempt to timeout in ajax |
| 308 | |
| 309 | if (_tutorobject.quiz_options.quiz_when_time_expires === 'autosubmit') { |
| 310 | /** |
| 311 | * Auto Submit |
| 312 | */ |
| 313 | $('form#tutor-answering-quiz').submit(); |
| 314 | |
| 315 | } else if (_tutorobject.quiz_options.quiz_when_time_expires === 'autoabandon') { |
| 316 | /** |
| 317 | * |
| 318 | * @type {jQuery} |
| 319 | * |
| 320 | * Current attempt will be cancel with attempt status attempt_timeout |
| 321 | */ |
| 322 | |
| 323 | var quiz_id = $('#tutor_quiz_id').val(); |
| 324 | var tutor_quiz_remaining_time_secs = $('#tutor_quiz_remaining_time_secs').val(); |
| 325 | var quiz_timeout_data = { quiz_id: quiz_id, action: 'tutor_quiz_timeout' }; |
| 326 | |
| 327 | $.ajax({ |
| 328 | url: _tutorobject.ajaxurl, |
| 329 | type: 'POST', |
| 330 | data: quiz_timeout_data, |
| 331 | success: function (data) { |
| 332 | if (data.success) { |
| 333 | window.location.reload(true); |
| 334 | } |
| 335 | }, |
| 336 | complete: function () { |
| 337 | $('#tutor-quiz-body').html(''); |
| 338 | window.location.reload(true); |
| 339 | } |
| 340 | }); |
| 341 | } |
| 342 | |
| 343 | } |
| 344 | time_now = time_now + 1000; |
| 345 | $tutor_quiz_time_update.html(countdown_human); |
| 346 | }, 1000); |
| 347 | } else { |
| 348 | $tutor_quiz_time_update.closest('.time-remaining').remove(); |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | var $quiz_start_form = $('#tutor-quiz-body form#tutor-start-quiz'); |
| 353 | if ($quiz_start_form.length) { |
| 354 | if (_tutorobject.quiz_options.quiz_auto_start === '1') { |
| 355 | $quiz_start_form.submit(); |
| 356 | } |
| 357 | } |
| 358 | |
| 359 | /** |
| 360 | * Quiz Frontend Review Action |
| 361 | * @since 1.4.0 |
| 362 | */ |
| 363 | $(document).on('click', '.quiz-manual-review-action', function (e) { |
| 364 | e.preventDefault(); |
| 365 | var $that = $(this), |
| 366 | attempt_id = $that.attr('data-attempt-id'), |
| 367 | attempt_answer_id = $that.attr('data-attempt-answer-id'), |
| 368 | mark_as = $that.attr('data-mark-as'); |
| 369 | |
| 370 | $.ajax({ |
| 371 | url: _tutorobject.ajaxurl, |
| 372 | type: 'GET', |
| 373 | data: { action: 'review_quiz_answer', attempt_id: attempt_id, attempt_answer_id: attempt_answer_id, mark_as: mark_as }, |
| 374 | beforeSend: function () { |
| 375 | $that.find('i').addClass('updating-icon'); |
| 376 | }, |
| 377 | success: function (data) { |
| 378 | location.reload(); |
| 379 | }, |
| 380 | complete: function () { |
| 381 | $that.find('i').removeClass('updating-icon'); |
| 382 | } |
| 383 | }); |
| 384 | }); |
| 385 | |
| 386 | // Quiz Review : Tooltip |
| 387 | $(".tooltip-btn").on("hover", function (e) { |
| 388 | $(this).toggleClass("active"); |
| 389 | }); |
| 390 | |
| 391 | // tutor course content accordion |
| 392 | |
| 393 | /** |
| 394 | * Toggle topic summery |
| 395 | * @since v.1.6.9 |
| 396 | */ |
| 397 | $('.tutor-course-title h4 .toogle-informaiton-icon').on('click', function (e) { |
| 398 | $(this).closest('.tutor-topics-in-single-lesson').find('.tutor-topics-summery').slideToggle(); |
| 399 | e.stopPropagation(); |
| 400 | }); |
| 401 | |
| 402 | $('.tutor-course-topic.tutor-active').find('.tutor-course-lessons').slideDown(); |
| 403 | $('.tutor-course-title').on('click', function () { |
| 404 | var lesson = $(this).siblings('.tutor-course-lessons'); |
| 405 | $(this).closest('.tutor-course-topic').toggleClass('tutor-active'); |
| 406 | lesson.slideToggle(); |
| 407 | }); |
| 408 | |
| 409 | $(document).on('click', '.tutor-topics-title h3 .toogle-informaiton-icon', function (e) { |
| 410 | $(this).closest('.tutor-topics-in-single-lesson').find('.tutor-topics-summery').slideToggle(); |
| 411 | e.stopPropagation(); |
| 412 | }); |
| 413 | |
| 414 | $(document).on('click', '.tutor-course-wishlist-btn', function (e) { |
| 415 | e.preventDefault(); |
| 416 | |
| 417 | var $that = $(this); |
| 418 | var course_id = $that.attr('data-course-id'); |
| 419 | |
| 420 | $.ajax({ |
| 421 | url: _tutorobject.ajaxurl, |
| 422 | type: 'POST', |
| 423 | data: { course_id: course_id, 'action': 'tutor_course_add_to_wishlist' }, |
| 424 | beforeSend: function () { |
| 425 | $that.addClass('updating-icon'); |
| 426 | }, |
| 427 | success: function (data) { |
| 428 | if (data.success) { |
| 429 | if (data.data.status === 'added') { |
| 430 | $that.addClass('has-wish-listed'); |
| 431 | } else { |
| 432 | $that.removeClass('has-wish-listed'); |
| 433 | } |
| 434 | } else { |
| 435 | window.location = data.data.redirect_to; |
| 436 | } |
| 437 | }, |
| 438 | complete: function () { |
| 439 | $that.removeClass('updating-icon'); |
| 440 | } |
| 441 | }); |
| 442 | }); |
| 443 | |
| 444 | /** |
| 445 | * Check if lesson has classic editor support |
| 446 | * If classic editor support, stop ajax load on the lesson page. |
| 447 | * |
| 448 | * @since v.1.0.0 |
| 449 | * |
| 450 | * @updated v.1.4.0 |
| 451 | */ |
| 452 | if (!_tutorobject.enable_lesson_classic_editor) { |
| 453 | |
| 454 | $(document).on('click', '.tutor-single-lesson-a', function (e) { |
| 455 | e.preventDefault(); |
| 456 | |
| 457 | var $that = $(this); |
| 458 | var lesson_id = $that.attr('data-lesson-id'); |
| 459 | var $wrap = $('#tutor-single-entry-content'); |
| 460 | |
| 461 | $.ajax({ |
| 462 | url: _tutorobject.ajaxurl, |
| 463 | type: 'POST', |
| 464 | data: { lesson_id: lesson_id, 'action': 'tutor_render_lesson_content' }, |
| 465 | beforeSend: function () { |
| 466 | var page_title = $that.find('.lesson_title').text(); |
| 467 | $('head title').text(page_title); |
| 468 | window.history.pushState('obj', page_title, $that.attr('href')); |
| 469 | $wrap.addClass('loading-lesson'); |
| 470 | $('.tutor-single-lesson-items').removeClass('active'); |
| 471 | $that.closest('.tutor-single-lesson-items').addClass('active'); |
| 472 | }, |
| 473 | success: function (data) { |
| 474 | $wrap.html(data.data.html); |
| 475 | videoPlayer.init(); |
| 476 | $('.tutor-lesson-sidebar').css('display', ''); |
| 477 | }, |
| 478 | complete: function () { |
| 479 | $wrap.removeClass('loading-lesson'); |
| 480 | } |
| 481 | }); |
| 482 | }); |
| 483 | |
| 484 | $(document).on('click', '.sidebar-single-quiz-a', function (e) { |
| 485 | e.preventDefault(); |
| 486 | |
| 487 | var $that = $(this); |
| 488 | var quiz_id = $that.attr('data-quiz-id'); |
| 489 | var page_title = $that.find('.lesson_title').text(); |
| 490 | var $wrap = $('#tutor-single-entry-content'); |
| 491 | |
| 492 | $.ajax({ |
| 493 | url: _tutorobject.ajaxurl, |
| 494 | type: 'POST', |
| 495 | data: { quiz_id: quiz_id, 'action': 'tutor_render_quiz_content' }, |
| 496 | beforeSend: function () { |
| 497 | $('head title').text(page_title); |
| 498 | window.history.pushState('obj', page_title, $that.attr('href')); |
| 499 | $wrap.addClass('loading-lesson'); |
| 500 | $('.tutor-single-lesson-items').removeClass('active'); |
| 501 | $that.closest('.tutor-single-lesson-items').addClass('active'); |
| 502 | }, |
| 503 | success: function (data) { |
| 504 | $wrap.html(data.data.html); |
| 505 | init_quiz_builder(); |
| 506 | $('.tutor-lesson-sidebar').css('display', ''); |
| 507 | }, |
| 508 | complete: function () { |
| 509 | $wrap.removeClass('loading-lesson'); |
| 510 | } |
| 511 | }); |
| 512 | }); |
| 513 | } |
| 514 | |
| 515 | /** |
| 516 | * @date 05 Feb, 2019 |
| 517 | */ |
| 518 | |
| 519 | $(document).on('click', '.tutor-lesson-sidebar-hide-bar', function (e) { |
| 520 | e.preventDefault(); |
| 521 | $('.tutor-lesson-sidebar').toggle(); |
| 522 | $('#tutor-single-entry-content').toggleClass("sidebar-hidden"); |
| 523 | |
| 524 | }); |
| 525 | |
| 526 | $(".tutor-tabs-btn-group a").on('click touchstart', function (e) { |
| 527 | e.preventDefault(); |
| 528 | var $that = $(this); |
| 529 | var tabSelector = $that.attr('href'); |
| 530 | $('.tutor-lesson-sidebar-tab-item').hide(); |
| 531 | $(tabSelector).show(); |
| 532 | |
| 533 | $('.tutor-tabs-btn-group a').removeClass('active'); |
| 534 | $that.addClass('active'); |
| 535 | }); |
| 536 | /** |
| 537 | * @date 18 Feb, 2019 |
| 538 | * @since v.1.0.0 |
| 539 | */ |
| 540 | |
| 541 | function init_quiz_builder() { |
| 542 | if (jQuery().sortable) { |
| 543 | $(".tutor-quiz-answers-wrap").sortable({ |
| 544 | handle: ".answer-sorting-bar", |
| 545 | start: function (e, ui) { |
| 546 | ui.placeholder.css('visibility', 'visible'); |
| 547 | }, |
| 548 | stop: function (e, ui) { |
| 549 | //Sorting Stopped... |
| 550 | }, |
| 551 | }).disableSelection(); |
| 552 | |
| 553 | $(".quiz-draggable-rand-answers, .quiz-answer-matching-droppable").sortable({ |
| 554 | connectWith: ".quiz-answer-matching-droppable", |
| 555 | placeholder: "drop-hover", |
| 556 | }).disableSelection(); |
| 557 | } |
| 558 | } |
| 559 | init_quiz_builder(); |
| 560 | /** |
| 561 | * Quiz view |
| 562 | * @date 22 Feb, 2019 |
| 563 | * @since v.1.0.0 |
| 564 | */ |
| 565 | |
| 566 | $(document).on('click', '.tutor-quiz-answer-next-btn', function (e) { |
| 567 | e.preventDefault(); |
| 568 | |
| 569 | var $that = $(this); |
| 570 | var $question_wrap = $that.closest('.quiz-attempt-single-question'); |
| 571 | /** |
| 572 | * Validating required answer |
| 573 | * @type {jQuery} |
| 574 | * |
| 575 | * @since v.1.6.1 |
| 576 | */ |
| 577 | |
| 578 | var validated = tutor_quiz_validation($question_wrap); |
| 579 | if (!validated) { |
| 580 | return; |
| 581 | } |
| 582 | |
| 583 | var feedBackNext = feedback_response($question_wrap); |
| 584 | if (!feedBackNext) { |
| 585 | return; |
| 586 | } |
| 587 | |
| 588 | var question_id = parseInt($that.closest('.quiz-attempt-single-question').attr('id').match(/\d+/)[0], 10); |
| 589 | |
| 590 | var next_question_id = $that.closest('.quiz-attempt-single-question').attr('data-next-question-id'); |
| 591 | |
| 592 | if (next_question_id) { |
| 593 | var $nextQuestion = $(next_question_id); |
| 594 | if ($nextQuestion && $nextQuestion.length) { |
| 595 | $('.quiz-attempt-single-question').hide(); |
| 596 | $nextQuestion.show(); |
| 597 | |
| 598 | /** |
| 599 | * If pagination exists, set active class |
| 600 | */ |
| 601 | |
| 602 | if ($('.tutor-quiz-questions-pagination').length) { |
| 603 | $('.tutor-quiz-question-paginate-item').removeClass('active'); |
| 604 | $('.tutor-quiz-questions-pagination a[href="' + next_question_id + '"]').addClass('active'); |
| 605 | } |
| 606 | |
| 607 | } |
| 608 | } |
| 609 | }); |
| 610 | |
| 611 | |
| 612 | $(document).on('click', '.tutor-quiz-answer-next-btn', function (e) { |
| 613 | e.preventDefault(); |
| 614 | |
| 615 | }); |
| 616 | |
| 617 | |
| 618 | $(document).on('submit', '#tutor-answering-quiz', function (e) { |
| 619 | var $questions_wrap = $('.quiz-attempt-single-question'); |
| 620 | var validated = true; |
| 621 | if ($questions_wrap.length) { |
| 622 | $questions_wrap.each(function (index, question) { |
| 623 | validated = tutor_quiz_validation($(question)); |
| 624 | validated = feedback_response($(question)); |
| 625 | }); |
| 626 | } |
| 627 | |
| 628 | if (!validated) { |
| 629 | e.preventDefault(); |
| 630 | } |
| 631 | |
| 632 | }); |
| 633 | |
| 634 | |
| 635 | $(document).on('click', '.tutor-quiz-question-paginate-item', function (e) { |
| 636 | e.preventDefault(); |
| 637 | var $that = $(this); |
| 638 | var $question = $($that.attr('href')); |
| 639 | $('.quiz-attempt-single-question').hide(); |
| 640 | $question.show(); |
| 641 | |
| 642 | //Active Class |
| 643 | $('.tutor-quiz-question-paginate-item').removeClass('active'); |
| 644 | $that.addClass('active'); |
| 645 | }); |
| 646 | |
| 647 | /** |
| 648 | * Limit Short Answer Question Type |
| 649 | */ |
| 650 | $(document).on('keyup', 'textarea.question_type_short_answer, textarea.question_type_open_ended', function (e) { |
| 651 | var $that = $(this); |
| 652 | var value = $that.val(); |
| 653 | var limit = $that.hasClass('question_type_short_answer') ? _tutorobject.quiz_options.short_answer_characters_limit : _tutorobject.quiz_options.open_ended_answer_characters_limit; |
| 654 | var remaining = limit - value.length; |
| 655 | |
| 656 | if (remaining < 1) { |
| 657 | $that.val(value.substr(0, limit)); |
| 658 | remaining = 0; |
| 659 | } |
| 660 | $that.closest('.tutor-quiz-answers-wrap').find('.characters_remaining').html(remaining); |
| 661 | }); |
| 662 | |
| 663 | /** |
| 664 | * |
| 665 | * @type {jQuery} |
| 666 | * |
| 667 | * Improved Quiz draggable answers drop accessibility |
| 668 | * Answers draggable wrap will be now same height. |
| 669 | * |
| 670 | * @since v.1.4.4 |
| 671 | */ |
| 672 | var countDraggableAnswers = $('.quiz-draggable-rand-answers').length; |
| 673 | if (countDraggableAnswers) { |
| 674 | $('.quiz-draggable-rand-answers').each(function () { |
| 675 | var $that = $(this); |
| 676 | var draggableDivHeight = $that.height(); |
| 677 | |
| 678 | $that.css({ "height": draggableDivHeight }); |
| 679 | }); |
| 680 | } |
| 681 | |
| 682 | |
| 683 | /** |
| 684 | * Quiz Validation Helper |
| 685 | * |
| 686 | * @since v.1.6.1 |
| 687 | */ |
| 688 | |
| 689 | function tutor_quiz_validation($question_wrap) { |
| 690 | var validated = true; |
| 691 | |
| 692 | var $required_answer_wrap = $question_wrap.find('.quiz-answer-required'); |
| 693 | |
| 694 | if ($required_answer_wrap.length) { |
| 695 | /** |
| 696 | * Radio field validation |
| 697 | * |
| 698 | * @type {jQuery} |
| 699 | * |
| 700 | * @since v.1.6.1 |
| 701 | */ |
| 702 | var $inputs = $required_answer_wrap.find('input'); |
| 703 | if ($inputs.length) { |
| 704 | var $type = $inputs.attr('type'); |
| 705 | if ($type === 'radio') { |
| 706 | if ($required_answer_wrap.find('input[type="radio"]:checked').length == 0) { |
| 707 | $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">Please select an option to answer</p>'); |
| 708 | validated = false; |
| 709 | } |
| 710 | } else if ($type === 'checkbox') { |
| 711 | if ($required_answer_wrap.find('input[type="checkbox"]:checked').length == 0) { |
| 712 | $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">Please select at least one option to answer.</p>'); |
| 713 | validated = false; |
| 714 | } |
| 715 | } else if ($type === 'text') { |
| 716 | //Fill in the gaps if many, validation all |
| 717 | $inputs.each(function (index, input) { |
| 718 | if (!$(input).val().trim().length) { |
| 719 | $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">The answer for this question is required</p>'); |
| 720 | validated = false; |
| 721 | } |
| 722 | }); |
| 723 | } |
| 724 | |
| 725 | } |
| 726 | if ($required_answer_wrap.find('textarea').length) { |
| 727 | if ($required_answer_wrap.find('textarea').val().trim().length < 1) { |
| 728 | $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">The answer for this question is required</p>'); |
| 729 | validated = false; |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | /** |
| 734 | * Matching Question |
| 735 | */ |
| 736 | var $matchingDropable = $required_answer_wrap.find('.quiz-answer-matching-droppable'); |
| 737 | if ($matchingDropable.length) { |
| 738 | |
| 739 | $matchingDropable.each(function (index, matching) { |
| 740 | if (!$(matching).find('.quiz-draggable-answer-item').length) { |
| 741 | $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">Please match all the items</p>'); |
| 742 | validated = false; |
| 743 | } |
| 744 | }); |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | return validated; |
| 749 | } |
| 750 | |
| 751 | function feedback_response($question_wrap) { |
| 752 | var goNext = false; |
| 753 | |
| 754 | var feedBackMode = $question_wrap.attr('data-quiz-feedback-mode'); |
| 755 | $('.wrong-right-text').remove(); |
| 756 | $('.quiz-answer-input-bottom').removeClass('wrong-answer right-answer'); |
| 757 | |
| 758 | var validatedTrue = true; |
| 759 | var $inputs = $question_wrap.find('input'); |
| 760 | var $checkedInputs = $question_wrap.find('input[type="radio"]:checked, input[type="checkbox"]:checked'); |
| 761 | |
| 762 | if (feedBackMode === 'retry') { |
| 763 | $checkedInputs.each(function () { |
| 764 | var $input = $(this); |
| 765 | |
| 766 | var $type = $input.attr('type'); |
| 767 | if ($type === 'radio' || $type === 'checkbox') { |
| 768 | var isTrue = $input.attr('data-is-correct') == '1'; |
| 769 | if ( !isTrue) { |
| 770 | if ($input.prop("checked")) { |
| 771 | $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>'); |
| 772 | } |
| 773 | validatedTrue = false; |
| 774 | } |
| 775 | } |
| 776 | }); |
| 777 | |
| 778 | $inputs.each(function () { |
| 779 | var $input = $(this); |
| 780 | var $type = $input.attr('type'); |
| 781 | if ($type === 'checkbox') { |
| 782 | var isTrue = $input.attr('data-is-correct') == '1'; |
| 783 | var checked = $input.is(':checked'); |
| 784 | |
| 785 | if (isTrue && !checked) { |
| 786 | $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">More answer for this question is required</p>'); |
| 787 | validatedTrue = false; |
| 788 | } |
| 789 | } |
| 790 | }); |
| 791 | |
| 792 | } else if (feedBackMode === 'reveal') { |
| 793 | $checkedInputs.each(function () { |
| 794 | var $input = $(this); |
| 795 | var isTrue = $input.attr('data-is-correct') == '1'; |
| 796 | if (!isTrue) { |
| 797 | validatedTrue = false; |
| 798 | } |
| 799 | }); |
| 800 | |
| 801 | $inputs.each(function () { |
| 802 | var $input = $(this); |
| 803 | |
| 804 | var $type = $input.attr('type'); |
| 805 | if ($type === 'radio' || $type === 'checkbox') { |
| 806 | var isTrue = $input.attr('data-is-correct') == '1'; |
| 807 | var checked = $input.is(':checked'); |
| 808 | |
| 809 | if (isTrue) { |
| 810 | $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>'); |
| 811 | } else { |
| 812 | if ($input.prop("checked")) { |
| 813 | $input.closest('.quiz-answer-input-bottom').addClass('wrong-answer'); |
| 814 | } |
| 815 | } |
| 816 | |
| 817 | if (isTrue && !checked) { |
| 818 | validatedTrue = false; |
| 819 | } |
| 820 | } |
| 821 | }); |
| 822 | } |
| 823 | |
| 824 | if (validatedTrue) { |
| 825 | goNext = true; |
| 826 | } |
| 827 | |
| 828 | return goNext; |
| 829 | } |
| 830 | |
| 831 | |
| 832 | /** |
| 833 | * Add to cart in guest mode, show login form |
| 834 | * |
| 835 | * @since v.1.0.4 |
| 836 | */ |
| 837 | |
| 838 | $(document).on('submit click', '.cart-required-login, .cart-required-login a, .cart-required-login form', function (e) { |
| 839 | e.preventDefault(); |
| 840 | |
| 841 | var login_url = $(this).data('login_page_url'); |
| 842 | login_url ? window.location.assign(login_url) : $('.tutor-cart-box-login-form').fadeIn(100); |
| 843 | }); |
| 844 | |
| 845 | $('.tutor-popup-form-close, .login-overlay-close').on('click', function () { |
| 846 | $('.tutor-cart-box-login-form').fadeOut(100); |
| 847 | }); |
| 848 | |
| 849 | $(document).on('keyup', function (e) { |
| 850 | if (e.keyCode === 27) { |
| 851 | $('.tutor-frontend-modal').hide(); |
| 852 | $('.tutor-cart-box-login-form').fadeOut(100); |
| 853 | } |
| 854 | }); |
| 855 | /** |
| 856 | * Share Link enable |
| 857 | * |
| 858 | * @since v.1.0.4 |
| 859 | */ |
| 860 | if ($.fn.ShareLink) { |
| 861 | var $social_share_wrap = $('.tutor-social-share-wrap'); |
| 862 | if ($social_share_wrap.length) { |
| 863 | var share_config = JSON.parse($social_share_wrap.attr('data-social-share-config')); |
| 864 | |
| 865 | $('.tutor_share').ShareLink({ |
| 866 | title: share_config.title, |
| 867 | text: share_config.text, |
| 868 | image: share_config.image, |
| 869 | class_prefix: 's_', |
| 870 | width: 640, |
| 871 | height: 480, |
| 872 | }); |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | /** |
| 877 | * Datepicker initiate |
| 878 | * |
| 879 | * @since v.1.1.2 |
| 880 | */ |
| 881 | if (jQuery.datepicker) { |
| 882 | $(".tutor_report_datepicker").datepicker({ "dateFormat": 'yy-mm-dd' }); |
| 883 | } |
| 884 | |
| 885 | |
| 886 | /** |
| 887 | * Withdraw Form Tab/Toggle |
| 888 | * |
| 889 | * @since v.1.1.2 |
| 890 | */ |
| 891 | |
| 892 | $(".withdraw-method-select-input").on('change', function (e) { |
| 893 | var $that = $(this); |
| 894 | $('.withdraw-method-form').hide(); |
| 895 | $('#withdraw-method-form-' + $that.closest('.withdraw-method-select').attr('data-withdraw-method')).show(); |
| 896 | }); |
| 897 | |
| 898 | $('.withdraw-method-select-input').each(function () { |
| 899 | var $that = $(this); |
| 900 | if ($that.is(":checked")) { |
| 901 | $('.withdraw-method-form').hide(); |
| 902 | $('#withdraw-method-form-' + $that.closest('.withdraw-method-select').attr('data-withdraw-method')).show(); |
| 903 | } |
| 904 | }); |
| 905 | |
| 906 | |
| 907 | |
| 908 | /** |
| 909 | * Setting account for withdraw earning |
| 910 | * |
| 911 | * @since v.1.2.0 |
| 912 | */ |
| 913 | $(document).on('submit', '#tutor-withdraw-account-set-form', function (e) { |
| 914 | e.preventDefault(); |
| 915 | |
| 916 | var $form = $(this); |
| 917 | var $btn = $form.find('.tutor_set_withdraw_account_btn'); |
| 918 | var data = $form.serialize(); |
| 919 | |
| 920 | $.ajax({ |
| 921 | url: _tutorobject.ajaxurl, |
| 922 | type: 'POST', |
| 923 | data: data, |
| 924 | beforeSend: function () { |
| 925 | $form.find('.tutor-success-msg').remove(); |
| 926 | $btn.addClass('updating-icon'); |
| 927 | }, |
| 928 | success: function (data) { |
| 929 | if (data.success) { |
| 930 | var successMsg = '<div class="tutor-success-msg" style="display: none;"><i class="tutor-icon-mark"></i> ' + data.data.msg + ' </div>'; |
| 931 | $btn.closest('.withdraw-account-save-btn-wrap').append(successMsg); |
| 932 | if ($form.find('.tutor-success-msg').length) { |
| 933 | $form.find('.tutor-success-msg').slideDown(); |
| 934 | } |
| 935 | setTimeout(function () { |
| 936 | $form.find('.tutor-success-msg').slideUp(); |
| 937 | }, 5000) |
| 938 | } |
| 939 | }, |
| 940 | complete: function () { |
| 941 | $btn.removeClass('updating-icon'); |
| 942 | } |
| 943 | }); |
| 944 | }); |
| 945 | |
| 946 | /** |
| 947 | * Make Withdraw Form |
| 948 | * |
| 949 | * @since v.1.2.0 |
| 950 | */ |
| 951 | |
| 952 | $(document).on('click', 'a.open-withdraw-form-btn', function (e) { |
| 953 | e.preventDefault(); |
| 954 | $('.tutor-earning-withdraw-form-wrap').slideToggle(); |
| 955 | }); |
| 956 | |
| 957 | $(document).on('submit', '#tutor-earning-withdraw-form', function (e) { |
| 958 | e.preventDefault(); |
| 959 | |
| 960 | var $form = $(this); |
| 961 | var $btn = $('#tutor-earning-withdraw-btn'); |
| 962 | var $responseDiv = $('#tutor-withdraw-form-response'); |
| 963 | var data = $form.serialize(); |
| 964 | |
| 965 | $.ajax({ |
| 966 | url: _tutorobject.ajaxurl, |
| 967 | type: 'POST', |
| 968 | data: data, |
| 969 | beforeSend: function () { |
| 970 | $form.find('.tutor-success-msg').remove(); |
| 971 | $btn.addClass('updating-icon'); |
| 972 | }, |
| 973 | success: function (data) { |
| 974 | var Msg; |
| 975 | if (data.success) { |
| 976 | |
| 977 | if (data.data.available_balance !== 'undefined') { |
| 978 | $('.withdraw-balance-col .available_balance').html(data.data.available_balance); |
| 979 | } |
| 980 | Msg = '<div class="tutor-success-msg"><i class="tutor-icon-mark"></i> ' + data.data.msg + ' </div>'; |
| 981 | |
| 982 | } else { |
| 983 | Msg = '<div class="tutor-error-msg"><i class="tutor-icon-line-cross"></i> ' + data.data.msg + ' </div>'; |
| 984 | } |
| 985 | |
| 986 | $responseDiv.html(Msg); |
| 987 | setTimeout(function () { |
| 988 | $responseDiv.html(''); |
| 989 | }, 5000) |
| 990 | }, |
| 991 | complete: function () { |
| 992 | $btn.removeClass('updating-icon'); |
| 993 | } |
| 994 | }); |
| 995 | }); |
| 996 | |
| 997 | var frontEndModal = $('.tutor-frontend-modal'); |
| 998 | frontEndModal.each(function () { |
| 999 | var modal = $(this), |
| 1000 | action = $(this).data('popup-rel'); |
| 1001 | $('[href="' + action + '"]').on('click', function (e) { |
| 1002 | modal.fadeIn(); |
| 1003 | e.preventDefault(); |
| 1004 | }); |
| 1005 | }); |
| 1006 | $(document).on('click', '.tm-close, .tutor-frontend-modal-overlay, .tutor-modal-btn-cancel', function () { |
| 1007 | frontEndModal.fadeOut(); |
| 1008 | }); |
| 1009 | |
| 1010 | /** |
| 1011 | * Delete Course |
| 1012 | */ |
| 1013 | $(document).on('click', '.tutor-dashboard-element-delete-btn', function (e) { |
| 1014 | e.preventDefault(); |
| 1015 | var element_id = $(this).attr('data-id'); |
| 1016 | $('#tutor-dashboard-delete-element-id').val(element_id); |
| 1017 | }); |
| 1018 | $(document).on('submit', '#tutor-dashboard-delete-element-form', function (e) { |
| 1019 | e.preventDefault(); |
| 1020 | |
| 1021 | var element_id = $('#tutor-dashboard-delete-element-id').val(); |
| 1022 | var $btn = $('.tutor-modal-element-delete-btn'); |
| 1023 | var data = $(this).serialize(); |
| 1024 | |
| 1025 | $.ajax({ |
| 1026 | url: _tutorobject.ajaxurl, |
| 1027 | type: 'POST', |
| 1028 | data: data, |
| 1029 | beforeSend: function () { |
| 1030 | $btn.addClass('updating-icon'); |
| 1031 | }, |
| 1032 | success: function (res) { |
| 1033 | if (res.success) { |
| 1034 | $('#tutor-dashboard-' + res.data.element + '-' + element_id).remove(); |
| 1035 | } |
| 1036 | }, |
| 1037 | complete: function () { |
| 1038 | $btn.removeClass('updating-icon'); |
| 1039 | $('.tutor-frontend-modal').hide(); |
| 1040 | } |
| 1041 | }); |
| 1042 | }); |
| 1043 | |
| 1044 | /** |
| 1045 | * Frontend Profile |
| 1046 | */ |
| 1047 | |
| 1048 | if (!$('#tutor_profile_photo_id').val()) { |
| 1049 | $('.tutor-profile-photo-delete-btn').hide(); |
| 1050 | } |
| 1051 | |
| 1052 | $(document).on('click', '.tutor-profile-photo-delete-btn', function () { |
| 1053 | $('.tutor-profile-photo-upload-wrap').find('img').attr('src', _tutorobject.placeholder_img_src); |
| 1054 | $('#tutor_profile_photo_id').val(''); |
| 1055 | $('.tutor-profile-photo-delete-btn').hide(); |
| 1056 | |
| 1057 | $.ajax({ |
| 1058 | url: _tutorobject.ajaxurl, |
| 1059 | type: 'POST', |
| 1060 | data: { 'action': 'tutor_profile_photo_remove' }, |
| 1061 | }); |
| 1062 | |
| 1063 | return false; |
| 1064 | }); |
| 1065 | |
| 1066 | /** |
| 1067 | * Assignment |
| 1068 | * |
| 1069 | * @since v.1.3.3 |
| 1070 | */ |
| 1071 | $(document).on('submit', '#tutor_assignment_start_form', function (e) { |
| 1072 | e.preventDefault(); |
| 1073 | |
| 1074 | var $that = $(this); |
| 1075 | var form_data = $that.serialize() + '&action=tutor_start_assignment'; |
| 1076 | |
| 1077 | $.ajax({ |
| 1078 | url: _tutorobject.ajaxurl, |
| 1079 | type: 'POST', |
| 1080 | data: form_data, |
| 1081 | beforeSend: function () { |
| 1082 | $('#tutor_assignment_start_btn').addClass('updating-icon'); |
| 1083 | }, |
| 1084 | success: function (data) { |
| 1085 | if (data.success) { |
| 1086 | location.reload(); |
| 1087 | } |
| 1088 | }, |
| 1089 | complete: function () { |
| 1090 | $('#tutor_assignment_start_btn').removeClass('updating-icon'); |
| 1091 | } |
| 1092 | }); |
| 1093 | }); |
| 1094 | |
| 1095 | /** |
| 1096 | * Assignment answer validation |
| 1097 | */ |
| 1098 | $(document).on('submit', '#tutor_assignment_submit_form', function (e) { |
| 1099 | var assignment_answer = $('textarea[name="assignment_answer"]').val(); |
| 1100 | if (assignment_answer.trim().length < 1) { |
| 1101 | $('#form_validation_response').html('<div class="tutor-error-msg">' + _tutorobject.text.assignment_text_validation_msg + '</div>'); |
| 1102 | e.preventDefault(); |
| 1103 | } |
| 1104 | }); |
| 1105 | |
| 1106 | /** |
| 1107 | * Course builder video |
| 1108 | * @since v.1.3.4 |
| 1109 | */ |
| 1110 | |
| 1111 | |
| 1112 | $(document).on('click', '.video_source_upload_wrap_html5 .video_upload_btn', function (event) { |
| 1113 | event.preventDefault(); |
| 1114 | |
| 1115 | var $that = $(this); |
| 1116 | var frame; |
| 1117 | // If the media frame already exists, reopen it. |
| 1118 | if (frame) { |
| 1119 | frame.open(); |
| 1120 | return; |
| 1121 | } |
| 1122 | frame = wp.media({ |
| 1123 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 1124 | button: { |
| 1125 | text: 'Use this media' |
| 1126 | }, |
| 1127 | library: { type: 'video' }, |
| 1128 | multiple: false // Set to true to allow multiple files to be selected |
| 1129 | }); |
| 1130 | frame.on('select', function () { |
| 1131 | // Get media attachment details from the frame state |
| 1132 | var attachment = frame.state().get('selection').first().toJSON(); |
| 1133 | $that.closest('.video_source_upload_wrap_html5').find('span.video_media_id').text(attachment.id).closest('p').show(); |
| 1134 | $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id); |
| 1135 | }); |
| 1136 | frame.open(); |
| 1137 | }); |
| 1138 | |
| 1139 | |
| 1140 | /** |
| 1141 | * Course and lesson sorting |
| 1142 | */ |
| 1143 | |
| 1144 | function enable_sorting_topic_lesson() { |
| 1145 | if (jQuery().sortable) { |
| 1146 | $(".course-contents").sortable({ |
| 1147 | handle: ".course-move-handle", |
| 1148 | start: function (e, ui) { |
| 1149 | ui.placeholder.css('visibility', 'visible'); |
| 1150 | }, |
| 1151 | stop: function (e, ui) { |
| 1152 | tutor_sorting_topics_and_lesson(); |
| 1153 | }, |
| 1154 | }); |
| 1155 | $(".tutor-lessons:not(.drop-lessons)").sortable({ |
| 1156 | connectWith: ".tutor-lessons", |
| 1157 | items: "div.course-content-item", |
| 1158 | start: function (e, ui) { |
| 1159 | ui.placeholder.css('visibility', 'visible'); |
| 1160 | }, |
| 1161 | stop: function (e, ui) { |
| 1162 | tutor_sorting_topics_and_lesson(); |
| 1163 | }, |
| 1164 | }); |
| 1165 | } |
| 1166 | } |
| 1167 | enable_sorting_topic_lesson(); |
| 1168 | function tutor_sorting_topics_and_lesson() { |
| 1169 | var topics = {}; |
| 1170 | $('.tutor-topics-wrap').each(function (index, item) { |
| 1171 | var $topic = $(this); |
| 1172 | var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10); |
| 1173 | var lessons = {}; |
| 1174 | |
| 1175 | $topic.find('.course-content-item').each(function (lessonIndex, lessonItem) { |
| 1176 | var $lesson = $(this); |
| 1177 | var lesson_id = parseInt($lesson.attr('id').match(/\d+/)[0], 10); |
| 1178 | |
| 1179 | lessons[lessonIndex] = lesson_id; |
| 1180 | }); |
| 1181 | topics[index] = { 'topic_id': topics_id, 'lesson_ids': lessons }; |
| 1182 | }); |
| 1183 | $('#tutor_topics_lessons_sorting').val(JSON.stringify(topics)); |
| 1184 | } |
| 1185 | |
| 1186 | /** |
| 1187 | * Lesson Update or Create Modal |
| 1188 | */ |
| 1189 | $(document).on('click', '.update_lesson_modal_btn', function (event) { |
| 1190 | event.preventDefault(); |
| 1191 | |
| 1192 | var $that = $(this); |
| 1193 | var content; |
| 1194 | var editor = tinyMCE.get('tutor_lesson_modal_editor'); |
| 1195 | if (editor) { |
| 1196 | content = editor.getContent(); |
| 1197 | } else { |
| 1198 | content = $('#' + inputid).val(); |
| 1199 | } |
| 1200 | |
| 1201 | var form_data = $(this).closest('form').serialize(); |
| 1202 | form_data += '&lesson_content=' + encodeURIComponent(content); |
| 1203 | |
| 1204 | $.ajax({ |
| 1205 | url: ajaxurl, |
| 1206 | type: 'POST', |
| 1207 | data: form_data, |
| 1208 | beforeSend: function () { |
| 1209 | $that.addClass('tutor-updating-message'); |
| 1210 | }, |
| 1211 | success: function (data) { |
| 1212 | if (data.success) { |
| 1213 | $('#tutor-course-content-wrap').html(data.data.course_contents); |
| 1214 | enable_sorting_topic_lesson(); |
| 1215 | |
| 1216 | //Close the modal |
| 1217 | $('.tutor-lesson-modal-wrap').removeClass('show'); |
| 1218 | } |
| 1219 | }, |
| 1220 | complete: function () { |
| 1221 | $that.removeClass('tutor-updating-message'); |
| 1222 | } |
| 1223 | }); |
| 1224 | }); |
| 1225 | |
| 1226 | /** |
| 1227 | * END: Tutor Course builder JS |
| 1228 | */ |
| 1229 | |
| 1230 | /** |
| 1231 | * Attachment in forntend course builder |
| 1232 | * @since v.1.3.4 |
| 1233 | */ |
| 1234 | $(document).on('click', 'a.tutor-delete-attachment', function (e) { |
| 1235 | e.preventDefault(); |
| 1236 | $(this).closest('.tutor-added-attachment').remove(); |
| 1237 | }); |
| 1238 | $(document).on('click', '.tutorUploadAttachmentBtn', function (e) { |
| 1239 | e.preventDefault(); |
| 1240 | |
| 1241 | var $that = $(this); |
| 1242 | var frame; |
| 1243 | if (frame) { |
| 1244 | frame.open(); |
| 1245 | return; |
| 1246 | } |
| 1247 | frame = wp.media({ |
| 1248 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 1249 | button: { |
| 1250 | text: 'Use this media' |
| 1251 | }, |
| 1252 | multiple: true // Set to true to allow multiple files to be selected |
| 1253 | }); |
| 1254 | frame.on('select', function () { |
| 1255 | var attachments = frame.state().get('selection').toJSON(); |
| 1256 | if (attachments.length) { |
| 1257 | for (var i = 0; i < attachments.length; i++) { |
| 1258 | var attachment = attachments[i]; |
| 1259 | |
| 1260 | 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>'; |
| 1261 | $that.closest('.tutor-lesson-attachments-metabox').find('.tutor-added-attachments-wrap').append(inputHtml); |
| 1262 | } |
| 1263 | } |
| 1264 | }); |
| 1265 | frame.open(); |
| 1266 | }); |
| 1267 | |
| 1268 | |
| 1269 | /** |
| 1270 | * Single Assignment Upload Button |
| 1271 | * @since v.1.3.4 |
| 1272 | */ |
| 1273 | $('form').on('change', '.tutor-assignment-file-upload', function () { |
| 1274 | $(this).siblings("label").find('span').html($(this).val().replace(/.*(\/|\\)/, '')); |
| 1275 | }); |
| 1276 | |
| 1277 | /** |
| 1278 | * Lesson Sidebar Topic Toggle |
| 1279 | * @since v.1.3.4 |
| 1280 | */ |
| 1281 | |
| 1282 | $(document).on('click', '.tutor-topics-in-single-lesson .tutor-topics-title h3, .tutor-single-lesson-topic-toggle', function (e) { |
| 1283 | var $that = $(this); |
| 1284 | var $parent = $that.closest('.tutor-topics-in-single-lesson'); |
| 1285 | $parent.toggleClass('tutor-topic-active'); |
| 1286 | $parent.find('.tutor-lessons-under-topic').slideToggle(); |
| 1287 | }); |
| 1288 | |
| 1289 | $('.tutor-single-lesson-items.active').closest('.tutor-lessons-under-topic').show(); |
| 1290 | $('.tutor-single-lesson-items.active').closest('.tutor-topics-in-single-lesson').addClass('tutor-topic-active'); |
| 1291 | $('.tutor-course-lesson.active').closest('.tutor-lessons-under-topic').show(); |
| 1292 | |
| 1293 | |
| 1294 | /** |
| 1295 | * Assignments Addons |
| 1296 | * @backend Support |
| 1297 | * |
| 1298 | */ |
| 1299 | |
| 1300 | |
| 1301 | /** |
| 1302 | * Tutor Assignments JS |
| 1303 | * @since v.1.3.3 |
| 1304 | */ |
| 1305 | $(document).on('click', '.tutor-create-assignments-btn', function (e) { |
| 1306 | e.preventDefault(); |
| 1307 | |
| 1308 | var $that = $(this); |
| 1309 | var topic_id = $(this).attr('data-topic-id'); |
| 1310 | var course_id = $('#post_ID').val(); |
| 1311 | |
| 1312 | $.ajax({ |
| 1313 | url: ajaxurl, |
| 1314 | type: 'POST', |
| 1315 | data: { topic_id: topic_id, course_id: course_id, action: 'tutor_load_assignments_builder_modal' }, |
| 1316 | beforeSend: function () { |
| 1317 | $that.addClass('tutor-updating-message'); |
| 1318 | }, |
| 1319 | success: function (data) { |
| 1320 | $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output); |
| 1321 | $('.tutor-lesson-modal-wrap').attr('data-topic-id', topic_id).addClass('show'); |
| 1322 | |
| 1323 | $(document).trigger('assignment_modal_loaded', { topic_id: topic_id, course_id: course_id }); |
| 1324 | |
| 1325 | tinymce.init(tinyMCEPreInit.mceInit.course_description); |
| 1326 | tinymce.execCommand('mceRemoveEditor', false, 'tutor_assignments_modal_editor'); |
| 1327 | tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor"); |
| 1328 | }, |
| 1329 | complete: function () { |
| 1330 | quicktags({ id: "tutor_assignments_modal_editor" }); |
| 1331 | $that.removeClass('tutor-updating-message'); |
| 1332 | } |
| 1333 | }); |
| 1334 | }); |
| 1335 | |
| 1336 | $(document).on('click', '.open-tutor-assignment-modal', function (e) { |
| 1337 | e.preventDefault(); |
| 1338 | |
| 1339 | var $that = $(this); |
| 1340 | var assignment_id = $that.attr('data-assignment-id'); |
| 1341 | var topic_id = $that.attr('data-topic-id'); |
| 1342 | var course_id = $('#post_ID').val(); |
| 1343 | |
| 1344 | $.ajax({ |
| 1345 | url: ajaxurl, |
| 1346 | type: 'POST', |
| 1347 | data: { assignment_id: assignment_id, topic_id: topic_id, course_id: course_id, action: 'tutor_load_assignments_builder_modal' }, |
| 1348 | beforeSend: function () { |
| 1349 | $that.addClass('tutor-updating-message'); |
| 1350 | }, |
| 1351 | success: function (data) { |
| 1352 | $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output); |
| 1353 | $('.tutor-lesson-modal-wrap').attr({ 'data-assignment-id': assignment_id, 'data-topic-id': topic_id }).addClass('show'); |
| 1354 | |
| 1355 | $(document).trigger('assignment_modal_loaded', { assignment_id: assignment_id, topic_id: topic_id, course_id: course_id }); |
| 1356 | |
| 1357 | tinymce.init(tinyMCEPreInit.mceInit.course_description); |
| 1358 | tinymce.execCommand('mceRemoveEditor', false, 'tutor_assignments_modal_editor'); |
| 1359 | tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor"); |
| 1360 | }, |
| 1361 | complete: function () { |
| 1362 | quicktags({ id: "tutor_assignments_modal_editor" }); |
| 1363 | $that.removeClass('tutor-updating-message'); |
| 1364 | } |
| 1365 | }); |
| 1366 | }); |
| 1367 | |
| 1368 | /** |
| 1369 | * Update Assignment Data |
| 1370 | */ |
| 1371 | $(document).on('click', '.update_assignment_modal_btn', function (event) { |
| 1372 | event.preventDefault(); |
| 1373 | |
| 1374 | var $that = $(this); |
| 1375 | var content; |
| 1376 | var editor = tinyMCE.get('tutor_assignments_modal_editor'); |
| 1377 | if (editor) { |
| 1378 | content = editor.getContent(); |
| 1379 | } else { |
| 1380 | content = $('#' + inputid).val(); |
| 1381 | } |
| 1382 | |
| 1383 | var form_data = $(this).closest('form').serialize(); |
| 1384 | form_data += '&assignment_content=' + content; |
| 1385 | |
| 1386 | $.ajax({ |
| 1387 | url: ajaxurl, |
| 1388 | type: 'POST', |
| 1389 | data: form_data, |
| 1390 | beforeSend: function () { |
| 1391 | $that.addClass('tutor-updating-message'); |
| 1392 | }, |
| 1393 | success: function (data) { |
| 1394 | if (data.success) { |
| 1395 | $('#tutor-course-content-wrap').html(data.data.course_contents); |
| 1396 | enable_sorting_topic_lesson(); |
| 1397 | |
| 1398 | //Close the modal |
| 1399 | $('.tutor-lesson-modal-wrap').removeClass('show'); |
| 1400 | } |
| 1401 | }, |
| 1402 | complete: function () { |
| 1403 | $that.removeClass('tutor-updating-message'); |
| 1404 | } |
| 1405 | }); |
| 1406 | }); |
| 1407 | |
| 1408 | /** |
| 1409 | * Add Assignment |
| 1410 | */ |
| 1411 | $(document).on('click', '.add-assignment-attachments', function (event) { |
| 1412 | event.preventDefault(); |
| 1413 | |
| 1414 | var $that = $(this); |
| 1415 | var frame; |
| 1416 | // If the media frame already exists, reopen it. |
| 1417 | if (frame) { |
| 1418 | frame.open(); |
| 1419 | return; |
| 1420 | } |
| 1421 | |
| 1422 | // Create a new media frame |
| 1423 | frame = wp.media({ |
| 1424 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 1425 | button: { |
| 1426 | text: 'Use this media' |
| 1427 | }, |
| 1428 | multiple: false // Set to true to allow multiple files to be selected |
| 1429 | }); |
| 1430 | |
| 1431 | // When an image is selected in the media frame... |
| 1432 | frame.on('select', function () { |
| 1433 | // Get media attachment details from the frame state |
| 1434 | var attachment = frame.state().get('selection').first().toJSON(); |
| 1435 | |
| 1436 | 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>'; |
| 1437 | |
| 1438 | $('#assignment-attached-file').append(field_markup); |
| 1439 | $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id); |
| 1440 | }); |
| 1441 | // Finally, open the modal on click |
| 1442 | frame.open(); |
| 1443 | }); |
| 1444 | |
| 1445 | $(document).on('click', '.remove-assignment-attachment-a', function (event) { |
| 1446 | event.preventDefault(); |
| 1447 | $(this).closest('.tutor-individual-attachment-file').remove(); |
| 1448 | }); |
| 1449 | |
| 1450 | |
| 1451 | /** |
| 1452 | * |
| 1453 | * @type {jQuery} |
| 1454 | * |
| 1455 | * Course builder auto draft save |
| 1456 | * |
| 1457 | * @since v.1.3.4 |
| 1458 | */ |
| 1459 | var tutor_course_builder = $('input[name="tutor_action"]').val(); |
| 1460 | if (tutor_course_builder === 'tutor_add_course_builder') { |
| 1461 | setInterval(auto_draft_save_course_builder, 30000); |
| 1462 | } |
| 1463 | |
| 1464 | function auto_draft_save_course_builder() { |
| 1465 | var form_data = $('form#tutor-frontend-course-builder').serialize(); |
| 1466 | $.ajax({ |
| 1467 | //url : _tutorobject.ajaxurl, |
| 1468 | type: 'POST', |
| 1469 | data: form_data + '&tutor_ajax_action=tutor_course_builder_draft_save', |
| 1470 | beforeSend: function () { |
| 1471 | $('.tutor-dashboard-builder-draft-btn span').text('Saving...'); |
| 1472 | }, |
| 1473 | success: function (data) { |
| 1474 | |
| 1475 | }, |
| 1476 | complete: function () { |
| 1477 | $('.tutor-dashboard-builder-draft-btn span').text('Save'); |
| 1478 | } |
| 1479 | }); |
| 1480 | } |
| 1481 | |
| 1482 | /** |
| 1483 | * |
| 1484 | * @type {jQuery} |
| 1485 | * |
| 1486 | * Course builder section toggle |
| 1487 | * |
| 1488 | * @since v.1.3.5 |
| 1489 | */ |
| 1490 | |
| 1491 | $('.tutor-course-builder-section-title').on('click', function () { |
| 1492 | if ($(this).find('i').hasClass("tutor-icon-up")) { |
| 1493 | $(this).find('i').removeClass('tutor-icon-up').addClass('tutor-icon-down'); |
| 1494 | } else { |
| 1495 | $(this).find('i').removeClass('tutor-icon-down').addClass('tutor-icon-up'); |
| 1496 | } |
| 1497 | $(this).next('div').slideToggle(); |
| 1498 | }); |
| 1499 | |
| 1500 | /** |
| 1501 | * Open Tutor Modal to edit review |
| 1502 | * @since v.1.4.0 |
| 1503 | */ |
| 1504 | $(document).on('click', '.open-tutor-edit-review-modal', function (e) { |
| 1505 | e.preventDefault(); |
| 1506 | |
| 1507 | var $that = $(this); |
| 1508 | var review_id = $that.attr('data-review-id'); |
| 1509 | |
| 1510 | var nonce_key = _tutorobject.nonce_key; |
| 1511 | |
| 1512 | var json_data = { review_id: review_id, action: 'tutor_load_edit_review_modal' }; |
| 1513 | json_data[nonce_key] = _tutorobject[nonce_key]; |
| 1514 | |
| 1515 | $.ajax({ |
| 1516 | url: _tutorobject.ajaxurl, |
| 1517 | type: 'POST', |
| 1518 | data: json_data, |
| 1519 | beforeSend: function () { |
| 1520 | $that.addClass('tutor-updating-message'); |
| 1521 | }, |
| 1522 | success: function (data) { |
| 1523 | if (typeof data.data !== 'undefined') { |
| 1524 | $('.tutor-edit-review-modal-wrap .modal-container').html(data.data.output); |
| 1525 | $('.tutor-edit-review-modal-wrap').attr('data-review-id', review_id).addClass('show'); |
| 1526 | } |
| 1527 | }, |
| 1528 | complete: function () { |
| 1529 | $that.removeClass('tutor-updating-message'); |
| 1530 | } |
| 1531 | }); |
| 1532 | }); |
| 1533 | |
| 1534 | /** |
| 1535 | * Update the rating |
| 1536 | * @since v.1.4.0 |
| 1537 | */ |
| 1538 | $(document).on('submit', '#tutor_update_review_form', function (e) { |
| 1539 | e.preventDefault(); |
| 1540 | |
| 1541 | var $that = $(this); |
| 1542 | var review_id = $that.closest('.tutor-edit-review-modal-wrap ').attr('data-review-id'); |
| 1543 | |
| 1544 | var nonce_key = _tutorobject.nonce_key; |
| 1545 | |
| 1546 | var rating = $that.find('input[name="tutor_rating_gen_input"]').val(); |
| 1547 | var review = $that.find('textarea[name="review"]').val(); |
| 1548 | review = review.trim(); |
| 1549 | |
| 1550 | var json_data = { review_id: review_id, rating: rating, review: review, action: 'tutor_update_review_modal' }; |
| 1551 | json_data[nonce_key] = _tutorobject[nonce_key]; |
| 1552 | |
| 1553 | $.ajax({ |
| 1554 | url: _tutorobject.ajaxurl, |
| 1555 | type: 'POST', |
| 1556 | data: json_data, |
| 1557 | beforeSend: function () { |
| 1558 | $that.find('button[type="submit"]').addClass('tutor-updating-message'); |
| 1559 | }, |
| 1560 | success: function (data) { |
| 1561 | if (data.success) { |
| 1562 | //Close the modal |
| 1563 | $('.tutor-edit-review-modal-wrap').removeClass('show'); |
| 1564 | location.reload(true); |
| 1565 | } |
| 1566 | }, |
| 1567 | complete: function () { |
| 1568 | $that.find('button[type="submit"]').removeClass('tutor-updating-message'); |
| 1569 | } |
| 1570 | }); |
| 1571 | }); |
| 1572 | |
| 1573 | /** |
| 1574 | * Profile photo upload |
| 1575 | * @since v.1.4.5 |
| 1576 | */ |
| 1577 | |
| 1578 | $(document).on('click', '#tutor_profile_photo_button', function (e) { |
| 1579 | e.preventDefault(); |
| 1580 | |
| 1581 | $('#tutor_profile_photo_file').trigger('click'); |
| 1582 | }); |
| 1583 | |
| 1584 | $(document).on('change', '#tutor_profile_photo_file', function (event) { |
| 1585 | event.preventDefault(); |
| 1586 | |
| 1587 | var $file = this; |
| 1588 | if ($file.files && $file.files[0]) { |
| 1589 | var reader = new FileReader(); |
| 1590 | reader.onload = function (e) { |
| 1591 | $('.tutor-profile-photo-upload-wrap').find('img').attr('src', e.target.result); |
| 1592 | } |
| 1593 | reader.readAsDataURL($file.files[0]); |
| 1594 | } |
| 1595 | }); |
| 1596 | |
| 1597 | /** |
| 1598 | * Addon, Tutor BuddyPress |
| 1599 | * Retrieve MetaInformation on BuddyPress message system |
| 1600 | * @for TutorLMS Pro |
| 1601 | * @since v.1.4.8 |
| 1602 | */ |
| 1603 | |
| 1604 | $(document).on('click', '.thread-content .subject', function (e) { |
| 1605 | var $btn = $(this); |
| 1606 | |
| 1607 | var thread_id = parseInt($btn.closest('.thread-content').attr('data-thread-id')); |
| 1608 | |
| 1609 | var nonce_key = _tutorobject.nonce_key; |
| 1610 | var json_data = { thread_id: thread_id, action: 'tutor_bp_retrieve_user_records_for_thread' }; |
| 1611 | json_data[nonce_key] = _tutorobject[nonce_key]; |
| 1612 | |
| 1613 | $.ajax({ |
| 1614 | type: 'POST', |
| 1615 | url: ajaxurl, |
| 1616 | data: json_data, |
| 1617 | beforeSend: function () { |
| 1618 | $('#tutor-bp-thread-wrap').html(''); |
| 1619 | }, |
| 1620 | success: function (data) { |
| 1621 | if (data.success) { |
| 1622 | $('#tutor-bp-thread-wrap').html(data.data.thread_head_html); |
| 1623 | tutor_bp_setting_enrolled_courses_list(); |
| 1624 | } |
| 1625 | } |
| 1626 | }); |
| 1627 | |
| 1628 | }); |
| 1629 | |
| 1630 | |
| 1631 | function tutor_bp_setting_enrolled_courses_list() { |
| 1632 | $('ul.tutor-bp-enrolled-course-list').each(function () { |
| 1633 | var $that = $(this); |
| 1634 | var $li = $that.find(' > li'); |
| 1635 | var itemShow = 3; |
| 1636 | |
| 1637 | if ($li.length > itemShow) { |
| 1638 | var plusCourseCount = $li.length - itemShow; |
| 1639 | $li.each(function (liIndex, liItem) { |
| 1640 | var $liItem = $(this); |
| 1641 | |
| 1642 | if (liIndex >= itemShow) { |
| 1643 | $liItem.hide(); |
| 1644 | } |
| 1645 | }); |
| 1646 | |
| 1647 | var infoHtml = '<a href="javascript:;" class="tutor_bp_plus_courses"><strong>+' + plusCourseCount + ' More </strong></a> Courses'; |
| 1648 | $that.closest('.tutor-bp-enrolled-courses-wrap').find('.thread-participant-enrolled-info').html(infoHtml); |
| 1649 | } |
| 1650 | |
| 1651 | $that.show(); |
| 1652 | }); |
| 1653 | } |
| 1654 | tutor_bp_setting_enrolled_courses_list(); |
| 1655 | |
| 1656 | $(document).on('click', 'a.tutor_bp_plus_courses', function (e) { |
| 1657 | e.preventDefault(); |
| 1658 | |
| 1659 | var $btn = $(this); |
| 1660 | $btn.closest('.tutor-bp-enrolled-courses-wrap').find('.tutor-bp-enrolled-course-list li').show(); |
| 1661 | $btn.closest('.thread-participant-enrolled-info').html(''); |
| 1662 | }); |
| 1663 | |
| 1664 | |
| 1665 | /** |
| 1666 | * Addon, Tutor Certificate |
| 1667 | * Certificate dropdown content and copy link |
| 1668 | * @for TutorLMS Pro |
| 1669 | * @since v.1.5.1 |
| 1670 | */ |
| 1671 | $(document).on('click', '.tutor-dropbtn', function (e) { |
| 1672 | var $content = $(this).parent().find(".tutor-dropdown-content"); |
| 1673 | $content.slideToggle(100); |
| 1674 | }); |
| 1675 | $(document).on('click', '.tutor-copy-link', function (e) { |
| 1676 | var $btn = $(this); |
| 1677 | var copy = '<i class="tutor-icon-copy"></i> Copy Link'; |
| 1678 | var copied = '<i class="tutor-icon-mark"></i> Copied'; |
| 1679 | var dummy = document.createElement('input'), |
| 1680 | text = window.location.href; |
| 1681 | document.body.appendChild(dummy); |
| 1682 | dummy.value = text; |
| 1683 | dummy.select(); |
| 1684 | document.execCommand('copy'); |
| 1685 | document.body.removeChild(dummy); |
| 1686 | $btn.html(copied); |
| 1687 | setTimeout(function () { |
| 1688 | $btn.html(copy); |
| 1689 | }, 2500); |
| 1690 | }); |
| 1691 | $(document).on('click', function (e) { |
| 1692 | var container = $(".tutor-dropdown"); |
| 1693 | var $content = container.find('.tutor-dropdown-content'); |
| 1694 | // if the target of the click isn't the container nor a descendant of the container |
| 1695 | if (!container.is(e.target) && container.has(e.target).length === 0) { |
| 1696 | $content.slideUp(100); |
| 1697 | } |
| 1698 | }); |
| 1699 | |
| 1700 | |
| 1701 | /** |
| 1702 | * Tutor ajax login |
| 1703 | * |
| 1704 | * @since v.1.6.3 |
| 1705 | */ |
| 1706 | $(document).on('submit', '.tutor-login-form-wrap #loginform', function (e) { |
| 1707 | e.preventDefault(); |
| 1708 | var $that = $(this); |
| 1709 | var $form_wrapper = $('.tutor-login-form-wrap'); |
| 1710 | var form_data = $that.serialize() + '&action=tutor_user_login'; |
| 1711 | $.ajax({ |
| 1712 | url: _tutorobject.ajaxurl, |
| 1713 | type: 'POST', |
| 1714 | data: form_data, |
| 1715 | success: function (response) { |
| 1716 | if (response.success) { |
| 1717 | location.assign(response.data.redirect); |
| 1718 | location.reload(); |
| 1719 | } else { |
| 1720 | if ($form_wrapper.find('.tutor-alert').length) { |
| 1721 | $form_wrapper.find('.tutor-alert').html(response.data); |
| 1722 | } else { |
| 1723 | $form_wrapper.prepend('<div class="tutor-alert tutor-alert-warning">' + response.data + '</div>'); |
| 1724 | } |
| 1725 | } |
| 1726 | }, |
| 1727 | }); |
| 1728 | }); |
| 1729 | |
| 1730 | }); |