PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 1.9.1
Tutor LMS – eLearning and online course solution v1.9.1
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 5 years ago gutenberg_blocks.js 5 years ago mce-button.js 5 years ago tutor-admin.js 5 years ago tutor-front.js 5 years ago tutor-setup.js 5 years ago tutor.js 5 years ago
tutor-front.js
2224 lines
1
2 jQuery(document).ready(function ($) {
3 'use strict';
4 /**
5 * wp.i18n translateable functions
6 * @since 1.9.0
7 */
8 const { __, _x, _n, _nx } = wp.i18n;
9 /**
10 * Initiate Select2
11 * @since v.1.3.4
12 */
13 if (jQuery().select2) {
14 $('.tutor_select2').select2({
15 escapeMarkup: function (markup) {
16 return markup;
17 }
18 });
19 }
20 //END: select2
21
22
23 /*!
24 * jQuery UI Touch Punch 0.2.3
25 *
26 * Copyright 2011–2014, Dave Furfero
27 * Dual licensed under the MIT or GPL Version 2 licenses.
28 *
29 * Depends:
30 * jquery.ui.widget.js
31 * jquery.ui.mouse.js
32 */
33 !function (a) { function f(a, b) { if (!(a.originalEvent.touches.length > 1)) { a.preventDefault(); var c = a.originalEvent.changedTouches[0], d = document.createEvent("MouseEvents"); d.initMouseEvent(b, !0, !0, window, 1, c.screenX, c.screenY, c.clientX, c.clientY, !1, !1, !1, !1, 0, null), a.target.dispatchEvent(d) } } if (a.support.touch = "ontouchend" in document, a.support.touch) { var e, b = a.ui.mouse.prototype, c = b._mouseInit, d = b._mouseDestroy; b._touchStart = function (a) { var b = this; !e && b._mouseCapture(a.originalEvent.changedTouches[0]) && (e = !0, b._touchMoved = !1, f(a, "mouseover"), f(a, "mousemove"), f(a, "mousedown")) }, b._touchMove = function (a) { e && (this._touchMoved = !0, f(a, "mousemove")) }, b._touchEnd = function (a) { e && (f(a, "mouseup"), f(a, "mouseout"), this._touchMoved || f(a, "click"), e = !1) }, b._mouseInit = function () { var b = this; b.element.bind({ touchstart: a.proxy(b, "_touchStart"), touchmove: a.proxy(b, "_touchMove"), touchend: a.proxy(b, "_touchEnd") }), c.call(b) }, b._mouseDestroy = function () { var b = this; b.element.unbind({ touchstart: a.proxy(b, "_touchStart"), touchmove: a.proxy(b, "_touchMove"), touchend: a.proxy(b, "_touchEnd") }), d.call(b) } } }(jQuery);
34
35 /**
36 * END jQuery UI Touch Punch
37 */
38
39
40 /* $(document).on('change', '.tutor-course-filter-form', function (e) {
41 e.preventDefault();
42 $(this).closest('form').submit();
43 }); */
44
45 const videoPlayer = {
46 ajaxurl: _tutorobject.ajaxurl,
47 nonce_key: _tutorobject.nonce_key,
48 video_data: function () {
49 const video_track_data = $('#tutor_video_tracking_information').val();
50 return video_track_data ? JSON.parse(video_track_data) : {};
51 },
52 track_player: function () {
53 const that = this;
54 if (typeof Plyr !== 'undefined') {
55 const player = new Plyr('#tutorPlayer');
56 const video_data = that.video_data();
57 player.on('ready', function (event) {
58 const instance = event.detail.plyr;
59 const { best_watch_time } = video_data;
60 if (best_watch_time > 0 && instance.duration > Math.round(best_watch_time)) {
61 instance.media.currentTime = best_watch_time;
62 }
63 that.sync_time(instance);
64 });
65
66 let tempTimeNow = 0;
67 let intervalSeconds = 30; //Send to tutor backend about video playing time in this interval
68 player.on('timeupdate', function (event) {
69 const instance = event.detail.plyr;
70 const tempTimeNowInSec = (tempTimeNow / 4); //timeupdate firing 250ms interval
71 if (tempTimeNowInSec >= intervalSeconds) {
72 that.sync_time(instance);
73 tempTimeNow = 0;
74 }
75 tempTimeNow++;
76 });
77
78 player.on('ended', function (event) {
79 const video_data = that.video_data();
80 const instance = event.detail.plyr;
81 const data = { is_ended: true };
82 that.sync_time(instance, data);
83 if (video_data.autoload_next_course_content) {
84 that.autoload_content();
85 }
86 });
87 }
88 },
89 sync_time: function (instance, options) {
90 const post_id = this.video_data().post_id;
91 //TUTOR is sending about video playback information to server.
92 let data = { action: 'sync_video_playback', currentTime: instance.currentTime, duration: instance.duration, post_id };
93 data[this.nonce_key] = _tutorobject[this.nonce_key];
94 let data_send = data;
95 if (options) {
96 data_send = Object.assign(data, options);
97 }
98 $.post(this.ajaxurl, data_send);
99 },
100 autoload_content: function () {
101 const post_id = this.video_data().post_id;
102 const data = { action: 'autoload_next_course_content', post_id };
103 data[this.nonce_key] = _tutorobject[this.nonce_key];
104 $.post(this.ajaxurl, data).done(function (response) {
105 if (response.success && response.data.next_url) {
106 location.href = response.data.next_url;
107 }
108 });
109 },
110 init: function () {
111 this.track_player();
112 }
113 };
114
115 /**
116 * Fire TUTOR video
117 * @since v.1.0.0
118 */
119 if ($('#tutorPlayer').length) {
120 videoPlayer.init();
121 }
122
123 $(document).on('change keyup paste', '.tutor_user_name', function () {
124 $(this).val(tutor_slugify($(this).val()));
125 });
126
127 function tutor_slugify(text) {
128 return text.toString().toLowerCase()
129 .replace(/\s+/g, '-') // Replace spaces with -
130 .replace(/[^\w\-]+/g, '') // Remove all non-word chars
131 .replace(/\-\-+/g, '-') // Replace multiple - with single -
132 .replace(/^-+/, '') // Trim - from start of text
133 .replace(/-+$/, ''); // Trim - from end of text
134 }
135
136 function toggle_star_(star){
137 star.add(star.prevAll()).filter('i').addClass('tutor-icon-star-full').removeClass('tutor-icon-star-line');
138 star.nextAll().filter('i').removeClass('tutor-icon-star-full').addClass('tutor-icon-star-line');
139 }
140
141 /**
142 * Hover tutor rating and set value
143 */
144 $(document).on('mouseover', '.tutor-write-review-box .tutor-star-rating-group i', function () {
145 toggle_star_($(this));
146 });
147
148 $(document).on('click', '.tutor-write-review-box .tutor-star-rating-group i', function () {
149 var rating = $(this).attr('data-rating-value');
150 $(this).closest('.tutor-star-rating-group').find('input[name="tutor_rating_gen_input"]').val(rating);
151
152 toggle_star_($(this));
153 });
154
155 $(document).on('mouseout', '.tutor-write-review-box .tutor-star-rating-group', function(){
156 var value = $(this).find('input[name="tutor_rating_gen_input"]').val();
157 var rating = parseInt(value);
158
159 var selected = $(this).find('[data-rating-value="'+rating+'"]');
160 (rating && selected && selected.length>0) ? toggle_star_(selected) : $(this).find('i').removeClass('tutor-icon-star-full').addClass('tutor-icon-star-line');
161 });
162
163 $(document).on('click', '.tutor_submit_review_btn', function (e) {
164 e.preventDefault();
165 var $that = $(this);
166 var rating = $that.closest('form').find('input[name="tutor_rating_gen_input"]').val();
167 var review = $that.closest('form').find('textarea[name="review"]').val();
168 review = review.trim();
169
170 var course_id = $('input[name="tutor_course_id"]').val();
171 var data = { course_id: course_id, rating: rating, review: review, action: 'tutor_place_rating' };
172
173 if(!rating || rating==0 || !review) {
174 alert(__('Rating and review required', 'tutor'));
175 return;
176 }
177
178 if (review) {
179 $.ajax({
180 url: _tutorobject.ajaxurl,
181 type: 'POST',
182 data: data,
183 beforeSend: function () {
184 $that.addClass('updating-icon');
185 },
186 success: function (data) {
187 var review_id = data.data.review_id;
188 var review = data.data.review;
189 $('.tutor-review-' + review_id + ' .review-content').html(review);
190 location.reload();
191 }
192 });
193 }
194 });
195
196 $(document).on('click', '.write-course-review-link-btn', function (e) {
197 e.preventDefault();
198 $(this).siblings('.tutor-write-review-form').slideToggle();
199 });
200
201 $(document).on('click', '.tutor-ask-question-btn', function (e) {
202 e.preventDefault();
203 $('.tutor-add-question-wrap').slideToggle();
204 });
205 $(document).on('click', '.tutor_question_cancel', function (e) {
206 e.preventDefault();
207 $('.tutor-add-question-wrap').toggle();
208 });
209
210 $(document).on('submit', '#tutor-ask-question-form', function (e) {
211 e.preventDefault();
212
213 var $form = $(this);
214
215 var data = $(this).serializeObject();
216 data.action = 'tutor_ask_question';
217
218 $.ajax({
219 url: _tutorobject.ajaxurl,
220 type: 'POST',
221 data: data,
222 beforeSend: function () {
223 $form.find('.tutor_ask_question_btn').addClass('updating-icon');
224 },
225 success: function (data) {
226 if (data.success) {
227 $('.tutor-add-question-wrap').hide();
228 window.location.reload();
229 }
230 },
231 complete: function () {
232 $form.find('.tutor_ask_question_btn').removeClass('updating-icon');
233 }
234 });
235 });
236
237 $(document).on('submit', '.tutor-add-answer-form', function (e) {
238 e.preventDefault();
239
240 var $form = $(this);
241 var data = $(this).serializeObject();
242 data.action = 'tutor_add_answer';
243
244 $.ajax({
245 url: _tutorobject.ajaxurl,
246 type: 'POST',
247 data: data,
248 beforeSend: function () {
249 $form.find('.tutor_add_answer_btn').addClass('updating-icon');
250 },
251 success: function (data) {
252 if (data.success) {
253 window.location.reload();
254 }
255 },
256 complete: function () {
257 $form.find('.tutor_add_answer_btn').removeClass('updating-icon');
258 }
259 });
260 });
261
262 $(document).on('focus', '.tutor_add_answer_textarea', function (e) {
263 e.preventDefault();
264
265 var question_id = $(this).closest('.tutor_add_answer_wrap').attr('data-question-id');
266 var conf = {
267 tinymce: {
268 wpautop: true,
269 //plugins : 'charmap colorpicker compat3x directionality fullscreen hr image lists media paste tabfocus textcolor wordpress wpautoresize wpdialogs wpeditimage wpemoji wpgallery wplink wptextpattern wpview',
270 toolbar1: 'bold italic underline bullist strikethrough numlist blockquote alignleft aligncenter alignright undo redo link unlink spellchecker fullscreen'
271 },
272 };
273 wp.editor.initialize('tutor_answer_' + question_id, conf);
274 });
275
276 $(document).on('click', '.tutor_cancel_wp_editor', function (e) {
277 e.preventDefault();
278 $(this).closest('.tutor_wp_editor_wrap').toggle();
279 $(this).closest('.tutor_add_answer_wrap').find('.tutor_wp_editor_show_btn_wrap').toggle();
280 var question_id = $(this).closest('.tutor_add_answer_wrap').attr('data-question-id');
281 wp.editor.remove('tutor_answer_' + question_id);
282 });
283
284 $(document).on('click', '.tutor_wp_editor_show_btn', function (e) {
285 e.preventDefault();
286 $(this).closest('.tutor_add_answer_wrap').find('.tutor_wp_editor_wrap').toggle();
287 $(this).closest('.tutor_wp_editor_show_btn_wrap').toggle();
288 });
289
290 /**
291 * Quiz attempt
292 */
293 var $tutor_quiz_time_update = $('#tutor-quiz-time-update');
294 var attempt_settings = null;
295 if ($tutor_quiz_time_update.length) {
296 attempt_settings = JSON.parse($tutor_quiz_time_update.attr('data-attempt-settings'));
297 var attempt_meta = JSON.parse($tutor_quiz_time_update.attr('data-attempt-meta'));
298
299 if (attempt_meta.time_limit.time_limit_seconds > 0) {
300 //No time Zero limit for
301 var countDownDate = new Date(attempt_settings.attempt_started_at).getTime() + (attempt_meta.time_limit.time_limit_seconds * 1000);
302 var time_now = new Date(attempt_meta.date_time_now).getTime();
303
304 var tutor_quiz_interval = setInterval(function () {
305 var distance = countDownDate - time_now;
306
307 var days = Math.floor(distance / (1000 * 60 * 60 * 24));
308 var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
309 var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
310 var seconds = Math.floor((distance % (1000 * 60)) / 1000);
311
312 var countdown_human = '';
313
314 if (days) {
315 countdown_human += days + "d ";
316 }
317 if (hours) {
318 countdown_human += hours + "h ";
319 }
320 if (minutes) {
321 countdown_human += minutes + "m ";
322 }
323 if (seconds) {
324 countdown_human += seconds + "s ";
325 }
326
327 if (distance < 0) {
328 clearInterval(tutor_quiz_interval);
329 countdown_human = "EXPIRED";
330 //Set the quiz attempt to timeout in ajax
331
332 if (_tutorobject.quiz_options.quiz_when_time_expires === 'autosubmit') {
333 /**
334 * Auto Submit
335 */
336 $('form#tutor-answering-quiz').submit();
337
338 } else if (_tutorobject.quiz_options.quiz_when_time_expires === 'autoabandon') {
339 /**
340 *
341 * @type {jQuery}
342 *
343 * Current attempt will be cancel with attempt status attempt_timeout
344 */
345
346 var quiz_id = $('#tutor_quiz_id').val();
347 var tutor_quiz_remaining_time_secs = $('#tutor_quiz_remaining_time_secs').val();
348 var quiz_timeout_data = { quiz_id: quiz_id, action: 'tutor_quiz_timeout' };
349
350 $.ajax({
351 url: _tutorobject.ajaxurl,
352 type: 'POST',
353 data: quiz_timeout_data,
354 success: function (data) {
355 if (data.success) {
356 window.location.reload(true);
357 }
358 },
359 complete: function () {
360 $('#tutor-quiz-body').html('');
361 window.location.reload(true);
362 }
363 });
364 }
365
366 }
367 time_now = time_now + 1000;
368 $tutor_quiz_time_update.html(countdown_human);
369 }, 1000);
370 } else {
371 $tutor_quiz_time_update.closest('.time-remaining').remove();
372 }
373 }
374
375 var $quiz_start_form = $('#tutor-quiz-body form#tutor-start-quiz');
376 if ($quiz_start_form.length) {
377 if (_tutorobject.quiz_options.quiz_auto_start === '1') {
378 $quiz_start_form.submit();
379 }
380 }
381
382 /**
383 * Quiz Frontend Review Action
384 * @since 1.4.0
385 */
386 $(document).on('click', '.quiz-manual-review-action', function (e) {
387 e.preventDefault();
388 var $that = $(this),
389 attempt_id = $that.attr('data-attempt-id'),
390 attempt_answer_id = $that.attr('data-attempt-answer-id'),
391 mark_as = $that.attr('data-mark-as');
392
393 $.ajax({
394 url: _tutorobject.ajaxurl,
395 type: 'GET',
396 data: { action: 'review_quiz_answer', attempt_id: attempt_id, attempt_answer_id: attempt_answer_id, mark_as: mark_as },
397 beforeSend: function () {
398 $that.find('i').addClass('updating-icon');
399 },
400 success: function (data) {
401 location.reload();
402 },
403 complete: function () {
404 $that.find('i').removeClass('updating-icon');
405 }
406 });
407 });
408
409 // Quiz Review : Tooltip
410 $(".tooltip-btn").on("hover", function (e) {
411 $(this).toggleClass("active");
412 });
413
414 // tutor course content accordion
415
416 /**
417 * Toggle topic summery
418 * @since v.1.6.9
419 */
420 $('.tutor-course-title h4 .toggle-information-icon').on('click', function (e) {
421 $(this).closest('.tutor-topics-in-single-lesson').find('.tutor-topics-summery').slideToggle();
422 e.stopPropagation();
423 });
424
425 $('.tutor-course-topic.tutor-active').find('.tutor-course-lessons').slideDown();
426 $('.tutor-course-title').on('click', function () {
427 var lesson = $(this).siblings('.tutor-course-lessons');
428 $(this).closest('.tutor-course-topic').toggleClass('tutor-active');
429 lesson.slideToggle();
430 });
431
432 $(document).on('click', '.tutor-topics-title h3 .toggle-information-icon', function (e) {
433 $(this).closest('.tutor-topics-in-single-lesson').find('.tutor-topics-summery').slideToggle();
434 e.stopPropagation();
435 });
436
437 $(document).on('click', '.tutor-course-wishlist-btn', function (e) {
438 e.preventDefault();
439
440 var $that = $(this);
441 var course_id = $that.attr('data-course-id');
442
443 $.ajax({
444 url: _tutorobject.ajaxurl,
445 type: 'POST',
446 data: { course_id: course_id, 'action': 'tutor_course_add_to_wishlist' },
447 beforeSend: function () {
448 $that.addClass('updating-icon');
449 },
450 success: function (data) {
451 if (data.success) {
452 if (data.data.status === 'added') {
453 $that.addClass('has-wish-listed');
454 } else {
455 $that.removeClass('has-wish-listed');
456 }
457 } else {
458 window.location = data.data.redirect_to;
459 }
460 },
461 complete: function () {
462 $that.removeClass('updating-icon');
463 }
464 });
465 });
466
467 /**
468 * Check if lesson has classic editor support
469 * If classic editor support, stop ajax load on the lesson page.
470 *
471 * @since v.1.0.0
472 *
473 * @updated v.1.4.0
474 */
475 if (!_tutorobject.enable_lesson_classic_editor) {
476
477 $(document).on('click', '.tutor-single-lesson-a', function (e) {
478 e.preventDefault();
479
480 var $that = $(this);
481 var lesson_id = $that.attr('data-lesson-id');
482 var $wrap = $('#tutor-single-entry-content');
483
484 $.ajax({
485 url: _tutorobject.ajaxurl,
486 type: 'POST',
487 data: { lesson_id: lesson_id, 'action': 'tutor_render_lesson_content' },
488 beforeSend: function () {
489 var page_title = $that.find('.lesson_title').text();
490 $('head title').text(page_title);
491 window.history.pushState('obj', page_title, $that.attr('href'));
492 $wrap.addClass('loading-lesson');
493 $('.tutor-single-lesson-items').removeClass('active');
494 $that.closest('.tutor-single-lesson-items').addClass('active');
495 },
496 success: function (data) {
497 $wrap.html(data.data.html);
498 videoPlayer.init();
499 $('.tutor-lesson-sidebar').css('display', '');
500 window.dispatchEvent(new window.Event('tutor_ajax_lesson_loaded')); // Some plugins like h5p needs notification on ajax load
501 },
502 complete: function () {
503 $wrap.removeClass('loading-lesson');
504 }
505 });
506 });
507
508 $(document).on('click', '.sidebar-single-quiz-a', function (e) {
509 e.preventDefault();
510
511 var $that = $(this);
512 var quiz_id = $that.attr('data-quiz-id');
513 var page_title = $that.find('.lesson_title').text();
514 var $wrap = $('#tutor-single-entry-content');
515
516 $.ajax({
517 url: _tutorobject.ajaxurl,
518 type: 'POST',
519 data: { quiz_id: quiz_id, 'action': 'tutor_render_quiz_content' },
520 beforeSend: function () {
521 $('head title').text(page_title);
522 window.history.pushState('obj', page_title, $that.attr('href'));
523 $wrap.addClass('loading-lesson');
524 $('.tutor-single-lesson-items').removeClass('active');
525 $that.closest('.tutor-single-lesson-items').addClass('active');
526 },
527 success: function (data) {
528 $wrap.html(data.data.html);
529 init_quiz_builder();
530 $('.tutor-lesson-sidebar').css('display', '');
531 },
532 complete: function () {
533 $wrap.removeClass('loading-lesson');
534 }
535 });
536 });
537 }
538
539 /**
540 * @date 05 Feb, 2019
541 */
542
543 $(document).on('click', '.tutor-lesson-sidebar-hide-bar', function (e) {
544 e.preventDefault();
545 $('.tutor-lesson-sidebar').toggle();
546 $('#tutor-single-entry-content').toggleClass("sidebar-hidden");
547
548 });
549
550 $(".tutor-tabs-btn-group a").on('click touchstart', function (e) {
551 e.preventDefault();
552 var $that = $(this);
553 var tabSelector = $that.attr('href');
554 $('.tutor-lesson-sidebar-tab-item').hide();
555 $(tabSelector).show();
556
557 $('.tutor-tabs-btn-group a').removeClass('active');
558 $that.addClass('active');
559 });
560 /**
561 * @date 18 Feb, 2019
562 * @since v.1.0.0
563 */
564
565 function init_quiz_builder() {
566 if (jQuery().sortable) {
567 $(".tutor-quiz-answers-wrap").sortable({
568 handle: ".answer-sorting-bar",
569 start: function (e, ui) {
570 ui.placeholder.css('visibility', 'visible');
571 },
572 stop: function (e, ui) {
573 //Sorting Stopped...
574 },
575 }).disableSelection();
576
577 $(".quiz-draggable-rand-answers, .quiz-answer-matching-droppable").sortable({
578 connectWith: ".quiz-answer-matching-droppable",
579 placeholder: "drop-hover",
580 }).disableSelection();
581 }
582 }
583 init_quiz_builder();
584 /**
585 * Quiz view
586 * @date 22 Feb, 2019
587 * @since v.1.0.0
588 */
589
590 $(document).on('click', '.tutor-quiz-answer-next-btn', function (e) {
591 e.preventDefault();
592
593 var $that = $(this);
594 var $question_wrap = $that.closest('.quiz-attempt-single-question');
595 /**
596 * Validating required answer
597 * @type {jQuery}
598 *
599 * @since v.1.6.1
600 */
601
602 var validated = tutor_quiz_validation($question_wrap);
603 if (!validated) {
604 return;
605 }
606
607 var feedBackNext = feedback_response($question_wrap);
608 if (!feedBackNext) {
609 return;
610 }
611
612 var question_id = parseInt($that.closest('.quiz-attempt-single-question').attr('id').match(/\d+/)[0], 10);
613
614 var next_question_id = $that.closest('.quiz-attempt-single-question').attr('data-next-question-id');
615
616 if (next_question_id) {
617 var $nextQuestion = $(next_question_id);
618 if ($nextQuestion && $nextQuestion.length) {
619 /**
620 * check if reveal mode wait for 500ms then
621 * hide question so that correct answer reveal
622 * @since 1.8.10
623 */
624
625 var feedBackMode = $question_wrap.attr('data-quiz-feedback-mode');
626 if(feedBackMode === 'reveal') {
627 setTimeout(()=>{
628 $('.quiz-attempt-single-question').hide();
629 $nextQuestion.show();
630 },
631 500);
632 } else {
633 $('.quiz-attempt-single-question').hide();
634 $nextQuestion.show();
635 }
636
637
638
639 /**
640 * If pagination exists, set active class
641 */
642
643 if ($('.tutor-quiz-questions-pagination').length) {
644 $('.tutor-quiz-question-paginate-item').removeClass('active');
645 $('.tutor-quiz-questions-pagination a[href="' + next_question_id + '"]').addClass('active');
646 }
647
648 }
649 }
650 });
651
652 $(document).on('submit', '#tutor-answering-quiz', function (e) {
653 var $questions_wrap = $('.quiz-attempt-single-question');
654 var validated = true;
655 if ($questions_wrap.length) {
656 $questions_wrap.each(function (index, question) {
657 validated = tutor_quiz_validation($(question));
658 validated = feedback_response($(question));
659 });
660 }
661
662 if (!validated) {
663 e.preventDefault();
664 }
665
666 });
667
668
669 $(document).on('click', '.tutor-quiz-question-paginate-item', function (e) {
670 e.preventDefault();
671 var $that = $(this);
672 var $question = $($that.attr('href'));
673 $('.quiz-attempt-single-question').hide();
674 $question.show();
675
676 //Active Class
677 $('.tutor-quiz-question-paginate-item').removeClass('active');
678 $that.addClass('active');
679 });
680
681 /**
682 * Limit Short Answer Question Type
683 */
684 $(document).on('keyup', 'textarea.question_type_short_answer, textarea.question_type_open_ended', function (e) {
685 var $that = $(this);
686 var value = $that.val();
687 var limit = $that.hasClass('question_type_short_answer') ? _tutorobject.quiz_options.short_answer_characters_limit : _tutorobject.quiz_options.open_ended_answer_characters_limit;
688 var remaining = limit - value.length;
689
690 if (remaining < 1) {
691 $that.val(value.substr(0, limit));
692 remaining = 0;
693 }
694 $that.closest('.tutor-quiz-answers-wrap').find('.characters_remaining').html(remaining);
695 });
696
697 /**
698 *
699 * @type {jQuery}
700 *
701 * Improved Quiz draggable answers drop accessibility
702 * Answers draggable wrap will be now same height.
703 *
704 * @since v.1.4.4
705 */
706 var countDraggableAnswers = $('.quiz-draggable-rand-answers').length;
707 if (countDraggableAnswers) {
708 $('.quiz-draggable-rand-answers').each(function () {
709 var $that = $(this);
710 var draggableDivHeight = $that.height();
711
712 $that.css({ "height": draggableDivHeight });
713 });
714 }
715
716
717 /**
718 * Quiz Validation Helper
719 *
720 * @since v.1.6.1
721 */
722
723 function tutor_quiz_validation($question_wrap) {
724 var validated = true;
725
726 var $required_answer_wrap = $question_wrap.find('.quiz-answer-required');
727
728 if ($required_answer_wrap.length) {
729 /**
730 * Radio field validation
731 *
732 * @type {jQuery}
733 *
734 * @since v.1.6.1
735 */
736 var $inputs = $required_answer_wrap.find('input');
737 if ($inputs.length) {
738 var $type = $inputs.attr('type');
739 if ($type === 'radio') {
740 if ($required_answer_wrap.find('input[type="radio"]:checked').length == 0) {
741 $question_wrap.find('.answer-help-block').html(`<p style="color: #dc3545">${__('Please select an option to answer', 'tutor')}</p>`);
742 validated = false;
743 }
744 } else if ($type === 'checkbox') {
745 if ($required_answer_wrap.find('input[type="checkbox"]:checked').length == 0) {
746 $question_wrap.find('.answer-help-block').html(`<p style="color: #dc3545">${__('Please select at least one option to answer.', 'tutor')}</p>`);
747 validated = false;
748 }
749 } else if ($type === 'text') {
750 //Fill in the gaps if many, validation all
751 $inputs.each(function (index, input) {
752 if (!$(input).val().trim().length) {
753 $question_wrap.find('.answer-help-block').html(`<p style="color: #dc3545">${__('The answer for this question is required', 'tutor')}</p>`);
754 validated = false;
755 }
756 });
757 }
758
759 }
760 if ($required_answer_wrap.find('textarea').length) {
761 if ($required_answer_wrap.find('textarea').val().trim().length < 1) {
762 $question_wrap.find('.answer-help-block').html(`<p style="color: #dc3545">${__('The answer for this question is required', 'tutor')}</p>`);
763 validated = false;
764 }
765 }
766
767 /**
768 * Matching Question
769 */
770 var $matchingDropable = $required_answer_wrap.find('.quiz-answer-matching-droppable');
771 if ($matchingDropable.length) {
772
773 $matchingDropable.each(function (index, matching) {
774 if (!$(matching).find('.quiz-draggable-answer-item').length) {
775 $question_wrap.find('.answer-help-block').html(`<p style="color: #dc3545">${__('Please match all the items', 'tutor')}</p>`);
776 validated = false;
777 }
778 });
779 }
780 }
781
782 return validated;
783 }
784
785 function feedback_response($question_wrap) {
786 var goNext = false;
787
788 // Prepare answer array
789 var quiz_answers = JSON.parse(atob(window.tutor_quiz_context.split('').reverse().join('')));
790 !Array.isArray(quiz_answers) ? quiz_answers=[] : 0;
791
792 // Evaluate result
793 var feedBackMode = $question_wrap.attr('data-quiz-feedback-mode');
794 $('.wrong-right-text').remove();
795 $('.quiz-answer-input-bottom').removeClass('wrong-answer right-answer');
796
797 var validatedTrue = true;
798 var $inputs = $question_wrap.find('input');
799 var $checkedInputs = $question_wrap.find('input[type="radio"]:checked, input[type="checkbox"]:checked');
800
801 if (feedBackMode === 'retry') {
802 $checkedInputs.each(function () {
803 var $input = $(this);
804
805 var $type = $input.attr('type');
806 if ($type === 'radio' || $type === 'checkbox') {
807 var isTrue = quiz_answers.indexOf($input.val())>-1; // $input.attr('data-is-correct') == '1';
808 if ( !isTrue) {
809 if ($input.prop("checked")) {
810 $input.closest('.quiz-answer-input-bottom').addClass('wrong-answer').append(`<span class="wrong-right-text"><i class="tutor-icon-line-cross"></i> ${__('Incorrect, Please try again', 'tutor')}</span>`);
811 }
812 validatedTrue = false;
813 }
814 }
815 });
816
817 $inputs.each(function () {
818 var $input = $(this);
819 var $type = $input.attr('type');
820 if ($type === 'checkbox') {
821 var isTrue = quiz_answers.indexOf($input.val())>-1; // $input.attr('data-is-correct') == '1';
822 var checked = $input.is(':checked');
823
824 if (isTrue && !checked) {
825 $question_wrap.find('.answer-help-block').html(`<p style="color: #dc3545">${__('More answer for this question is required', 'tutor')}</p>`);
826 validatedTrue = false;
827 }
828 }
829 });
830
831 } else if (feedBackMode === 'reveal') {
832 $checkedInputs.each(function () {
833 var $input = $(this);
834 var isTrue = quiz_answers.indexOf($input.val())>-1; // $input.attr('data-is-correct') == '1';
835 if (!isTrue) {
836 validatedTrue = false;
837 }
838 });
839
840 $inputs.each(function () {
841 var $input = $(this);
842
843 var $type = $input.attr('type');
844 if ($type === 'radio' || $type === 'checkbox') {
845 var isTrue = quiz_answers.indexOf($input.val())>-1; // $input.attr('data-is-correct') == '1';
846 var checked = $input.is(':checked');
847
848 if (isTrue) {
849 $input.closest('.quiz-answer-input-bottom').addClass('right-answer').append(`<span class="wrong-right-text"><i class="tutor-icon-checkbox-pen-outline"></i>${__('Correct Answer', 'tutor')}</span>`);
850 } else {
851 if ($input.prop("checked")) {
852 $input.closest('.quiz-answer-input-bottom').addClass('wrong-answer');
853 }
854 }
855
856 if (isTrue && !checked) {
857 validatedTrue = false;
858 }
859 }
860 });
861 }
862
863 if (validatedTrue) {
864 goNext = true;
865 }
866
867 return goNext;
868 }
869
870
871 /**
872 * Add to cart in guest mode, show login form
873 *
874 * @since v.1.0.4
875 */
876
877 $(document).on('submit click', '.cart-required-login, .cart-required-login a, .cart-required-login form', function (e) {
878 e.preventDefault();
879
880 var login_url = $(this).data('login_page_url');
881 login_url ? window.location.assign(login_url) : $('.tutor-cart-box-login-form').fadeIn(100);
882 });
883
884 $('.tutor-popup-form-close, .login-overlay-close').on('click', function () {
885 $('.tutor-cart-box-login-form').fadeOut(100);
886 });
887
888 $(document).on('keyup', function (e) {
889 if (e.keyCode === 27) {
890 $('.tutor-frontend-modal').hide();
891 $('.tutor-cart-box-login-form').fadeOut(100);
892 }
893 });
894 /**
895 * Share Link enable
896 *
897 * @since v.1.0.4
898 */
899 if ($.fn.ShareLink) {
900 var $social_share_wrap = $('.tutor-social-share-wrap');
901 if ($social_share_wrap.length) {
902 var share_config = JSON.parse($social_share_wrap.attr('data-social-share-config'));
903
904 $('.tutor_share').ShareLink({
905 title: share_config.title,
906 text: share_config.text,
907 image: share_config.image,
908 class_prefix: 's_',
909 width: 640,
910 height: 480,
911 });
912 }
913 }
914
915 /**
916 * Datepicker initiate
917 *
918 * @since v.1.1.2
919 */
920 if (jQuery.datepicker) {
921 $(".tutor_report_datepicker").datepicker({ "dateFormat": 'yy-mm-dd' });
922 }
923
924
925 /**
926 * Withdraw Form Tab/Toggle
927 *
928 * @since v.1.1.2
929 */
930
931 $(".withdraw-method-select-input").on('change', function (e) {
932 var $that = $(this);
933 $('.withdraw-method-form').hide();
934 $('#withdraw-method-form-' + $that.closest('.withdraw-method-select').attr('data-withdraw-method')).show();
935 });
936
937 $('.withdraw-method-select-input').each(function () {
938 var $that = $(this);
939 if ($that.is(":checked")) {
940 $('.withdraw-method-form').hide();
941 $('#withdraw-method-form-' + $that.closest('.withdraw-method-select').attr('data-withdraw-method')).show();
942 }
943 });
944
945
946
947 /**
948 * Setting account for withdraw earning
949 *
950 * @since v.1.2.0
951 */
952 $(document).on('submit', '#tutor-withdraw-account-set-form', function (e) {
953 e.preventDefault();
954
955 var $form = $(this);
956 var $btn = $form.find('.tutor_set_withdraw_account_btn');
957 var data = $form.serializeObject();
958
959 $.ajax({
960 url: _tutorobject.ajaxurl,
961 type: 'POST',
962 data: data,
963 beforeSend: function () {
964 $form.find('.tutor-success-msg').remove();
965 $btn.addClass('updating-icon');
966 },
967 success: function (data) {
968 if (data.success) {
969 var successMsg = '<div class="tutor-success-msg" style="display: none;"><i class="tutor-icon-mark"></i> ' + data.data.msg + ' </div>';
970 $btn.closest('.withdraw-account-save-btn-wrap').append(successMsg);
971 if ($form.find('.tutor-success-msg').length) {
972 $form.find('.tutor-success-msg').slideDown();
973 }
974 setTimeout(function () {
975 $form.find('.tutor-success-msg').slideUp();
976 }, 5000)
977 }
978 },
979 complete: function () {
980 $btn.removeClass('updating-icon');
981 }
982 });
983 });
984
985 /**
986 * Make Withdraw Form
987 *
988 * @since v.1.2.0
989 */
990
991 $(document).on('click', 'a.open-withdraw-form-btn, .close-withdraw-form-btn', function (e) {
992 e.preventDefault();
993
994 if($(this).data('reload')=='yes'){
995 window.location.reload();
996 return;
997 }
998
999 $('.tutor-earning-withdraw-form-wrap').toggle().find('[name="tutor_withdraw_amount"]').val('');
1000 $('.tutor-withdrawal-pop-up-success').hide().next().show();
1001 $('html, body').css('overflow', ($('.tutor-earning-withdraw-form-wrap').is(':visible') ? 'hidden' : 'auto'));
1002 });
1003
1004 $(document).on('submit', '#tutor-earning-withdraw-form', function (e) {
1005 e.preventDefault();
1006
1007 var $form = $(this);
1008 var $btn = $('#tutor-earning-withdraw-btn');
1009 var $responseDiv = $('.tutor-withdraw-form-response');
1010 var data = $form.serializeObject();
1011
1012 $.ajax({
1013 url: _tutorobject.ajaxurl,
1014 type: 'POST',
1015 data: data,
1016 beforeSend: function () {
1017 $form.find('.tutor-success-msg').remove();
1018 $btn.addClass('updating-icon');
1019 },
1020 success: function (data) {
1021 var Msg;
1022 if (data.success) {
1023
1024 if (data.data.available_balance !== 'undefined') {
1025 $('.withdraw-balance-col .available_balance').html(data.data.available_balance);
1026 }
1027
1028 $('.tutor-withdrawal-pop-up-success').show().next().hide();
1029
1030 } else {
1031 Msg = '<div class="tutor-error-msg inline-image-text is-inline-block">\
1032 <img src="'+window._tutorobject.tutor_url+'assets/images/icon-cross.svg"/> \
1033 <div>\
1034 <b>Error</b><br/>\
1035 <span>'+ data.data.msg + '</span>\
1036 </div>\
1037 </div>';
1038
1039 $responseDiv.html(Msg);
1040 setTimeout(function () {
1041 $responseDiv.html('');
1042 }, 5000)
1043 }
1044 },
1045 complete: function () {
1046 $btn.removeClass('updating-icon');
1047 }
1048 });
1049 });
1050
1051 var frontEndModal = $('.tutor-frontend-modal');
1052 frontEndModal.each(function () {
1053 var modal = $(this),
1054 action = $(this).data('popup-rel');
1055 $('[href="' + action + '"]').on('click', function (e) {
1056 modal.fadeIn();
1057 e.preventDefault();
1058 });
1059 });
1060 $(document).on('click', '.tm-close, .tutor-frontend-modal-overlay, .tutor-modal-btn-cancel', function () {
1061 frontEndModal.fadeOut();
1062 });
1063
1064 /**
1065 * Delete Course
1066 */
1067 $(document).on('click', '.tutor-dashboard-element-delete-btn', function (e) {
1068 e.preventDefault();
1069 var element_id = $(this).attr('data-id');
1070 $('#tutor-dashboard-delete-element-id').val(element_id);
1071 });
1072 $(document).on('submit', '#tutor-dashboard-delete-element-form', function (e) {
1073 e.preventDefault();
1074
1075 var element_id = $('#tutor-dashboard-delete-element-id').val();
1076 var $btn = $('.tutor-modal-element-delete-btn');
1077 var data = $(this).serializeObject();
1078
1079 $.ajax({
1080 url: _tutorobject.ajaxurl,
1081 type: 'POST',
1082 data: data,
1083 beforeSend: function () {
1084 $btn.addClass('updating-icon');
1085 },
1086 success: function (res) {
1087 if (res.success) {
1088 $('#tutor-dashboard-' + res.data.element + '-' + element_id).remove();
1089 }
1090 },
1091 complete: function () {
1092 $btn.removeClass('updating-icon');
1093 $('.tutor-frontend-modal').hide();
1094 }
1095 });
1096 });
1097
1098 /**
1099 * Frontend Profile
1100 */
1101
1102 if (!$('#tutor_profile_photo_id').val()) {
1103 $('.tutor-profile-photo-delete-btn').hide();
1104 }
1105
1106 $(document).on('click', '.tutor-profile-photo-delete-btn', function () {
1107 $('.tutor-profile-photo-upload-wrap').find('img').attr('src', _tutorobject.placeholder_img_src);
1108 $('#tutor_profile_photo_id').val('');
1109 $('.tutor-profile-photo-delete-btn').hide();
1110
1111 $.ajax({
1112 url: _tutorobject.ajaxurl,
1113 type: 'POST',
1114 data: { 'action': 'tutor_profile_photo_remove' },
1115 });
1116
1117 return false;
1118 });
1119
1120 /**
1121 * Assignment
1122 *
1123 * @since v.1.3.3
1124 */
1125 $(document).on('submit', '#tutor_assignment_start_form', function (e) {
1126 e.preventDefault();
1127
1128 var $that = $(this);
1129 var form_data = $that.serializeObject();
1130 form_data.action = 'tutor_start_assignment';
1131
1132 $.ajax({
1133 url: _tutorobject.ajaxurl,
1134 type: 'POST',
1135 data: form_data,
1136 beforeSend: function () {
1137 $('#tutor_assignment_start_btn').addClass('updating-icon');
1138 },
1139 success: function (data) {
1140 if (data.success) {
1141 location.reload();
1142 }
1143 },
1144 complete: function () {
1145 $('#tutor_assignment_start_btn').removeClass('updating-icon');
1146 }
1147 });
1148 });
1149
1150 /**
1151 * Assignment answer validation
1152 */
1153 $(document).on('submit', '#tutor_assignment_submit_form', function (e) {
1154 var assignment_answer = $('textarea[name="assignment_answer"]').val();
1155 if (assignment_answer.trim().length < 1) {
1156 $('#form_validation_response').html('<div class="tutor-error-msg">' + __('Assignment answer can not be empty', 'tutor') + '</div>');
1157 e.preventDefault();
1158 }
1159 });
1160
1161 /**
1162 * Course builder video
1163 * @since v.1.3.4
1164 */
1165
1166
1167 $(document).on('click', '.video_source_upload_wrap_html5 .video_upload_btn', function (event) {
1168 event.preventDefault();
1169
1170 var $that = $(this);
1171 var frame;
1172 // If the media frame already exists, reopen it.
1173 if (frame) {
1174 frame.open();
1175 return;
1176 }
1177 frame = wp.media({
1178 title: 'Select or Upload Media Of Your Chosen Persuasion',
1179 button: {
1180 text: 'Use this media'
1181 },
1182 library: { type: 'video' },
1183 multiple: false // Set to true to allow multiple files to be selected
1184 });
1185 frame.on('select', function () {
1186 // Get media attachment details from the frame state
1187 var attachment = frame.state().get('selection').first().toJSON();
1188 $that.closest('.video_source_upload_wrap_html5').find('span.video_media_id').data('video_url', attachment.url).text(attachment.id).trigger('paste').closest('p').show();
1189 $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id);
1190 });
1191 frame.open();
1192 });
1193
1194
1195 /**
1196 * Course and lesson sorting
1197 */
1198
1199 function enable_sorting_topic_lesson() {
1200 if (jQuery().sortable) {
1201 $(".course-contents").sortable({
1202 handle: ".course-move-handle",
1203 start: function (e, ui) {
1204 ui.placeholder.css('visibility', 'visible');
1205 },
1206 stop: function (e, ui) {
1207 tutor_sorting_topics_and_lesson();
1208 },
1209 });
1210 $(".tutor-lessons:not(.drop-lessons)").sortable({
1211 connectWith: ".tutor-lessons",
1212 items: "div.course-content-item",
1213 start: function (e, ui) {
1214 ui.placeholder.css('visibility', 'visible');
1215 },
1216 stop: function (e, ui) {
1217 tutor_sorting_topics_and_lesson();
1218 },
1219 });
1220 }
1221 }
1222 enable_sorting_topic_lesson();
1223 function tutor_sorting_topics_and_lesson() {
1224 var topics = {};
1225 $('.tutor-topics-wrap').each(function (index, item) {
1226 var $topic = $(this);
1227 var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10);
1228 var lessons = {};
1229
1230 $topic.find('.course-content-item').each(function (lessonIndex, lessonItem) {
1231 var $lesson = $(this);
1232 var lesson_id = parseInt($lesson.attr('id').match(/\d+/)[0], 10);
1233
1234 lessons[lessonIndex] = lesson_id;
1235 });
1236 topics[index] = { 'topic_id': topics_id, 'lesson_ids': lessons };
1237 });
1238 $('#tutor_topics_lessons_sorting').val(JSON.stringify(topics));
1239 }
1240
1241 /**
1242 * Lesson Update or Create Modal
1243 */
1244 $(document).on('click', '.update_lesson_modal_btn', function (event) {
1245 event.preventDefault();
1246
1247 var $that = $(this);
1248 var content;
1249 var editor = tinyMCE.get('tutor_lesson_modal_editor');
1250 if (editor) {
1251 content = editor.getContent();
1252 } else {
1253 content = $('#' + inputid).val();
1254 }
1255
1256 var form_data = $(this).closest('form').serializeObject();
1257 form_data.lesson_content = content;
1258
1259 $.ajax({
1260 url: ajaxurl,
1261 type: 'POST',
1262 data: form_data,
1263 beforeSend: function () {
1264 $that.addClass('tutor-updating-message');
1265 },
1266 success: function (data) {
1267 if (data.success) {
1268 $('#tutor-course-content-wrap').html(data.data.course_contents);
1269 enable_sorting_topic_lesson();
1270
1271 //Close the modal
1272 $('.tutor-lesson-modal-wrap').removeClass('show');
1273
1274 tutor_toast(__('Done', 'tutor'), $that.data('toast_success_message'), 'success');
1275 }
1276 else {
1277 tutor_toast(__('Failed', 'tutor'), __('Lesson Update Failed', 'tutor'), 'error');
1278 }
1279 },
1280 error: function() {
1281 tutor_toast(__('Failed', 'tutor'), __('Lesson Update Failed', 'tutor'), 'error');
1282 },
1283 complete: function () {
1284 $that.removeClass('tutor-updating-message');
1285 }
1286 });
1287 });
1288
1289 /**
1290 * END: Tutor Course builder JS
1291 */
1292
1293 /**
1294 * Attachment in forntend course builder
1295 * @since v.1.3.4
1296 */
1297 $(document).on('click', 'a.tutor-delete-attachment', function (e) {
1298 e.preventDefault();
1299 $(this).closest('.tutor-added-attachment').remove();
1300 });
1301 $(document).on('click', '.tutorUploadAttachmentBtn', function (e) {
1302 e.preventDefault();
1303
1304 var $that = $(this);
1305 var frame;
1306 if (frame) {
1307 frame.open();
1308 return;
1309 }
1310 frame = wp.media({
1311 title: 'Select or Upload Media Of Your Chosen Persuasion',
1312 button: {
1313 text: 'Use this media'
1314 },
1315 multiple: true // Set to true to allow multiple files to be selected
1316 });
1317 frame.on('select', function () {
1318 var attachments = frame.state().get('selection').toJSON();
1319 if (attachments.length) {
1320 for (var i = 0; i < attachments.length; i++) {
1321 var attachment = attachments[i];
1322
1323 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>';
1324 $that.closest('.tutor-lesson-attachments-metabox').find('.tutor-added-attachments-wrap').append(inputHtml);
1325 }
1326 }
1327 });
1328 frame.open();
1329 });
1330
1331
1332 /**
1333 * Single Assignment Upload Button
1334 * @since v.1.3.4
1335 */
1336 $('form').on('change', '.tutor-assignment-file-upload', function () {
1337 $(this).siblings("label").find('span').html($(this).val().replace(/.*(\/|\\)/, ''));
1338 });
1339
1340 /**
1341 * Lesson Sidebar Topic Toggle
1342 * @since v.1.3.4
1343 */
1344
1345 $(document).on('click', '.tutor-topics-in-single-lesson .tutor-topics-title h3, .tutor-single-lesson-topic-toggle', function (e) {
1346 var $that = $(this);
1347 var $parent = $that.closest('.tutor-topics-in-single-lesson');
1348 $parent.toggleClass('tutor-topic-active');
1349 $parent.find('.tutor-lessons-under-topic').slideToggle();
1350 });
1351
1352 $('.tutor-single-lesson-items.active').closest('.tutor-lessons-under-topic').show();
1353 $('.tutor-single-lesson-items.active').closest('.tutor-topics-in-single-lesson').addClass('tutor-topic-active');
1354 $('.tutor-course-lesson.active').closest('.tutor-lessons-under-topic').show();
1355
1356
1357 /**
1358 * Assignments Addons
1359 * @backend Support
1360 *
1361 */
1362
1363
1364 /**
1365 * Tutor Assignments JS
1366 * @since v.1.3.3
1367 */
1368 $(document).on('click', '.tutor-create-assignments-btn', function (e) {
1369 e.preventDefault();
1370
1371 var $that = $(this);
1372 var topic_id = $(this).attr('data-topic-id');
1373 var course_id = $('#post_ID').val();
1374
1375 $.ajax({
1376 url: ajaxurl,
1377 type: 'POST',
1378 data: { topic_id: topic_id, course_id: course_id, action: 'tutor_load_assignments_builder_modal' },
1379 beforeSend: function () {
1380 $that.addClass('tutor-updating-message');
1381 },
1382 success: function (data) {
1383 $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output);
1384 $('.tutor-lesson-modal-wrap').attr('data-topic-id', topic_id).addClass('show');
1385
1386 $(document).trigger('assignment_modal_loaded', { topic_id: topic_id, course_id: course_id });
1387
1388 tinymce.init(tinyMCEPreInit.mceInit.course_description);
1389 tinymce.execCommand('mceRemoveEditor', false, 'tutor_assignments_modal_editor');
1390 tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor");
1391 },
1392 complete: function () {
1393 quicktags({ id: "tutor_assignments_modal_editor" });
1394 $that.removeClass('tutor-updating-message');
1395 }
1396 });
1397 });
1398
1399 $(document).on('click', '.open-tutor-assignment-modal', function (e) {
1400 e.preventDefault();
1401
1402 var $that = $(this);
1403 var assignment_id = $that.attr('data-assignment-id');
1404 var topic_id = $that.attr('data-topic-id');
1405 var course_id = $('#post_ID').val();
1406
1407 $.ajax({
1408 url: ajaxurl,
1409 type: 'POST',
1410 data: { assignment_id: assignment_id, topic_id: topic_id, course_id: course_id, action: 'tutor_load_assignments_builder_modal' },
1411 beforeSend: function () {
1412 $that.addClass('tutor-updating-message');
1413 },
1414 success: function (data) {
1415 $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output);
1416 $('.tutor-lesson-modal-wrap').attr({ 'data-assignment-id': assignment_id, 'data-topic-id': topic_id }).addClass('show');
1417
1418 $(document).trigger('assignment_modal_loaded', { assignment_id: assignment_id, topic_id: topic_id, course_id: course_id });
1419
1420 tinymce.init(tinyMCEPreInit.mceInit.course_description);
1421 tinymce.execCommand('mceRemoveEditor', false, 'tutor_assignments_modal_editor');
1422 tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor");
1423 },
1424 complete: function () {
1425 quicktags({ id: "tutor_assignments_modal_editor" });
1426 $that.removeClass('tutor-updating-message');
1427 }
1428 });
1429 });
1430
1431 /**
1432 * Update Assignment Data
1433 */
1434 $(document).on('click', '.update_assignment_modal_btn', function (event) {
1435 event.preventDefault();
1436
1437 var $that = $(this);
1438 var content;
1439 var editor = tinyMCE.get('tutor_assignments_modal_editor');
1440 if (editor) {
1441 content = editor.getContent();
1442 } else {
1443 content = $('#' + inputid).val();
1444 }
1445
1446 var form_data = $(this).closest('form').serializeObject();
1447 form_data.assignment_content = content;
1448
1449 $.ajax({
1450 url: ajaxurl,
1451 type: 'POST',
1452 data: form_data,
1453 beforeSend: function () {
1454 $that.addClass('tutor-updating-message');
1455 },
1456 success: function (data) {
1457 if (data.success) {
1458 $('#tutor-course-content-wrap').html(data.data.course_contents);
1459 enable_sorting_topic_lesson();
1460
1461 //Close the modal
1462 $('.tutor-lesson-modal-wrap').removeClass('show');
1463
1464 tutor_toast(__('Done', 'tutor'), $that.data('toast_success_message'), 'success');
1465 }
1466 else {
1467 tutor_toast(__('Failed', 'tutor'), __('Assignment Update Failed', 'tutor'), 'error');
1468 }
1469 },
1470 error: function() {
1471 tutor_toast(__('Failed', 'tutor'), __('Assignment Update Failed', 'tutor'), 'error');
1472 },
1473 complete: function () {
1474 $that.removeClass('tutor-updating-message');
1475 }
1476 });
1477 });
1478
1479 /**
1480 * Add Assignment
1481 */
1482 $(document).on('click', '.add-assignment-attachments', function (event) {
1483 event.preventDefault();
1484
1485 var $that = $(this);
1486 var frame;
1487 // If the media frame already exists, reopen it.
1488 if (frame) {
1489 frame.open();
1490 return;
1491 }
1492
1493 // Create a new media frame
1494 frame = wp.media({
1495 title: 'Select or Upload Media Of Your Chosen Persuasion',
1496 button: {
1497 text: 'Use this media'
1498 },
1499 multiple: false // Set to true to allow multiple files to be selected
1500 });
1501
1502 // When an image is selected in the media frame...
1503 frame.on('select', function () {
1504 // Get media attachment details from the frame state
1505 var attachment = frame.state().get('selection').first().toJSON();
1506
1507 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>';
1508
1509 $('#assignment-attached-file').append(field_markup);
1510 $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id);
1511 });
1512 // Finally, open the modal on click
1513 frame.open();
1514 });
1515
1516 $(document).on('click', '.remove-assignment-attachment-a', function (event) {
1517 event.preventDefault();
1518 $(this).closest('.tutor-individual-attachment-file').remove();
1519 });
1520
1521
1522 /**
1523 *
1524 * @type {jQuery}
1525 *
1526 * Course builder auto draft save
1527 *
1528 * @since v.1.3.4
1529 */
1530 var tutor_course_builder = $('input[name="tutor_action"]').val();
1531 if (tutor_course_builder === 'tutor_add_course_builder') {
1532 setInterval(auto_draft_save_course_builder, 30000);
1533 }
1534
1535 function auto_draft_save_course_builder() {
1536
1537 var form_data = $('form#tutor-frontend-course-builder').serializeObject();
1538 form_data.tutor_ajax_action = 'tutor_course_builder_draft_save';
1539
1540 $.ajax({
1541 //url : _tutorobject.ajaxurl,
1542 type: 'POST',
1543 data: form_data,
1544 beforeSend: function () {
1545 $('.tutor-dashboard-builder-draft-btn span').text('Saving...');
1546 },
1547 success: function (data) {
1548
1549 },
1550 complete: function () {
1551 $('.tutor-dashboard-builder-draft-btn span').text('Save');
1552 }
1553 });
1554 }
1555
1556 /**
1557 *
1558 * @type {jQuery}
1559 *
1560 * Course builder section toggle
1561 *
1562 * @since v.1.3.5
1563 */
1564
1565 $('.tutor-course-builder-section-title').on('click', function () {
1566 if ($(this).find('i').hasClass("tutor-icon-up")) {
1567 $(this).find('i').removeClass('tutor-icon-up').addClass('tutor-icon-down');
1568 } else {
1569 $(this).find('i').removeClass('tutor-icon-down').addClass('tutor-icon-up');
1570 }
1571 $(this).next('div').slideToggle();
1572 });
1573
1574 /**
1575 * Open Tutor Modal to edit review
1576 * @since v.1.4.0
1577 */
1578 $(document).on('click', '.open-tutor-edit-review-modal', function (e) {
1579 e.preventDefault();
1580
1581 var $that = $(this);
1582 var review_id = $that.attr('data-review-id');
1583
1584 var nonce_key = _tutorobject.nonce_key;
1585
1586 var json_data = { review_id: review_id, action: 'tutor_load_edit_review_modal' };
1587 json_data[nonce_key] = _tutorobject[nonce_key];
1588
1589 $.ajax({
1590 url: _tutorobject.ajaxurl,
1591 type: 'POST',
1592 data: json_data,
1593 beforeSend: function () {
1594 $that.addClass('tutor-updating-message');
1595 },
1596 success: function (data) {
1597 if (typeof data.data !== 'undefined') {
1598 $('.tutor-edit-review-modal-wrap .modal-container').html(data.data.output);
1599 $('.tutor-edit-review-modal-wrap').attr('data-review-id', review_id).addClass('show');
1600 }
1601 },
1602 complete: function () {
1603 $that.removeClass('tutor-updating-message');
1604 }
1605 });
1606 });
1607
1608 /**
1609 * Update the rating
1610 * @since v.1.4.0
1611 */
1612 $(document).on('submit', '#tutor_update_review_form', function (e) {
1613 e.preventDefault();
1614
1615 var $that = $(this);
1616 var review_id = $that.closest('.tutor-edit-review-modal-wrap ').attr('data-review-id');
1617
1618 var nonce_key = _tutorobject.nonce_key;
1619
1620 var rating = $that.find('input[name="tutor_rating_gen_input"]').val();
1621 var review = $that.find('textarea[name="review"]').val();
1622 review = review.trim();
1623
1624 var json_data = { review_id: review_id, rating: rating, review: review, action: 'tutor_update_review_modal' };
1625 json_data[nonce_key] = _tutorobject[nonce_key];
1626
1627 $.ajax({
1628 url: _tutorobject.ajaxurl,
1629 type: 'POST',
1630 data: json_data,
1631 beforeSend: function () {
1632 $that.find('button[type="submit"]').addClass('tutor-updating-message');
1633 },
1634 success: function (data) {
1635 if (data.success) {
1636 //Close the modal
1637 $('.tutor-edit-review-modal-wrap').removeClass('show');
1638 location.reload(true);
1639 }
1640 },
1641 complete: function () {
1642 $that.find('button[type="submit"]').removeClass('tutor-updating-message');
1643 }
1644 });
1645 });
1646
1647 /**
1648 * Profile photo upload
1649 * @since v.1.4.5
1650 */
1651
1652 $(document).on('click', '#tutor_profile_photo_button', function (e) {
1653 e.preventDefault();
1654
1655 $('#tutor_profile_photo_file').trigger('click');
1656 });
1657
1658 $(document).on('change', '#tutor_profile_photo_file', function (event) {
1659 event.preventDefault();
1660
1661 var $file = this;
1662 if ($file.files && $file.files[0]) {
1663 var reader = new FileReader();
1664 reader.onload = function (e) {
1665 $('.tutor-profile-photo-upload-wrap').find('img').attr('src', e.target.result);
1666 }
1667 reader.readAsDataURL($file.files[0]);
1668 }
1669 });
1670
1671 /**
1672 * Addon, Tutor BuddyPress
1673 * Retrieve MetaInformation on BuddyPress message system
1674 * @for TutorLMS Pro
1675 * @since v.1.4.8
1676 */
1677
1678 $(document).on('click', '.thread-content .subject', function (e) {
1679 var $btn = $(this);
1680
1681 var thread_id = parseInt($btn.closest('.thread-content').attr('data-thread-id'));
1682
1683 var nonce_key = _tutorobject.nonce_key;
1684 var json_data = { thread_id: thread_id, action: 'tutor_bp_retrieve_user_records_for_thread' };
1685 json_data[nonce_key] = _tutorobject[nonce_key];
1686
1687 $.ajax({
1688 type: 'POST',
1689 url: ajaxurl,
1690 data: json_data,
1691 beforeSend: function () {
1692 $('#tutor-bp-thread-wrap').html('');
1693 },
1694 success: function (data) {
1695 if (data.success) {
1696 $('#tutor-bp-thread-wrap').html(data.data.thread_head_html);
1697 tutor_bp_setting_enrolled_courses_list();
1698 }
1699 }
1700 });
1701
1702 });
1703
1704
1705 function tutor_bp_setting_enrolled_courses_list() {
1706 $('ul.tutor-bp-enrolled-course-list').each(function () {
1707 var $that = $(this);
1708 var $li = $that.find(' > li');
1709 var itemShow = 3;
1710
1711 if ($li.length > itemShow) {
1712 var plusCourseCount = $li.length - itemShow;
1713 $li.each(function (liIndex, liItem) {
1714 var $liItem = $(this);
1715
1716 if (liIndex >= itemShow) {
1717 $liItem.hide();
1718 }
1719 });
1720
1721 var infoHtml = '<a href="javascript:;" class="tutor_bp_plus_courses"><strong>+' + plusCourseCount + ' More </strong></a> Courses';
1722 $that.closest('.tutor-bp-enrolled-courses-wrap').find('.thread-participant-enrolled-info').html(infoHtml);
1723 }
1724
1725 $that.show();
1726 });
1727 }
1728 tutor_bp_setting_enrolled_courses_list();
1729
1730 $(document).on('click', 'a.tutor_bp_plus_courses', function (e) {
1731 e.preventDefault();
1732
1733 var $btn = $(this);
1734 $btn.closest('.tutor-bp-enrolled-courses-wrap').find('.tutor-bp-enrolled-course-list li').show();
1735 $btn.closest('.thread-participant-enrolled-info').html('');
1736 });
1737
1738
1739 /**
1740 * Addon, Tutor Certificate
1741 * Certificate dropdown content and copy link
1742 * @for TutorLMS Pro
1743 * @since v.1.5.1
1744 */
1745 //$(document).on('click', '.tutor-dropbtn', function (e) {
1746 $('.tutor-dropbtn').click(function(){
1747
1748 var $content = $(this).parent().find(".tutor-dropdown-content");
1749 $content.slideToggle(100);
1750 })
1751
1752
1753 //$(document).on('click', '.tutor-copy-link', function (e) {
1754 $('.tutor-copy-link').click(function (e) {
1755 var $btn = $(this);
1756 var copy = '<i class="tutor-icon-copy"></i> Copy Link';
1757 var copied = '<i class="tutor-icon-mark"></i> Copied';
1758 var dummy = document.createElement('input'),
1759 text = window.location.href;
1760 document.body.appendChild(dummy);
1761 dummy.value = text;
1762 dummy.select();
1763 document.execCommand('copy');
1764 document.body.removeChild(dummy);
1765 $btn.html(copied);
1766 setTimeout(function () {
1767 $btn.html(copy);
1768 }, 2500);
1769 });
1770
1771 $(document).on('click', function (e) {
1772 var container = $(".tutor-dropdown");
1773 var $content = container.find('.tutor-dropdown-content');
1774 // if the target of the click isn't the container nor a descendant of the container
1775 if (!container.is(e.target) && container.has(e.target).length === 0) {
1776 $content.slideUp(100);
1777 }
1778 });
1779
1780
1781 /**
1782 * Tutor ajax login
1783 *
1784 * @since v.1.6.3
1785 */
1786 $(document).on('submit', '.tutor-login-form-wrap #loginform', function (e) {
1787 e.preventDefault();
1788
1789 var $that = $(this);
1790 var $form_wrapper = $('.tutor-login-form-wrap');
1791
1792 var form_data = $that.serializeObject();
1793 form_data.action = 'tutor_user_login';
1794
1795 $.ajax({
1796 url: _tutorobject.ajaxurl,
1797 type: 'POST',
1798 data: form_data,
1799 success: function (response) {
1800 if (response.success) {
1801 location.assign(response.data.redirect);
1802 location.reload();
1803 } else {
1804 if ($form_wrapper.find('.tutor-alert').length) {
1805 $form_wrapper.find('.tutor-alert').html(response.data);
1806 } else {
1807 $form_wrapper.prepend('<div class="tutor-alert tutor-alert-warning">' + response.data + '</div>');
1808 }
1809 }
1810 },
1811 });
1812 });
1813
1814 /**
1815 * Show hide is course public checkbox (frontend dashboard editor)
1816 *
1817 * @since v.1.7.2
1818 */
1819 var price_type = $('.tutor-frontend-builder-course-price [name="tutor_course_price_type"]');
1820 if(price_type.length==0){
1821 $('#_tutor_is_course_public_meta_checkbox').show();
1822 }
1823 else{
1824 price_type.change(function(){
1825 if($(this).prop('checked')){
1826 var method = $(this).val()=='paid' ? 'hide' : 'show';
1827 $('#_tutor_is_course_public_meta_checkbox')[method]();
1828 }
1829 }).trigger('change');
1830 }
1831
1832 /**
1833 * Withdrawal page tooltip
1834 *
1835 * @since v.1.7.4
1836 */
1837 // Fully accessible tooltip jQuery plugin with delegation.
1838 // Ideal for view containers that may re-render content.
1839 (function ($) {
1840 $.fn.tutor_tooltip = function () {
1841 this
1842
1843 // Delegate to tooltip, Hide if tooltip receives mouse or is clicked (tooltip may stick if parent has focus)
1844 .on('mouseenter click', '.tooltip', function (e) {
1845 e.stopPropagation();
1846 $(this).removeClass('isVisible');
1847 })
1848 // Delegate to parent of tooltip, Show tooltip if parent receives mouse or focus
1849 .on('mouseenter focus', ':has(>.tooltip)', function (e) {
1850 if (!$(this).prop('disabled')) { // IE 8 fix to prevent tooltip on `disabled` elements
1851 $(this)
1852 .find('.tooltip')
1853 .addClass('isVisible');
1854 }
1855 })
1856 // Delegate to parent of tooltip, Hide tooltip if parent loses mouse or focus
1857 .on('mouseleave blur keydown', ':has(>.tooltip)', function (e) {
1858 if (e.type === 'keydown') {
1859 if(e.which === 27) {
1860 $(this)
1861 .find('.tooltip')
1862 .removeClass('isVisible');
1863 }
1864 } else {
1865 $(this)
1866 .find('.tooltip')
1867 .removeClass('isVisible');
1868 }
1869 });
1870 return this;
1871 };
1872 }(jQuery));
1873
1874 // Bind event listener to container element
1875 jQuery('.tutor-tooltip-inside').tutor_tooltip();
1876
1877
1878
1879 /**
1880 * Manage course filter
1881 *
1882 * @since v.1.7.2
1883 */
1884 var filter_container = $('.tutor-course-filter-container form');
1885 var loop_container = $('.tutor-course-filter-loop-container');
1886 var filter_modifier = {};
1887
1888 // Sidebar checkbox value change
1889 filter_container.on('submit', function(e) {
1890 e.preventDefault();
1891 })
1892 .find('input').change(function(e){
1893
1894 var filter_criteria = Object.assign( filter_container.serializeObject(), filter_modifier);
1895 filter_criteria.action = 'tutor_course_filter_ajax';
1896
1897 loop_container.html('<center><img src="'+window._tutorobject.loading_icon_url+'"/></center>');
1898 $(this).closest('form').find('.tutor-clear-all-filter').show();
1899
1900 $.ajax({
1901 url:window._tutorobject.ajaxurl,
1902 type:'POST',
1903 data:filter_criteria,
1904 success:function(r) {
1905 loop_container.html(r).find('.tutor-pagination-wrap a').each(function(){
1906 $(this).attr('data-href', $(this).attr('href')).attr('href', '#');
1907 });
1908 }
1909 })
1910 });
1911
1912 // Alter pagination
1913 loop_container.on('click', '.tutor-pagination-wrap a', function(e){
1914 var url = $(this).data('href') || $(this).attr('href');
1915
1916 if(url){
1917 url = new URL(url);
1918 var page = url.searchParams.get("paged");
1919
1920 if(page){
1921 e.preventDefault();
1922 filter_modifier.page = page;
1923 filter_container.find('input:first').trigger('change');
1924 }
1925 }
1926 });
1927
1928 // Alter sort filter
1929 loop_container.on('change', 'select[name="tutor_course_filter"]', function() {
1930 filter_modifier.tutor_course_filter = $(this).val();
1931 filter_container.find('input:first').trigger('change');
1932 });
1933
1934 // Refresh page after coming back to course archive page from cart
1935 var archive_loop = $('.tutor-course-loop');
1936 if(archive_loop.length>0){
1937 window.sessionStorage.getItem('tutor_refresh_archive')==='yes' ? window.location.reload() : 0;
1938 window.sessionStorage.removeItem('tutor_refresh_archive');
1939 archive_loop.on('click', '.tutor-loop-cart-btn-wrap', function(){
1940 window.sessionStorage.setItem('tutor_refresh_archive', 'yes');
1941 });
1942 }
1943
1944 /**
1945 * Profile Photo and Cover Photo editor
1946 *
1947 * @since v.1.7.5
1948 */
1949 var PhotoEditor=function(photo_editor){
1950
1951 this.dialogue_box = photo_editor.find('#tutor_photo_dialogue_box');
1952
1953
1954 this.open_dialogue_box = function(name){
1955 this.dialogue_box.attr('name', name);
1956 this.dialogue_box.trigger('click');
1957 }
1958
1959 this.validate_image = function(file){
1960 return true;
1961 }
1962
1963 this.upload_selected_image = function(name, file){
1964 if(!file || !this.validate_image(file)){
1965 return;
1966 }
1967
1968 var nonce = tutor_get_nonce_data(true);
1969
1970 var context = this;
1971 context.toggle_loader(name, true);
1972
1973 // Prepare payload to upload
1974 var form_data = new FormData();
1975 form_data.append('action', 'tutor_user_photo_upload');
1976 form_data.append('photo_type', name);
1977 form_data.append('photo_file', file, file.name);
1978 form_data.append(nonce.key, nonce.value);
1979
1980 $.ajax({
1981 url:window._tutorobject.ajaxurl,
1982 data:form_data,
1983 type:'POST',
1984 processData: false,
1985 contentType: false,
1986 error:context.error_alert,
1987 complete:function(){
1988 context.toggle_loader(name, false);
1989 }
1990 })
1991 }
1992
1993 this.accept_upload_image=function(context, e){
1994 var file = e.currentTarget.files[0] || null;
1995 context.update_preview(e.currentTarget.name, file);
1996 context.upload_selected_image(e.currentTarget.name, file);
1997 $(e.currentTarget).val('');
1998 }
1999
2000 this.delete_image=function(name){
2001 var context = this;
2002 context.toggle_loader(name, true);
2003
2004 $.ajax({
2005 url:window._tutorobject.ajaxurl,
2006 data:{action:'tutor_user_photo_remove', photo_type:name},
2007 type:'POST',
2008 error:context.error_alert,
2009 complete:function(){
2010 context.toggle_loader(name, false);
2011 }
2012 });
2013 }
2014
2015 this.update_preview=function(name, file){
2016 var renderer = photo_editor.find(name=='cover_photo' ? '#tutor_cover_area' : '#tutor_profile_area');
2017
2018 if(!file){
2019 renderer.css('background-image', 'url('+renderer.data('fallback')+')');
2020 this.delete_image(name);
2021 return;
2022 }
2023
2024 var reader = new FileReader();
2025 reader.onload = function(e) {
2026 renderer.css('background-image', 'url('+e.target.result+')');
2027 }
2028
2029 reader.readAsDataURL(file);
2030 }
2031
2032 this.toggle_profile_pic_action=function(show){
2033 var method = show===undefined ? 'toggleClass' : (show ? 'addClass' : 'removeClass');
2034 photo_editor[method]('pop-up-opened');
2035 }
2036
2037 this.error_alert=function(){
2038 alert('Something Went Wrong.');
2039 }
2040
2041 this.toggle_loader = function(name, show){
2042 photo_editor.find('#tutor_photo_meta_area .loader-area').css('display', (show ? 'block' : 'none'));
2043 }
2044
2045 this.initialize = function(){
2046 var context = this;
2047
2048 this.dialogue_box.change(function(e){context.accept_upload_image(context, e)});
2049
2050 photo_editor.find('#tutor_profile_area .tutor_overlay, #tutor_pp_option>div:last-child').click(function(){context.toggle_profile_pic_action()});
2051
2052 // Upload new
2053 photo_editor.find('.tutor_cover_uploader').click(function(){context.open_dialogue_box('cover_photo')});
2054 photo_editor.find('.tutor_pp_uploader').click(function(){context.open_dialogue_box('profile_photo')});
2055
2056 // Delete existing
2057 photo_editor.find('.tutor_cover_deleter').click(function(){context.update_preview('cover_photo', null)});
2058 photo_editor.find('.tutor_pp_deleter').click(function(){context.update_preview('profile_photo', null)});
2059 }
2060 }
2061
2062 var photo_editor = $('#tutor_profile_cover_photo_editor');
2063 photo_editor.length>0 ? new PhotoEditor(photo_editor).initialize() : 0;
2064
2065
2066 /**
2067 *
2068 * Instructor list filter
2069 *
2070 * @since v.1.8.4
2071 */
2072 // Get values on course category selection
2073 $('.tutor-instructor-filter').each(function() {
2074
2075 var root = $(this);
2076 var filter_args = {};
2077 var time_out;
2078
2079 function run_instructor_filter(name, value, page_number) {
2080
2081 // Prepare http payload
2082 var result_container = root.find('.filter-result-container');
2083 var html_cache = result_container.html();
2084 var attributes = root.data();
2085 attributes.current_page = page_number || 1;
2086
2087 name ? filter_args[name] = value : filter_args = {};
2088 filter_args.attributes = attributes;
2089 filter_args.action = 'load_filtered_instructor';
2090
2091 // Show loading icon
2092 result_container.html('<div style="text-align:center"><img src="'+window._tutorobject.loading_icon_url+'"/></div>');
2093
2094 $.ajax({
2095 url: window._tutorobject.ajaxurl,
2096 data: filter_args,
2097 type: 'POST',
2098 success: function(r) {
2099 result_container.html(r);
2100 },
2101 error: function() {
2102 result_container.html(html_cache);
2103 tutor_toast('Failed', 'Request Error', 'error');
2104 }
2105 })
2106 }
2107
2108 root.on('change', '.course-category-filter [type="checkbox"]', function() {
2109
2110 var values = {};
2111
2112 $(this).closest('.course-category-filter').find('input:checked').each(function() {
2113 values[$(this).val()] = $(this).parent().text();
2114 });
2115
2116 // Show selected cat list
2117 var cat_parent = root.find('.selected-cate-list').empty();
2118 var cat_ids = Object.keys(values);
2119
2120 cat_ids.forEach(function(value) {
2121 cat_parent.append('<span>'+values[value]+' <span class="tutor-icon-line-cross" data-cat_id="'+value+'"></span></span>');
2122 });
2123
2124 cat_ids.length ? cat_parent.append('<span data-cat_id="0">Clear All</span>') : 0;
2125
2126 run_instructor_filter($(this).attr('name'), cat_ids);
2127 })
2128 .on('click', '.selected-cate-list [data-cat_id]', function() {
2129
2130 var id = $(this).data('cat_id');
2131 var inputs = root.find('.mobile-filter-popup [type="checkbox"]');
2132 id ? inputs = inputs.filter('[value="'+id+'"]') : 0;
2133
2134 inputs.prop('checked', false).trigger('change');
2135 })
2136 .on('input', '.filter-pc [name="keyword"]', function() {
2137 // Get values on search keyword change
2138
2139 var val = $(this).val();
2140
2141 time_out ? window.clearTimeout(time_out) : 0;
2142
2143 time_out = window.setTimeout(function() {
2144
2145 run_instructor_filter('keyword', val);
2146 time_out = null;
2147
2148 }, 500);
2149 })
2150 .on('click', '[data-page_number]', function(e) {
2151
2152 // On pagination click
2153 e.preventDefault();
2154
2155 run_instructor_filter(null, null, $(this).data( 'page_number' ) );
2156
2157 }).on('click', '.clear-instructor-filter', function() {
2158
2159 // Clear filter
2160 var root = $(this).closest('.tutor-instructor-filter');
2161
2162 root.find('input[type="checkbox"]').prop('checked', false);
2163
2164 root.find('[name="keyword"]').val('');
2165
2166 run_instructor_filter();
2167 })
2168 .on('click', '.mobile-filter-container i', function () {
2169 // Open mobile screen filter
2170 $(this).parent().next().addClass('is-opened');
2171 })
2172 .on('click', '.mobile-filter-popup button', function() {
2173
2174 $('.mobile-filter-popup [type="checkbox"]').trigger('change');
2175
2176 // Close mobile screen filter
2177 $(this).closest('.mobile-filter-popup').removeClass('is-opened');
2178
2179 }).on('input', '.filter-mobile [name="keyword"]', function() {
2180
2181 // Sync keyword with two screen
2182
2183 root.find('.filter-pc [name="keyword"]').val($(this).val()).trigger('input');
2184
2185 }).on('change', '.mobile-filter-popup [type="checkbox"]', function(e) {
2186
2187 if(e.originalEvent) {
2188 return;
2189 }
2190
2191 // Sync category with two screen
2192 var name = $(this).attr('name');
2193 var val = $(this).val();
2194 var checked = $(this).prop('checked');
2195
2196 root.find('.course-category-filter [name="'+name+'"]').filter('[value="'+val+'"]').prop('checked', checked).trigger('change');
2197
2198 }).on('mousedown touchstart', '.expand-instructor-filter', function(e) {
2199
2200 var window_height = $(window).height();
2201 var el = root.find('.mobile-filter-popup>div');
2202 var el_top = window_height-el.height();
2203 var plus = ((e.originalEvent.touches || [])[0] || e).clientY - el_top;
2204
2205 root.on('mousemove touchmove', function(e){
2206
2207 var y = ((e.originalEvent.touches || [])[0] || e).clientY;
2208
2209 var height = (window_height-y)+plus;
2210
2211 (height>200 && height<=window_height) ? el.css('height', height+'px') : 0;
2212 });
2213
2214 }).on('mouseup touchend', function(){
2215
2216 root.off('mousemove touchmove');
2217 })
2218 .on('click', '.mobile-filter-popup>div', function(e) {
2219 e.stopImmediatePropagation();
2220 }).on('click', '.mobile-filter-popup', function(e) {
2221 $(this).removeClass('is-opened');;
2222 });
2223 });
2224 });