PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 1.4.0
Tutor LMS – eLearning and online course solution v1.4.0
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.js 6 years ago
tutor-front.js
1336 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 $(document).on('change', '.tutor-course-filter-form', function(e){
18 e.preventDefault();
19 $(this).closest('form').submit();
20 });
21
22 const videoPlayer = {
23 nonce_key : _tutorobject.nonce_key,
24 video_track_data : $('#tutor_video_tracking_information').val(),
25 track_player : function(){
26 var that = this;
27
28 var video_data = this.video_track_data ? JSON.parse(this.video_track_data) : {};
29
30 if (typeof Plyr !== 'undefined') {
31 const player = new Plyr('#tutorPlayer');
32
33 player.on('ready', function(event){
34 const instance = event.detail.plyr;
35 if (video_data.best_watch_time > 0) {
36 instance.media.currentTime = video_data.best_watch_time;
37 }
38 that.sync_time(instance);
39 });
40
41 var tempTimeNow = 0;
42 var intervalSeconds = 60; //Send to tutor backend about video playing time in this interval
43 player.on('timeupdate', function(event){
44 const instance = event.detail.plyr;
45
46 var tempTimeNowInSec = (tempTimeNow / 4); //timeupdate firing 250ms interval
47 if (tempTimeNowInSec >= intervalSeconds){
48 that.sync_time(instance);
49 tempTimeNow = 0;
50 }
51 tempTimeNow++;
52 });
53
54 player.on('ended', function(event){
55 const instance = event.detail.plyr;
56
57 var data = {is_ended:true};
58 that.sync_time(instance, data)
59 });
60 }
61 },
62 sync_time: function(instance, options){
63 /**
64 * TUTOR is sending about video playback information to server.
65 */
66 var video_data = this.video_track_data ? JSON.parse(this.video_track_data) : {};
67 var data = {action: 'sync_video_playback', currentTime : instance.currentTime, duration:instance.duration, post_id : video_data.post_id};
68 data[this.nonce_key] = _tutorobject[this.nonce_key];
69
70 var data_send = data;
71 if(options){
72 data_send = Object.assign(data, options);
73 }
74 $.post(_tutorobject.ajaxurl, data_send);
75 },
76 init: function(){
77 this.track_player();
78 }
79 };
80
81 /**
82 * Fire TUTOR video
83 * @since v.1.0.0
84 */
85 if ($('#tutorPlayer').length){
86 videoPlayer.init();
87 }
88
89 $(document).on('change keyup paste', '.tutor_user_name', function(){
90 $(this).val(tutor_slugify($(this).val()));
91 });
92
93 function tutor_slugify(text) {
94 return text.toString().toLowerCase()
95 .replace(/\s+/g, '-') // Replace spaces with -
96 .replace(/[^\w\-]+/g, '') // Remove all non-word chars
97 .replace(/\-\-+/g, '-') // Replace multiple - with single -
98 .replace(/^-+/, '') // Trim - from start of text
99 .replace(/-+$/, ''); // Trim - from end of text
100 }
101
102 /**
103 * Hover tutor rating and set value
104 */
105 $(document).on('hover', '.tutor-write-review-box .tutor-star-rating-group i', function(){
106 $(this).closest('.tutor-star-rating-group').find('i').removeClass('tutor-icon-star-full').addClass('tutor-icon-star-line');
107 var currentRateValue = $(this).attr('data-rating-value');
108 for (var i = 1; i<= currentRateValue; i++){
109 $(this).closest('.tutor-star-rating-group').find('i[data-rating-value="'+i+'"]').removeClass('tutor-icon-star-line').addClass('tutor-icon-star-full');
110 }
111 $(this).closest('.tutor-star-rating-group').find('input[name="tutor_rating_gen_input"]').val(currentRateValue);
112 });
113
114 $(document).on('click', '.tutor-star-rating-group i', function(){
115 var rating = $(this).attr('data-rating-value');
116 $(this).closest('.tutor-star-rating-group').find('input[name="tutor_rating_gen_input"]').val(rating);
117 });
118
119 $(document).on('click', '.tutor_submit_review_btn', function (e) {
120 e.preventDefault();
121 var $that = $(this);
122 var rating = $that.closest('form').find('input[name="tutor_rating_gen_input"]').val();
123 var review = $that.closest('form').find('textarea[name="review"]').val();
124 review = review.trim();
125
126 var course_id = $('input[name="tutor_course_id"]').val();
127 var data = {course_id : course_id, rating : rating, review:review, action: 'tutor_place_rating' };
128
129 if (review) {
130 $.ajax({
131 url: _tutorobject.ajaxurl,
132 type: 'POST',
133 data: data,
134 beforeSend: function () {
135 $that.addClass('updating-icon');
136 },
137 success: function (data) {
138 var review_id = data.data.review_id;
139 var review = data.data.review;
140 $('.tutor-review-'+review_id+' .review-content').html(review);
141 location.reload();
142 }
143 });
144 }
145 });
146
147 $(document).on('click', '.write-course-review-link-btn', function(e){
148 e.preventDefault();
149 $(this).siblings('.tutor-write-review-form').slideToggle();
150 });
151
152 $(document).on('click', '.tutor-ask-question-btn', function(e){
153 e.preventDefault();
154 $('.tutor-add-question-wrap').slideToggle();
155 });
156 $(document).on('click', '.tutor_question_cancel', function(e){
157 e.preventDefault();
158 $('.tutor-add-question-wrap').toggle();
159 });
160
161 $(document).on('submit', '#tutor-ask-question-form', function(e){
162 e.preventDefault();
163
164 var $form = $(this);
165 var data = $(this).serialize()+'&action=tutor_ask_question';
166
167 $.ajax({
168 url: _tutorobject.ajaxurl,
169 type: 'POST',
170 data: data,
171 beforeSend: function () {
172 $form.find('.tutor_ask_question_btn').addClass('updating-icon');
173 },
174 success: function (data) {
175 if (data.success){
176 $('.tutor-add-question-wrap').hide();
177 window.location.reload();
178 }
179 },
180 complete: function () {
181 $form.find('.tutor_ask_question_btn').removeClass('updating-icon');
182 }
183 });
184 });
185
186 $(document).on('submit', '.tutor-add-answer-form', function(e){
187 e.preventDefault();
188
189 var $form = $(this);
190 var data = $(this).serialize()+'&action=tutor_add_answer';
191
192 $.ajax({
193 url: _tutorobject.ajaxurl,
194 type: 'POST',
195 data: data,
196 beforeSend: function () {
197 $form.find('.tutor_add_answer_btn').addClass('updating-icon');
198 },
199 success: function (data) {
200 if (data.success){
201 window.location.reload();
202 }
203 },
204 complete: function () {
205 $form.find('.tutor_add_answer_btn').removeClass('updating-icon');
206 }
207 });
208 });
209
210 $(document).on('focus', '.tutor_add_answer_textarea', function(e){
211 e.preventDefault();
212
213 var question_id = $(this).closest('.tutor_add_answer_wrap').attr('data-question-id');
214 var conf = {
215 tinymce: {
216 wpautop:true,
217 //plugins : 'charmap colorpicker compat3x directionality fullscreen hr image lists media paste tabfocus textcolor wordpress wpautoresize wpdialogs wpeditimage wpemoji wpgallery wplink wptextpattern wpview',
218 toolbar1: 'bold italic underline bullist strikethrough numlist blockquote alignleft aligncenter alignright undo redo link unlink spellchecker fullscreen'
219 },
220 };
221 wp.editor.initialize('tutor_answer_'+question_id, conf);
222 });
223
224 $(document).on('click', '.tutor_cancel_wp_editor', function(e){
225 e.preventDefault();
226 $(this).closest('.tutor_wp_editor_wrap').toggle();
227 $(this).closest('.tutor_add_answer_wrap').find('.tutor_wp_editor_show_btn_wrap').toggle();
228 var question_id = $(this).closest('.tutor_add_answer_wrap').attr('data-question-id');
229 wp.editor.remove('tutor_answer_'+question_id);
230 });
231
232 $(document).on('click', '.tutor_wp_editor_show_btn', function(e){
233 e.preventDefault();
234 $(this).closest('.tutor_add_answer_wrap').find('.tutor_wp_editor_wrap').toggle();
235 $(this).closest('.tutor_wp_editor_show_btn_wrap').toggle();
236 });
237
238 /**
239 * Quiz attempt
240 */
241 var $tutor_quiz_time_update = $('#tutor-quiz-time-update');
242 var attempt_settings = null;
243 if ($tutor_quiz_time_update.length){
244 attempt_settings = JSON.parse($tutor_quiz_time_update.attr('data-attempt-settings'));
245 var attempt_meta = JSON.parse($tutor_quiz_time_update.attr('data-attempt-meta'));
246
247 if (attempt_meta.time_limit.time_limit_seconds > 0) {
248 //No time Zero limit for
249 var countDownDate = new Date(attempt_settings.attempt_started_at).getTime() + (attempt_meta.time_limit.time_limit_seconds * 1000);
250 var time_now = new Date(attempt_meta.date_time_now).getTime();
251
252 var tutor_quiz_interval = setInterval(function () {
253 var distance = countDownDate - time_now;
254
255 var days = Math.floor(distance / (1000 * 60 * 60 * 24));
256 var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
257 var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
258 var seconds = Math.floor((distance % (1000 * 60)) / 1000);
259
260 var countdown_human = '';
261
262 if (days) {
263 countdown_human += days + "d ";
264 }
265 if (hours) {
266 countdown_human += hours + "h ";
267 }
268 if (minutes) {
269 countdown_human += minutes + "m ";
270 }
271 if (seconds) {
272 countdown_human += seconds + "s ";
273 }
274
275 if (distance < 0) {
276 clearInterval(tutor_quiz_interval);
277 countdown_human = "EXPIRED";
278 //Set the quiz attempt to timeout in ajax
279
280 if (_tutorobject.options.quiz_when_time_expires === 'autosubmit') {
281 /**
282 * Auto Submit
283 */
284 $('form#tutor-answering-quiz').submit();
285
286 } else if (_tutorobject.options.quiz_when_time_expires === 'autoabandon') {
287 /**
288 *
289 * @type {jQuery}
290 *
291 * Current attempt will be cancel with attempt status attempt_timeout
292 */
293
294 var quiz_id = $('#tutor_quiz_id').val();
295 var tutor_quiz_remaining_time_secs = $('#tutor_quiz_remaining_time_secs').val();
296 var quiz_timeout_data = {quiz_id: quiz_id, action: 'tutor_quiz_timeout'};
297
298 $.ajax({
299 url: _tutorobject.ajaxurl,
300 type: 'POST',
301 data: quiz_timeout_data,
302 success: function (data) {
303 if (data.success) {
304 window.location.reload(true);
305 }
306 },
307 complete: function () {
308 $('#tutor-quiz-body').html('');
309 window.location.reload(true);
310 }
311 });
312 }
313
314 }
315 time_now = time_now + 1000;
316 $tutor_quiz_time_update.html(countdown_human);
317 }, 1000);
318 }else{
319 $tutor_quiz_time_update.closest('.time-remaining').remove();
320 }
321 }
322
323 var $quiz_start_form = $('#tutor-quiz-body form#tutor-start-quiz');
324 if ($quiz_start_form.length){
325 if (_tutorobject.quiz_options.quiz_auto_start === '1'){
326 $quiz_start_form.submit();
327 }
328 }
329
330 /**
331 * Quiz Frontend Review Action
332 * @since 1.4.0
333 */
334 $(document).on('click', '.quiz-manual-review-action', function(e){
335 e.preventDefault();
336 var $that = $(this),
337 attempt_id = $that.attr('data-attempt-id'),
338 attempt_answer_id = $that.attr('data-attempt-answer-id'),
339 mark_as = $that.attr('data-mark-as');
340
341 $.ajax({
342 url : _tutorobject.ajaxurl,
343 type : 'GET',
344 data : {action:'review_quiz_answer', attempt_id: attempt_id, attempt_answer_id : attempt_answer_id, mark_as : mark_as },
345 beforeSend: function () {
346 $that.find('i').addClass('updating-icon');
347 },
348 success: function (data) {
349 location.reload();
350 },
351 complete: function () {
352 $that.find('i').removeClass('updating-icon');
353 }
354 });
355 });
356
357 // tutor course content accordion
358 $('.tutor-course-topic.tutor-active').find('.tutor-course-lessons').slideDown();
359 $('.tutor-course-title').on('click', function () {
360 var lesson = $(this).siblings('.tutor-course-lessons');
361 $(this).closest('.tutor-course-topic').toggleClass('tutor-active');
362 lesson.slideToggle();
363 });
364
365 $(document).on('click', '.tutor-topics-title h3 .toogle-informaiton-icon', function (e) {
366 $(this).closest('.tutor-topics-in-single-lesson').find('.tutor-topics-summery').slideToggle();
367 e.stopPropagation();
368 });
369
370 $(document).on('click', '.tutor-course-wishlist-btn', function (e) {
371 e.preventDefault();
372
373 var $that = $(this);
374 var course_id = $that.attr('data-course-id');
375
376 $.ajax({
377 url: _tutorobject.ajaxurl,
378 type: 'POST',
379 data: {course_id : course_id, 'action': 'tutor_course_add_to_wishlist'},
380 beforeSend: function () {
381 $that.addClass('updating-icon');
382 },
383 success: function (data) {
384 if (data.success){
385 if (data.data.status === 'added'){
386 $that.addClass('has-wish-listed');
387 }else{
388 $that.removeClass('has-wish-listed');
389 }
390 }else{
391 window.location = data.data.redirect_to;
392 }
393 },
394 complete: function () {
395 $that.removeClass('updating-icon');
396 }
397 });
398 });
399
400 /**
401 * Check if lesson has classic editor support
402 * If classic editor support, stop ajax load on the lesson page.
403 *
404 * @since v.1.0.0
405 *
406 * @updated v.1.4.0
407 */
408 if ( ! _tutorobject.enable_lesson_classic_editor) {
409
410 $(document).on('click', '.tutor-single-lesson-a', function (e) {
411 e.preventDefault();
412
413 var $that = $(this);
414 var lesson_id = $that.attr('data-lesson-id');
415 var $wrap = $('#tutor-single-entry-content');
416
417 $.ajax({
418 url: _tutorobject.ajaxurl,
419 type: 'POST',
420 data: {lesson_id : lesson_id, 'action': 'tutor_render_lesson_content'},
421 beforeSend: function () {
422 var page_title = $that.find('.lesson_title').text();
423 $('head title').text(page_title);
424 window.history.pushState('obj', page_title, $that.attr('href'));
425 $wrap.addClass('loading-lesson');
426 $('.tutor-single-lesson-items').removeClass('active');
427 $that.closest('.tutor-single-lesson-items').addClass('active');
428 },
429 success: function (data) {
430 $wrap.html(data.data.html);
431 videoPlayer.init();
432 $('.tutor-lesson-sidebar').css('display', '');
433 },
434 complete: function () {
435 $wrap.removeClass('loading-lesson');
436 }
437 });
438 });
439
440 $(document).on('click', '.sidebar-single-quiz-a', function (e) {
441 e.preventDefault();
442
443 var $that = $(this);
444 var quiz_id = $that.attr('data-quiz-id');
445 var page_title = $that.find('.lesson_title').text();
446 var $wrap = $('#tutor-single-entry-content');
447
448 $.ajax({
449 url: _tutorobject.ajaxurl,
450 type: 'POST',
451 data: {quiz_id : quiz_id, 'action': 'tutor_render_quiz_content'},
452 beforeSend: function () {
453 $('head title').text(page_title);
454 window.history.pushState('obj', page_title, $that.attr('href'));
455 $wrap.addClass('loading-lesson');
456 $('.tutor-single-lesson-items').removeClass('active');
457 $that.closest('.tutor-single-lesson-items').addClass('active');
458 },
459 success: function (data) {
460 $wrap.html(data.data.html);
461 init_quiz_builder();
462 $('.tutor-lesson-sidebar').css('display', '');
463 },
464 complete: function () {
465 $wrap.removeClass('loading-lesson');
466 }
467 });
468 });
469 }
470
471 /**
472 * @date 05 Feb, 2019
473 */
474
475 $(document).on('click', '.tutor-lesson-sidebar-hide-bar', function(e){
476 e.preventDefault();
477 $('.tutor-lesson-sidebar').toggle();
478 $('#tutor-single-entry-content').toggleClass("sidebar-hidden");
479
480 });
481
482 $(".tutor-tabs-btn-group a").on('click touchstart', function (e) {
483 e.preventDefault();
484 var $that = $(this);
485 var tabSelector = $that.attr('href');
486 $('.tutor-lesson-sidebar-tab-item').hide();
487 $(tabSelector).show();
488
489 $('.tutor-tabs-btn-group a').removeClass('active');
490 $that.addClass('active');
491 });
492 /**
493 * @date 18 Feb, 2019
494 * @since v.1.0.0
495 */
496
497 function init_quiz_builder() {
498 if (jQuery().sortable) {
499 $(".tutor-quiz-answers-wrap").sortable({
500 handle: ".answer-sorting-bar",
501 start: function (e, ui) {
502 ui.placeholder.css('visibility', 'visible');
503 },
504 stop: function (e, ui) {
505
506 //Sorting Stopped...
507 },
508 }).disableSelection();
509 ;
510
511
512 $(".quiz-draggable-rand-answers, .quiz-answer-matching-droppable").sortable({
513 connectWith: ".quiz-answer-matching-droppable",
514 placeholder: "drop-hover"
515
516 }).disableSelection();
517 }
518 }
519 init_quiz_builder();
520 /**
521 * Quiz view
522 * @date 22 Feb, 2019
523 * @since v.1.0.0
524 */
525
526 $(document).on('click', '.tutor-quiz-answer-next-btn', function (e) {
527 e.preventDefault();
528 var $that = $(this);
529 var question_id = parseInt($that.closest('.quiz-attempt-single-question').attr('id').match(/\d+/)[0], 10);
530
531 var next_question_id = $that.closest('.quiz-attempt-single-question').attr('data-next-question-id');
532
533 if (next_question_id) {
534 var $nextQuestion = $(next_question_id);
535 if ($nextQuestion && $nextQuestion.length) {
536 $('.quiz-attempt-single-question').hide();
537 $nextQuestion.show();
538
539 /**
540 * If pagination exists, set active class
541 */
542
543 if ($('.tutor-quiz-questions-pagination').length){
544 $('.tutor-quiz-question-paginate-item').removeClass('active');
545 $('.tutor-quiz-questions-pagination a[href="'+next_question_id+'"]').addClass('active');
546 }
547
548 }
549 }
550 });
551 $(document).on('click', '.tutor-quiz-question-paginate-item', function (e) {
552 e.preventDefault();
553 var $that = $(this);
554 var $question = $($that.attr('href'));
555 $('.quiz-attempt-single-question').hide();
556 $question.show();
557
558 //Active Class
559 $('.tutor-quiz-question-paginate-item').removeClass('active');
560 $that.addClass('active');
561 });
562
563 /**
564 * Limit Short Answer Question Type
565 */
566 $(document).on('keyup', 'textarea.question_type_short_answer', function (e) {
567 var $that = $(this);
568 var value = $that.val();
569 var limit = _tutorobject.quiz_options.short_answer_characters_limit;
570 var remaining = limit - value.length;
571
572 if (remaining < 1){
573 $that.val(value.substr(0, limit));
574 remaining = 0;
575 }
576 $that.closest('.tutor-quiz-answers-wrap').find('.characters_remaining').html(remaining);
577 });
578
579 /**
580 * Add to cart in guest mode, show login form
581 *
582 * @since v.1.0.4
583 */
584
585 $(document).on('submit click', '.cart-required-login, .cart-required-login a, .cart-required-login form', function (e) {
586 e.preventDefault();
587
588 $('.tutor-cart-box-login-form').fadeIn(100);
589 });
590
591 $('.tutor-popup-form-close, .login-overlay-close').on('click', function () {
592 $('.tutor-cart-box-login-form').fadeOut(100);
593 });
594
595 $(document).on('keyup', function (e) {
596 if (e.keyCode === 27) {
597 $('.tutor-frontend-modal').hide();
598 $('.tutor-cart-box-login-form').fadeOut(100);
599 }
600 });
601 /**
602 * Share Link enable
603 *
604 * @since v.1.0.4
605 */
606 if($.fn.ShareLink){
607 var $social_share_wrap = $('.tutor-social-share-wrap');
608 if ($social_share_wrap.length) {
609 var share_config = JSON.parse($social_share_wrap.attr('data-social-share-config'));
610
611 $('.tutor_share').ShareLink({
612 title: share_config.title,
613 text: share_config.text,
614 image: share_config.image,
615 class_prefix: 's_',
616 width: 640,
617 height: 480,
618 });
619 }
620 }
621
622 /**
623 * Datepicker initiate
624 *
625 * @since v.1.1.2
626 */
627 if (jQuery.datepicker){
628 $( ".tutor_report_datepicker" ).datepicker({"dateFormat" : 'yy-mm-dd'});
629 }
630
631
632 /**
633 * Withdraw Form Tab/Toggle
634 *
635 * @since v.1.1.2
636 */
637
638 $(".withdraw-method-select-input").on('change', function(e){
639 var $that = $(this);
640 $('.withdraw-method-form').hide();
641 $('#withdraw-method-form-'+$that.closest('.withdraw-method-select').attr('data-withdraw-method')).show();
642 });
643
644 $('.withdraw-method-select-input').each(function () {
645 var $that = $(this);
646 if($that.is(":checked")){
647 $('.withdraw-method-form').hide();
648 $('#withdraw-method-form-'+$that.closest('.withdraw-method-select').attr('data-withdraw-method')).show();
649 }
650 });
651
652
653
654 /**
655 * Setting account for withdraw earning
656 *
657 * @since v.1.2.0
658 */
659 $(document).on('submit', '#tutor-withdraw-account-set-form', function(e){
660 e.preventDefault();
661
662 var $form = $(this);
663 var $btn = $form.find('.tutor_set_withdraw_account_btn');
664 var data = $form.serialize();
665
666 $.ajax({
667 url: _tutorobject.ajaxurl,
668 type: 'POST',
669 data: data,
670 beforeSend: function () {
671 $form.find('.tutor-success-msg').remove();
672 $btn.addClass('updating-icon');
673 },
674 success: function (data) {
675 if (data.success){
676 var successMsg = '<div class="tutor-success-msg" style="display: none;"><i class="tutor-icon-mark"></i> '+data.data.msg+' </div>';
677 $btn.closest('.withdraw-account-save-btn-wrap').append(successMsg);
678 if ($form.find('.tutor-success-msg').length) {
679 $form.find('.tutor-success-msg').slideDown();
680 }
681 setTimeout(function () {
682 $form.find('.tutor-success-msg').slideUp();
683 }, 5000)
684 }
685 },
686 complete: function () {
687 $btn.removeClass('updating-icon');
688 }
689 });
690 });
691
692 /**
693 * Make Withdraw Form
694 *
695 * @since v.1.2.0
696 */
697
698 $(document).on('click', 'a.open-withdraw-form-btn', function(e){
699 e.preventDefault();
700 $('.tutor-earning-withdraw-form-wrap').slideToggle();
701 });
702
703 $(document).on('submit', '#tutor-earning-withdraw-form', function(e){
704 e.preventDefault();
705
706 var $form = $(this);
707 var $btn = $('#tutor-earning-withdraw-btn');
708 var $responseDiv = $('#tutor-withdraw-form-response');
709 var data = $form.serialize();
710
711 $.ajax({
712 url: _tutorobject.ajaxurl,
713 type: 'POST',
714 data: data,
715 beforeSend: function () {
716 $form.find('.tutor-success-msg').remove();
717 $btn.addClass('updating-icon');
718 },
719 success: function (data) {
720 var Msg;
721 if (data.success){
722
723 if (data.data.available_balance !== 'undefined') {
724 $('.withdraw-balance-col .available_balance').html(data.data.available_balance);
725 }
726 Msg = '<div class="tutor-success-msg"><i class="tutor-icon-mark"></i> '+data.data.msg+' </div>';
727
728 }else{
729 Msg = '<div class="tutor-error-msg"><i class="tutor-icon-line-cross"></i> '+data.data.msg+' </div>';
730 }
731
732 $responseDiv.html(Msg);
733 setTimeout(function () {
734 $responseDiv.html('');
735 }, 5000)
736 },
737 complete: function () {
738 $btn.removeClass('updating-icon');
739 }
740 });
741 });
742
743 var frontEndModal = $('.tutor-frontend-modal');
744 frontEndModal.each(function () {
745 var modal = $(this),
746 action = $(this).data('popup-rel');
747 $('[href="'+action+'"]').on('click', function (e) {
748 modal.fadeIn();
749 e.preventDefault();
750 });
751 });
752 $(document).on('click', '.tm-close, .tutor-frontend-modal-overlay, .tutor-modal-btn-cancel', function () {
753 frontEndModal.fadeOut();
754 });
755
756 /**
757 * Delete Course
758 */
759 $(document).on('click', '.tutor-mycourse-delete-btn', function (e) {
760 e.preventDefault();
761 var course_id = $(this).attr('data-course-id');
762 $('#tutor-course-delete-id').val(course_id);
763 });
764 $(document).on('submit', '#tutor-delete-course-form', function (e) {
765 e.preventDefault();
766
767 var course_id = $('#tutor-course-delete-id').val();
768 var $btn = $('.tutor-modal-course-delete-btn');
769 var data = $(this).serialize();
770
771 $.ajax({
772 url: _tutorobject.ajaxurl,
773 type: 'POST',
774 data: data,
775 beforeSend: function () {
776 $btn.addClass('updating-icon');
777 },
778 success: function (data) {
779 if (data.success){
780 $('#tutor-dashboard-course-'+course_id).remove();
781 }
782 },
783 complete: function () {
784 $btn.removeClass('updating-icon');
785 $('.tutor-frontend-modal').hide();
786 }
787 });
788 });
789
790 /**
791 * Frontend Profile
792 */
793
794 if (! $('#tutor_profile_photo_id').val()) {
795 $('.tutor-profile-photo-delete-btn').hide();
796 }
797 // Uploading files
798 var file_frame;
799 $( document ).on( 'click', '.tutor-profile-photo-upload-btn', function( event ) {
800 event.preventDefault();
801
802 if ( file_frame ) {
803 file_frame.open();
804 return;
805 }
806 file_frame = wp.media.frames.downloadable_file = wp.media({
807 title: 'Choose an image',
808 button: {
809 text: 'Use image'
810 },
811 multiple: false
812 });
813 file_frame.on( 'select', function() {
814 var attachment = file_frame.state().get( 'selection' ).first().toJSON();
815 var attachment_thumbnail = attachment.sizes.thumbnail || attachment.sizes.full;
816
817 $( '#tutor_profile_photo_id' ).val( attachment.id );
818 $( '.tutor-profile-photo-upload-wrap' ).find( 'img' ).attr( 'src', attachment_thumbnail.url );
819 $( '.tutor-profile-photo-delete-btn' ).show();
820 });
821 file_frame.open();
822 });
823
824 $( document ).on( 'click', '.tutor-profile-photo-delete-btn', function() {
825 $( '.tutor-profile-photo-upload-wrap' ).find( 'img' ).attr( 'src', _tutorobject.placeholder_img_src );
826 $( '#tutor_profile_photo_id' ).val( '' );
827 $( '.tutor-profile-photo-delete-btn' ).hide();
828 return false;
829 });
830
831
832 /**
833 * Assignment
834 *
835 * @since v.1.3.3
836 */
837
838 $( document ).on( 'submit', '#tutor_assignment_start_form', function(e) {
839 e.preventDefault();
840
841 var $that = $(this);
842 var form_data = $that.serialize()+'&action=tutor_start_assignment';
843
844 $.ajax({
845 url: _tutorobject.ajaxurl,
846 type: 'POST',
847 data: form_data,
848 beforeSend: function () {
849 $('#tutor_assignment_start_btn').addClass('updating-icon');
850 },
851 success: function (data) {
852 if (data.success){
853 location.reload();
854 }
855 },
856 complete : function () {
857 $('#tutor_assignment_start_btn').removeClass('updating-icon');
858 }
859 });
860 });
861
862 /**
863 * Assignment answer validation
864 */
865 $( document ).on( 'submit', '#tutor_assignment_submit_form', function(e) {
866 var assignment_answer = $('textarea[name="assignment_answer"]').val();
867 if (assignment_answer.trim().length < 1) {
868 $('#form_validation_response').html('<div class="tutor-error-msg">'+_tutorobject.text.assignment_text_validation_msg+'</div>');
869 e.preventDefault();
870 }
871 });
872
873 /**
874 * Course builder video
875 * @since v.1.3.4
876 */
877
878
879 $(document).on( 'click', '.video_source_upload_wrap_html5 .video_upload_btn', function( event ){
880 event.preventDefault();
881
882 var $that = $(this);
883 var frame;
884 // If the media frame already exists, reopen it.
885 if ( frame ) {
886 frame.open();
887 return;
888 }
889 frame = wp.media({
890 title: 'Select or Upload Media Of Your Chosen Persuasion',
891 button: {
892 text: 'Use this media'
893 },
894 multiple: false // Set to true to allow multiple files to be selected
895 });
896 frame.on( 'select', function() {
897 // Get media attachment details from the frame state
898 var attachment = frame.state().get('selection').first().toJSON();
899 $that.closest('.video_source_upload_wrap_html5').find('span.video_media_id').text(attachment.id).closest('p').show();
900 $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id);
901 });
902 frame.open();
903 });
904
905
906 /**
907 * Course and lesson sorting
908 */
909
910 function enable_sorting_topic_lesson(){
911 if (jQuery().sortable) {
912 $(".course-contents").sortable({
913 handle: ".course-move-handle",
914 start: function (e, ui) {
915 ui.placeholder.css('visibility', 'visible');
916 },
917 stop: function (e, ui) {
918 tutor_sorting_topics_and_lesson();
919 },
920 });
921 $(".tutor-lessons:not(.drop-lessons)").sortable({
922 connectWith: ".tutor-lessons",
923 items: "div.course-content-item",
924 start: function (e, ui) {
925 ui.placeholder.css('visibility', 'visible');
926 },
927 stop: function (e, ui) {
928 tutor_sorting_topics_and_lesson();
929 },
930 });
931 }
932 }
933 enable_sorting_topic_lesson();
934 function tutor_sorting_topics_and_lesson(){
935 var topics = {};
936 $('.tutor-topics-wrap').each(function(index, item){
937 var $topic = $(this);
938 var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10);
939 var lessons = {};
940
941 $topic.find('.course-content-item').each(function(lessonIndex, lessonItem){
942 var $lesson = $(this);
943 var lesson_id = parseInt($lesson.attr('id').match(/\d+/)[0], 10);
944
945 lessons[lessonIndex] = lesson_id;
946 });
947 topics[index] = { 'topic_id' : topics_id, 'lesson_ids' : lessons };
948 });
949 $('#tutor_topics_lessons_sorting').val(JSON.stringify(topics));
950 }
951
952 /**
953 * Lesson Update or Create Modal
954 */
955 $(document).on( 'click', '.update_lesson_modal_btn', function( event ){
956 event.preventDefault();
957
958 var $that = $(this);
959 var content;
960 var editor = tinyMCE.get('tutor_lesson_modal_editor');
961 if (editor) {
962 content = editor.getContent();
963 } else {
964 content = $('#'+inputid).val();
965 }
966
967 var form_data = $(this).closest('form').serialize();
968 form_data += '&lesson_content='+content;
969
970 $.ajax({
971 url : ajaxurl,
972 type : 'POST',
973 data : form_data,
974 beforeSend: function () {
975 $that.addClass('tutor-updating-message');
976 },
977 success: function (data) {
978 if (data.success){
979 $('#tutor-course-content-wrap').html(data.data.course_contents);
980 enable_sorting_topic_lesson();
981
982 //Close the modal
983 $('.tutor-lesson-modal-wrap').removeClass('show');
984 }
985 },
986 complete: function () {
987 $that.removeClass('tutor-updating-message');
988 }
989 });
990 });
991
992 /**
993 * END: Tutor Course builder JS
994 */
995
996 /**
997 * Attachment in forntend course builder
998 * @since v.1.3.4
999 */
1000 $(document).on('click', 'a.tutor-delete-attachment', function(e){
1001 e.preventDefault();
1002 $(this).closest('.tutor-added-attachment').remove();
1003 });
1004 $(document).on('click', '.tutorUploadAttachmentBtn', function(e){
1005 e.preventDefault();
1006
1007 var $that = $(this);
1008 var frame;
1009 if ( frame ) {
1010 frame.open();
1011 return;
1012 }
1013 frame = wp.media({
1014 title: 'Select or Upload Media Of Your Chosen Persuasion',
1015 button: {
1016 text: 'Use this media'
1017 },
1018 multiple: true // Set to true to allow multiple files to be selected
1019 });
1020 frame.on( 'select', function() {
1021 var attachments = frame.state().get('selection').toJSON();
1022 if (attachments.length){
1023 for (var i=0; i < attachments.length; i++){
1024 var attachment = attachments[i];
1025
1026 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>';
1027 $that.closest('.tutor-lesson-attachments-metabox').find('.tutor-added-attachments-wrap').append(inputHtml);
1028 }
1029 }
1030 });
1031 frame.open();
1032 });
1033
1034
1035 /**
1036 * Single Assignment Upload Button
1037 * @since v.1.3.4
1038 */
1039 $('form').on('change', '.tutor-assignment-file-upload', function () {
1040 $(this).siblings("label").find('span').html($(this).val().replace(/.*(\/|\\)/, ''));
1041 });
1042
1043 /**
1044 * Lesson Sidebar Topic Toggle
1045 * @since v.1.3.4
1046 */
1047
1048 $(document).on('click', '.tutor-topics-in-single-lesson .tutor-topics-title h3, .tutor-single-lesson-topic-toggle', function (e) {
1049 var $that = $(this);
1050 var $parent = $that.closest('.tutor-topics-in-single-lesson');
1051 $parent.toggleClass('tutor-topic-active');
1052 $parent.find('.tutor-lessons-under-topic').slideToggle();
1053 });
1054
1055 $('.tutor-single-lesson-items.active').closest('.tutor-lessons-under-topic').show();
1056 $('.tutor-single-lesson-items.active').closest('.tutor-topics-in-single-lesson').addClass('tutor-topic-active');
1057
1058
1059 /**
1060 * Assignments Addons
1061 * @backend Support
1062 *
1063 */
1064
1065
1066 /**
1067 * Tutor Assignments JS
1068 * @since v.1.3.3
1069 */
1070 $(document).on('click', '.tutor-create-assignments-btn', function(e){
1071 e.preventDefault();
1072
1073 var $that = $(this);
1074 var topic_id = $(this).attr('data-topic-id');
1075 var course_id = $('#post_ID').val();
1076
1077 $.ajax({
1078 url : ajaxurl,
1079 type : 'POST',
1080 data : {topic_id : topic_id, course_id : course_id, action: 'tutor_load_assignments_builder_modal'},
1081 beforeSend: function () {
1082 $that.addClass('tutor-updating-message');
1083 },
1084 success: function (data) {
1085 $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output);
1086 $('.tutor-lesson-modal-wrap').attr('data-topic-id', topic_id).addClass('show');
1087
1088 tinymce.init(tinyMCEPreInit.mceInit.course_description);
1089 tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_assignments_modal_editor' );
1090 tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor");
1091 },
1092 complete: function () {
1093 quicktags({id : "tutor_assignments_modal_editor"});
1094 $that.removeClass('tutor-updating-message');
1095 }
1096 });
1097 });
1098
1099 $(document).on('click', '.open-tutor-assignment-modal', function(e){
1100 e.preventDefault();
1101
1102 var $that = $(this);
1103 var assignment_id = $that.attr('data-assignment-id');
1104 var topic_id = $that.attr('data-topic-id');
1105 var course_id = $('#post_ID').val();
1106
1107 $.ajax({
1108 url : ajaxurl,
1109 type : 'POST',
1110 data : {assignment_id : assignment_id, topic_id : topic_id, course_id : course_id, action: 'tutor_load_assignments_builder_modal'},
1111 beforeSend: function () {
1112 $that.addClass('tutor-updating-message');
1113 },
1114 success: function (data) {
1115 $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output);
1116 $('.tutor-lesson-modal-wrap').attr({'data-assignment-id' : assignment_id, 'data-topic-id':topic_id}).addClass('show');
1117
1118 tinymce.init(tinyMCEPreInit.mceInit.course_description);
1119 tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_assignments_modal_editor' );
1120 tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor");
1121 },
1122 complete: function () {
1123 quicktags({id : "tutor_assignments_modal_editor"});
1124 $that.removeClass('tutor-updating-message');
1125 }
1126 });
1127 });
1128
1129 /**
1130 * Update Assignment Data
1131 */
1132 $(document).on( 'click', '.update_assignment_modal_btn', function( event ){
1133 event.preventDefault();
1134
1135 var $that = $(this);
1136 var content;
1137 var editor = tinyMCE.get('tutor_assignments_modal_editor');
1138 if (editor) {
1139 content = editor.getContent();
1140 } else {
1141 content = $('#'+inputid).val();
1142 }
1143
1144 var form_data = $(this).closest('form').serialize();
1145 form_data += '&assignment_content='+content;
1146
1147 $.ajax({
1148 url : ajaxurl,
1149 type : 'POST',
1150 data : form_data,
1151 beforeSend: function () {
1152 $that.addClass('tutor-updating-message');
1153 },
1154 success: function (data) {
1155 if (data.success){
1156 $('#tutor-course-content-wrap').html(data.data.course_contents);
1157 enable_sorting_topic_lesson();
1158
1159 //Close the modal
1160 $('.tutor-lesson-modal-wrap').removeClass('show');
1161 }
1162 },
1163 complete: function () {
1164 $that.removeClass('tutor-updating-message');
1165 }
1166 });
1167 });
1168
1169 /**
1170 * Add Assignment
1171 */
1172 $(document).on( 'click', '.add-assignment-attachments', function( event ){
1173 event.preventDefault();
1174
1175 var $that = $(this);
1176 var frame;
1177 // If the media frame already exists, reopen it.
1178 if ( frame ) {
1179 frame.open();
1180 return;
1181 }
1182
1183 // Create a new media frame
1184 frame = wp.media({
1185 title: 'Select or Upload Media Of Your Chosen Persuasion',
1186 button: {
1187 text: 'Use this media'
1188 },
1189 multiple: false // Set to true to allow multiple files to be selected
1190 });
1191
1192 // When an image is selected in the media frame...
1193 frame.on( 'select', function() {
1194 // Get media attachment details from the frame state
1195 var attachment = frame.state().get('selection').first().toJSON();
1196
1197 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"> &times; Remove</a></div>';
1198
1199 $('#assignment-attached-file').append(field_markup);
1200 $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id);
1201 });
1202 // Finally, open the modal on click
1203 frame.open();
1204 });
1205
1206 $(document).on( 'click', '.remove-assignment-attachment-a', function( event ){
1207 event.preventDefault();
1208 $(this).closest('.tutor-individual-attachment-file').remove();
1209 });
1210
1211
1212 /**
1213 *
1214 * @type {jQuery}
1215 *
1216 * Course builder auto draft save
1217 *
1218 * @since v.1.3.4
1219 */
1220 var tutor_course_builder = $('input[name="tutor_action"]').val();
1221 if (tutor_course_builder === 'tutor_add_course_builder'){
1222 setInterval(auto_draft_save_course_builder, 30000);
1223 }
1224
1225 function auto_draft_save_course_builder(){
1226 var form_data = $('form#tutor-frontend-course-builder').serialize();
1227 $.ajax({
1228 //url : _tutorobject.ajaxurl,
1229 type : 'POST',
1230 data : form_data+'&tutor_ajax_action=tutor_course_builder_draft_save',
1231 beforeSend: function () {
1232 $('.tutor-dashboard-builder-draft-btn span').text('Saving...');
1233 },
1234 success: function (data) {
1235
1236 },
1237 complete: function () {
1238 $('.tutor-dashboard-builder-draft-btn span').text('Save');
1239 }
1240 });
1241 }
1242
1243 /**
1244 *
1245 * @type {jQuery}
1246 *
1247 * Course builder section toggle
1248 *
1249 * @since v.1.3.5
1250 */
1251
1252 $('.tutor-course-builder-section-title').on('click', function () {
1253 if($(this).find('i').hasClass("tutor-icon-up")){
1254 $(this).find('i').removeClass('tutor-icon-up').addClass('tutor-icon-down');
1255 }else{
1256 $(this).find('i').removeClass('tutor-icon-down').addClass('tutor-icon-up');
1257 }
1258 $(this).next('div').slideToggle();
1259 });
1260
1261 /**
1262 * Open Tutor Modal to edit review
1263 * @since v.1.4.0
1264 */
1265 $(document).on('click', '.open-tutor-edit-review-modal', function(e){
1266 e.preventDefault();
1267
1268 var $that = $(this);
1269 var review_id = $that.attr('data-review-id');
1270
1271 var nonce_key = _tutorobject.nonce_key;
1272
1273 var json_data = {review_id : review_id, action: 'tutor_load_edit_review_modal'};
1274 json_data[nonce_key] = _tutorobject[nonce_key];
1275
1276 $.ajax({
1277 url : _tutorobject.ajaxurl,
1278 type : 'POST',
1279 data : json_data,
1280 beforeSend: function () {
1281 $that.addClass('tutor-updating-message');
1282 },
1283 success: function (data) {
1284 if (typeof data.data !== 'undefined') {
1285 $('.tutor-edit-review-modal-wrap .modal-container').html(data.data.output);
1286 $('.tutor-edit-review-modal-wrap').attr('data-review-id', review_id).addClass('show');
1287 }
1288 },
1289 complete: function () {
1290 $that.removeClass('tutor-updating-message');
1291 }
1292 });
1293 });
1294
1295 /**
1296 * Update the rating
1297 * @since v.1.4.0
1298 */
1299 $(document).on('submit', '#tutor_update_review_form', function(e){
1300 e.preventDefault();
1301
1302 var $that = $(this);
1303 var review_id = $that.closest('.tutor-edit-review-modal-wrap ').attr('data-review-id');
1304
1305 var nonce_key = _tutorobject.nonce_key;
1306
1307 var rating = $that.find('input[name="tutor_rating_gen_input"]').val();
1308 var review = $that.find('textarea[name="review"]').val();
1309 review = review.trim();
1310
1311 var json_data = {review_id : review_id, rating : rating, review : review, action: 'tutor_update_review_modal'};
1312 json_data[nonce_key] = _tutorobject[nonce_key];
1313
1314 $.ajax({
1315 url : _tutorobject.ajaxurl,
1316 type : 'POST',
1317 data : json_data,
1318 beforeSend: function () {
1319 $that.find('button[type="submit"]').addClass('tutor-updating-message');
1320 },
1321 success: function (data) {
1322 if (data.success){
1323 //Close the modal
1324 $('.tutor-edit-review-modal-wrap').removeClass('show');
1325 location.reload(true);
1326 }
1327 },
1328 complete: function () {
1329 $that.find('button[type="submit"]').removeClass('tutor-updating-message');
1330 }
1331 });
1332 });
1333
1334
1335
1336 });