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.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
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
568 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 return;
240 }
241
242 var countDownDate = new Date(attempt_settings.attempt_started_at).getTime() + (attempt_meta.time_limit.time_limit_seconds * 1000);
243 var time_now = new Date(attempt_meta.date_time_now).getTime();
244
245 var tutor_quiz_interval = setInterval(function() {
246 var distance = countDownDate - time_now;
247
248 var days = Math.floor(distance / (1000 * 60 * 60 * 24));
249 var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
250 var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
251 var seconds = Math.floor((distance % (1000 * 60)) / 1000);
252
253 var countdown_human = '';
254
255 if (days){
256 countdown_human += days + "d ";
257 }
258 if (hours){
259 countdown_human += hours + "h ";
260 }
261 if (minutes){
262 countdown_human += minutes + "m ";
263 }
264 if (seconds){
265 countdown_human += seconds + "s ";
266 }
267
268 if (distance < 0) {
269 clearInterval(tutor_quiz_interval);
270 countdown_human = "EXPIRED";
271 //Set the quiz attempt to timeout in ajax
272
273 if (_tutorobject.options.quiz_when_time_expires === 'autosubmit'){
274 /**
275 * Auto Submit
276 */
277 $('form#tutor-answering-quiz').submit();
278
279 } else if(_tutorobject.options.quiz_when_time_expires === 'autoabandon'){
280 /**
281 *
282 * @type {jQuery}
283 *
284 * Current attempt will be cancel with attempt status attempt_timeout
285 */
286
287 var quiz_id = $('#tutor_quiz_id').val();
288 var tutor_quiz_remaining_time_secs = $('#tutor_quiz_remaining_time_secs').val();
289 var quiz_timeout_data = { quiz_id : quiz_id, action : 'tutor_quiz_timeout' };
290
291 $.ajax({
292 url: _tutorobject.ajaxurl,
293 type: 'POST',
294 data: quiz_timeout_data,
295 success: function (data) {
296 if (data.success){
297 window.location.reload(true);
298 }
299 },
300 complete: function () {
301 $('#tutor-quiz-body').html('');
302 window.location.reload(true);
303 }
304 });
305
306 }
307
308 }
309 time_now = time_now + 1000;
310 $tutor_quiz_time_update.html(countdown_human);
311 }, 1000);
312 }
313
314 var $quiz_start_form = $('#tutor-quiz-body form#tutor-start-quiz');
315 if ($quiz_start_form.length){
316 if (_tutorobject.quiz_options.quiz_auto_start === '1'){
317 $quiz_start_form.submit();
318 }
319 }
320
321 // tutor course content accordion
322 $('.tutor-course-topic.tutor-active').find('.tutor-course-lessons').slideDown();
323 $('.tutor-course-title').on('click', function () {
324 var lesson = $(this).siblings('.tutor-course-lessons');
325 $(this).closest('.tutor-course-topic').toggleClass('tutor-active');
326 lesson.slideToggle();
327 });
328
329 $('.tutor-topics-title').on('click', function () {
330 $(this).siblings('.tutor-topics-summery').slideToggle();
331 });
332
333 $(document).on('click', '.tutor-course-wishlist-btn', function (e) {
334 e.preventDefault();
335
336 var $that = $(this);
337 var course_id = $that.attr('data-course-id');
338
339 $.ajax({
340 url: _tutorobject.ajaxurl,
341 type: 'POST',
342 data: {course_id : course_id, 'action': 'tutor_course_add_to_wishlist'},
343 beforeSend: function () {
344 $that.addClass('updating-icon');
345 },
346 success: function (data) {
347 if (data.success){
348 if (data.data.status === 'added'){
349 $that.addClass('has-wish-listed');
350 }else{
351 $that.removeClass('has-wish-listed');
352 }
353 }else{
354 window.location = data.data.redirect_to;
355 }
356 },
357 complete: function () {
358 $that.removeClass('updating-icon');
359 }
360 });
361 });
362
363 $(document).on('click', '.tutor-single-lesson-a', function (e) {
364 e.preventDefault();
365
366 var $that = $(this);
367 var lesson_id = $that.attr('data-lesson-id');
368 var $wrap = $('#tutor-single-entry-content');
369
370 $.ajax({
371 url: _tutorobject.ajaxurl,
372 type: 'POST',
373 data: {lesson_id : lesson_id, 'action': 'tutor_render_lesson_content'},
374 beforeSend: function () {
375 var page_title = $that.find('.lesson_title').text();
376 $('head title').text(page_title);
377 window.history.pushState('obj', page_title, $that.attr('href'));
378 $wrap.addClass('loading-lesson');
379 $('.tutor-single-lesson-items').removeClass('active');
380 $that.closest('.tutor-single-lesson-items').addClass('active');
381 },
382 success: function (data) {
383 $wrap.html(data.data.html);
384 videoPlayer.init();
385 },
386 complete: function () {
387 $wrap.removeClass('loading-lesson');
388 }
389 });
390 });
391
392 $(document).on('click', '.sidebar-single-quiz-a', function (e) {
393 e.preventDefault();
394
395 var $that = $(this);
396 var quiz_id = $that.attr('data-quiz-id');
397 var page_title = $that.find('.lesson_title').text();
398 var $wrap = $('#tutor-single-entry-content');
399
400 $.ajax({
401 url: _tutorobject.ajaxurl,
402 type: 'POST',
403 data: {quiz_id : quiz_id, 'action': 'tutor_render_quiz_content'},
404 beforeSend: function () {
405 $('head title').text(page_title);
406 window.history.pushState('obj', page_title, $that.attr('href'));
407 $wrap.addClass('loading-lesson');
408 $('.tutor-single-lesson-items').removeClass('active');
409 $that.closest('.tutor-single-lesson-items').addClass('active');
410 },
411 success: function (data) {
412 $wrap.html(data.data.html);
413 },
414 complete: function () {
415 $wrap.removeClass('loading-lesson');
416 }
417 });
418
419
420 });
421
422 /**
423 * @date 05 Feb, 2019
424 */
425
426 $(document).on('click', '.tutor-lesson-sidebar-hide-bar', function(e){
427 e.preventDefault();
428 $('.tutor-lesson-sidebar').toggle();
429 });
430
431 $(document).on('click', '.tutor-tabs-btn-group a', function (e) {
432 e.preventDefault();
433 var $that = $(this);
434
435 var tabSelector = $that.attr('href');
436 $('.tutor-lesson-sidebar-tab-item').hide();
437 $(tabSelector).show();
438
439 $('.tutor-tabs-btn-group a').removeClass('active');
440 $that.addClass('active');
441 });
442 /**
443 * @date 18 Feb, 2019
444 * @since v.1.0.0
445 */
446
447 if (jQuery().sortable) {
448 $(".tutor-quiz-answers-wrap").sortable({
449 handle: ".answer-sorting-bar",
450 start: function (e, ui) {
451 ui.placeholder.css('visibility', 'visible');
452 },
453 stop: function (e, ui) {
454
455 //Sorting Stopped...
456 },
457 }).disableSelection();;
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 /**
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-cart-box-login-form').fadeOut(100);
545 }
546 });
547 /**
548 * Share Link enable
549 *
550 * @since v.1.0.4
551 */
552 if($.fn.ShareLink){
553 var $social_share_wrap = $('.tutor-social-share-wrap');
554 if ($social_share_wrap.length) {
555 var share_config = JSON.parse($social_share_wrap.attr('data-social-share-config'));
556
557 $('.tutor_share').ShareLink({
558 title: share_config.title,
559 text: share_config.text,
560 image: share_config.image,
561 class_prefix: 's_',
562 width: 640,
563 height: 480,
564 });
565 }
566 }
567
568 });