PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 1.3.3
Tutor LMS – eLearning and online course solution v1.3.3
4.0.1 4.0.0 3.9.15 3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.11 1.2.12 1.2.13 1.2.20 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.15 1.9.16 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.4.0 2.5.0 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.1.0 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / assets / js / tutor-front.js
tutor / assets / js Last commit date
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-front.js
812 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 location.reload();
129 }
130 });
131 }
132 });
133
134 $(document).on('click', '.write-course-review-link-btn', function(e){
135 e.preventDefault();
136 $(this).siblings('.tutor-write-review-form').slideToggle();
137 });
138
139 $(document).on('click', '.tutor-ask-question-btn', function(e){
140 e.preventDefault();
141 $('.tutor-add-question-wrap').slideToggle();
142 });
143 $(document).on('click', '.tutor_question_cancel', function(e){
144 e.preventDefault();
145 $('.tutor-add-question-wrap').toggle();
146 });
147
148 $(document).on('submit', '#tutor-ask-question-form', function(e){
149 e.preventDefault();
150
151 var $form = $(this);
152 var data = $(this).serialize()+'&action=tutor_ask_question';
153
154 $.ajax({
155 url: _tutorobject.ajaxurl,
156 type: 'POST',
157 data: data,
158 beforeSend: function () {
159 $form.find('.tutor_ask_question_btn').addClass('updating-icon');
160 },
161 success: function (data) {
162 if (data.success){
163 $('.tutor-add-question-wrap').hide();
164 window.location.reload();
165 }
166 },
167 complete: function () {
168 $form.find('.tutor_ask_question_btn').removeClass('updating-icon');
169 }
170 });
171 });
172
173 $(document).on('submit', '.tutor-add-answer-form', function(e){
174 e.preventDefault();
175
176 var $form = $(this);
177 var data = $(this).serialize()+'&action=tutor_add_answer';
178
179 $.ajax({
180 url: _tutorobject.ajaxurl,
181 type: 'POST',
182 data: data,
183 beforeSend: function () {
184 $form.find('.tutor_add_answer_btn').addClass('updating-icon');
185 },
186 success: function (data) {
187 if (data.success){
188 window.location.reload();
189 }
190 },
191 complete: function () {
192 $form.find('.tutor_add_answer_btn').removeClass('updating-icon');
193 }
194 });
195 });
196
197 $(document).on('focus', '.tutor_add_answer_textarea', function(e){
198 e.preventDefault();
199
200 var question_id = $(this).closest('.tutor_add_answer_wrap').attr('data-question-id');
201 var conf = {
202 tinymce: {
203 wpautop:true,
204 //plugins : 'charmap colorpicker compat3x directionality fullscreen hr image lists media paste tabfocus textcolor wordpress wpautoresize wpdialogs wpeditimage wpemoji wpgallery wplink wptextpattern wpview',
205 toolbar1: 'bold italic underline bullist strikethrough numlist blockquote alignleft aligncenter alignright undo redo link unlink spellchecker fullscreen'
206 },
207 };
208 wp.editor.initialize('tutor_answer_'+question_id, conf);
209 });
210
211 $(document).on('click', '.tutor_cancel_wp_editor', function(e){
212 e.preventDefault();
213 $(this).closest('.tutor_wp_editor_wrap').toggle();
214 $(this).closest('.tutor_add_answer_wrap').find('.tutor_wp_editor_show_btn_wrap').toggle();
215 var question_id = $(this).closest('.tutor_add_answer_wrap').attr('data-question-id');
216 wp.editor.remove('tutor_answer_'+question_id);
217 });
218
219 $(document).on('click', '.tutor_wp_editor_show_btn', function(e){
220 e.preventDefault();
221 $(this).closest('.tutor_add_answer_wrap').find('.tutor_wp_editor_wrap').toggle();
222 $(this).closest('.tutor_wp_editor_show_btn_wrap').toggle();
223 });
224
225 /**
226 * Quiz attempt
227 */
228 var $tutor_quiz_time_update = $('#tutor-quiz-time-update');
229 var attempt_settings = null;
230 if ($tutor_quiz_time_update.length){
231 attempt_settings = JSON.parse($tutor_quiz_time_update.attr('data-attempt-settings'));
232 var attempt_meta = JSON.parse($tutor_quiz_time_update.attr('data-attempt-meta'));
233
234 if (attempt_meta.time_limit.time_limit_seconds > 0) {
235 //No time Zero limit for
236 var countDownDate = new Date(attempt_settings.attempt_started_at).getTime() + (attempt_meta.time_limit.time_limit_seconds * 1000);
237 var time_now = new Date(attempt_meta.date_time_now).getTime();
238
239 var tutor_quiz_interval = setInterval(function () {
240 var distance = countDownDate - time_now;
241
242 var days = Math.floor(distance / (1000 * 60 * 60 * 24));
243 var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
244 var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
245 var seconds = Math.floor((distance % (1000 * 60)) / 1000);
246
247 var countdown_human = '';
248
249 if (days) {
250 countdown_human += days + "d ";
251 }
252 if (hours) {
253 countdown_human += hours + "h ";
254 }
255 if (minutes) {
256 countdown_human += minutes + "m ";
257 }
258 if (seconds) {
259 countdown_human += seconds + "s ";
260 }
261
262 if (distance < 0) {
263 clearInterval(tutor_quiz_interval);
264 countdown_human = "EXPIRED";
265 //Set the quiz attempt to timeout in ajax
266
267 if (_tutorobject.options.quiz_when_time_expires === 'autosubmit') {
268 /**
269 * Auto Submit
270 */
271 $('form#tutor-answering-quiz').submit();
272
273 } else if (_tutorobject.options.quiz_when_time_expires === 'autoabandon') {
274 /**
275 *
276 * @type {jQuery}
277 *
278 * Current attempt will be cancel with attempt status attempt_timeout
279 */
280
281 var quiz_id = $('#tutor_quiz_id').val();
282 var tutor_quiz_remaining_time_secs = $('#tutor_quiz_remaining_time_secs').val();
283 var quiz_timeout_data = {quiz_id: quiz_id, action: 'tutor_quiz_timeout'};
284
285 $.ajax({
286 url: _tutorobject.ajaxurl,
287 type: 'POST',
288 data: quiz_timeout_data,
289 success: function (data) {
290 if (data.success) {
291 window.location.reload(true);
292 }
293 },
294 complete: function () {
295 $('#tutor-quiz-body').html('');
296 window.location.reload(true);
297 }
298 });
299 }
300
301 }
302 time_now = time_now + 1000;
303 $tutor_quiz_time_update.html(countdown_human);
304 }, 1000);
305 }else{
306 $tutor_quiz_time_update.closest('.time-remaining').remove();
307 }
308 }
309
310 var $quiz_start_form = $('#tutor-quiz-body form#tutor-start-quiz');
311 if ($quiz_start_form.length){
312 if (_tutorobject.quiz_options.quiz_auto_start === '1'){
313 $quiz_start_form.submit();
314 }
315 }
316
317 // tutor course content accordion
318 $('.tutor-course-topic.tutor-active').find('.tutor-course-lessons').slideDown();
319 $('.tutor-course-title').on('click', function () {
320 var lesson = $(this).siblings('.tutor-course-lessons');
321 $(this).closest('.tutor-course-topic').toggleClass('tutor-active');
322 lesson.slideToggle();
323 });
324
325 $('.tutor-topics-title').on('click', function () {
326 $(this).siblings('.tutor-topics-summery').slideToggle();
327 });
328
329 $(document).on('click', '.tutor-course-wishlist-btn', function (e) {
330 e.preventDefault();
331
332 var $that = $(this);
333 var course_id = $that.attr('data-course-id');
334
335 $.ajax({
336 url: _tutorobject.ajaxurl,
337 type: 'POST',
338 data: {course_id : course_id, 'action': 'tutor_course_add_to_wishlist'},
339 beforeSend: function () {
340 $that.addClass('updating-icon');
341 },
342 success: function (data) {
343 if (data.success){
344 if (data.data.status === 'added'){
345 $that.addClass('has-wish-listed');
346 }else{
347 $that.removeClass('has-wish-listed');
348 }
349 }else{
350 window.location = data.data.redirect_to;
351 }
352 },
353 complete: function () {
354 $that.removeClass('updating-icon');
355 }
356 });
357 });
358
359 $(document).on('click', '.tutor-single-lesson-a', function (e) {
360 e.preventDefault();
361
362 var $that = $(this);
363 var lesson_id = $that.attr('data-lesson-id');
364 var $wrap = $('#tutor-single-entry-content');
365
366 $.ajax({
367 url: _tutorobject.ajaxurl,
368 type: 'POST',
369 data: {lesson_id : lesson_id, 'action': 'tutor_render_lesson_content'},
370 beforeSend: function () {
371 var page_title = $that.find('.lesson_title').text();
372 $('head title').text(page_title);
373 window.history.pushState('obj', page_title, $that.attr('href'));
374 $wrap.addClass('loading-lesson');
375 $('.tutor-single-lesson-items').removeClass('active');
376 $that.closest('.tutor-single-lesson-items').addClass('active');
377 },
378 success: function (data) {
379 $wrap.html(data.data.html);
380 videoPlayer.init();
381 $('.tutor-lesson-sidebar').css('display', '');
382 },
383 complete: function () {
384 $wrap.removeClass('loading-lesson');
385 }
386 });
387 });
388
389 $(document).on('click', '.sidebar-single-quiz-a', function (e) {
390 e.preventDefault();
391
392 var $that = $(this);
393 var quiz_id = $that.attr('data-quiz-id');
394 var page_title = $that.find('.lesson_title').text();
395 var $wrap = $('#tutor-single-entry-content');
396
397 $.ajax({
398 url: _tutorobject.ajaxurl,
399 type: 'POST',
400 data: {quiz_id : quiz_id, 'action': 'tutor_render_quiz_content'},
401 beforeSend: function () {
402 $('head title').text(page_title);
403 window.history.pushState('obj', page_title, $that.attr('href'));
404 $wrap.addClass('loading-lesson');
405 $('.tutor-single-lesson-items').removeClass('active');
406 $that.closest('.tutor-single-lesson-items').addClass('active');
407 },
408 success: function (data) {
409 $wrap.html(data.data.html);
410 init_quiz_builder();
411 $('.tutor-lesson-sidebar').css('display', '');
412 },
413 complete: function () {
414 $wrap.removeClass('loading-lesson');
415 }
416 });
417 });
418
419 /**
420 * @date 05 Feb, 2019
421 */
422
423 $(document).on('click', '.tutor-lesson-sidebar-hide-bar', function(e){
424 e.preventDefault();
425 $('.tutor-lesson-sidebar').toggle();
426 });
427
428 $(document).on('click', '.tutor-tabs-btn-group a', function (e) {
429 e.preventDefault();
430 var $that = $(this);
431
432 var tabSelector = $that.attr('href');
433 $('.tutor-lesson-sidebar-tab-item').hide();
434 $(tabSelector).show();
435
436 $('.tutor-tabs-btn-group a').removeClass('active');
437 $that.addClass('active');
438 });
439 /**
440 * @date 18 Feb, 2019
441 * @since v.1.0.0
442 */
443
444 function init_quiz_builder() {
445 if (jQuery().sortable) {
446 $(".tutor-quiz-answers-wrap").sortable({
447 handle: ".answer-sorting-bar",
448 start: function (e, ui) {
449 ui.placeholder.css('visibility', 'visible');
450 },
451 stop: function (e, ui) {
452
453 //Sorting Stopped...
454 },
455 }).disableSelection();
456 ;
457
458
459 $(".quiz-draggable-rand-answers, .quiz-answer-matching-droppable").sortable({
460 connectWith: ".quiz-answer-matching-droppable",
461 placeholder: "drop-hover"
462
463 }).disableSelection();
464 }
465 }
466 init_quiz_builder();
467 /**
468 * Quiz view
469 * @date 22 Feb, 2019
470 * @since v.1.0.0
471 */
472
473 $(document).on('click', '.tutor-quiz-answer-next-btn', function (e) {
474 e.preventDefault();
475 var $that = $(this);
476 var question_id = parseInt($that.closest('.quiz-attempt-single-question').attr('id').match(/\d+/)[0], 10);
477
478 var next_question_id = $that.closest('.quiz-attempt-single-question').attr('data-next-question-id');
479
480 if (next_question_id) {
481 var $nextQuestion = $(next_question_id);
482 if ($nextQuestion && $nextQuestion.length) {
483 $('.quiz-attempt-single-question').hide();
484 $nextQuestion.show();
485
486 /**
487 * If pagination exists, set active class
488 */
489
490 if ($('.tutor-quiz-questions-pagination').length){
491 $('.tutor-quiz-question-paginate-item').removeClass('active');
492 $('.tutor-quiz-questions-pagination a[href="'+next_question_id+'"]').addClass('active');
493 }
494
495 }
496 }
497 });
498 $(document).on('click', '.tutor-quiz-question-paginate-item', function (e) {
499 e.preventDefault();
500 var $that = $(this);
501 var $question = $($that.attr('href'));
502 $('.quiz-attempt-single-question').hide();
503 $question.show();
504
505 //Active Class
506 $('.tutor-quiz-question-paginate-item').removeClass('active');
507 $that.addClass('active');
508 });
509
510 /**
511 * Limit Short Answer Question Type
512 */
513 $(document).on('keyup', 'textarea.question_type_short_answer', function (e) {
514 var $that = $(this);
515 var value = $that.val();
516 var limit = _tutorobject.quiz_options.short_answer_characters_limit;
517 var remaining = limit - value.length;
518
519 if (remaining < 1){
520 $that.val(value.substr(0, limit));
521 remaining = 0;
522 }
523 $that.closest('.tutor-quiz-answers-wrap').find('.characters_remaining').html(remaining);
524 });
525
526 /**
527 * Add to cart in guest mode, show login form
528 *
529 * @since v.1.0.4
530 */
531
532 $(document).on('submit click', '.cart-required-login, .cart-required-login a, .cart-required-login form', function (e) {
533 e.preventDefault();
534
535 $('.tutor-cart-box-login-form').fadeIn(100);
536 });
537
538 $('.tutor-popup-form-close').on('click', function () {
539 $('.tutor-cart-box-login-form').fadeOut(100);
540 });
541
542 $(document).on('keyup', function (e) {
543 if (e.keyCode === 27) {
544 $('.tutor-frontend-modal').hide();
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
579 /**
580 * Withdraw Form Tab/Toggle
581 *
582 * @since v.1.1.2
583 */
584
585 $(".withdraw-method-select-input").on('change', function(e){
586 var $that = $(this);
587 $('.withdraw-method-form').hide();
588 $('#withdraw-method-form-'+$that.closest('.withdraw-method-select').attr('data-withdraw-method')).show();
589 });
590
591 $('.withdraw-method-select-input').each(function () {
592 var $that = $(this);
593 if($that.is(":checked")){
594 $('.withdraw-method-form').hide();
595 $('#withdraw-method-form-'+$that.closest('.withdraw-method-select').attr('data-withdraw-method')).show();
596 }
597 });
598
599
600
601 /**
602 * Setting account for withdraw earning
603 *
604 * @since v.1.2.0
605 */
606 $(document).on('submit', '#tutor-withdraw-account-set-form', function(e){
607 e.preventDefault();
608
609 var $form = $(this);
610 var $btn = $form.find('.tutor_set_withdraw_account_btn');
611 var data = $form.serialize();
612
613 $.ajax({
614 url: _tutorobject.ajaxurl,
615 type: 'POST',
616 data: data,
617 beforeSend: function () {
618 $form.find('.tutor-success-msg').remove();
619 $btn.addClass('updating-icon');
620 },
621 success: function (data) {
622 if (data.success){
623 var successMsg = '<div class="tutor-success-msg" style="display: none;"><i class="tutor-icon-mark"></i> '+data.data.msg+' </div>';
624 $btn.closest('.withdraw-account-save-btn-wrap').append(successMsg);
625 if ($form.find('.tutor-success-msg').length) {
626 $form.find('.tutor-success-msg').slideDown();
627 }
628 setTimeout(function () {
629 $form.find('.tutor-success-msg').slideUp();
630 }, 5000)
631 }
632 },
633 complete: function () {
634 $btn.removeClass('updating-icon');
635 }
636 });
637 });
638
639 /**
640 * Make Withdraw Form
641 *
642 * @since v.1.2.0
643 */
644
645 $(document).on('click', 'a.open-withdraw-form-btn', function(e){
646 e.preventDefault();
647 $('.tutor-earning-withdraw-form-wrap').slideToggle();
648 });
649
650 $(document).on('submit', '#tutor-earning-withdraw-form', function(e){
651 e.preventDefault();
652
653 var $form = $(this);
654 var $btn = $('#tutor-earning-withdraw-btn');
655 var $responseDiv = $('#tutor-withdraw-form-response');
656 var data = $form.serialize();
657
658 $.ajax({
659 url: _tutorobject.ajaxurl,
660 type: 'POST',
661 data: data,
662 beforeSend: function () {
663 $form.find('.tutor-success-msg').remove();
664 $btn.addClass('updating-icon');
665 },
666 success: function (data) {
667 var Msg;
668 if (data.success){
669
670 if (data.data.available_balance !== 'undefined') {
671 $('.withdraw-balance-col .available_balance').html(data.data.available_balance);
672 }
673 Msg = '<div class="tutor-success-msg"><i class="tutor-icon-mark"></i> '+data.data.msg+' </div>';
674
675 }else{
676 Msg = '<div class="tutor-error-msg"><i class="tutor-icon-line-cross"></i> '+data.data.msg+' </div>';
677 }
678
679 $responseDiv.html(Msg);
680 setTimeout(function () {
681 $responseDiv.html('');
682 }, 5000)
683 },
684 complete: function () {
685 $btn.removeClass('updating-icon');
686 }
687 });
688 });
689
690 var frontEndModal = $('.tutor-frontend-modal');
691 frontEndModal.each(function () {
692 var modal = $(this),
693 action = $(this).data('popup-rel');
694 $('[href="'+action+'"]').on('click', function (e) {
695 modal.fadeIn();
696 e.preventDefault();
697 });
698 });
699 $(document).on('click', '.tm-close, .tutor-frontend-modal-overlay, .tutor-modal-btn-cancel', function () {
700 frontEndModal.fadeOut();
701 });
702
703 /**
704 * Delete Course
705 */
706 $(document).on('click', '.tutor-mycourse-delete-btn', function (e) {
707 e.preventDefault();
708 var course_id = $(this).attr('data-course-id');
709 $('#tutor-course-delete-id').val(course_id);
710 });
711 $(document).on('submit', '#tutor-delete-course-form', function (e) {
712 e.preventDefault();
713
714 var course_id = $('#tutor-course-delete-id').val();
715 var $btn = $('.tutor-modal-course-delete-btn');
716 var data = $(this).serialize();
717
718 $.ajax({
719 url: _tutorobject.ajaxurl,
720 type: 'POST',
721 data: data,
722 beforeSend: function () {
723 $btn.addClass('updating-icon');
724 },
725 success: function (data) {
726 if (data.success){
727 $('#tutor-dashboard-course-'+course_id).remove();
728 }
729 },
730 complete: function () {
731 $btn.removeClass('updating-icon');
732 $('.tutor-frontend-modal').hide();
733 }
734 });
735 });
736
737 /**
738 * Frontend Profile
739 */
740
741 if (! $('#tutor_profile_photo_id').val()) {
742 $('.tutor-profile-photo-delete-btn').hide();
743 }
744 // Uploading files
745 var file_frame;
746 $( document ).on( 'click', '.tutor-profile-photo-upload-btn', function( event ) {
747 event.preventDefault();
748
749 if ( file_frame ) {
750 file_frame.open();
751 return;
752 }
753 file_frame = wp.media.frames.downloadable_file = wp.media({
754 title: 'Choose an image',
755 button: {
756 text: 'Use image'
757 },
758 multiple: false
759 });
760 file_frame.on( 'select', function() {
761 var attachment = file_frame.state().get( 'selection' ).first().toJSON();
762 var attachment_thumbnail = attachment.sizes.thumbnail || attachment.sizes.full;
763
764 $( '#tutor_profile_photo_id' ).val( attachment.id );
765 $( '.tutor-profile-photo-upload-wrap' ).find( 'img' ).attr( 'src', attachment_thumbnail.url );
766 $( '.tutor-profile-photo-delete-btn' ).show();
767 });
768 file_frame.open();
769 });
770
771 $( document ).on( 'click', '.tutor-profile-photo-delete-btn', function() {
772 $( '.tutor-profile-photo-upload-wrap' ).find( 'img' ).attr( 'src', _tutorobject.placeholder_img_src );
773 $( '#tutor_profile_photo_id' ).val( '' );
774 $( '.tutor-profile-photo-delete-btn' ).hide();
775 return false;
776 });
777
778
779 /**
780 * Assignment
781 *
782 * @since v.1.3.3
783 */
784
785 $( document ).on( 'submit', '#tutor_assignment_start_form', function(e) {
786 e.preventDefault();
787
788 var $that = $(this);
789 var form_data = $that.serialize()+'&action=tutor_start_assignment';
790
791 $.ajax({
792 url: _tutorobject.ajaxurl,
793 type: 'POST',
794 data: form_data,
795 beforeSend: function () {
796 $('#tutor_assignment_start_btn').addClass('updating-icon');
797 },
798 success: function (data) {
799 if (data.success){
800 location.reload();
801 }
802 },
803 complete : function () {
804 $('#tutor_assignment_start_btn').removeClass('updating-icon');
805 }
806 });
807
808 });
809
810
811
812 });