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