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