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.js
6 years ago
tutor-front.js
1493 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.options.quiz_when_time_expires === 'autosubmit') { |
| 310 | /** |
| 311 | * Auto Submit |
| 312 | */ |
| 313 | $('form#tutor-answering-quiz').submit(); |
| 314 | |
| 315 | } else if (_tutorobject.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 | var $that = $(this); |
| 554 | var question_id = parseInt($that.closest('.quiz-attempt-single-question').attr('id').match(/\d+/)[0], 10); |
| 555 | |
| 556 | var next_question_id = $that.closest('.quiz-attempt-single-question').attr('data-next-question-id'); |
| 557 | |
| 558 | if (next_question_id) { |
| 559 | var $nextQuestion = $(next_question_id); |
| 560 | if ($nextQuestion && $nextQuestion.length) { |
| 561 | $('.quiz-attempt-single-question').hide(); |
| 562 | $nextQuestion.show(); |
| 563 | |
| 564 | /** |
| 565 | * If pagination exists, set active class |
| 566 | */ |
| 567 | |
| 568 | if ($('.tutor-quiz-questions-pagination').length){ |
| 569 | $('.tutor-quiz-question-paginate-item').removeClass('active'); |
| 570 | $('.tutor-quiz-questions-pagination a[href="'+next_question_id+'"]').addClass('active'); |
| 571 | } |
| 572 | |
| 573 | } |
| 574 | } |
| 575 | }); |
| 576 | $(document).on('click', '.tutor-quiz-question-paginate-item', function (e) { |
| 577 | e.preventDefault(); |
| 578 | var $that = $(this); |
| 579 | var $question = $($that.attr('href')); |
| 580 | $('.quiz-attempt-single-question').hide(); |
| 581 | $question.show(); |
| 582 | |
| 583 | //Active Class |
| 584 | $('.tutor-quiz-question-paginate-item').removeClass('active'); |
| 585 | $that.addClass('active'); |
| 586 | }); |
| 587 | |
| 588 | /** |
| 589 | * Limit Short Answer Question Type |
| 590 | */ |
| 591 | $(document).on('keyup', 'textarea.question_type_short_answer', function (e) { |
| 592 | var $that = $(this); |
| 593 | var value = $that.val(); |
| 594 | var limit = _tutorobject.quiz_options.short_answer_characters_limit; |
| 595 | var remaining = limit - value.length; |
| 596 | |
| 597 | if (remaining < 1){ |
| 598 | $that.val(value.substr(0, limit)); |
| 599 | remaining = 0; |
| 600 | } |
| 601 | $that.closest('.tutor-quiz-answers-wrap').find('.characters_remaining').html(remaining); |
| 602 | }); |
| 603 | |
| 604 | /** |
| 605 | * |
| 606 | * @type {jQuery} |
| 607 | * |
| 608 | * Improved Quiz draggable answers drop accessibility |
| 609 | * Answers draggable wrap will be now same height. |
| 610 | * |
| 611 | * @since v.1.4.4 |
| 612 | */ |
| 613 | var countDraggableAnswers = $('.quiz-draggable-rand-answers').length; |
| 614 | if (countDraggableAnswers){ |
| 615 | $('.quiz-draggable-rand-answers').each(function(){ |
| 616 | var $that = $(this); |
| 617 | var draggableDivHeight = $that.height(); |
| 618 | |
| 619 | $that.css({"height": draggableDivHeight}); |
| 620 | }); |
| 621 | } |
| 622 | |
| 623 | /** |
| 624 | * Add to cart in guest mode, show login form |
| 625 | * |
| 626 | * @since v.1.0.4 |
| 627 | */ |
| 628 | |
| 629 | $(document).on('submit click', '.cart-required-login, .cart-required-login a, .cart-required-login form', function (e) { |
| 630 | e.preventDefault(); |
| 631 | |
| 632 | $('.tutor-cart-box-login-form').fadeIn(100); |
| 633 | }); |
| 634 | |
| 635 | $('.tutor-popup-form-close, .login-overlay-close').on('click', function () { |
| 636 | $('.tutor-cart-box-login-form').fadeOut(100); |
| 637 | }); |
| 638 | |
| 639 | $(document).on('keyup', function (e) { |
| 640 | if (e.keyCode === 27) { |
| 641 | $('.tutor-frontend-modal').hide(); |
| 642 | $('.tutor-cart-box-login-form').fadeOut(100); |
| 643 | } |
| 644 | }); |
| 645 | /** |
| 646 | * Share Link enable |
| 647 | * |
| 648 | * @since v.1.0.4 |
| 649 | */ |
| 650 | if($.fn.ShareLink){ |
| 651 | var $social_share_wrap = $('.tutor-social-share-wrap'); |
| 652 | if ($social_share_wrap.length) { |
| 653 | var share_config = JSON.parse($social_share_wrap.attr('data-social-share-config')); |
| 654 | |
| 655 | $('.tutor_share').ShareLink({ |
| 656 | title: share_config.title, |
| 657 | text: share_config.text, |
| 658 | image: share_config.image, |
| 659 | class_prefix: 's_', |
| 660 | width: 640, |
| 661 | height: 480, |
| 662 | }); |
| 663 | } |
| 664 | } |
| 665 | |
| 666 | /** |
| 667 | * Datepicker initiate |
| 668 | * |
| 669 | * @since v.1.1.2 |
| 670 | */ |
| 671 | if (jQuery.datepicker){ |
| 672 | $( ".tutor_report_datepicker" ).datepicker({"dateFormat" : 'yy-mm-dd'}); |
| 673 | } |
| 674 | |
| 675 | |
| 676 | /** |
| 677 | * Withdraw Form Tab/Toggle |
| 678 | * |
| 679 | * @since v.1.1.2 |
| 680 | */ |
| 681 | |
| 682 | $(".withdraw-method-select-input").on('change', function(e){ |
| 683 | var $that = $(this); |
| 684 | $('.withdraw-method-form').hide(); |
| 685 | $('#withdraw-method-form-'+$that.closest('.withdraw-method-select').attr('data-withdraw-method')).show(); |
| 686 | }); |
| 687 | |
| 688 | $('.withdraw-method-select-input').each(function () { |
| 689 | var $that = $(this); |
| 690 | if($that.is(":checked")){ |
| 691 | $('.withdraw-method-form').hide(); |
| 692 | $('#withdraw-method-form-'+$that.closest('.withdraw-method-select').attr('data-withdraw-method')).show(); |
| 693 | } |
| 694 | }); |
| 695 | |
| 696 | |
| 697 | |
| 698 | /** |
| 699 | * Setting account for withdraw earning |
| 700 | * |
| 701 | * @since v.1.2.0 |
| 702 | */ |
| 703 | $(document).on('submit', '#tutor-withdraw-account-set-form', function(e){ |
| 704 | e.preventDefault(); |
| 705 | |
| 706 | var $form = $(this); |
| 707 | var $btn = $form.find('.tutor_set_withdraw_account_btn'); |
| 708 | var data = $form.serialize(); |
| 709 | |
| 710 | $.ajax({ |
| 711 | url: _tutorobject.ajaxurl, |
| 712 | type: 'POST', |
| 713 | data: data, |
| 714 | beforeSend: function () { |
| 715 | $form.find('.tutor-success-msg').remove(); |
| 716 | $btn.addClass('updating-icon'); |
| 717 | }, |
| 718 | success: function (data) { |
| 719 | if (data.success){ |
| 720 | var successMsg = '<div class="tutor-success-msg" style="display: none;"><i class="tutor-icon-mark"></i> '+data.data.msg+' </div>'; |
| 721 | $btn.closest('.withdraw-account-save-btn-wrap').append(successMsg); |
| 722 | if ($form.find('.tutor-success-msg').length) { |
| 723 | $form.find('.tutor-success-msg').slideDown(); |
| 724 | } |
| 725 | setTimeout(function () { |
| 726 | $form.find('.tutor-success-msg').slideUp(); |
| 727 | }, 5000) |
| 728 | } |
| 729 | }, |
| 730 | complete: function () { |
| 731 | $btn.removeClass('updating-icon'); |
| 732 | } |
| 733 | }); |
| 734 | }); |
| 735 | |
| 736 | /** |
| 737 | * Make Withdraw Form |
| 738 | * |
| 739 | * @since v.1.2.0 |
| 740 | */ |
| 741 | |
| 742 | $(document).on('click', 'a.open-withdraw-form-btn', function(e){ |
| 743 | e.preventDefault(); |
| 744 | $('.tutor-earning-withdraw-form-wrap').slideToggle(); |
| 745 | }); |
| 746 | |
| 747 | $(document).on('submit', '#tutor-earning-withdraw-form', function(e){ |
| 748 | e.preventDefault(); |
| 749 | |
| 750 | var $form = $(this); |
| 751 | var $btn = $('#tutor-earning-withdraw-btn'); |
| 752 | var $responseDiv = $('#tutor-withdraw-form-response'); |
| 753 | var data = $form.serialize(); |
| 754 | |
| 755 | $.ajax({ |
| 756 | url: _tutorobject.ajaxurl, |
| 757 | type: 'POST', |
| 758 | data: data, |
| 759 | beforeSend: function () { |
| 760 | $form.find('.tutor-success-msg').remove(); |
| 761 | $btn.addClass('updating-icon'); |
| 762 | }, |
| 763 | success: function (data) { |
| 764 | var Msg; |
| 765 | if (data.success){ |
| 766 | |
| 767 | if (data.data.available_balance !== 'undefined') { |
| 768 | $('.withdraw-balance-col .available_balance').html(data.data.available_balance); |
| 769 | } |
| 770 | Msg = '<div class="tutor-success-msg"><i class="tutor-icon-mark"></i> '+data.data.msg+' </div>'; |
| 771 | |
| 772 | }else{ |
| 773 | Msg = '<div class="tutor-error-msg"><i class="tutor-icon-line-cross"></i> '+data.data.msg+' </div>'; |
| 774 | } |
| 775 | |
| 776 | $responseDiv.html(Msg); |
| 777 | setTimeout(function () { |
| 778 | $responseDiv.html(''); |
| 779 | }, 5000) |
| 780 | }, |
| 781 | complete: function () { |
| 782 | $btn.removeClass('updating-icon'); |
| 783 | } |
| 784 | }); |
| 785 | }); |
| 786 | |
| 787 | var frontEndModal = $('.tutor-frontend-modal'); |
| 788 | frontEndModal.each(function () { |
| 789 | var modal = $(this), |
| 790 | action = $(this).data('popup-rel'); |
| 791 | $('[href="'+action+'"]').on('click', function (e) { |
| 792 | modal.fadeIn(); |
| 793 | e.preventDefault(); |
| 794 | }); |
| 795 | }); |
| 796 | $(document).on('click', '.tm-close, .tutor-frontend-modal-overlay, .tutor-modal-btn-cancel', function () { |
| 797 | frontEndModal.fadeOut(); |
| 798 | }); |
| 799 | |
| 800 | /** |
| 801 | * Delete Course |
| 802 | */ |
| 803 | $(document).on('click', '.tutor-mycourse-delete-btn', function (e) { |
| 804 | e.preventDefault(); |
| 805 | var course_id = $(this).attr('data-course-id'); |
| 806 | $('#tutor-course-delete-id').val(course_id); |
| 807 | }); |
| 808 | $(document).on('submit', '#tutor-delete-course-form', function (e) { |
| 809 | e.preventDefault(); |
| 810 | |
| 811 | var course_id = $('#tutor-course-delete-id').val(); |
| 812 | var $btn = $('.tutor-modal-course-delete-btn'); |
| 813 | var data = $(this).serialize(); |
| 814 | |
| 815 | $.ajax({ |
| 816 | url: _tutorobject.ajaxurl, |
| 817 | type: 'POST', |
| 818 | data: data, |
| 819 | beforeSend: function () { |
| 820 | $btn.addClass('updating-icon'); |
| 821 | }, |
| 822 | success: function (data) { |
| 823 | if (data.success){ |
| 824 | $('#tutor-dashboard-course-'+course_id).remove(); |
| 825 | } |
| 826 | }, |
| 827 | complete: function () { |
| 828 | $btn.removeClass('updating-icon'); |
| 829 | $('.tutor-frontend-modal').hide(); |
| 830 | } |
| 831 | }); |
| 832 | }); |
| 833 | |
| 834 | /** |
| 835 | * Frontend Profile |
| 836 | */ |
| 837 | |
| 838 | if (! $('#tutor_profile_photo_id').val()) { |
| 839 | $('.tutor-profile-photo-delete-btn').hide(); |
| 840 | } |
| 841 | |
| 842 | $( document ).on( 'click', '.tutor-profile-photo-delete-btn', function() { |
| 843 | $( '.tutor-profile-photo-upload-wrap' ).find( 'img' ).attr( 'src', _tutorobject.placeholder_img_src ); |
| 844 | $( '#tutor_profile_photo_id' ).val( '' ); |
| 845 | $( '.tutor-profile-photo-delete-btn' ).hide(); |
| 846 | |
| 847 | $.ajax({ |
| 848 | url: _tutorobject.ajaxurl, |
| 849 | type: 'POST', |
| 850 | data: {'action' : 'tutor_profile_photo_remove'}, |
| 851 | }); |
| 852 | |
| 853 | return false; |
| 854 | }); |
| 855 | |
| 856 | |
| 857 | |
| 858 | /** |
| 859 | * Assignment |
| 860 | * |
| 861 | * @since v.1.3.3 |
| 862 | */ |
| 863 | |
| 864 | $( document ).on( 'submit', '#tutor_assignment_start_form', function(e) { |
| 865 | e.preventDefault(); |
| 866 | |
| 867 | var $that = $(this); |
| 868 | var form_data = $that.serialize()+'&action=tutor_start_assignment'; |
| 869 | |
| 870 | $.ajax({ |
| 871 | url: _tutorobject.ajaxurl, |
| 872 | type: 'POST', |
| 873 | data: form_data, |
| 874 | beforeSend: function () { |
| 875 | $('#tutor_assignment_start_btn').addClass('updating-icon'); |
| 876 | }, |
| 877 | success: function (data) { |
| 878 | if (data.success){ |
| 879 | location.reload(); |
| 880 | } |
| 881 | }, |
| 882 | complete : function () { |
| 883 | $('#tutor_assignment_start_btn').removeClass('updating-icon'); |
| 884 | } |
| 885 | }); |
| 886 | }); |
| 887 | |
| 888 | /** |
| 889 | * Assignment answer validation |
| 890 | */ |
| 891 | $( document ).on( 'submit', '#tutor_assignment_submit_form', function(e) { |
| 892 | var assignment_answer = $('textarea[name="assignment_answer"]').val(); |
| 893 | if (assignment_answer.trim().length < 1) { |
| 894 | $('#form_validation_response').html('<div class="tutor-error-msg">'+_tutorobject.text.assignment_text_validation_msg+'</div>'); |
| 895 | e.preventDefault(); |
| 896 | } |
| 897 | }); |
| 898 | |
| 899 | /** |
| 900 | * Course builder video |
| 901 | * @since v.1.3.4 |
| 902 | */ |
| 903 | |
| 904 | |
| 905 | $(document).on( 'click', '.video_source_upload_wrap_html5 .video_upload_btn', function( event ){ |
| 906 | event.preventDefault(); |
| 907 | |
| 908 | var $that = $(this); |
| 909 | var frame; |
| 910 | // If the media frame already exists, reopen it. |
| 911 | if ( frame ) { |
| 912 | frame.open(); |
| 913 | return; |
| 914 | } |
| 915 | frame = wp.media({ |
| 916 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 917 | button: { |
| 918 | text: 'Use this media' |
| 919 | }, |
| 920 | multiple: false // Set to true to allow multiple files to be selected |
| 921 | }); |
| 922 | frame.on( 'select', function() { |
| 923 | // Get media attachment details from the frame state |
| 924 | var attachment = frame.state().get('selection').first().toJSON(); |
| 925 | $that.closest('.video_source_upload_wrap_html5').find('span.video_media_id').text(attachment.id).closest('p').show(); |
| 926 | $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id); |
| 927 | }); |
| 928 | frame.open(); |
| 929 | }); |
| 930 | |
| 931 | |
| 932 | /** |
| 933 | * Course and lesson sorting |
| 934 | */ |
| 935 | |
| 936 | function enable_sorting_topic_lesson(){ |
| 937 | if (jQuery().sortable) { |
| 938 | $(".course-contents").sortable({ |
| 939 | handle: ".course-move-handle", |
| 940 | start: function (e, ui) { |
| 941 | ui.placeholder.css('visibility', 'visible'); |
| 942 | }, |
| 943 | stop: function (e, ui) { |
| 944 | tutor_sorting_topics_and_lesson(); |
| 945 | }, |
| 946 | }); |
| 947 | $(".tutor-lessons:not(.drop-lessons)").sortable({ |
| 948 | connectWith: ".tutor-lessons", |
| 949 | items: "div.course-content-item", |
| 950 | start: function (e, ui) { |
| 951 | ui.placeholder.css('visibility', 'visible'); |
| 952 | }, |
| 953 | stop: function (e, ui) { |
| 954 | tutor_sorting_topics_and_lesson(); |
| 955 | }, |
| 956 | }); |
| 957 | } |
| 958 | } |
| 959 | enable_sorting_topic_lesson(); |
| 960 | function tutor_sorting_topics_and_lesson(){ |
| 961 | var topics = {}; |
| 962 | $('.tutor-topics-wrap').each(function(index, item){ |
| 963 | var $topic = $(this); |
| 964 | var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10); |
| 965 | var lessons = {}; |
| 966 | |
| 967 | $topic.find('.course-content-item').each(function(lessonIndex, lessonItem){ |
| 968 | var $lesson = $(this); |
| 969 | var lesson_id = parseInt($lesson.attr('id').match(/\d+/)[0], 10); |
| 970 | |
| 971 | lessons[lessonIndex] = lesson_id; |
| 972 | }); |
| 973 | topics[index] = { 'topic_id' : topics_id, 'lesson_ids' : lessons }; |
| 974 | }); |
| 975 | $('#tutor_topics_lessons_sorting').val(JSON.stringify(topics)); |
| 976 | } |
| 977 | |
| 978 | /** |
| 979 | * Lesson Update or Create Modal |
| 980 | */ |
| 981 | $(document).on( 'click', '.update_lesson_modal_btn', function( event ){ |
| 982 | event.preventDefault(); |
| 983 | |
| 984 | var $that = $(this); |
| 985 | var content; |
| 986 | var editor = tinyMCE.get('tutor_lesson_modal_editor'); |
| 987 | if (editor) { |
| 988 | content = editor.getContent(); |
| 989 | } else { |
| 990 | content = $('#'+inputid).val(); |
| 991 | } |
| 992 | |
| 993 | var form_data = $(this).closest('form').serialize(); |
| 994 | form_data += '&lesson_content='+content; |
| 995 | |
| 996 | $.ajax({ |
| 997 | url : ajaxurl, |
| 998 | type : 'POST', |
| 999 | data : form_data, |
| 1000 | beforeSend: function () { |
| 1001 | $that.addClass('tutor-updating-message'); |
| 1002 | }, |
| 1003 | success: function (data) { |
| 1004 | if (data.success){ |
| 1005 | $('#tutor-course-content-wrap').html(data.data.course_contents); |
| 1006 | enable_sorting_topic_lesson(); |
| 1007 | |
| 1008 | //Close the modal |
| 1009 | $('.tutor-lesson-modal-wrap').removeClass('show'); |
| 1010 | } |
| 1011 | }, |
| 1012 | complete: function () { |
| 1013 | $that.removeClass('tutor-updating-message'); |
| 1014 | } |
| 1015 | }); |
| 1016 | }); |
| 1017 | |
| 1018 | /** |
| 1019 | * END: Tutor Course builder JS |
| 1020 | */ |
| 1021 | |
| 1022 | /** |
| 1023 | * Attachment in forntend course builder |
| 1024 | * @since v.1.3.4 |
| 1025 | */ |
| 1026 | $(document).on('click', 'a.tutor-delete-attachment', function(e){ |
| 1027 | e.preventDefault(); |
| 1028 | $(this).closest('.tutor-added-attachment').remove(); |
| 1029 | }); |
| 1030 | $(document).on('click', '.tutorUploadAttachmentBtn', function(e){ |
| 1031 | e.preventDefault(); |
| 1032 | |
| 1033 | var $that = $(this); |
| 1034 | var frame; |
| 1035 | if ( frame ) { |
| 1036 | frame.open(); |
| 1037 | return; |
| 1038 | } |
| 1039 | frame = wp.media({ |
| 1040 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 1041 | button: { |
| 1042 | text: 'Use this media' |
| 1043 | }, |
| 1044 | multiple: true // Set to true to allow multiple files to be selected |
| 1045 | }); |
| 1046 | frame.on( 'select', function() { |
| 1047 | var attachments = frame.state().get('selection').toJSON(); |
| 1048 | if (attachments.length){ |
| 1049 | for (var i=0; i < attachments.length; i++){ |
| 1050 | var attachment = attachments[i]; |
| 1051 | |
| 1052 | 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>'; |
| 1053 | $that.closest('.tutor-lesson-attachments-metabox').find('.tutor-added-attachments-wrap').append(inputHtml); |
| 1054 | } |
| 1055 | } |
| 1056 | }); |
| 1057 | frame.open(); |
| 1058 | }); |
| 1059 | |
| 1060 | |
| 1061 | /** |
| 1062 | * Single Assignment Upload Button |
| 1063 | * @since v.1.3.4 |
| 1064 | */ |
| 1065 | $('form').on('change', '.tutor-assignment-file-upload', function () { |
| 1066 | $(this).siblings("label").find('span').html($(this).val().replace(/.*(\/|\\)/, '')); |
| 1067 | }); |
| 1068 | |
| 1069 | /** |
| 1070 | * Lesson Sidebar Topic Toggle |
| 1071 | * @since v.1.3.4 |
| 1072 | */ |
| 1073 | |
| 1074 | $(document).on('click', '.tutor-topics-in-single-lesson .tutor-topics-title h3, .tutor-single-lesson-topic-toggle', function (e) { |
| 1075 | var $that = $(this); |
| 1076 | var $parent = $that.closest('.tutor-topics-in-single-lesson'); |
| 1077 | $parent.toggleClass('tutor-topic-active'); |
| 1078 | $parent.find('.tutor-lessons-under-topic').slideToggle(); |
| 1079 | }); |
| 1080 | |
| 1081 | $('.tutor-single-lesson-items.active').closest('.tutor-lessons-under-topic').show(); |
| 1082 | $('.tutor-single-lesson-items.active').closest('.tutor-topics-in-single-lesson').addClass('tutor-topic-active'); |
| 1083 | |
| 1084 | |
| 1085 | /** |
| 1086 | * Assignments Addons |
| 1087 | * @backend Support |
| 1088 | * |
| 1089 | */ |
| 1090 | |
| 1091 | |
| 1092 | /** |
| 1093 | * Tutor Assignments JS |
| 1094 | * @since v.1.3.3 |
| 1095 | */ |
| 1096 | $(document).on('click', '.tutor-create-assignments-btn', function(e){ |
| 1097 | e.preventDefault(); |
| 1098 | |
| 1099 | var $that = $(this); |
| 1100 | var topic_id = $(this).attr('data-topic-id'); |
| 1101 | var course_id = $('#post_ID').val(); |
| 1102 | |
| 1103 | $.ajax({ |
| 1104 | url : ajaxurl, |
| 1105 | type : 'POST', |
| 1106 | data : {topic_id : topic_id, course_id : course_id, action: 'tutor_load_assignments_builder_modal'}, |
| 1107 | beforeSend: function () { |
| 1108 | $that.addClass('tutor-updating-message'); |
| 1109 | }, |
| 1110 | success: function (data) { |
| 1111 | $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output); |
| 1112 | $('.tutor-lesson-modal-wrap').attr('data-topic-id', topic_id).addClass('show'); |
| 1113 | |
| 1114 | $(document).trigger('assignment_modal_loaded', {topic_id : topic_id, course_id : course_id}); |
| 1115 | |
| 1116 | tinymce.init(tinyMCEPreInit.mceInit.course_description); |
| 1117 | tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_assignments_modal_editor' ); |
| 1118 | tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor"); |
| 1119 | }, |
| 1120 | complete: function () { |
| 1121 | quicktags({id : "tutor_assignments_modal_editor"}); |
| 1122 | $that.removeClass('tutor-updating-message'); |
| 1123 | } |
| 1124 | }); |
| 1125 | }); |
| 1126 | |
| 1127 | $(document).on('click', '.open-tutor-assignment-modal', function(e){ |
| 1128 | e.preventDefault(); |
| 1129 | |
| 1130 | var $that = $(this); |
| 1131 | var assignment_id = $that.attr('data-assignment-id'); |
| 1132 | var topic_id = $that.attr('data-topic-id'); |
| 1133 | var course_id = $('#post_ID').val(); |
| 1134 | |
| 1135 | $.ajax({ |
| 1136 | url : ajaxurl, |
| 1137 | type : 'POST', |
| 1138 | data : {assignment_id : assignment_id, topic_id : topic_id, course_id : course_id, action: 'tutor_load_assignments_builder_modal'}, |
| 1139 | beforeSend: function () { |
| 1140 | $that.addClass('tutor-updating-message'); |
| 1141 | }, |
| 1142 | success: function (data) { |
| 1143 | $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output); |
| 1144 | $('.tutor-lesson-modal-wrap').attr({'data-assignment-id' : assignment_id, 'data-topic-id':topic_id}).addClass('show'); |
| 1145 | |
| 1146 | $(document).trigger('assignment_modal_loaded', {assignment_id : assignment_id, topic_id : topic_id, course_id : course_id}); |
| 1147 | |
| 1148 | tinymce.init(tinyMCEPreInit.mceInit.course_description); |
| 1149 | tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_assignments_modal_editor' ); |
| 1150 | tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor"); |
| 1151 | }, |
| 1152 | complete: function () { |
| 1153 | quicktags({id : "tutor_assignments_modal_editor"}); |
| 1154 | $that.removeClass('tutor-updating-message'); |
| 1155 | } |
| 1156 | }); |
| 1157 | }); |
| 1158 | |
| 1159 | /** |
| 1160 | * Update Assignment Data |
| 1161 | */ |
| 1162 | $(document).on( 'click', '.update_assignment_modal_btn', function( event ){ |
| 1163 | event.preventDefault(); |
| 1164 | |
| 1165 | var $that = $(this); |
| 1166 | var content; |
| 1167 | var editor = tinyMCE.get('tutor_assignments_modal_editor'); |
| 1168 | if (editor) { |
| 1169 | content = editor.getContent(); |
| 1170 | } else { |
| 1171 | content = $('#'+inputid).val(); |
| 1172 | } |
| 1173 | |
| 1174 | var form_data = $(this).closest('form').serialize(); |
| 1175 | form_data += '&assignment_content='+content; |
| 1176 | |
| 1177 | $.ajax({ |
| 1178 | url : ajaxurl, |
| 1179 | type : 'POST', |
| 1180 | data : form_data, |
| 1181 | beforeSend: function () { |
| 1182 | $that.addClass('tutor-updating-message'); |
| 1183 | }, |
| 1184 | success: function (data) { |
| 1185 | if (data.success){ |
| 1186 | $('#tutor-course-content-wrap').html(data.data.course_contents); |
| 1187 | enable_sorting_topic_lesson(); |
| 1188 | |
| 1189 | //Close the modal |
| 1190 | $('.tutor-lesson-modal-wrap').removeClass('show'); |
| 1191 | } |
| 1192 | }, |
| 1193 | complete: function () { |
| 1194 | $that.removeClass('tutor-updating-message'); |
| 1195 | } |
| 1196 | }); |
| 1197 | }); |
| 1198 | |
| 1199 | /** |
| 1200 | * Add Assignment |
| 1201 | */ |
| 1202 | $(document).on( 'click', '.add-assignment-attachments', function( event ){ |
| 1203 | event.preventDefault(); |
| 1204 | |
| 1205 | var $that = $(this); |
| 1206 | var frame; |
| 1207 | // If the media frame already exists, reopen it. |
| 1208 | if ( frame ) { |
| 1209 | frame.open(); |
| 1210 | return; |
| 1211 | } |
| 1212 | |
| 1213 | // Create a new media frame |
| 1214 | frame = wp.media({ |
| 1215 | title: 'Select or Upload Media Of Your Chosen Persuasion', |
| 1216 | button: { |
| 1217 | text: 'Use this media' |
| 1218 | }, |
| 1219 | multiple: false // Set to true to allow multiple files to be selected |
| 1220 | }); |
| 1221 | |
| 1222 | // When an image is selected in the media frame... |
| 1223 | frame.on( 'select', function() { |
| 1224 | // Get media attachment details from the frame state |
| 1225 | var attachment = frame.state().get('selection').first().toJSON(); |
| 1226 | |
| 1227 | 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>'; |
| 1228 | |
| 1229 | $('#assignment-attached-file').append(field_markup); |
| 1230 | $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id); |
| 1231 | }); |
| 1232 | // Finally, open the modal on click |
| 1233 | frame.open(); |
| 1234 | }); |
| 1235 | |
| 1236 | $(document).on( 'click', '.remove-assignment-attachment-a', function( event ){ |
| 1237 | event.preventDefault(); |
| 1238 | $(this).closest('.tutor-individual-attachment-file').remove(); |
| 1239 | }); |
| 1240 | |
| 1241 | |
| 1242 | /** |
| 1243 | * |
| 1244 | * @type {jQuery} |
| 1245 | * |
| 1246 | * Course builder auto draft save |
| 1247 | * |
| 1248 | * @since v.1.3.4 |
| 1249 | */ |
| 1250 | var tutor_course_builder = $('input[name="tutor_action"]').val(); |
| 1251 | if (tutor_course_builder === 'tutor_add_course_builder'){ |
| 1252 | setInterval(auto_draft_save_course_builder, 30000); |
| 1253 | } |
| 1254 | |
| 1255 | function auto_draft_save_course_builder(){ |
| 1256 | var form_data = $('form#tutor-frontend-course-builder').serialize(); |
| 1257 | $.ajax({ |
| 1258 | //url : _tutorobject.ajaxurl, |
| 1259 | type : 'POST', |
| 1260 | data : form_data+'&tutor_ajax_action=tutor_course_builder_draft_save', |
| 1261 | beforeSend: function () { |
| 1262 | $('.tutor-dashboard-builder-draft-btn span').text('Saving...'); |
| 1263 | }, |
| 1264 | success: function (data) { |
| 1265 | |
| 1266 | }, |
| 1267 | complete: function () { |
| 1268 | $('.tutor-dashboard-builder-draft-btn span').text('Save'); |
| 1269 | } |
| 1270 | }); |
| 1271 | } |
| 1272 | |
| 1273 | /** |
| 1274 | * |
| 1275 | * @type {jQuery} |
| 1276 | * |
| 1277 | * Course builder section toggle |
| 1278 | * |
| 1279 | * @since v.1.3.5 |
| 1280 | */ |
| 1281 | |
| 1282 | $('.tutor-course-builder-section-title').on('click', function () { |
| 1283 | if($(this).find('i').hasClass("tutor-icon-up")){ |
| 1284 | $(this).find('i').removeClass('tutor-icon-up').addClass('tutor-icon-down'); |
| 1285 | }else{ |
| 1286 | $(this).find('i').removeClass('tutor-icon-down').addClass('tutor-icon-up'); |
| 1287 | } |
| 1288 | $(this).next('div').slideToggle(); |
| 1289 | }); |
| 1290 | |
| 1291 | /** |
| 1292 | * Open Tutor Modal to edit review |
| 1293 | * @since v.1.4.0 |
| 1294 | */ |
| 1295 | $(document).on('click', '.open-tutor-edit-review-modal', function(e){ |
| 1296 | e.preventDefault(); |
| 1297 | |
| 1298 | var $that = $(this); |
| 1299 | var review_id = $that.attr('data-review-id'); |
| 1300 | |
| 1301 | var nonce_key = _tutorobject.nonce_key; |
| 1302 | |
| 1303 | var json_data = {review_id : review_id, action: 'tutor_load_edit_review_modal'}; |
| 1304 | json_data[nonce_key] = _tutorobject[nonce_key]; |
| 1305 | |
| 1306 | $.ajax({ |
| 1307 | url : _tutorobject.ajaxurl, |
| 1308 | type : 'POST', |
| 1309 | data : json_data, |
| 1310 | beforeSend: function () { |
| 1311 | $that.addClass('tutor-updating-message'); |
| 1312 | }, |
| 1313 | success: function (data) { |
| 1314 | if (typeof data.data !== 'undefined') { |
| 1315 | $('.tutor-edit-review-modal-wrap .modal-container').html(data.data.output); |
| 1316 | $('.tutor-edit-review-modal-wrap').attr('data-review-id', review_id).addClass('show'); |
| 1317 | } |
| 1318 | }, |
| 1319 | complete: function () { |
| 1320 | $that.removeClass('tutor-updating-message'); |
| 1321 | } |
| 1322 | }); |
| 1323 | }); |
| 1324 | |
| 1325 | /** |
| 1326 | * Update the rating |
| 1327 | * @since v.1.4.0 |
| 1328 | */ |
| 1329 | $(document).on('submit', '#tutor_update_review_form', function(e){ |
| 1330 | e.preventDefault(); |
| 1331 | |
| 1332 | var $that = $(this); |
| 1333 | var review_id = $that.closest('.tutor-edit-review-modal-wrap ').attr('data-review-id'); |
| 1334 | |
| 1335 | var nonce_key = _tutorobject.nonce_key; |
| 1336 | |
| 1337 | var rating = $that.find('input[name="tutor_rating_gen_input"]').val(); |
| 1338 | var review = $that.find('textarea[name="review"]').val(); |
| 1339 | review = review.trim(); |
| 1340 | |
| 1341 | var json_data = {review_id : review_id, rating : rating, review : review, action: 'tutor_update_review_modal'}; |
| 1342 | json_data[nonce_key] = _tutorobject[nonce_key]; |
| 1343 | |
| 1344 | $.ajax({ |
| 1345 | url : _tutorobject.ajaxurl, |
| 1346 | type : 'POST', |
| 1347 | data : json_data, |
| 1348 | beforeSend: function () { |
| 1349 | $that.find('button[type="submit"]').addClass('tutor-updating-message'); |
| 1350 | }, |
| 1351 | success: function (data) { |
| 1352 | if (data.success){ |
| 1353 | //Close the modal |
| 1354 | $('.tutor-edit-review-modal-wrap').removeClass('show'); |
| 1355 | location.reload(true); |
| 1356 | } |
| 1357 | }, |
| 1358 | complete: function () { |
| 1359 | $that.find('button[type="submit"]').removeClass('tutor-updating-message'); |
| 1360 | } |
| 1361 | }); |
| 1362 | }); |
| 1363 | |
| 1364 | /** |
| 1365 | * Profile photo upload |
| 1366 | * @since v.1.4.5 |
| 1367 | */ |
| 1368 | |
| 1369 | $(document).on('click', '#tutor_profile_photo_button', function(e){ |
| 1370 | e.preventDefault(); |
| 1371 | |
| 1372 | $('#tutor_profile_photo_file').trigger('click'); |
| 1373 | }); |
| 1374 | |
| 1375 | $(document).on('change', '#tutor_profile_photo_file', function(event){ |
| 1376 | event.preventDefault(); |
| 1377 | |
| 1378 | var $file = this; |
| 1379 | if ($file.files && $file.files[0]) { |
| 1380 | var reader = new FileReader(); |
| 1381 | reader.onload = function(e) { |
| 1382 | $( '.tutor-profile-photo-upload-wrap' ).find( 'img' ).attr( 'src', e.target.result); |
| 1383 | } |
| 1384 | reader.readAsDataURL($file.files[0]); |
| 1385 | } |
| 1386 | }); |
| 1387 | |
| 1388 | /** |
| 1389 | * Addon, Tutor BuddyPress |
| 1390 | * Retrieve MetaInformation on BuddyPress message system |
| 1391 | * @for TutorLMS Pro |
| 1392 | * @since v.1.4.8 |
| 1393 | */ |
| 1394 | |
| 1395 | $(document).on('click', '.thread-content .subject', function(e){ |
| 1396 | var $btn = $(this); |
| 1397 | |
| 1398 | var thread_id = parseInt($btn.closest('.thread-content').attr('data-thread-id')); |
| 1399 | |
| 1400 | var nonce_key = _tutorobject.nonce_key; |
| 1401 | var json_data = {thread_id : thread_id, action: 'tutor_bp_retrieve_user_records_for_thread'}; |
| 1402 | json_data[nonce_key] = _tutorobject[nonce_key]; |
| 1403 | |
| 1404 | $.ajax({ |
| 1405 | type: 'POST', |
| 1406 | url: ajaxurl, |
| 1407 | data: json_data, |
| 1408 | beforeSend: function(){ |
| 1409 | $('#tutor-bp-thread-wrap').html(''); |
| 1410 | }, |
| 1411 | success: function (data) { |
| 1412 | if (data.success){ |
| 1413 | $('#tutor-bp-thread-wrap').html(data.data.thread_head_html); |
| 1414 | tutor_bp_setting_enrolled_courses_list(); |
| 1415 | } |
| 1416 | } |
| 1417 | }); |
| 1418 | |
| 1419 | }); |
| 1420 | |
| 1421 | |
| 1422 | function tutor_bp_setting_enrolled_courses_list(){ |
| 1423 | $('ul.tutor-bp-enrolled-course-list').each(function(){ |
| 1424 | var $that = $(this); |
| 1425 | var $li = $that.find(' > li'); |
| 1426 | var itemShow = 3; |
| 1427 | |
| 1428 | if ($li.length > itemShow){ |
| 1429 | var plusCourseCount = $li.length - itemShow; |
| 1430 | $li.each(function(liIndex, liItem){ |
| 1431 | var $liItem = $(this); |
| 1432 | |
| 1433 | if (liIndex >= itemShow){ |
| 1434 | $liItem.hide(); |
| 1435 | } |
| 1436 | }); |
| 1437 | |
| 1438 | var infoHtml = '<a href="javascript:;" class="tutor_bp_plus_courses"><strong>+'+plusCourseCount+' More </strong></a> Courses'; |
| 1439 | $that.closest('.tutor-bp-enrolled-courses-wrap').find('.thread-participant-enrolled-info').html(infoHtml); |
| 1440 | } |
| 1441 | |
| 1442 | $that.show(); |
| 1443 | }); |
| 1444 | } |
| 1445 | tutor_bp_setting_enrolled_courses_list(); |
| 1446 | |
| 1447 | $(document).on('click', 'a.tutor_bp_plus_courses', function(e){ |
| 1448 | e.preventDefault(); |
| 1449 | |
| 1450 | var $btn = $(this); |
| 1451 | $btn.closest('.tutor-bp-enrolled-courses-wrap').find('.tutor-bp-enrolled-course-list li').show(); |
| 1452 | $btn.closest('.thread-participant-enrolled-info').html(''); |
| 1453 | }); |
| 1454 | |
| 1455 | |
| 1456 | |
| 1457 | /** |
| 1458 | * Addon, Tutor Certificate |
| 1459 | * Certificate dropdown content and copy link |
| 1460 | * @for TutorLMS Pro |
| 1461 | * @since v.1.5.1 |
| 1462 | */ |
| 1463 | $(document).on('click', '.tutor-dropbtn', function (e) { |
| 1464 | var $content = $(this).parent().find(".tutor-dropdown-content"); |
| 1465 | $content.slideToggle(100); |
| 1466 | }); |
| 1467 | $(document).on('click', '.tutor-copy-link', function (e) { |
| 1468 | var $btn = $(this); |
| 1469 | var copy = '<i class="tutor-icon-copy"></i> Copy Link'; |
| 1470 | var copied = '<i class="tutor-icon-mark"></i> Copied'; |
| 1471 | var dummy = document.createElement('input'), |
| 1472 | text = window.location.href; |
| 1473 | document.body.appendChild(dummy); |
| 1474 | dummy.value = text; |
| 1475 | dummy.select(); |
| 1476 | document.execCommand('copy'); |
| 1477 | document.body.removeChild(dummy); |
| 1478 | $btn.html(copied); |
| 1479 | setTimeout( function() { |
| 1480 | $btn.html(copy); |
| 1481 | }, 2500); |
| 1482 | }); |
| 1483 | $(document).on('click', function(e) { |
| 1484 | var container = $(".tutor-dropdown"); |
| 1485 | var $content = container.find('.tutor-dropdown-content'); |
| 1486 | // if the target of the click isn't the container nor a descendant of the container |
| 1487 | if (!container.is(e.target) && container.has(e.target).length === 0) { |
| 1488 | $content.slideUp(100); |
| 1489 | } |
| 1490 | }); |
| 1491 | |
| 1492 | |
| 1493 | }); |