Chart.bundle.min.js
6 years ago
gutenberg_blocks.js
6 years ago
mce-button.js
6 years ago
tutor-admin.js
6 years ago
tutor-front.js
6 years ago
tutor-setup.js
6 years ago
tutor.js
6 years ago
tutor-front.js
1603 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 | // tutor course content accordion |
| 387 | $('.tutor-course-topic.tutor-active').find('.tutor-course-lessons').slideDown(); |
| 388 | $('.tutor-course-title').on('click', function () { |
| 389 | var lesson = $(this).siblings('.tutor-course-lessons'); |
| 390 | $(this).closest('.tutor-course-topic').toggleClass('tutor-active'); |
| 391 | lesson.slideToggle(); |
| 392 | }); |
| 393 | |
| 394 | $(document).on('click', '.tutor-topics-title h3 .toogle-informaiton-icon', function (e) { |
| 395 | $(this).closest('.tutor-topics-in-single-lesson').find('.tutor-topics-summery').slideToggle(); |
| 396 | e.stopPropagation(); |
| 397 | }); |
| 398 | |
| 399 | $(document).on('click', '.tutor-course-wishlist-btn', function (e) { |
| 400 | e.preventDefault(); |
| 401 | |
| 402 | var $that = $(this); |
| 403 | var course_id = $that.attr('data-course-id'); |
| 404 | |
| 405 | $.ajax({ |
| 406 | url: _tutorobject.ajaxurl, |
| 407 | type: 'POST', |
| 408 | data: {course_id : course_id, 'action': 'tutor_course_add_to_wishlist'}, |
| 409 | beforeSend: function () { |
| 410 | $that.addClass('updating-icon'); |
| 411 | }, |
| 412 | success: function (data) { |
| 413 | if (data.success){ |
| 414 | if (data.data.status === 'added'){ |
| 415 | $that.addClass('has-wish-listed'); |
| 416 | }else{ |
| 417 | $that.removeClass('has-wish-listed'); |
| 418 | } |
| 419 | }else{ |
| 420 | window.location = data.data.redirect_to; |
| 421 | } |
| 422 | }, |
| 423 | complete: function () { |
| 424 | $that.removeClass('updating-icon'); |
| 425 | } |
| 426 | }); |
| 427 | }); |
| 428 | |
| 429 | /** |
| 430 | * Check if lesson has classic editor support |
| 431 | * If classic editor support, stop ajax load on the lesson page. |
| 432 | * |
| 433 | * @since v.1.0.0 |
| 434 | * |
| 435 | * @updated v.1.4.0 |
| 436 | */ |
| 437 | if ( ! _tutorobject.enable_lesson_classic_editor) { |
| 438 | |
| 439 | $(document).on('click', '.tutor-single-lesson-a', function (e) { |
| 440 | e.preventDefault(); |
| 441 | |
| 442 | var $that = $(this); |
| 443 | var lesson_id = $that.attr('data-lesson-id'); |
| 444 | var $wrap = $('#tutor-single-entry-content'); |
| 445 | |
| 446 | $.ajax({ |
| 447 | url: _tutorobject.ajaxurl, |
| 448 | type: 'POST', |
| 449 | data: {lesson_id : lesson_id, 'action': 'tutor_render_lesson_content'}, |
| 450 | beforeSend: function () { |
| 451 | var page_title = $that.find('.lesson_title').text(); |
| 452 | $('head title').text(page_title); |
| 453 | window.history.pushState('obj', page_title, $that.attr('href')); |
| 454 | $wrap.addClass('loading-lesson'); |
| 455 | $('.tutor-single-lesson-items').removeClass('active'); |
| 456 | $that.closest('.tutor-single-lesson-items').addClass('active'); |
| 457 | }, |
| 458 | success: function (data) { |
| 459 | $wrap.html(data.data.html); |
| 460 | videoPlayer.init(); |
| 461 | $('.tutor-lesson-sidebar').css('display', ''); |
| 462 | }, |
| 463 | complete: function () { |
| 464 | $wrap.removeClass('loading-lesson'); |
| 465 | } |
| 466 | }); |
| 467 | }); |
| 468 | |
| 469 | $(document).on('click', '.sidebar-single-quiz-a', function (e) { |
| 470 | e.preventDefault(); |
| 471 | |
| 472 | var $that = $(this); |
| 473 | var quiz_id = $that.attr('data-quiz-id'); |
| 474 | var page_title = $that.find('.lesson_title').text(); |
| 475 | var $wrap = $('#tutor-single-entry-content'); |
| 476 | |
| 477 | $.ajax({ |
| 478 | url: _tutorobject.ajaxurl, |
| 479 | type: 'POST', |
| 480 | data: {quiz_id : quiz_id, 'action': 'tutor_render_quiz_content'}, |
| 481 | beforeSend: function () { |
| 482 | $('head title').text(page_title); |
| 483 | window.history.pushState('obj', page_title, $that.attr('href')); |
| 484 | $wrap.addClass('loading-lesson'); |
| 485 | $('.tutor-single-lesson-items').removeClass('active'); |
| 486 | $that.closest('.tutor-single-lesson-items').addClass('active'); |
| 487 | }, |
| 488 | success: function (data) { |
| 489 | $wrap.html(data.data.html); |
| 490 | init_quiz_builder(); |
| 491 | $('.tutor-lesson-sidebar').css('display', ''); |
| 492 | }, |
| 493 | complete: function () { |
| 494 | $wrap.removeClass('loading-lesson'); |
| 495 | } |
| 496 | }); |
| 497 | }); |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * @date 05 Feb, 2019 |
| 502 | */ |
| 503 | |
| 504 | $(document).on('click', '.tutor-lesson-sidebar-hide-bar', function(e){ |
| 505 | e.preventDefault(); |
| 506 | $('.tutor-lesson-sidebar').toggle(); |
| 507 | $('#tutor-single-entry-content').toggleClass("sidebar-hidden"); |
| 508 | |
| 509 | }); |
| 510 | |
| 511 | $(".tutor-tabs-btn-group a").on('click touchstart', function (e) { |
| 512 | e.preventDefault(); |
| 513 | var $that = $(this); |
| 514 | var tabSelector = $that.attr('href'); |
| 515 | $('.tutor-lesson-sidebar-tab-item').hide(); |
| 516 | $(tabSelector).show(); |
| 517 | |
| 518 | $('.tutor-tabs-btn-group a').removeClass('active'); |
| 519 | $that.addClass('active'); |
| 520 | }); |
| 521 | /** |
| 522 | * @date 18 Feb, 2019 |
| 523 | * @since v.1.0.0 |
| 524 | */ |
| 525 | |
| 526 | function init_quiz_builder() { |
| 527 | if (jQuery().sortable) { |
| 528 | $(".tutor-quiz-answers-wrap").sortable({ |
| 529 | handle: ".answer-sorting-bar", |
| 530 | start: function (e, ui) { |
| 531 | ui.placeholder.css('visibility', 'visible'); |
| 532 | }, |
| 533 | stop: function (e, ui) { |
| 534 | //Sorting Stopped... |
| 535 | }, |
| 536 | }).disableSelection(); |
| 537 | |
| 538 | $(".quiz-draggable-rand-answers, .quiz-answer-matching-droppable").sortable({ |
| 539 | connectWith: ".quiz-answer-matching-droppable", |
| 540 | placeholder: "drop-hover", |
| 541 | }).disableSelection(); |
| 542 | } |
| 543 | } |
| 544 | init_quiz_builder(); |
| 545 | /** |
| 546 | * Quiz view |
| 547 | * @date 22 Feb, 2019 |
| 548 | * @since v.1.0.0 |
| 549 | */ |
| 550 | |
| 551 | $(document).on('click', '.tutor-quiz-answer-next-btn', function (e) { |
| 552 | e.preventDefault(); |
| 553 | |
| 554 | var $that = $(this); |
| 555 | var $question_wrap = $that.closest('.quiz-attempt-single-question'); |
| 556 | /** |
| 557 | * Validating required answer |
| 558 | * @type {jQuery} |
| 559 | * |
| 560 | * @since v.1.6.1 |
| 561 | */ |
| 562 | |
| 563 | var validated = tutor_quiz_validation($question_wrap); |
| 564 | if ( ! validated){ |
| 565 | return; |
| 566 | } |
| 567 | |
| 568 | var question_id = parseInt($that.closest('.quiz-attempt-single-question').attr('id').match(/\d+/)[0], 10); |
| 569 | |
| 570 | var next_question_id = $that.closest('.quiz-attempt-single-question').attr('data-next-question-id'); |
| 571 | |
| 572 | if (next_question_id) { |
| 573 | var $nextQuestion = $(next_question_id); |
| 574 | if ($nextQuestion && $nextQuestion.length) { |
| 575 | $('.quiz-attempt-single-question').hide(); |
| 576 | $nextQuestion.show(); |
| 577 | |
| 578 | /** |
| 579 | * If pagination exists, set active class |
| 580 | */ |
| 581 | |
| 582 | if ($('.tutor-quiz-questions-pagination').length){ |
| 583 | $('.tutor-quiz-question-paginate-item').removeClass('active'); |
| 584 | $('.tutor-quiz-questions-pagination a[href="'+next_question_id+'"]').addClass('active'); |
| 585 | } |
| 586 | |
| 587 | } |
| 588 | } |
| 589 | }); |
| 590 | |
| 591 | |
| 592 | $(document).on('submit', '#tutor-answering-quiz', function (e) { |
| 593 | var $questions_wrap = $('.quiz-attempt-single-question'); |
| 594 | var validated = true; |
| 595 | if ($questions_wrap.length){ |
| 596 | $questions_wrap.each(function(index, question){ |
| 597 | validated = tutor_quiz_validation($(question)); |
| 598 | }); |
| 599 | } |
| 600 | |
| 601 | if ( ! validated){ |
| 602 | e.preventDefault(); |
| 603 | } |
| 604 | |
| 605 | }); |
| 606 | |
| 607 | |
| 608 | $(document).on('click', '.tutor-quiz-question-paginate-item', function (e) { |
| 609 | e.preventDefault(); |
| 610 | var $that = $(this); |
| 611 | var $question = $($that.attr('href')); |
| 612 | $('.quiz-attempt-single-question').hide(); |
| 613 | $question.show(); |
| 614 | |
| 615 | //Active Class |
| 616 | $('.tutor-quiz-question-paginate-item').removeClass('active'); |
| 617 | $that.addClass('active'); |
| 618 | }); |
| 619 | |
| 620 | /** |
| 621 | * Limit Short Answer Question Type |
| 622 | */ |
| 623 | $(document).on('keyup', 'textarea.question_type_short_answer', function (e) { |
| 624 | var $that = $(this); |
| 625 | var value = $that.val(); |
| 626 | var limit = _tutorobject.quiz_options.short_answer_characters_limit; |
| 627 | var remaining = limit - value.length; |
| 628 | |
| 629 | if (remaining < 1){ |
| 630 | $that.val(value.substr(0, limit)); |
| 631 | remaining = 0; |
| 632 | } |
| 633 | $that.closest('.tutor-quiz-answers-wrap').find('.characters_remaining').html(remaining); |
| 634 | }); |
| 635 | |
| 636 | /** |
| 637 | * |
| 638 | * @type {jQuery} |
| 639 | * |
| 640 | * Improved Quiz draggable answers drop accessibility |
| 641 | * Answers draggable wrap will be now same height. |
| 642 | * |
| 643 | * @since v.1.4.4 |
| 644 | */ |
| 645 | var countDraggableAnswers = $('.quiz-draggable-rand-answers').length; |
| 646 | if (countDraggableAnswers){ |
| 647 | $('.quiz-draggable-rand-answers').each(function(){ |
| 648 | var $that = $(this); |
| 649 | var draggableDivHeight = $that.height(); |
| 650 | |
| 651 | $that.css({"height": draggableDivHeight}); |
| 652 | }); |
| 653 | } |
| 654 | |
| 655 | |
| 656 | /** |
| 657 | * Quiz Validation Helper |
| 658 | * |
| 659 | * @since v.1.6.1 |
| 660 | */ |
| 661 | |
| 662 | function tutor_quiz_validation($question_wrap){ |
| 663 | var validated = true; |
| 664 | |
| 665 | var $required_answer_wrap = $question_wrap.find('.quiz-answer-required'); |
| 666 | |
| 667 | |
| 668 | if ($required_answer_wrap.length){ |
| 669 | |
| 670 | /** |
| 671 | * Radio field validation |
| 672 | * |
| 673 | * @type {jQuery} |
| 674 | * |
| 675 | * @since v.1.6.1 |
| 676 | */ |
| 677 | var $inputs = $required_answer_wrap.find('input'); |
| 678 | if ($inputs.length){ |
| 679 | var $type = $inputs.attr('type'); |
| 680 | if ($type === 'radio') { |
| 681 | if ($required_answer_wrap.find('input[type="radio"]:checked').length == 0) { |
| 682 | $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">Please select an option to answer</p>'); |
| 683 | validated = false; |
| 684 | } |
| 685 | }else if ($type === 'checkbox'){ |
| 686 | if ($required_answer_wrap.find('input[type="checkbox"]:checked').length == 0) { |
| 687 | $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">Please select at least one option to answer.</p>'); |
| 688 | validated = false; |
| 689 | } |
| 690 | }else if($type === 'text'){ |
| 691 | //Fill in the gaps if many, validation all |
| 692 | $inputs.each(function(index, input){ |
| 693 | if ( ! $(input).val().trim().length){ |
| 694 | $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">The answer for this question is required</p>'); |
| 695 | validated = false; |
| 696 | } |
| 697 | }); |
| 698 | } |
| 699 | |
| 700 | } |
| 701 | if ($required_answer_wrap.find('textarea').length) { |
| 702 | if ($required_answer_wrap.find('textarea').val().trim().length < 1){ |
| 703 | $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">The answer for this question is required</p>'); |
| 704 | validated = false; |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | /** |
| 709 | * Matching Question |
| 710 | */ |
| 711 | var $matchingDropable = $required_answer_wrap.find('.quiz-answer-matching-droppable'); |
| 712 | if ($matchingDropable.length){ |
| 713 | |
| 714 | $matchingDropable.each(function(index, matching){ |
| 715 | if ( ! $(matching).find('.quiz-draggable-answer-item').length){ |
| 716 | $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">Please match all the items</p>'); |
| 717 | validated = false; |
| 718 | } |
| 719 | |
| 720 | }); |
| 721 | |
| 722 | } |
| 723 | |
| 724 | |
| 725 | |
| 726 | } |
| 727 | |
| 728 | return validated; |
| 729 | } |
| 730 | |
| 731 | |
| 732 | |
| 733 | /** |
| 734 | * Add to cart in guest mode, show login form |
| 735 | * |
| 736 | * @since v.1.0.4 |
| 737 | */ |
| 738 | |
| 739 | $(document).on('submit click', '.cart-required-login, .cart-required-login a, .cart-required-login form', function (e) { |
| 740 | e.preventDefault(); |
| 741 | |
| 742 | $('.tutor-cart-box-login-form').fadeIn(100); |
| 743 | }); |
| 744 | |
| 745 | $('.tutor-popup-form-close, .login-overlay-close').on('click', function () { |
| 746 | $('.tutor-cart-box-login-form').fadeOut(100); |
| 747 | }); |
| 748 | |
| 749 | $(document).on('keyup', function (e) { |
| 750 | if (e.keyCode === 27) { |
| 751 | $('.tutor-frontend-modal').hide(); |
| 752 | $('.tutor-cart-box-login-form').fadeOut(100); |
| 753 | } |
| 754 | }); |
| 755 | /** |
| 756 | * Share Link enable |
| 757 | * |
| 758 | * @since v.1.0.4 |
| 759 | */ |
| 760 | if($.fn.ShareLink){ |
| 761 | var $social_share_wrap = $('.tutor-social-share-wrap'); |
| 762 | if ($social_share_wrap.length) { |
| 763 | var share_config = JSON.parse($social_share_wrap.attr('data-social-share-config')); |
| 764 | |
| 765 | $('.tutor_share').ShareLink({ |
| 766 | title: share_config.title, |
| 767 | text: share_config.text, |
| 768 | image: share_config.image, |
| 769 | class_prefix: 's_', |
| 770 | width: 640, |
| 771 | height: 480, |
| 772 | }); |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | /** |
| 777 | * Datepicker initiate |
| 778 | * |
| 779 | * @since v.1.1.2 |
| 780 | */ |
| 781 | if (jQuery.datepicker){ |
| 782 | $( ".tutor_report_datepicker" ).datepicker({"dateFormat" : 'yy-mm-dd'}); |
| 783 | } |
| 784 | |
| 785 | |
| 786 | /** |
| 787 | * Withdraw Form Tab/Toggle |
| 788 | * |
| 789 | * @since v.1.1.2 |
| 790 | */ |
| 791 | |
| 792 | $(".withdraw-method-select-input").on('change', function(e){ |
| 793 | var $that = $(this); |
| 794 | $('.withdraw-method-form').hide(); |
| 795 | $('#withdraw-method-form-'+$that.closest('.withdraw-method-select').attr('data-withdraw-method')).show(); |
| 796 | }); |
| 797 | |
| 798 | $('.withdraw-method-select-input').each(function () { |
| 799 | var $that = $(this); |
| 800 | if($that.is(":checked")){ |
| 801 | $('.withdraw-method-form').hide(); |
| 802 | $('#withdraw-method-form-'+$that.closest('.withdraw-method-select').attr('data-withdraw-method')).show(); |
| 803 | } |
| 804 | }); |
| 805 | |
| 806 | |
| 807 | |
| 808 | /** |
| 809 | * Setting account for withdraw earning |
| 810 | * |
| 811 | * @since v.1.2.0 |
| 812 | */ |
| 813 | $(document).on('submit', '#tutor-withdraw-account-set-form', function(e){ |
| 814 | e.preventDefault(); |
| 815 | |
| 816 | var $form = $(this); |
| 817 | var $btn = $form.find('.tutor_set_withdraw_account_btn'); |
| 818 | var data = $form.serialize(); |
| 819 | |
| 820 | $.ajax({ |
| 821 | url: _tutorobject.ajaxurl, |
| 822 | type: 'POST', |
| 823 | data: data, |
| 824 | beforeSend: function () { |
| 825 | $form.find('.tutor-success-msg').remove(); |
| 826 | $btn.addClass('updating-icon'); |
| 827 | }, |
| 828 | success: function (data) { |
| 829 | if (data.success){ |
| 830 | var successMsg = '<div class="tutor-success-msg" style="display: none;"><i class="tutor-icon-mark"></i> '+data.data.msg+' </div>'; |
| 831 | $btn.closest('.withdraw-account-save-btn-wrap').append(successMsg); |
| 832 | if ($form.find('.tutor-success-msg').length) { |
| 833 | $form.find('.tutor-success-msg').slideDown(); |
| 834 | } |
| 835 | setTimeout(function () { |
| 836 | $form.find('.tutor-success-msg').slideUp(); |
| 837 | }, 5000) |
| 838 | } |
| 839 | }, |
| 840 | complete: function () { |
| 841 | $btn.removeClass('updating-icon'); |
| 842 | } |
| 843 | }); |
| 844 | }); |
| 845 | |
| 846 | /** |
| 847 | * Make Withdraw Form |
| 848 | * |
| 849 | * @since v.1.2.0 |
| 850 | */ |
| 851 | |
| 852 | $(document).on('click', 'a.open-withdraw-form-btn', function(e){ |
| 853 | e.preventDefault(); |
| 854 | $('.tutor-earning-withdraw-form-wrap').slideToggle(); |
| 855 | }); |
| 856 | |
| 857 | $(document).on('submit', '#tutor-earning-withdraw-form', function(e){ |
| 858 | e.preventDefault(); |
| 859 | |
| 860 | var $form = $(this); |
| 861 | var $btn = $('#tutor-earning-withdraw-btn'); |
| 862 | var $responseDiv = $('#tutor-withdraw-form-response'); |
| 863 | var data = $form.serialize(); |
| 864 | |
| 865 | $.ajax({ |
| 866 | url: _tutorobject.ajaxurl, |
| 867 | type: 'POST', |
| 868 | data: data, |
| 869 | beforeSend: function () { |
| 870 | $form.find('.tutor-success-msg').remove(); |
| 871 | $btn.addClass('updating-icon'); |
| 872 | }, |
| 873 | success: function (data) { |
| 874 | var Msg; |
| 875 | if (data.success){ |
| 876 | |
| 877 | if (data.data.available_balance !== 'undefined') { |
| 878 | $('.withdraw-balance-col .available_balance').html(data.data.available_balance); |
| 879 | } |
| 880 | Msg = '<div class="tutor-success-msg"><i class="tutor-icon-mark"></i> '+data.data.msg+' </div>'; |
| 881 | |
| 882 | }else{ |
| 883 | Msg = '<div class="tutor-error-msg"><i class="tutor-icon-line-cross"></i> '+data.data.msg+' </div>'; |
| 884 | } |
| 885 | |
| 886 | $responseDiv.html(Msg); |
| 887 | setTimeout(function () { |
| 888 | $responseDiv.html(''); |
| 889 | }, 5000) |
| 890 | }, |
| 891 | complete: function () { |
| 892 | $btn.removeClass('updating-icon'); |
| 893 | } |
| 894 | }); |
| 895 | }); |
| 896 | |
| 897 | var frontEndModal = $('.tutor-frontend-modal'); |
| 898 | frontEndModal.each(function () { |
| 899 | var modal = $(this), |
| 900 | action = $(this).data('popup-rel'); |
| 901 | $('[href="'+action+'"]').on('click', function (e) { |
| 902 | modal.fadeIn(); |
| 903 | e.preventDefault(); |
| 904 | }); |
| 905 | }); |
| 906 | $(document).on('click', '.tm-close, .tutor-frontend-modal-overlay, .tutor-modal-btn-cancel', function () { |
| 907 | frontEndModal.fadeOut(); |
| 908 | }); |
| 909 | |
| 910 | /** |
| 911 | * Delete Course |
| 912 | */ |
| 913 | $(document).on('click', '.tutor-mycourse-delete-btn', function (e) { |
| 914 | e.preventDefault(); |
| 915 | var course_id = $(this).attr('data-course-id'); |
| 916 | $('#tutor-course-delete-id').val(course_id); |
| 917 | }); |
| 918 | $(document).on('submit', '#tutor-delete-course-form', function (e) { |
| 919 | e.preventDefault(); |
| 920 | |
| 921 | var course_id = $('#tutor-course-delete-id').val(); |
| 922 | var $btn = $('.tutor-modal-course-delete-btn'); |
| 923 | var data = $(this).serialize(); |
| 924 | |
| 925 | $.ajax({ |
| 926 | url: _tutorobject.ajaxurl, |
| 927 | type: 'POST', |
| 928 | data: data, |
| 929 | beforeSend: function () { |
| 930 | $btn.addClass('updating-icon'); |
| 931 | }, |
| 932 | success: function (data) { |
| 933 | if (data.success){ |
| 934 | $('#tutor-dashboard-course-'+course_id).remove(); |
| 935 | } |
| 936 | }, |
| 937 | complete: function () { |
| 938 | $btn.removeClass('updating-icon'); |
| 939 | $('.tutor-frontend-modal').hide(); |
| 940 | } |
| 941 | }); |
| 942 | }); |
| 943 | |
| 944 | /** |
| 945 | * Frontend Profile |
| 946 | */ |
| 947 | |
| 948 | if (! $('#tutor_profile_photo_id').val()) { |
| 949 | $('.tutor-profile-photo-delete-btn').hide(); |
| 950 | } |
| 951 | |
| 952 | $( document ).on( 'click', '.tutor-profile-photo-delete-btn', function() { |
| 953 | $( '.tutor-profile-photo-upload-wrap' ).find( 'img' ).attr( 'src', _tutorobject.placeholder_img_src ); |
| 954 | $( '#tutor_profile_photo_id' ).val( '' ); |
| 955 | $( '.tutor-profile-photo-delete-btn' ).hide(); |
| 956 | |
| 957 | $.ajax({ |
| 958 | url: _tutorobject.ajaxurl, |
| 959 | type: 'POST', |
| 960 | data: {'action' : 'tutor_profile_photo_remove'}, |
| 961 | }); |
| 962 | |
| 963 | return false; |
| 964 | }); |
| 965 | |
| 966 | |
| 967 | |
| 968 | /** |
| 969 | * Assignment |
| 970 | * |
| 971 | * @since v.1.3.3 |
| 972 | */ |
| 973 | |
| 974 | $( document ).on( 'submit', '#tutor_assignment_start_form', function(e) { |
| 975 | e.preventDefault(); |
| 976 | |
| 977 | var $that = $(this); |
| 978 | var form_data = $that.serialize()+'&action=tutor_start_assignment'; |
| 979 | |
| 980 | $.ajax({ |
| 981 | url: _tutorobject.ajaxurl, |
| 982 | type: 'POST', |
| 983 | data: form_data, |
| 984 | beforeSend: function () { |
| 985 | $('#tutor_assignment_start_btn').addClass('updating-icon'); |
| 986 | }, |
| 987 | success: function (data) { |
| 988 | if (data.success){ |
| 989 | location.reload(); |
| 990 | } |
| 991 | }, |
| 992 | complete : function () { |
| 993 | $('#tutor_assignment_start_btn').removeClass('updating-icon'); |
| 994 | } |
| 995 | }); |
| 996 | }); |
| 997 | |
| 998 | /** |
| 999 | * Assignment answer validation |
| 1000 | */ |
| 1001 | $( document ).on( 'submit', '#tutor_assignment_submit_form', function(e) { |
| 1002 | var assignment_answer = $('textarea[name="assignment_answer"]').val(); |
| 1003 | if (assignment_answer.trim().length < 1) { |
| 1004 | $('#form_validation_response').html('<div class="tutor-error-msg">'+_tutorobject.text.assignment_text_validation_msg+'</div>'); |
| 1005 | e.preventDefault(); |
| 1006 | } |
| 1007 | }); |
| 1008 | |
| 1009 | /** |
| 1010 | * Course builder video |
| 1011 | * @since v.1.3.4 |
| 1012 | */ |
| 1013 | |
| 1014 | |
| 1015 | $(document).on( 'click', '.video_source_upload_wrap_html5 .video_upload_btn', function( event ){ |
| 1016 | event.preventDefault(); |
| 1017 | |
| 1018 | var $that = $(this); |
| 1019 | var frame; |
| 1020 | // If the media frame already exists, reopen it. |
| 1021 | if ( frame ) { |
| 1022 | frame.open(); |
| 1023 | return; |
| 1024 | } |
| 1025 | frame = wp.media({ |
| 1026 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 1027 | button: { |
| 1028 | text: 'Use this media' |
| 1029 | }, |
| 1030 | multiple: false // Set to true to allow multiple files to be selected |
| 1031 | }); |
| 1032 | frame.on( 'select', function() { |
| 1033 | // Get media attachment details from the frame state |
| 1034 | var attachment = frame.state().get('selection').first().toJSON(); |
| 1035 | $that.closest('.video_source_upload_wrap_html5').find('span.video_media_id').text(attachment.id).closest('p').show(); |
| 1036 | $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id); |
| 1037 | }); |
| 1038 | frame.open(); |
| 1039 | }); |
| 1040 | |
| 1041 | |
| 1042 | /** |
| 1043 | * Course and lesson sorting |
| 1044 | */ |
| 1045 | |
| 1046 | function enable_sorting_topic_lesson(){ |
| 1047 | if (jQuery().sortable) { |
| 1048 | $(".course-contents").sortable({ |
| 1049 | handle: ".course-move-handle", |
| 1050 | start: function (e, ui) { |
| 1051 | ui.placeholder.css('visibility', 'visible'); |
| 1052 | }, |
| 1053 | stop: function (e, ui) { |
| 1054 | tutor_sorting_topics_and_lesson(); |
| 1055 | }, |
| 1056 | }); |
| 1057 | $(".tutor-lessons:not(.drop-lessons)").sortable({ |
| 1058 | connectWith: ".tutor-lessons", |
| 1059 | items: "div.course-content-item", |
| 1060 | start: function (e, ui) { |
| 1061 | ui.placeholder.css('visibility', 'visible'); |
| 1062 | }, |
| 1063 | stop: function (e, ui) { |
| 1064 | tutor_sorting_topics_and_lesson(); |
| 1065 | }, |
| 1066 | }); |
| 1067 | } |
| 1068 | } |
| 1069 | enable_sorting_topic_lesson(); |
| 1070 | function tutor_sorting_topics_and_lesson(){ |
| 1071 | var topics = {}; |
| 1072 | $('.tutor-topics-wrap').each(function(index, item){ |
| 1073 | var $topic = $(this); |
| 1074 | var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10); |
| 1075 | var lessons = {}; |
| 1076 | |
| 1077 | $topic.find('.course-content-item').each(function(lessonIndex, lessonItem){ |
| 1078 | var $lesson = $(this); |
| 1079 | var lesson_id = parseInt($lesson.attr('id').match(/\d+/)[0], 10); |
| 1080 | |
| 1081 | lessons[lessonIndex] = lesson_id; |
| 1082 | }); |
| 1083 | topics[index] = { 'topic_id' : topics_id, 'lesson_ids' : lessons }; |
| 1084 | }); |
| 1085 | $('#tutor_topics_lessons_sorting').val(JSON.stringify(topics)); |
| 1086 | } |
| 1087 | |
| 1088 | /** |
| 1089 | * Lesson Update or Create Modal |
| 1090 | */ |
| 1091 | $(document).on( 'click', '.update_lesson_modal_btn', function( event ){ |
| 1092 | event.preventDefault(); |
| 1093 | |
| 1094 | var $that = $(this); |
| 1095 | var content; |
| 1096 | var editor = tinyMCE.get('tutor_lesson_modal_editor'); |
| 1097 | if (editor) { |
| 1098 | content = editor.getContent(); |
| 1099 | } else { |
| 1100 | content = $('#'+inputid).val(); |
| 1101 | } |
| 1102 | |
| 1103 | var form_data = $(this).closest('form').serialize(); |
| 1104 | form_data += '&lesson_content='+encodeURIComponent(content); |
| 1105 | |
| 1106 | $.ajax({ |
| 1107 | url : ajaxurl, |
| 1108 | type : 'POST', |
| 1109 | data : form_data, |
| 1110 | beforeSend: function () { |
| 1111 | $that.addClass('tutor-updating-message'); |
| 1112 | }, |
| 1113 | success: function (data) { |
| 1114 | if (data.success){ |
| 1115 | $('#tutor-course-content-wrap').html(data.data.course_contents); |
| 1116 | enable_sorting_topic_lesson(); |
| 1117 | |
| 1118 | //Close the modal |
| 1119 | $('.tutor-lesson-modal-wrap').removeClass('show'); |
| 1120 | } |
| 1121 | }, |
| 1122 | complete: function () { |
| 1123 | $that.removeClass('tutor-updating-message'); |
| 1124 | } |
| 1125 | }); |
| 1126 | }); |
| 1127 | |
| 1128 | /** |
| 1129 | * END: Tutor Course builder JS |
| 1130 | */ |
| 1131 | |
| 1132 | /** |
| 1133 | * Attachment in forntend course builder |
| 1134 | * @since v.1.3.4 |
| 1135 | */ |
| 1136 | $(document).on('click', 'a.tutor-delete-attachment', function(e){ |
| 1137 | e.preventDefault(); |
| 1138 | $(this).closest('.tutor-added-attachment').remove(); |
| 1139 | }); |
| 1140 | $(document).on('click', '.tutorUploadAttachmentBtn', function(e){ |
| 1141 | e.preventDefault(); |
| 1142 | |
| 1143 | var $that = $(this); |
| 1144 | var frame; |
| 1145 | if ( frame ) { |
| 1146 | frame.open(); |
| 1147 | return; |
| 1148 | } |
| 1149 | frame = wp.media({ |
| 1150 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 1151 | button: { |
| 1152 | text: 'Use this media' |
| 1153 | }, |
| 1154 | multiple: true // Set to true to allow multiple files to be selected |
| 1155 | }); |
| 1156 | frame.on( 'select', function() { |
| 1157 | var attachments = frame.state().get('selection').toJSON(); |
| 1158 | if (attachments.length){ |
| 1159 | for (var i=0; i < attachments.length; i++){ |
| 1160 | var attachment = attachments[i]; |
| 1161 | |
| 1162 | 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>'; |
| 1163 | $that.closest('.tutor-lesson-attachments-metabox').find('.tutor-added-attachments-wrap').append(inputHtml); |
| 1164 | } |
| 1165 | } |
| 1166 | }); |
| 1167 | frame.open(); |
| 1168 | }); |
| 1169 | |
| 1170 | |
| 1171 | /** |
| 1172 | * Single Assignment Upload Button |
| 1173 | * @since v.1.3.4 |
| 1174 | */ |
| 1175 | $('form').on('change', '.tutor-assignment-file-upload', function () { |
| 1176 | $(this).siblings("label").find('span').html($(this).val().replace(/.*(\/|\\)/, '')); |
| 1177 | }); |
| 1178 | |
| 1179 | /** |
| 1180 | * Lesson Sidebar Topic Toggle |
| 1181 | * @since v.1.3.4 |
| 1182 | */ |
| 1183 | |
| 1184 | $(document).on('click', '.tutor-topics-in-single-lesson .tutor-topics-title h3, .tutor-single-lesson-topic-toggle', function (e) { |
| 1185 | var $that = $(this); |
| 1186 | var $parent = $that.closest('.tutor-topics-in-single-lesson'); |
| 1187 | $parent.toggleClass('tutor-topic-active'); |
| 1188 | $parent.find('.tutor-lessons-under-topic').slideToggle(); |
| 1189 | }); |
| 1190 | |
| 1191 | $('.tutor-single-lesson-items.active').closest('.tutor-lessons-under-topic').show(); |
| 1192 | $('.tutor-single-lesson-items.active').closest('.tutor-topics-in-single-lesson').addClass('tutor-topic-active'); |
| 1193 | $('.tutor-course-lesson.active').closest('.tutor-lessons-under-topic').show(); |
| 1194 | |
| 1195 | |
| 1196 | /** |
| 1197 | * Assignments Addons |
| 1198 | * @backend Support |
| 1199 | * |
| 1200 | */ |
| 1201 | |
| 1202 | |
| 1203 | /** |
| 1204 | * Tutor Assignments JS |
| 1205 | * @since v.1.3.3 |
| 1206 | */ |
| 1207 | $(document).on('click', '.tutor-create-assignments-btn', function(e){ |
| 1208 | e.preventDefault(); |
| 1209 | |
| 1210 | var $that = $(this); |
| 1211 | var topic_id = $(this).attr('data-topic-id'); |
| 1212 | var course_id = $('#post_ID').val(); |
| 1213 | |
| 1214 | $.ajax({ |
| 1215 | url : ajaxurl, |
| 1216 | type : 'POST', |
| 1217 | data : {topic_id : topic_id, course_id : course_id, action: 'tutor_load_assignments_builder_modal'}, |
| 1218 | beforeSend: function () { |
| 1219 | $that.addClass('tutor-updating-message'); |
| 1220 | }, |
| 1221 | success: function (data) { |
| 1222 | $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output); |
| 1223 | $('.tutor-lesson-modal-wrap').attr('data-topic-id', topic_id).addClass('show'); |
| 1224 | |
| 1225 | $(document).trigger('assignment_modal_loaded', {topic_id : topic_id, course_id : course_id}); |
| 1226 | |
| 1227 | tinymce.init(tinyMCEPreInit.mceInit.course_description); |
| 1228 | tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_assignments_modal_editor' ); |
| 1229 | tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor"); |
| 1230 | }, |
| 1231 | complete: function () { |
| 1232 | quicktags({id : "tutor_assignments_modal_editor"}); |
| 1233 | $that.removeClass('tutor-updating-message'); |
| 1234 | } |
| 1235 | }); |
| 1236 | }); |
| 1237 | |
| 1238 | $(document).on('click', '.open-tutor-assignment-modal', function(e){ |
| 1239 | e.preventDefault(); |
| 1240 | |
| 1241 | var $that = $(this); |
| 1242 | var assignment_id = $that.attr('data-assignment-id'); |
| 1243 | var topic_id = $that.attr('data-topic-id'); |
| 1244 | var course_id = $('#post_ID').val(); |
| 1245 | |
| 1246 | $.ajax({ |
| 1247 | url : ajaxurl, |
| 1248 | type : 'POST', |
| 1249 | data : {assignment_id : assignment_id, topic_id : topic_id, course_id : course_id, action: 'tutor_load_assignments_builder_modal'}, |
| 1250 | beforeSend: function () { |
| 1251 | $that.addClass('tutor-updating-message'); |
| 1252 | }, |
| 1253 | success: function (data) { |
| 1254 | $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output); |
| 1255 | $('.tutor-lesson-modal-wrap').attr({'data-assignment-id' : assignment_id, 'data-topic-id':topic_id}).addClass('show'); |
| 1256 | |
| 1257 | $(document).trigger('assignment_modal_loaded', {assignment_id : assignment_id, topic_id : topic_id, course_id : course_id}); |
| 1258 | |
| 1259 | tinymce.init(tinyMCEPreInit.mceInit.course_description); |
| 1260 | tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_assignments_modal_editor' ); |
| 1261 | tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor"); |
| 1262 | }, |
| 1263 | complete: function () { |
| 1264 | quicktags({id : "tutor_assignments_modal_editor"}); |
| 1265 | $that.removeClass('tutor-updating-message'); |
| 1266 | } |
| 1267 | }); |
| 1268 | }); |
| 1269 | |
| 1270 | /** |
| 1271 | * Update Assignment Data |
| 1272 | */ |
| 1273 | $(document).on( 'click', '.update_assignment_modal_btn', function( event ){ |
| 1274 | event.preventDefault(); |
| 1275 | |
| 1276 | var $that = $(this); |
| 1277 | var content; |
| 1278 | var editor = tinyMCE.get('tutor_assignments_modal_editor'); |
| 1279 | if (editor) { |
| 1280 | content = editor.getContent(); |
| 1281 | } else { |
| 1282 | content = $('#'+inputid).val(); |
| 1283 | } |
| 1284 | |
| 1285 | var form_data = $(this).closest('form').serialize(); |
| 1286 | form_data += '&assignment_content='+content; |
| 1287 | |
| 1288 | $.ajax({ |
| 1289 | url : ajaxurl, |
| 1290 | type : 'POST', |
| 1291 | data : form_data, |
| 1292 | beforeSend: function () { |
| 1293 | $that.addClass('tutor-updating-message'); |
| 1294 | }, |
| 1295 | success: function (data) { |
| 1296 | if (data.success){ |
| 1297 | $('#tutor-course-content-wrap').html(data.data.course_contents); |
| 1298 | enable_sorting_topic_lesson(); |
| 1299 | |
| 1300 | //Close the modal |
| 1301 | $('.tutor-lesson-modal-wrap').removeClass('show'); |
| 1302 | } |
| 1303 | }, |
| 1304 | complete: function () { |
| 1305 | $that.removeClass('tutor-updating-message'); |
| 1306 | } |
| 1307 | }); |
| 1308 | }); |
| 1309 | |
| 1310 | /** |
| 1311 | * Add Assignment |
| 1312 | */ |
| 1313 | $(document).on( 'click', '.add-assignment-attachments', function( event ){ |
| 1314 | event.preventDefault(); |
| 1315 | |
| 1316 | var $that = $(this); |
| 1317 | var frame; |
| 1318 | // If the media frame already exists, reopen it. |
| 1319 | if ( frame ) { |
| 1320 | frame.open(); |
| 1321 | return; |
| 1322 | } |
| 1323 | |
| 1324 | // Create a new media frame |
| 1325 | frame = wp.media({ |
| 1326 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 1327 | button: { |
| 1328 | text: 'Use this media' |
| 1329 | }, |
| 1330 | multiple: false // Set to true to allow multiple files to be selected |
| 1331 | }); |
| 1332 | |
| 1333 | // When an image is selected in the media frame... |
| 1334 | frame.on( 'select', function() { |
| 1335 | // Get media attachment details from the frame state |
| 1336 | var attachment = frame.state().get('selection').first().toJSON(); |
| 1337 | |
| 1338 | 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>'; |
| 1339 | |
| 1340 | $('#assignment-attached-file').append(field_markup); |
| 1341 | $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id); |
| 1342 | }); |
| 1343 | // Finally, open the modal on click |
| 1344 | frame.open(); |
| 1345 | }); |
| 1346 | |
| 1347 | $(document).on( 'click', '.remove-assignment-attachment-a', function( event ){ |
| 1348 | event.preventDefault(); |
| 1349 | $(this).closest('.tutor-individual-attachment-file').remove(); |
| 1350 | }); |
| 1351 | |
| 1352 | |
| 1353 | /** |
| 1354 | * |
| 1355 | * @type {jQuery} |
| 1356 | * |
| 1357 | * Course builder auto draft save |
| 1358 | * |
| 1359 | * @since v.1.3.4 |
| 1360 | */ |
| 1361 | var tutor_course_builder = $('input[name="tutor_action"]').val(); |
| 1362 | if (tutor_course_builder === 'tutor_add_course_builder'){ |
| 1363 | setInterval(auto_draft_save_course_builder, 30000); |
| 1364 | } |
| 1365 | |
| 1366 | function auto_draft_save_course_builder(){ |
| 1367 | var form_data = $('form#tutor-frontend-course-builder').serialize(); |
| 1368 | $.ajax({ |
| 1369 | //url : _tutorobject.ajaxurl, |
| 1370 | type : 'POST', |
| 1371 | data : form_data+'&tutor_ajax_action=tutor_course_builder_draft_save', |
| 1372 | beforeSend: function () { |
| 1373 | $('.tutor-dashboard-builder-draft-btn span').text('Saving...'); |
| 1374 | }, |
| 1375 | success: function (data) { |
| 1376 | |
| 1377 | }, |
| 1378 | complete: function () { |
| 1379 | $('.tutor-dashboard-builder-draft-btn span').text('Save'); |
| 1380 | } |
| 1381 | }); |
| 1382 | } |
| 1383 | |
| 1384 | /** |
| 1385 | * |
| 1386 | * @type {jQuery} |
| 1387 | * |
| 1388 | * Course builder section toggle |
| 1389 | * |
| 1390 | * @since v.1.3.5 |
| 1391 | */ |
| 1392 | |
| 1393 | $('.tutor-course-builder-section-title').on('click', function () { |
| 1394 | if($(this).find('i').hasClass("tutor-icon-up")){ |
| 1395 | $(this).find('i').removeClass('tutor-icon-up').addClass('tutor-icon-down'); |
| 1396 | }else{ |
| 1397 | $(this).find('i').removeClass('tutor-icon-down').addClass('tutor-icon-up'); |
| 1398 | } |
| 1399 | $(this).next('div').slideToggle(); |
| 1400 | }); |
| 1401 | |
| 1402 | /** |
| 1403 | * Open Tutor Modal to edit review |
| 1404 | * @since v.1.4.0 |
| 1405 | */ |
| 1406 | $(document).on('click', '.open-tutor-edit-review-modal', function(e){ |
| 1407 | e.preventDefault(); |
| 1408 | |
| 1409 | var $that = $(this); |
| 1410 | var review_id = $that.attr('data-review-id'); |
| 1411 | |
| 1412 | var nonce_key = _tutorobject.nonce_key; |
| 1413 | |
| 1414 | var json_data = {review_id : review_id, action: 'tutor_load_edit_review_modal'}; |
| 1415 | json_data[nonce_key] = _tutorobject[nonce_key]; |
| 1416 | |
| 1417 | $.ajax({ |
| 1418 | url : _tutorobject.ajaxurl, |
| 1419 | type : 'POST', |
| 1420 | data : json_data, |
| 1421 | beforeSend: function () { |
| 1422 | $that.addClass('tutor-updating-message'); |
| 1423 | }, |
| 1424 | success: function (data) { |
| 1425 | if (typeof data.data !== 'undefined') { |
| 1426 | $('.tutor-edit-review-modal-wrap .modal-container').html(data.data.output); |
| 1427 | $('.tutor-edit-review-modal-wrap').attr('data-review-id', review_id).addClass('show'); |
| 1428 | } |
| 1429 | }, |
| 1430 | complete: function () { |
| 1431 | $that.removeClass('tutor-updating-message'); |
| 1432 | } |
| 1433 | }); |
| 1434 | }); |
| 1435 | |
| 1436 | /** |
| 1437 | * Update the rating |
| 1438 | * @since v.1.4.0 |
| 1439 | */ |
| 1440 | $(document).on('submit', '#tutor_update_review_form', function(e){ |
| 1441 | e.preventDefault(); |
| 1442 | |
| 1443 | var $that = $(this); |
| 1444 | var review_id = $that.closest('.tutor-edit-review-modal-wrap ').attr('data-review-id'); |
| 1445 | |
| 1446 | var nonce_key = _tutorobject.nonce_key; |
| 1447 | |
| 1448 | var rating = $that.find('input[name="tutor_rating_gen_input"]').val(); |
| 1449 | var review = $that.find('textarea[name="review"]').val(); |
| 1450 | review = review.trim(); |
| 1451 | |
| 1452 | var json_data = {review_id : review_id, rating : rating, review : review, action: 'tutor_update_review_modal'}; |
| 1453 | json_data[nonce_key] = _tutorobject[nonce_key]; |
| 1454 | |
| 1455 | $.ajax({ |
| 1456 | url : _tutorobject.ajaxurl, |
| 1457 | type : 'POST', |
| 1458 | data : json_data, |
| 1459 | beforeSend: function () { |
| 1460 | $that.find('button[type="submit"]').addClass('tutor-updating-message'); |
| 1461 | }, |
| 1462 | success: function (data) { |
| 1463 | if (data.success){ |
| 1464 | //Close the modal |
| 1465 | $('.tutor-edit-review-modal-wrap').removeClass('show'); |
| 1466 | location.reload(true); |
| 1467 | } |
| 1468 | }, |
| 1469 | complete: function () { |
| 1470 | $that.find('button[type="submit"]').removeClass('tutor-updating-message'); |
| 1471 | } |
| 1472 | }); |
| 1473 | }); |
| 1474 | |
| 1475 | /** |
| 1476 | * Profile photo upload |
| 1477 | * @since v.1.4.5 |
| 1478 | */ |
| 1479 | |
| 1480 | $(document).on('click', '#tutor_profile_photo_button', function(e){ |
| 1481 | e.preventDefault(); |
| 1482 | |
| 1483 | $('#tutor_profile_photo_file').trigger('click'); |
| 1484 | }); |
| 1485 | |
| 1486 | $(document).on('change', '#tutor_profile_photo_file', function(event){ |
| 1487 | event.preventDefault(); |
| 1488 | |
| 1489 | var $file = this; |
| 1490 | if ($file.files && $file.files[0]) { |
| 1491 | var reader = new FileReader(); |
| 1492 | reader.onload = function(e) { |
| 1493 | $( '.tutor-profile-photo-upload-wrap' ).find( 'img' ).attr( 'src', e.target.result); |
| 1494 | } |
| 1495 | reader.readAsDataURL($file.files[0]); |
| 1496 | } |
| 1497 | }); |
| 1498 | |
| 1499 | /** |
| 1500 | * Addon, Tutor BuddyPress |
| 1501 | * Retrieve MetaInformation on BuddyPress message system |
| 1502 | * @for TutorLMS Pro |
| 1503 | * @since v.1.4.8 |
| 1504 | */ |
| 1505 | |
| 1506 | $(document).on('click', '.thread-content .subject', function(e){ |
| 1507 | var $btn = $(this); |
| 1508 | |
| 1509 | var thread_id = parseInt($btn.closest('.thread-content').attr('data-thread-id')); |
| 1510 | |
| 1511 | var nonce_key = _tutorobject.nonce_key; |
| 1512 | var json_data = {thread_id : thread_id, action: 'tutor_bp_retrieve_user_records_for_thread'}; |
| 1513 | json_data[nonce_key] = _tutorobject[nonce_key]; |
| 1514 | |
| 1515 | $.ajax({ |
| 1516 | type: 'POST', |
| 1517 | url: ajaxurl, |
| 1518 | data: json_data, |
| 1519 | beforeSend: function(){ |
| 1520 | $('#tutor-bp-thread-wrap').html(''); |
| 1521 | }, |
| 1522 | success: function (data) { |
| 1523 | if (data.success){ |
| 1524 | $('#tutor-bp-thread-wrap').html(data.data.thread_head_html); |
| 1525 | tutor_bp_setting_enrolled_courses_list(); |
| 1526 | } |
| 1527 | } |
| 1528 | }); |
| 1529 | |
| 1530 | }); |
| 1531 | |
| 1532 | |
| 1533 | function tutor_bp_setting_enrolled_courses_list(){ |
| 1534 | $('ul.tutor-bp-enrolled-course-list').each(function(){ |
| 1535 | var $that = $(this); |
| 1536 | var $li = $that.find(' > li'); |
| 1537 | var itemShow = 3; |
| 1538 | |
| 1539 | if ($li.length > itemShow){ |
| 1540 | var plusCourseCount = $li.length - itemShow; |
| 1541 | $li.each(function(liIndex, liItem){ |
| 1542 | var $liItem = $(this); |
| 1543 | |
| 1544 | if (liIndex >= itemShow){ |
| 1545 | $liItem.hide(); |
| 1546 | } |
| 1547 | }); |
| 1548 | |
| 1549 | var infoHtml = '<a href="javascript:;" class="tutor_bp_plus_courses"><strong>+'+plusCourseCount+' More </strong></a> Courses'; |
| 1550 | $that.closest('.tutor-bp-enrolled-courses-wrap').find('.thread-participant-enrolled-info').html(infoHtml); |
| 1551 | } |
| 1552 | |
| 1553 | $that.show(); |
| 1554 | }); |
| 1555 | } |
| 1556 | tutor_bp_setting_enrolled_courses_list(); |
| 1557 | |
| 1558 | $(document).on('click', 'a.tutor_bp_plus_courses', function(e){ |
| 1559 | e.preventDefault(); |
| 1560 | |
| 1561 | var $btn = $(this); |
| 1562 | $btn.closest('.tutor-bp-enrolled-courses-wrap').find('.tutor-bp-enrolled-course-list li').show(); |
| 1563 | $btn.closest('.thread-participant-enrolled-info').html(''); |
| 1564 | }); |
| 1565 | |
| 1566 | |
| 1567 | |
| 1568 | /** |
| 1569 | * Addon, Tutor Certificate |
| 1570 | * Certificate dropdown content and copy link |
| 1571 | * @for TutorLMS Pro |
| 1572 | * @since v.1.5.1 |
| 1573 | */ |
| 1574 | $(document).on('click', '.tutor-dropbtn', function (e) { |
| 1575 | var $content = $(this).parent().find(".tutor-dropdown-content"); |
| 1576 | $content.slideToggle(100); |
| 1577 | }); |
| 1578 | $(document).on('click', '.tutor-copy-link', function (e) { |
| 1579 | var $btn = $(this); |
| 1580 | var copy = '<i class="tutor-icon-copy"></i> Copy Link'; |
| 1581 | var copied = '<i class="tutor-icon-mark"></i> Copied'; |
| 1582 | var dummy = document.createElement('input'), |
| 1583 | text = window.location.href; |
| 1584 | document.body.appendChild(dummy); |
| 1585 | dummy.value = text; |
| 1586 | dummy.select(); |
| 1587 | document.execCommand('copy'); |
| 1588 | document.body.removeChild(dummy); |
| 1589 | $btn.html(copied); |
| 1590 | setTimeout( function() { |
| 1591 | $btn.html(copy); |
| 1592 | }, 2500); |
| 1593 | }); |
| 1594 | $(document).on('click', function(e) { |
| 1595 | var container = $(".tutor-dropdown"); |
| 1596 | var $content = container.find('.tutor-dropdown-content'); |
| 1597 | // if the target of the click isn't the container nor a descendant of the container |
| 1598 | if (!container.is(e.target) && container.has(e.target).length === 0) { |
| 1599 | $content.slideUp(100); |
| 1600 | } |
| 1601 | }); |
| 1602 | |
| 1603 | }); |