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.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
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
387 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-ratings-wrap i', function(){
93 $(this).closest('.tutor-ratings-wrap').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-ratings-wrap').find('i[data-rating-value="'+i+'"]').removeClass('tutor-icon-star-line').addClass('tutor-icon-star-full');
97 }
98 });
99
100 $(document).on('click', '.tutor-ratings-wrap i', function(){
101 var rating = $(this).attr('data-rating-value');
102 var course_id = $('input[name="tutor_course_id"]').val();
103 var data = {course_id : course_id, rating:rating, action: 'tutor_place_rating' };
104
105 $.post(_tutorobject.ajaxurl, data);
106 });
107
108 $(document).on('click', '.tutor_submit_review_btn', function (e) {
109 e.preventDefault();
110 var $that = $(this);
111 var review = $(this).closest('form').find('textarea[name="review"]').val();
112 review = review.trim();
113
114 var course_id = $('input[name="tutor_course_id"]').val();
115 var data = {course_id : course_id, review:review, action: 'tutor_place_rating' };
116
117 if (review) {
118 $.ajax({
119 url: _tutorobject.ajaxurl,
120 type: 'POST',
121 data: data,
122 beforeSend: function () {
123 $that.addClass('updating-icon');
124 },
125 success: function (data) {
126 var review_id = data.data.review_id;
127 var review = data.data.review;
128 $('.tutor-review-'+review_id+' .review-content').html(review);
129 },
130 complete: function () {
131 $('.tutor-write-review-form').slideUp();
132 $that.removeClass('updating-icon');
133 }
134 });
135 }
136 });
137
138 $(document).on('click', '.write-course-review-link-btn', function(e){
139 e.preventDefault();
140 $(this).siblings('.tutor-write-review-form').slideToggle();
141 });
142
143 $(document).on('click', '.tutor-ask-question-btn', function(e){
144 e.preventDefault();
145 $('.tutor-add-question-wrap').slideToggle();
146 });
147 $(document).on('click', '.tutor_question_cancel', function(e){
148 e.preventDefault();
149 $('.tutor-add-question-wrap').toggle();
150 });
151
152 $(document).on('submit', '#tutor-ask-question-form', function(e){
153 e.preventDefault();
154
155 var $form = $(this);
156 var data = $(this).serialize()+'&action=tutor_ask_question';
157
158 $.ajax({
159 url: _tutorobject.ajaxurl,
160 type: 'POST',
161 data: data,
162 beforeSend: function () {
163 $form.find('.tutor_ask_question_btn').addClass('updating-icon');
164 },
165 success: function (data) {
166 if (data.success){
167 $('.tutor-add-question-wrap').hide();
168 window.location.reload();
169 }
170 },
171 complete: function () {
172 $form.find('.tutor_ask_question_btn').removeClass('updating-icon');
173 }
174 });
175 });
176
177 $(document).on('submit', '.tutor-add-answer-form', function(e){
178 e.preventDefault();
179
180 var $form = $(this);
181 var data = $(this).serialize()+'&action=tutor_add_answer';
182
183 $.ajax({
184 url: _tutorobject.ajaxurl,
185 type: 'POST',
186 data: data,
187 beforeSend: function () {
188 $form.find('.tutor_add_answer_btn').addClass('updating-icon');
189 },
190 success: function (data) {
191 if (data.success){
192 window.location.reload();
193 }
194 },
195 complete: function () {
196 $form.find('.tutor_add_answer_btn').removeClass('updating-icon');
197 }
198 });
199 });
200
201 $(document).on('focus', '.tutor_add_answer_textarea', function(e){
202 e.preventDefault();
203
204 var question_id = $(this).closest('.tutor_add_answer_wrap').attr('data-question-id');
205 var conf = {
206 tinymce: {
207 wpautop:true,
208 //plugins : 'charmap colorpicker compat3x directionality fullscreen hr image lists media paste tabfocus textcolor wordpress wpautoresize wpdialogs wpeditimage wpemoji wpgallery wplink wptextpattern wpview',
209 toolbar1: 'bold italic underline bullist strikethrough numlist blockquote alignleft aligncenter alignright undo redo link unlink spellchecker fullscreen'
210 },
211 };
212 wp.editor.initialize('tutor_answer_'+question_id, conf);
213 });
214
215 $(document).on('click', '.tutor_cancel_wp_editor', function(e){
216 e.preventDefault();
217 $(this).closest('.tutor_wp_editor_wrap').toggle();
218 $(this).closest('.tutor_add_answer_wrap').find('.tutor_wp_editor_show_btn_wrap').toggle();
219 var question_id = $(this).closest('.tutor_add_answer_wrap').attr('data-question-id');
220 wp.editor.remove('tutor_answer_'+question_id);
221 });
222
223 $(document).on('click', '.tutor_wp_editor_show_btn', function(e){
224 e.preventDefault();
225 $(this).closest('.tutor_add_answer_wrap').find('.tutor_wp_editor_wrap').toggle();
226 $(this).closest('.tutor_wp_editor_show_btn_wrap').toggle();
227 });
228
229 /**
230 * Quiz attempt
231 */
232 var $tutor_quiz_time_update = $('#tutor-quiz-time-update');
233 var attempt_settings = null;
234 if ($tutor_quiz_time_update.length){
235 attempt_settings = JSON.parse($tutor_quiz_time_update.attr('data-attempt-settings'));
236 var attempt_meta = JSON.parse($tutor_quiz_time_update.attr('data-attempt-meta'));
237
238 var countDownDate = new Date(attempt_settings.quiz_started_at).getTime() + (attempt_meta.time_limit_seconds * 1000);
239 var time_now = new Date(attempt_meta.date_time_now).getTime();
240
241 var tutor_quiz_interval = setInterval(function() {
242 var distance = countDownDate - time_now;
243
244 var days = Math.floor(distance / (1000 * 60 * 60 * 24));
245 var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
246 var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
247 var seconds = Math.floor((distance % (1000 * 60)) / 1000);
248
249 var countdown_human = '';
250
251 if (days){
252 countdown_human += days + "d ";
253 }
254 if (hours){
255 countdown_human += hours + "h ";
256 }
257 if (minutes){
258 countdown_human += minutes + "m ";
259 }
260 if (seconds){
261 countdown_human += seconds + "s ";
262 }
263
264 if (distance < 0) {
265 clearInterval(tutor_quiz_interval);
266 countdown_human = "EXPIRED";
267 //Set the quiz attempt to timeout in ajax
268
269 var quiz_id = $('#tutor_quiz_id').val();
270 var tutor_quiz_remaining_time_secs = $('#tutor_quiz_remaining_time_secs').val();
271 var quiz_timeout_data = { quiz_id : quiz_id, action : 'tutor_quiz_timeout' };
272
273 $.ajax({
274 url: _tutorobject.ajaxurl,
275 type: 'POST',
276 data: quiz_timeout_data,
277 success: function (data) {
278 if (data.success){
279 window.location.reload(true);
280 }
281 },
282 complete: function () {
283 $('#tutor-quiz-body').html('');
284 window.location.reload(true);
285 }
286 });
287 }
288 time_now = time_now + 1000;
289 $tutor_quiz_time_update.html(countdown_human);
290 }, 1000);
291 }
292
293 // tutor course content accordion
294 $('.tutor-course-topic.tutor-active').find('.tutor-course-lessons').slideDown();
295 $('.tutor-course-title').on('click', function () {
296 var lesson = $(this).siblings('.tutor-course-lessons');
297 $(this).closest('.tutor-course-topic').toggleClass('tutor-active');
298 lesson.slideToggle();
299 });
300
301 $('.tutor-topics-title').on('click', function () {
302 $(this).siblings('.tutor-topics-summery').slideToggle();
303 });
304
305 $(document).on('click', '.tutor-course-wishlist-btn', function (e) {
306 e.preventDefault();
307
308 var $that = $(this);
309 var course_id = $that.attr('data-course-id');
310
311 $.ajax({
312 url: _tutorobject.ajaxurl,
313 type: 'POST',
314 data: {course_id : course_id, 'action': 'tutor_course_add_to_wishlist'},
315 beforeSend: function () {
316 $that.addClass('updating-icon');
317 },
318 success: function (data) {
319 if (data.success){
320 if (data.data.status === 'added'){
321 $that.addClass('has-wish-listed');
322 }else{
323 $that.removeClass('has-wish-listed');
324 }
325 }else{
326 window.location = data.data.redirect_to;
327 }
328 },
329 complete: function () {
330 $that.removeClass('updating-icon');
331 }
332 });
333 });
334
335 $(document).on('click', '.tutor-single-lesson-a', function (e) {
336 e.preventDefault();
337
338 var $that = $(this);
339 var lesson_id = $that.attr('data-lesson-id');
340 var $wrap = $('#tutor-single-lesson-entry-content');
341
342 $.ajax({
343 url: _tutorobject.ajaxurl,
344 type: 'POST',
345 data: {lesson_id : lesson_id, 'action': 'tutor_render_lesson_content'},
346 beforeSend: function () {
347 var page_title = $that.find('.lesson_title').text();
348 $('head title').text(page_title);
349 window.history.pushState('obj', page_title, $that.attr('href'));
350 $wrap.addClass('loading-lesson');
351 $('.tutor-single-lesson-items').removeClass('active');
352 $that.closest('.tutor-single-lesson-items').addClass('active');
353 },
354 success: function (data) {
355 $wrap.html(data.data.html);
356 videoPlayer.init();
357 },
358 complete: function () {
359 $wrap.removeClass('loading-lesson');
360 }
361 });
362 });
363
364 /**
365 * @date 05 Feb, 2019
366 */
367
368 $(document).on('click', '.tutor-lesson-sidebar-hide-bar', function(e){
369 e.preventDefault();
370 $('.tutor-lesson-sidebar').toggle();
371 });
372
373 $(document).on('click', '.tutor-tabs-btn-group a', function (e) {
374 e.preventDefault();
375 var $that = $(this);
376
377
378 var tabSelector = $that.attr('href');
379 $('.tutor-lesson-sidebar-tab-item').hide();
380 $(tabSelector).show();
381
382 $('.tutor-tabs-btn-group a').removeClass('active');
383 $that.addClass('active');
384 });
385
386
387 });