Chart.bundle.min.js
7 years ago
gutenberg_blocks.js
7 years ago
mce-button.js
7 years ago
tutor-admin.js
7 years ago
tutor-front.js
7 years ago
tutor-front.js
677 lines
| 1 | jQuery(document).ready(function($){ |
| 2 | 'use strict'; |
| 3 | |
| 4 | $(document).on('change', '.tutor-course-filter-form', function(e){ |
| 5 | e.preventDefault(); |
| 6 | $(this).closest('form').submit(); |
| 7 | }); |
| 8 | |
| 9 | const videoPlayer = { |
| 10 | nonce_key : _tutorobject.nonce_key, |
| 11 | video_track_data : $('#tutor_video_tracking_information').val(), |
| 12 | track_player : function(){ |
| 13 | var that = this; |
| 14 | |
| 15 | var video_data = this.video_track_data ? JSON.parse(this.video_track_data) : {}; |
| 16 | |
| 17 | if (typeof Plyr !== 'undefined') { |
| 18 | const player = new Plyr('#tutorPlayer'); |
| 19 | |
| 20 | player.on('ready', function(event){ |
| 21 | const instance = event.detail.plyr; |
| 22 | if (video_data.best_watch_time > 0) { |
| 23 | instance.media.currentTime = video_data.best_watch_time; |
| 24 | } |
| 25 | that.sync_time(instance); |
| 26 | }); |
| 27 | |
| 28 | var tempTimeNow = 0; |
| 29 | var intervalSeconds = 60; //Send to tutor backend about video playing time in this interval |
| 30 | player.on('timeupdate', function(event){ |
| 31 | const instance = event.detail.plyr; |
| 32 | |
| 33 | var tempTimeNowInSec = (tempTimeNow / 4); //timeupdate firing 250ms interval |
| 34 | if (tempTimeNowInSec >= intervalSeconds){ |
| 35 | that.sync_time(instance); |
| 36 | tempTimeNow = 0; |
| 37 | } |
| 38 | tempTimeNow++; |
| 39 | }); |
| 40 | |
| 41 | player.on('ended', function(event){ |
| 42 | const instance = event.detail.plyr; |
| 43 | |
| 44 | var data = {is_ended:true}; |
| 45 | that.sync_time(instance, data) |
| 46 | }); |
| 47 | } |
| 48 | }, |
| 49 | sync_time: function(instance, options){ |
| 50 | /** |
| 51 | * TUTOR is sending about video playback information to server. |
| 52 | */ |
| 53 | var video_data = this.video_track_data ? JSON.parse(this.video_track_data) : {}; |
| 54 | var data = {action: 'sync_video_playback', currentTime : instance.currentTime, duration:instance.duration, post_id : video_data.post_id}; |
| 55 | data[this.nonce_key] = _tutorobject[this.nonce_key]; |
| 56 | |
| 57 | var data_send = data; |
| 58 | if(options){ |
| 59 | data_send = Object.assign(data, options); |
| 60 | } |
| 61 | $.post(_tutorobject.ajaxurl, data_send); |
| 62 | }, |
| 63 | init: function(){ |
| 64 | this.track_player(); |
| 65 | } |
| 66 | }; |
| 67 | |
| 68 | /** |
| 69 | * Fire TUTOR video |
| 70 | * @since v.1.0.0 |
| 71 | */ |
| 72 | if ($('#tutorPlayer').length){ |
| 73 | videoPlayer.init(); |
| 74 | } |
| 75 | |
| 76 | $(document).on('change keyup paste', '.tutor_user_name', function(){ |
| 77 | $(this).val(tutor_slugify($(this).val())); |
| 78 | }); |
| 79 | |
| 80 | function tutor_slugify(text) { |
| 81 | return text.toString().toLowerCase() |
| 82 | .replace(/\s+/g, '-') // Replace spaces with - |
| 83 | .replace(/[^\w\-]+/g, '') // Remove all non-word chars |
| 84 | .replace(/\-\-+/g, '-') // Replace multiple - with single - |
| 85 | .replace(/^-+/, '') // Trim - from start of text |
| 86 | .replace(/-+$/, ''); // Trim - from end of text |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Hover tutor rating and set value |
| 91 | */ |
| 92 | $(document).on('hover', '.tutor-write-review-box .tutor-star-rating-group i', function(){ |
| 93 | $(this).closest('.tutor-star-rating-group').find('i').removeClass('tutor-icon-star-full').addClass('tutor-icon-star-line'); |
| 94 | var currentRateValue = $(this).attr('data-rating-value'); |
| 95 | for (var i = 1; i<= currentRateValue; i++){ |
| 96 | $(this).closest('.tutor-star-rating-group').find('i[data-rating-value="'+i+'"]').removeClass('tutor-icon-star-line').addClass('tutor-icon-star-full'); |
| 97 | } |
| 98 | $(this).closest('.tutor-star-rating-group').find('input[name="tutor_rating_gen_input"]').val(currentRateValue); |
| 99 | }); |
| 100 | |
| 101 | $(document).on('click', '.tutor-star-rating-group i', function(){ |
| 102 | var rating = $(this).attr('data-rating-value'); |
| 103 | $(this).closest('.tutor-star-rating-group').find('input[name="tutor_rating_gen_input"]').val(rating); |
| 104 | }); |
| 105 | |
| 106 | $(document).on('click', '.tutor_submit_review_btn', function (e) { |
| 107 | e.preventDefault(); |
| 108 | var $that = $(this); |
| 109 | var rating = $that.closest('form').find('input[name="tutor_rating_gen_input"]').val(); |
| 110 | var review = $that.closest('form').find('textarea[name="review"]').val(); |
| 111 | review = review.trim(); |
| 112 | |
| 113 | var course_id = $('input[name="tutor_course_id"]').val(); |
| 114 | var data = {course_id : course_id, rating : rating, review:review, action: 'tutor_place_rating' }; |
| 115 | |
| 116 | if (review) { |
| 117 | $.ajax({ |
| 118 | url: _tutorobject.ajaxurl, |
| 119 | type: 'POST', |
| 120 | data: data, |
| 121 | beforeSend: function () { |
| 122 | $that.addClass('updating-icon'); |
| 123 | }, |
| 124 | success: function (data) { |
| 125 | var review_id = data.data.review_id; |
| 126 | var review = data.data.review; |
| 127 | $('.tutor-review-'+review_id+' .review-content').html(review); |
| 128 | }, |
| 129 | complete: function () { |
| 130 | $('.tutor-write-review-form').slideUp(); |
| 131 | $that.removeClass('updating-icon'); |
| 132 | } |
| 133 | }); |
| 134 | } |
| 135 | }); |
| 136 | |
| 137 | $(document).on('click', '.write-course-review-link-btn', function(e){ |
| 138 | e.preventDefault(); |
| 139 | $(this).siblings('.tutor-write-review-form').slideToggle(); |
| 140 | }); |
| 141 | |
| 142 | $(document).on('click', '.tutor-ask-question-btn', function(e){ |
| 143 | e.preventDefault(); |
| 144 | $('.tutor-add-question-wrap').slideToggle(); |
| 145 | }); |
| 146 | $(document).on('click', '.tutor_question_cancel', function(e){ |
| 147 | e.preventDefault(); |
| 148 | $('.tutor-add-question-wrap').toggle(); |
| 149 | }); |
| 150 | |
| 151 | $(document).on('submit', '#tutor-ask-question-form', function(e){ |
| 152 | e.preventDefault(); |
| 153 | |
| 154 | var $form = $(this); |
| 155 | var data = $(this).serialize()+'&action=tutor_ask_question'; |
| 156 | |
| 157 | $.ajax({ |
| 158 | url: _tutorobject.ajaxurl, |
| 159 | type: 'POST', |
| 160 | data: data, |
| 161 | beforeSend: function () { |
| 162 | $form.find('.tutor_ask_question_btn').addClass('updating-icon'); |
| 163 | }, |
| 164 | success: function (data) { |
| 165 | if (data.success){ |
| 166 | $('.tutor-add-question-wrap').hide(); |
| 167 | window.location.reload(); |
| 168 | } |
| 169 | }, |
| 170 | complete: function () { |
| 171 | $form.find('.tutor_ask_question_btn').removeClass('updating-icon'); |
| 172 | } |
| 173 | }); |
| 174 | }); |
| 175 | |
| 176 | $(document).on('submit', '.tutor-add-answer-form', function(e){ |
| 177 | e.preventDefault(); |
| 178 | |
| 179 | var $form = $(this); |
| 180 | var data = $(this).serialize()+'&action=tutor_add_answer'; |
| 181 | |
| 182 | $.ajax({ |
| 183 | url: _tutorobject.ajaxurl, |
| 184 | type: 'POST', |
| 185 | data: data, |
| 186 | beforeSend: function () { |
| 187 | $form.find('.tutor_add_answer_btn').addClass('updating-icon'); |
| 188 | }, |
| 189 | success: function (data) { |
| 190 | if (data.success){ |
| 191 | window.location.reload(); |
| 192 | } |
| 193 | }, |
| 194 | complete: function () { |
| 195 | $form.find('.tutor_add_answer_btn').removeClass('updating-icon'); |
| 196 | } |
| 197 | }); |
| 198 | }); |
| 199 | |
| 200 | $(document).on('focus', '.tutor_add_answer_textarea', function(e){ |
| 201 | e.preventDefault(); |
| 202 | |
| 203 | var question_id = $(this).closest('.tutor_add_answer_wrap').attr('data-question-id'); |
| 204 | var conf = { |
| 205 | tinymce: { |
| 206 | wpautop:true, |
| 207 | //plugins : 'charmap colorpicker compat3x directionality fullscreen hr image lists media paste tabfocus textcolor wordpress wpautoresize wpdialogs wpeditimage wpemoji wpgallery wplink wptextpattern wpview', |
| 208 | toolbar1: 'bold italic underline bullist strikethrough numlist blockquote alignleft aligncenter alignright undo redo link unlink spellchecker fullscreen' |
| 209 | }, |
| 210 | }; |
| 211 | wp.editor.initialize('tutor_answer_'+question_id, conf); |
| 212 | }); |
| 213 | |
| 214 | $(document).on('click', '.tutor_cancel_wp_editor', function(e){ |
| 215 | e.preventDefault(); |
| 216 | $(this).closest('.tutor_wp_editor_wrap').toggle(); |
| 217 | $(this).closest('.tutor_add_answer_wrap').find('.tutor_wp_editor_show_btn_wrap').toggle(); |
| 218 | var question_id = $(this).closest('.tutor_add_answer_wrap').attr('data-question-id'); |
| 219 | wp.editor.remove('tutor_answer_'+question_id); |
| 220 | }); |
| 221 | |
| 222 | $(document).on('click', '.tutor_wp_editor_show_btn', function(e){ |
| 223 | e.preventDefault(); |
| 224 | $(this).closest('.tutor_add_answer_wrap').find('.tutor_wp_editor_wrap').toggle(); |
| 225 | $(this).closest('.tutor_wp_editor_show_btn_wrap').toggle(); |
| 226 | }); |
| 227 | |
| 228 | /** |
| 229 | * Quiz attempt |
| 230 | */ |
| 231 | var $tutor_quiz_time_update = $('#tutor-quiz-time-update'); |
| 232 | var attempt_settings = null; |
| 233 | if ($tutor_quiz_time_update.length){ |
| 234 | attempt_settings = JSON.parse($tutor_quiz_time_update.attr('data-attempt-settings')); |
| 235 | var attempt_meta = JSON.parse($tutor_quiz_time_update.attr('data-attempt-meta')); |
| 236 | |
| 237 | if (attempt_meta.time_limit.time_limit_seconds > 0) { |
| 238 | //No time Zero limit for |
| 239 | var countDownDate = new Date(attempt_settings.attempt_started_at).getTime() + (attempt_meta.time_limit.time_limit_seconds * 1000); |
| 240 | var time_now = new Date(attempt_meta.date_time_now).getTime(); |
| 241 | |
| 242 | var tutor_quiz_interval = setInterval(function () { |
| 243 | var distance = countDownDate - time_now; |
| 244 | |
| 245 | var days = Math.floor(distance / (1000 * 60 * 60 * 24)); |
| 246 | var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); |
| 247 | var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); |
| 248 | var seconds = Math.floor((distance % (1000 * 60)) / 1000); |
| 249 | |
| 250 | var countdown_human = ''; |
| 251 | |
| 252 | if (days) { |
| 253 | countdown_human += days + "d "; |
| 254 | } |
| 255 | if (hours) { |
| 256 | countdown_human += hours + "h "; |
| 257 | } |
| 258 | if (minutes) { |
| 259 | countdown_human += minutes + "m "; |
| 260 | } |
| 261 | if (seconds) { |
| 262 | countdown_human += seconds + "s "; |
| 263 | } |
| 264 | |
| 265 | if (distance < 0) { |
| 266 | clearInterval(tutor_quiz_interval); |
| 267 | countdown_human = "EXPIRED"; |
| 268 | //Set the quiz attempt to timeout in ajax |
| 269 | |
| 270 | if (_tutorobject.options.quiz_when_time_expires === 'autosubmit') { |
| 271 | /** |
| 272 | * Auto Submit |
| 273 | */ |
| 274 | $('form#tutor-answering-quiz').submit(); |
| 275 | |
| 276 | } else if (_tutorobject.options.quiz_when_time_expires === 'autoabandon') { |
| 277 | /** |
| 278 | * |
| 279 | * @type {jQuery} |
| 280 | * |
| 281 | * Current attempt will be cancel with attempt status attempt_timeout |
| 282 | */ |
| 283 | |
| 284 | var quiz_id = $('#tutor_quiz_id').val(); |
| 285 | var tutor_quiz_remaining_time_secs = $('#tutor_quiz_remaining_time_secs').val(); |
| 286 | var quiz_timeout_data = {quiz_id: quiz_id, action: 'tutor_quiz_timeout'}; |
| 287 | |
| 288 | $.ajax({ |
| 289 | url: _tutorobject.ajaxurl, |
| 290 | type: 'POST', |
| 291 | data: quiz_timeout_data, |
| 292 | success: function (data) { |
| 293 | if (data.success) { |
| 294 | window.location.reload(true); |
| 295 | } |
| 296 | }, |
| 297 | complete: function () { |
| 298 | $('#tutor-quiz-body').html(''); |
| 299 | window.location.reload(true); |
| 300 | } |
| 301 | }); |
| 302 | } |
| 303 | |
| 304 | } |
| 305 | time_now = time_now + 1000; |
| 306 | $tutor_quiz_time_update.html(countdown_human); |
| 307 | }, 1000); |
| 308 | }else{ |
| 309 | $tutor_quiz_time_update.closest('.time-remaining').remove(); |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | var $quiz_start_form = $('#tutor-quiz-body form#tutor-start-quiz'); |
| 314 | if ($quiz_start_form.length){ |
| 315 | if (_tutorobject.quiz_options.quiz_auto_start === '1'){ |
| 316 | $quiz_start_form.submit(); |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | // tutor course content accordion |
| 321 | $('.tutor-course-topic.tutor-active').find('.tutor-course-lessons').slideDown(); |
| 322 | $('.tutor-course-title').on('click', function () { |
| 323 | var lesson = $(this).siblings('.tutor-course-lessons'); |
| 324 | $(this).closest('.tutor-course-topic').toggleClass('tutor-active'); |
| 325 | lesson.slideToggle(); |
| 326 | }); |
| 327 | |
| 328 | $('.tutor-topics-title').on('click', function () { |
| 329 | $(this).siblings('.tutor-topics-summery').slideToggle(); |
| 330 | }); |
| 331 | |
| 332 | $(document).on('click', '.tutor-course-wishlist-btn', function (e) { |
| 333 | e.preventDefault(); |
| 334 | |
| 335 | var $that = $(this); |
| 336 | var course_id = $that.attr('data-course-id'); |
| 337 | |
| 338 | $.ajax({ |
| 339 | url: _tutorobject.ajaxurl, |
| 340 | type: 'POST', |
| 341 | data: {course_id : course_id, 'action': 'tutor_course_add_to_wishlist'}, |
| 342 | beforeSend: function () { |
| 343 | $that.addClass('updating-icon'); |
| 344 | }, |
| 345 | success: function (data) { |
| 346 | if (data.success){ |
| 347 | if (data.data.status === 'added'){ |
| 348 | $that.addClass('has-wish-listed'); |
| 349 | }else{ |
| 350 | $that.removeClass('has-wish-listed'); |
| 351 | } |
| 352 | }else{ |
| 353 | window.location = data.data.redirect_to; |
| 354 | } |
| 355 | }, |
| 356 | complete: function () { |
| 357 | $that.removeClass('updating-icon'); |
| 358 | } |
| 359 | }); |
| 360 | }); |
| 361 | |
| 362 | $(document).on('click', '.tutor-single-lesson-a', function (e) { |
| 363 | e.preventDefault(); |
| 364 | |
| 365 | var $that = $(this); |
| 366 | var lesson_id = $that.attr('data-lesson-id'); |
| 367 | var $wrap = $('#tutor-single-entry-content'); |
| 368 | |
| 369 | $.ajax({ |
| 370 | url: _tutorobject.ajaxurl, |
| 371 | type: 'POST', |
| 372 | data: {lesson_id : lesson_id, 'action': 'tutor_render_lesson_content'}, |
| 373 | beforeSend: function () { |
| 374 | var page_title = $that.find('.lesson_title').text(); |
| 375 | $('head title').text(page_title); |
| 376 | window.history.pushState('obj', page_title, $that.attr('href')); |
| 377 | $wrap.addClass('loading-lesson'); |
| 378 | $('.tutor-single-lesson-items').removeClass('active'); |
| 379 | $that.closest('.tutor-single-lesson-items').addClass('active'); |
| 380 | }, |
| 381 | success: function (data) { |
| 382 | $wrap.html(data.data.html); |
| 383 | videoPlayer.init(); |
| 384 | }, |
| 385 | complete: function () { |
| 386 | $wrap.removeClass('loading-lesson'); |
| 387 | } |
| 388 | }); |
| 389 | }); |
| 390 | |
| 391 | $(document).on('click', '.sidebar-single-quiz-a', function (e) { |
| 392 | e.preventDefault(); |
| 393 | |
| 394 | var $that = $(this); |
| 395 | var quiz_id = $that.attr('data-quiz-id'); |
| 396 | var page_title = $that.find('.lesson_title').text(); |
| 397 | var $wrap = $('#tutor-single-entry-content'); |
| 398 | |
| 399 | $.ajax({ |
| 400 | url: _tutorobject.ajaxurl, |
| 401 | type: 'POST', |
| 402 | data: {quiz_id : quiz_id, 'action': 'tutor_render_quiz_content'}, |
| 403 | beforeSend: function () { |
| 404 | $('head title').text(page_title); |
| 405 | window.history.pushState('obj', page_title, $that.attr('href')); |
| 406 | $wrap.addClass('loading-lesson'); |
| 407 | $('.tutor-single-lesson-items').removeClass('active'); |
| 408 | $that.closest('.tutor-single-lesson-items').addClass('active'); |
| 409 | }, |
| 410 | success: function (data) { |
| 411 | $wrap.html(data.data.html); |
| 412 | init_quiz_builder(); |
| 413 | }, |
| 414 | complete: function () { |
| 415 | $wrap.removeClass('loading-lesson'); |
| 416 | } |
| 417 | }); |
| 418 | }); |
| 419 | |
| 420 | /** |
| 421 | * @date 05 Feb, 2019 |
| 422 | */ |
| 423 | |
| 424 | $(document).on('click', '.tutor-lesson-sidebar-hide-bar', function(e){ |
| 425 | e.preventDefault(); |
| 426 | $('.tutor-lesson-sidebar').toggle(); |
| 427 | }); |
| 428 | |
| 429 | $(document).on('click', '.tutor-tabs-btn-group a', function (e) { |
| 430 | e.preventDefault(); |
| 431 | var $that = $(this); |
| 432 | |
| 433 | var tabSelector = $that.attr('href'); |
| 434 | $('.tutor-lesson-sidebar-tab-item').hide(); |
| 435 | $(tabSelector).show(); |
| 436 | |
| 437 | $('.tutor-tabs-btn-group a').removeClass('active'); |
| 438 | $that.addClass('active'); |
| 439 | }); |
| 440 | /** |
| 441 | * @date 18 Feb, 2019 |
| 442 | * @since v.1.0.0 |
| 443 | */ |
| 444 | |
| 445 | function init_quiz_builder() { |
| 446 | if (jQuery().sortable) { |
| 447 | $(".tutor-quiz-answers-wrap").sortable({ |
| 448 | handle: ".answer-sorting-bar", |
| 449 | start: function (e, ui) { |
| 450 | ui.placeholder.css('visibility', 'visible'); |
| 451 | }, |
| 452 | stop: function (e, ui) { |
| 453 | |
| 454 | //Sorting Stopped... |
| 455 | }, |
| 456 | }).disableSelection(); |
| 457 | ; |
| 458 | |
| 459 | |
| 460 | $(".quiz-draggable-rand-answers, .quiz-answer-matching-droppable").sortable({ |
| 461 | connectWith: ".quiz-answer-matching-droppable", |
| 462 | placeholder: "drop-hover" |
| 463 | |
| 464 | }).disableSelection(); |
| 465 | } |
| 466 | } |
| 467 | init_quiz_builder(); |
| 468 | /** |
| 469 | * Quiz view |
| 470 | * @date 22 Feb, 2019 |
| 471 | * @since v.1.0.0 |
| 472 | */ |
| 473 | |
| 474 | $(document).on('click', '.tutor-quiz-answer-next-btn', function (e) { |
| 475 | e.preventDefault(); |
| 476 | var $that = $(this); |
| 477 | var question_id = parseInt($that.closest('.quiz-attempt-single-question').attr('id').match(/\d+/)[0], 10); |
| 478 | |
| 479 | var next_question_id = $that.closest('.quiz-attempt-single-question').attr('data-next-question-id'); |
| 480 | |
| 481 | if (next_question_id) { |
| 482 | var $nextQuestion = $(next_question_id); |
| 483 | if ($nextQuestion && $nextQuestion.length) { |
| 484 | $('.quiz-attempt-single-question').hide(); |
| 485 | $nextQuestion.show(); |
| 486 | |
| 487 | /** |
| 488 | * If pagination exists, set active class |
| 489 | */ |
| 490 | |
| 491 | if ($('.tutor-quiz-questions-pagination').length){ |
| 492 | $('.tutor-quiz-question-paginate-item').removeClass('active'); |
| 493 | $('.tutor-quiz-questions-pagination a[href="'+next_question_id+'"]').addClass('active'); |
| 494 | } |
| 495 | |
| 496 | } |
| 497 | } |
| 498 | }); |
| 499 | $(document).on('click', '.tutor-quiz-question-paginate-item', function (e) { |
| 500 | e.preventDefault(); |
| 501 | var $that = $(this); |
| 502 | var $question = $($that.attr('href')); |
| 503 | $('.quiz-attempt-single-question').hide(); |
| 504 | $question.show(); |
| 505 | |
| 506 | //Active Class |
| 507 | $('.tutor-quiz-question-paginate-item').removeClass('active'); |
| 508 | $that.addClass('active'); |
| 509 | }); |
| 510 | |
| 511 | /** |
| 512 | * Limit Short Answer Question Type |
| 513 | */ |
| 514 | $(document).on('keyup', 'textarea.question_type_short_answer', function (e) { |
| 515 | var $that = $(this); |
| 516 | var value = $that.val(); |
| 517 | var limit = _tutorobject.quiz_options.short_answer_characters_limit; |
| 518 | var remaining = limit - value.length; |
| 519 | |
| 520 | if (remaining < 1){ |
| 521 | $that.val(value.substr(0, limit)); |
| 522 | remaining = 0; |
| 523 | } |
| 524 | $that.closest('.tutor-quiz-answers-wrap').find('.characters_remaining').html(remaining); |
| 525 | }); |
| 526 | |
| 527 | /** |
| 528 | * Add to cart in guest mode, show login form |
| 529 | * |
| 530 | * @since v.1.0.4 |
| 531 | */ |
| 532 | |
| 533 | $(document).on('submit click', '.cart-required-login, .cart-required-login a, .cart-required-login form', function (e) { |
| 534 | e.preventDefault(); |
| 535 | |
| 536 | $('.tutor-cart-box-login-form').fadeIn(100); |
| 537 | }); |
| 538 | |
| 539 | $('.tutor-popup-form-close').on('click', function () { |
| 540 | $('.tutor-cart-box-login-form').fadeOut(100); |
| 541 | }); |
| 542 | |
| 543 | $(document).on('keyup', function (e) { |
| 544 | if (e.keyCode === 27) { |
| 545 | $('.tutor-cart-box-login-form').fadeOut(100); |
| 546 | } |
| 547 | }); |
| 548 | /** |
| 549 | * Share Link enable |
| 550 | * |
| 551 | * @since v.1.0.4 |
| 552 | */ |
| 553 | if($.fn.ShareLink){ |
| 554 | var $social_share_wrap = $('.tutor-social-share-wrap'); |
| 555 | if ($social_share_wrap.length) { |
| 556 | var share_config = JSON.parse($social_share_wrap.attr('data-social-share-config')); |
| 557 | |
| 558 | $('.tutor_share').ShareLink({ |
| 559 | title: share_config.title, |
| 560 | text: share_config.text, |
| 561 | image: share_config.image, |
| 562 | class_prefix: 's_', |
| 563 | width: 640, |
| 564 | height: 480, |
| 565 | }); |
| 566 | } |
| 567 | } |
| 568 | |
| 569 | /** |
| 570 | * Datepicker initiate |
| 571 | * |
| 572 | * @since v.1.1.2 |
| 573 | */ |
| 574 | if (jQuery.datepicker){ |
| 575 | $( ".tutor_report_datepicker" ).datepicker({"dateFormat" : 'yy-mm-dd'}); |
| 576 | } |
| 577 | |
| 578 | $(document).on('click', '.withdraw-method-select-input', function(e){ |
| 579 | var $that = $(this); |
| 580 | var method_id = $that.closest('.withdraw-method-select').attr('data-withdraw-method'); |
| 581 | |
| 582 | $('.withdraw-method-form').hide(); |
| 583 | $('#withdraw-method-form-'+method_id).show(); |
| 584 | }); |
| 585 | |
| 586 | /** |
| 587 | * Setting account for withdraw earning |
| 588 | * |
| 589 | * @since v.1.2.0 |
| 590 | */ |
| 591 | $(document).on('submit', '#tutor-withdraw-account-set-form', function(e){ |
| 592 | e.preventDefault(); |
| 593 | |
| 594 | var $form = $(this); |
| 595 | var $btn = $form.find('.tutor_set_withdraw_account_btn'); |
| 596 | var data = $form.serialize(); |
| 597 | |
| 598 | $.ajax({ |
| 599 | url: _tutorobject.ajaxurl, |
| 600 | type: 'POST', |
| 601 | data: data, |
| 602 | beforeSend: function () { |
| 603 | $form.find('.tutor-success-msg').remove(); |
| 604 | $btn.addClass('updating-icon'); |
| 605 | }, |
| 606 | success: function (data) { |
| 607 | if (data.success){ |
| 608 | var successMsg = '<div class="tutor-success-msg" style="display: none;"><i class="tutor-icon-mark"></i> '+data.data.msg+' </div>'; |
| 609 | $btn.closest('.withdraw-account-save-btn-wrap').append(successMsg); |
| 610 | if ($form.find('.tutor-success-msg').length) { |
| 611 | $form.find('.tutor-success-msg').slideDown(); |
| 612 | } |
| 613 | setTimeout(function () { |
| 614 | $form.find('.tutor-success-msg').slideUp(); |
| 615 | }, 5000) |
| 616 | } |
| 617 | }, |
| 618 | complete: function () { |
| 619 | $btn.removeClass('updating-icon'); |
| 620 | } |
| 621 | }); |
| 622 | }); |
| 623 | |
| 624 | /** |
| 625 | * Make Withdraw Form |
| 626 | * |
| 627 | * @since v.1.2.0 |
| 628 | */ |
| 629 | |
| 630 | $(document).on('click', 'a.open-withdraw-form-btn', function(e){ |
| 631 | e.preventDefault(); |
| 632 | $('.tutor-earning-withdraw-form-wrap').slideToggle(); |
| 633 | }); |
| 634 | |
| 635 | $(document).on('submit', '#tutor-earning-withdraw-form', function(e){ |
| 636 | e.preventDefault(); |
| 637 | |
| 638 | var $form = $(this); |
| 639 | var $btn = $('#tutor-earning-withdraw-btn'); |
| 640 | var $responseDiv = $('#tutor-withdraw-form-response'); |
| 641 | var data = $form.serialize(); |
| 642 | |
| 643 | $.ajax({ |
| 644 | url: _tutorobject.ajaxurl, |
| 645 | type: 'POST', |
| 646 | data: data, |
| 647 | beforeSend: function () { |
| 648 | $form.find('.tutor-success-msg').remove(); |
| 649 | $btn.addClass('updating-icon'); |
| 650 | }, |
| 651 | success: function (data) { |
| 652 | var Msg; |
| 653 | if (data.success){ |
| 654 | |
| 655 | if (data.data.available_balance !== 'undefined') { |
| 656 | $('.withdraw-balance-col .available_balance').html(data.data.available_balance); |
| 657 | } |
| 658 | Msg = '<div class="tutor-success-msg"><i class="tutor-icon-mark"></i> '+data.data.msg+' </div>'; |
| 659 | |
| 660 | }else{ |
| 661 | Msg = '<div class="tutor-error-msg"><i class="tutor-icon-line-cross"></i> '+data.data.msg+' </div>'; |
| 662 | } |
| 663 | |
| 664 | $responseDiv.html(Msg); |
| 665 | setTimeout(function () { |
| 666 | $responseDiv.html(''); |
| 667 | }, 5000) |
| 668 | }, |
| 669 | complete: function () { |
| 670 | $btn.removeClass('updating-icon'); |
| 671 | } |
| 672 | }); |
| 673 | }); |
| 674 | |
| 675 | |
| 676 | |
| 677 | }); |