PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 1.6.6
Tutor LMS – eLearning and online course solution v1.6.6
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
1718 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 /**
132 * Hover tutor rating and set value
133 */
134 $(document).on('hover', '.tutor-write-review-box .tutor-star-rating-group i', function () {
135 $(this).closest('.tutor-star-rating-group').find('i').removeClass('tutor-icon-star-full').addClass('tutor-icon-star-line');
136 var currentRateValue = $(this).attr('data-rating-value');
137 for (var i = 1; i <= currentRateValue; i++) {
138 $(this).closest('.tutor-star-rating-group').find('i[data-rating-value="' + i + '"]').removeClass('tutor-icon-star-line').addClass('tutor-icon-star-full');
139 }
140 $(this).closest('.tutor-star-rating-group').find('input[name="tutor_rating_gen_input"]').val(currentRateValue);
141 });
142
143 $(document).on('click', '.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
148 $(document).on('click', '.tutor_submit_review_btn', function (e) {
149 e.preventDefault();
150 var $that = $(this);
151 var rating = $that.closest('form').find('input[name="tutor_rating_gen_input"]').val();
152 var review = $that.closest('form').find('textarea[name="review"]').val();
153 review = review.trim();
154
155 var course_id = $('input[name="tutor_course_id"]').val();
156 var data = { course_id: course_id, rating: rating, review: review, action: 'tutor_place_rating' };
157
158 if (review) {
159 $.ajax({
160 url: _tutorobject.ajaxurl,
161 type: 'POST',
162 data: data,
163 beforeSend: function () {
164 $that.addClass('updating-icon');
165 },
166 success: function (data) {
167 var review_id = data.data.review_id;
168 var review = data.data.review;
169 $('.tutor-review-' + review_id + ' .review-content').html(review);
170 location.reload();
171 }
172 });
173 }
174 });
175
176 $(document).on('click', '.write-course-review-link-btn', function (e) {
177 e.preventDefault();
178 $(this).siblings('.tutor-write-review-form').slideToggle();
179 });
180
181 $(document).on('click', '.tutor-ask-question-btn', function (e) {
182 e.preventDefault();
183 $('.tutor-add-question-wrap').slideToggle();
184 });
185 $(document).on('click', '.tutor_question_cancel', function (e) {
186 e.preventDefault();
187 $('.tutor-add-question-wrap').toggle();
188 });
189
190 $(document).on('submit', '#tutor-ask-question-form', function (e) {
191 e.preventDefault();
192
193 var $form = $(this);
194 var data = $(this).serialize() + '&action=tutor_ask_question';
195
196 $.ajax({
197 url: _tutorobject.ajaxurl,
198 type: 'POST',
199 data: data,
200 beforeSend: function () {
201 $form.find('.tutor_ask_question_btn').addClass('updating-icon');
202 },
203 success: function (data) {
204 if (data.success) {
205 $('.tutor-add-question-wrap').hide();
206 window.location.reload();
207 }
208 },
209 complete: function () {
210 $form.find('.tutor_ask_question_btn').removeClass('updating-icon');
211 }
212 });
213 });
214
215 $(document).on('submit', '.tutor-add-answer-form', function (e) {
216 e.preventDefault();
217
218 var $form = $(this);
219 var data = $(this).serialize() + '&action=tutor_add_answer';
220
221 $.ajax({
222 url: _tutorobject.ajaxurl,
223 type: 'POST',
224 data: data,
225 beforeSend: function () {
226 $form.find('.tutor_add_answer_btn').addClass('updating-icon');
227 },
228 success: function (data) {
229 if (data.success) {
230 window.location.reload();
231 }
232 },
233 complete: function () {
234 $form.find('.tutor_add_answer_btn').removeClass('updating-icon');
235 }
236 });
237 });
238
239 $(document).on('focus', '.tutor_add_answer_textarea', function (e) {
240 e.preventDefault();
241
242 var question_id = $(this).closest('.tutor_add_answer_wrap').attr('data-question-id');
243 var conf = {
244 tinymce: {
245 wpautop: true,
246 //plugins : 'charmap colorpicker compat3x directionality fullscreen hr image lists media paste tabfocus textcolor wordpress wpautoresize wpdialogs wpeditimage wpemoji wpgallery wplink wptextpattern wpview',
247 toolbar1: 'bold italic underline bullist strikethrough numlist blockquote alignleft aligncenter alignright undo redo link unlink spellchecker fullscreen'
248 },
249 };
250 wp.editor.initialize('tutor_answer_' + question_id, conf);
251 });
252
253 $(document).on('click', '.tutor_cancel_wp_editor', function (e) {
254 e.preventDefault();
255 $(this).closest('.tutor_wp_editor_wrap').toggle();
256 $(this).closest('.tutor_add_answer_wrap').find('.tutor_wp_editor_show_btn_wrap').toggle();
257 var question_id = $(this).closest('.tutor_add_answer_wrap').attr('data-question-id');
258 wp.editor.remove('tutor_answer_' + question_id);
259 });
260
261 $(document).on('click', '.tutor_wp_editor_show_btn', function (e) {
262 e.preventDefault();
263 $(this).closest('.tutor_add_answer_wrap').find('.tutor_wp_editor_wrap').toggle();
264 $(this).closest('.tutor_wp_editor_show_btn_wrap').toggle();
265 });
266
267 /**
268 * Quiz attempt
269 */
270 var $tutor_quiz_time_update = $('#tutor-quiz-time-update');
271 var attempt_settings = null;
272 if ($tutor_quiz_time_update.length) {
273 attempt_settings = JSON.parse($tutor_quiz_time_update.attr('data-attempt-settings'));
274 var attempt_meta = JSON.parse($tutor_quiz_time_update.attr('data-attempt-meta'));
275
276 if (attempt_meta.time_limit.time_limit_seconds > 0) {
277 //No time Zero limit for
278 var countDownDate = new Date(attempt_settings.attempt_started_at).getTime() + (attempt_meta.time_limit.time_limit_seconds * 1000);
279 var time_now = new Date(attempt_meta.date_time_now).getTime();
280
281 var tutor_quiz_interval = setInterval(function () {
282 var distance = countDownDate - time_now;
283
284 var days = Math.floor(distance / (1000 * 60 * 60 * 24));
285 var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
286 var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
287 var seconds = Math.floor((distance % (1000 * 60)) / 1000);
288
289 var countdown_human = '';
290
291 if (days) {
292 countdown_human += days + "d ";
293 }
294 if (hours) {
295 countdown_human += hours + "h ";
296 }
297 if (minutes) {
298 countdown_human += minutes + "m ";
299 }
300 if (seconds) {
301 countdown_human += seconds + "s ";
302 }
303
304 if (distance < 0) {
305 clearInterval(tutor_quiz_interval);
306 countdown_human = "EXPIRED";
307 //Set the quiz attempt to timeout in ajax
308
309 if (_tutorobject.quiz_options.quiz_when_time_expires === 'autosubmit') {
310 /**
311 * Auto Submit
312 */
313 $('form#tutor-answering-quiz').submit();
314
315 } else if (_tutorobject.quiz_options.quiz_when_time_expires === 'autoabandon') {
316 /**
317 *
318 * @type {jQuery}
319 *
320 * Current attempt will be cancel with attempt status attempt_timeout
321 */
322
323 var quiz_id = $('#tutor_quiz_id').val();
324 var tutor_quiz_remaining_time_secs = $('#tutor_quiz_remaining_time_secs').val();
325 var quiz_timeout_data = { quiz_id: quiz_id, action: 'tutor_quiz_timeout' };
326
327 $.ajax({
328 url: _tutorobject.ajaxurl,
329 type: 'POST',
330 data: quiz_timeout_data,
331 success: function (data) {
332 if (data.success) {
333 window.location.reload(true);
334 }
335 },
336 complete: function () {
337 $('#tutor-quiz-body').html('');
338 window.location.reload(true);
339 }
340 });
341 }
342
343 }
344 time_now = time_now + 1000;
345 $tutor_quiz_time_update.html(countdown_human);
346 }, 1000);
347 } else {
348 $tutor_quiz_time_update.closest('.time-remaining').remove();
349 }
350 }
351
352 var $quiz_start_form = $('#tutor-quiz-body form#tutor-start-quiz');
353 if ($quiz_start_form.length) {
354 if (_tutorobject.quiz_options.quiz_auto_start === '1') {
355 $quiz_start_form.submit();
356 }
357 }
358
359 /**
360 * Quiz Frontend Review Action
361 * @since 1.4.0
362 */
363 $(document).on('click', '.quiz-manual-review-action', function (e) {
364 e.preventDefault();
365 var $that = $(this),
366 attempt_id = $that.attr('data-attempt-id'),
367 attempt_answer_id = $that.attr('data-attempt-answer-id'),
368 mark_as = $that.attr('data-mark-as');
369
370 $.ajax({
371 url: _tutorobject.ajaxurl,
372 type: 'GET',
373 data: { action: 'review_quiz_answer', attempt_id: attempt_id, attempt_answer_id: attempt_answer_id, mark_as: mark_as },
374 beforeSend: function () {
375 $that.find('i').addClass('updating-icon');
376 },
377 success: function (data) {
378 location.reload();
379 },
380 complete: function () {
381 $that.find('i').removeClass('updating-icon');
382 }
383 });
384 });
385
386 // Quiz Review : Tooltip
387 $(".tooltip-btn").on("hover", function (e) {
388 $(this).toggleClass("active");
389 });
390
391 // tutor course content accordion
392 $('.tutor-course-topic.tutor-active').find('.tutor-course-lessons').slideDown();
393 $('.tutor-course-title').on('click', function () {
394 var lesson = $(this).siblings('.tutor-course-lessons');
395 $(this).closest('.tutor-course-topic').toggleClass('tutor-active');
396 lesson.slideToggle();
397 });
398
399 $(document).on('click', '.tutor-topics-title h3 .toogle-informaiton-icon', function (e) {
400 $(this).closest('.tutor-topics-in-single-lesson').find('.tutor-topics-summery').slideToggle();
401 e.stopPropagation();
402 });
403
404 $(document).on('click', '.tutor-course-wishlist-btn', function (e) {
405 e.preventDefault();
406
407 var $that = $(this);
408 var course_id = $that.attr('data-course-id');
409
410 $.ajax({
411 url: _tutorobject.ajaxurl,
412 type: 'POST',
413 data: { course_id: course_id, 'action': 'tutor_course_add_to_wishlist' },
414 beforeSend: function () {
415 $that.addClass('updating-icon');
416 },
417 success: function (data) {
418 if (data.success) {
419 if (data.data.status === 'added') {
420 $that.addClass('has-wish-listed');
421 } else {
422 $that.removeClass('has-wish-listed');
423 }
424 } else {
425 window.location = data.data.redirect_to;
426 }
427 },
428 complete: function () {
429 $that.removeClass('updating-icon');
430 }
431 });
432 });
433
434 /**
435 * Check if lesson has classic editor support
436 * If classic editor support, stop ajax load on the lesson page.
437 *
438 * @since v.1.0.0
439 *
440 * @updated v.1.4.0
441 */
442 if (!_tutorobject.enable_lesson_classic_editor) {
443
444 $(document).on('click', '.tutor-single-lesson-a', function (e) {
445 e.preventDefault();
446
447 var $that = $(this);
448 var lesson_id = $that.attr('data-lesson-id');
449 var $wrap = $('#tutor-single-entry-content');
450
451 $.ajax({
452 url: _tutorobject.ajaxurl,
453 type: 'POST',
454 data: { lesson_id: lesson_id, 'action': 'tutor_render_lesson_content' },
455 beforeSend: function () {
456 var page_title = $that.find('.lesson_title').text();
457 $('head title').text(page_title);
458 window.history.pushState('obj', page_title, $that.attr('href'));
459 $wrap.addClass('loading-lesson');
460 $('.tutor-single-lesson-items').removeClass('active');
461 $that.closest('.tutor-single-lesson-items').addClass('active');
462 },
463 success: function (data) {
464 $wrap.html(data.data.html);
465 videoPlayer.init();
466 $('.tutor-lesson-sidebar').css('display', '');
467 },
468 complete: function () {
469 $wrap.removeClass('loading-lesson');
470 }
471 });
472 });
473
474 $(document).on('click', '.sidebar-single-quiz-a', function (e) {
475 e.preventDefault();
476
477 var $that = $(this);
478 var quiz_id = $that.attr('data-quiz-id');
479 var page_title = $that.find('.lesson_title').text();
480 var $wrap = $('#tutor-single-entry-content');
481
482 $.ajax({
483 url: _tutorobject.ajaxurl,
484 type: 'POST',
485 data: { quiz_id: quiz_id, 'action': 'tutor_render_quiz_content' },
486 beforeSend: function () {
487 $('head title').text(page_title);
488 window.history.pushState('obj', page_title, $that.attr('href'));
489 $wrap.addClass('loading-lesson');
490 $('.tutor-single-lesson-items').removeClass('active');
491 $that.closest('.tutor-single-lesson-items').addClass('active');
492 },
493 success: function (data) {
494 $wrap.html(data.data.html);
495 init_quiz_builder();
496 $('.tutor-lesson-sidebar').css('display', '');
497 },
498 complete: function () {
499 $wrap.removeClass('loading-lesson');
500 }
501 });
502 });
503 }
504
505 /**
506 * @date 05 Feb, 2019
507 */
508
509 $(document).on('click', '.tutor-lesson-sidebar-hide-bar', function (e) {
510 e.preventDefault();
511 $('.tutor-lesson-sidebar').toggle();
512 $('#tutor-single-entry-content').toggleClass("sidebar-hidden");
513
514 });
515
516 $(".tutor-tabs-btn-group a").on('click touchstart', function (e) {
517 e.preventDefault();
518 var $that = $(this);
519 var tabSelector = $that.attr('href');
520 $('.tutor-lesson-sidebar-tab-item').hide();
521 $(tabSelector).show();
522
523 $('.tutor-tabs-btn-group a').removeClass('active');
524 $that.addClass('active');
525 });
526 /**
527 * @date 18 Feb, 2019
528 * @since v.1.0.0
529 */
530
531 function init_quiz_builder() {
532 if (jQuery().sortable) {
533 $(".tutor-quiz-answers-wrap").sortable({
534 handle: ".answer-sorting-bar",
535 start: function (e, ui) {
536 ui.placeholder.css('visibility', 'visible');
537 },
538 stop: function (e, ui) {
539 //Sorting Stopped...
540 },
541 }).disableSelection();
542
543 $(".quiz-draggable-rand-answers, .quiz-answer-matching-droppable").sortable({
544 connectWith: ".quiz-answer-matching-droppable",
545 placeholder: "drop-hover",
546 }).disableSelection();
547 }
548 }
549 init_quiz_builder();
550 /**
551 * Quiz view
552 * @date 22 Feb, 2019
553 * @since v.1.0.0
554 */
555
556 $(document).on('click', '.tutor-quiz-answer-next-btn', function (e) {
557 e.preventDefault();
558
559 var $that = $(this);
560 var $question_wrap = $that.closest('.quiz-attempt-single-question');
561 /**
562 * Validating required answer
563 * @type {jQuery}
564 *
565 * @since v.1.6.1
566 */
567
568 var validated = tutor_quiz_validation($question_wrap);
569 if (!validated) {
570 return;
571 }
572
573 var feedBackNext = feedback_response($question_wrap);
574 if (!feedBackNext) {
575 return;
576 }
577
578 var question_id = parseInt($that.closest('.quiz-attempt-single-question').attr('id').match(/\d+/)[0], 10);
579
580 var next_question_id = $that.closest('.quiz-attempt-single-question').attr('data-next-question-id');
581
582 if (next_question_id) {
583 var $nextQuestion = $(next_question_id);
584 if ($nextQuestion && $nextQuestion.length) {
585 $('.quiz-attempt-single-question').hide();
586 $nextQuestion.show();
587
588 /**
589 * If pagination exists, set active class
590 */
591
592 if ($('.tutor-quiz-questions-pagination').length) {
593 $('.tutor-quiz-question-paginate-item').removeClass('active');
594 $('.tutor-quiz-questions-pagination a[href="' + next_question_id + '"]').addClass('active');
595 }
596
597 }
598 }
599 });
600
601
602 $(document).on('click', '.tutor-quiz-answer-next-btn', function (e) {
603 e.preventDefault();
604
605 });
606
607
608 $(document).on('submit', '#tutor-answering-quiz', function (e) {
609 var $questions_wrap = $('.quiz-attempt-single-question');
610 var validated = true;
611 if ($questions_wrap.length) {
612 $questions_wrap.each(function (index, question) {
613 validated = tutor_quiz_validation($(question));
614 validated = feedback_response($(question));
615 });
616 }
617
618 if (!validated) {
619 e.preventDefault();
620 }
621
622 });
623
624
625 $(document).on('click', '.tutor-quiz-question-paginate-item', function (e) {
626 e.preventDefault();
627 var $that = $(this);
628 var $question = $($that.attr('href'));
629 $('.quiz-attempt-single-question').hide();
630 $question.show();
631
632 //Active Class
633 $('.tutor-quiz-question-paginate-item').removeClass('active');
634 $that.addClass('active');
635 });
636
637 /**
638 * Limit Short Answer Question Type
639 */
640 $(document).on('keyup', 'textarea.question_type_short_answer, textarea.question_type_open_ended', function (e) {
641 var $that = $(this);
642 var value = $that.val();
643 var limit = $that.hasClass('question_type_short_answer') ? _tutorobject.quiz_options.short_answer_characters_limit : _tutorobject.quiz_options.open_ended_answer_characters_limit;
644 var remaining = limit - value.length;
645
646 if (remaining < 1) {
647 $that.val(value.substr(0, limit));
648 remaining = 0;
649 }
650 $that.closest('.tutor-quiz-answers-wrap').find('.characters_remaining').html(remaining);
651 });
652
653 /**
654 *
655 * @type {jQuery}
656 *
657 * Improved Quiz draggable answers drop accessibility
658 * Answers draggable wrap will be now same height.
659 *
660 * @since v.1.4.4
661 */
662 var countDraggableAnswers = $('.quiz-draggable-rand-answers').length;
663 if (countDraggableAnswers) {
664 $('.quiz-draggable-rand-answers').each(function () {
665 var $that = $(this);
666 var draggableDivHeight = $that.height();
667
668 $that.css({ "height": draggableDivHeight });
669 });
670 }
671
672
673 /**
674 * Quiz Validation Helper
675 *
676 * @since v.1.6.1
677 */
678
679 function tutor_quiz_validation($question_wrap) {
680 var validated = true;
681
682 var $required_answer_wrap = $question_wrap.find('.quiz-answer-required');
683
684 if ($required_answer_wrap.length) {
685 /**
686 * Radio field validation
687 *
688 * @type {jQuery}
689 *
690 * @since v.1.6.1
691 */
692 var $inputs = $required_answer_wrap.find('input');
693 if ($inputs.length) {
694 var $type = $inputs.attr('type');
695 if ($type === 'radio') {
696 if ($required_answer_wrap.find('input[type="radio"]:checked').length == 0) {
697 $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">Please select an option to answer</p>');
698 validated = false;
699 }
700 } else if ($type === 'checkbox') {
701 if ($required_answer_wrap.find('input[type="checkbox"]:checked').length == 0) {
702 $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">Please select at least one option to answer.</p>');
703 validated = false;
704 }
705 } else if ($type === 'text') {
706 //Fill in the gaps if many, validation all
707 $inputs.each(function (index, input) {
708 if (!$(input).val().trim().length) {
709 $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">The answer for this question is required</p>');
710 validated = false;
711 }
712 });
713 }
714
715 }
716 if ($required_answer_wrap.find('textarea').length) {
717 if ($required_answer_wrap.find('textarea').val().trim().length < 1) {
718 $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">The answer for this question is required</p>');
719 validated = false;
720 }
721 }
722
723 /**
724 * Matching Question
725 */
726 var $matchingDropable = $required_answer_wrap.find('.quiz-answer-matching-droppable');
727 if ($matchingDropable.length) {
728
729 $matchingDropable.each(function (index, matching) {
730 if (!$(matching).find('.quiz-draggable-answer-item').length) {
731 $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">Please match all the items</p>');
732 validated = false;
733 }
734 });
735 }
736 }
737
738 return validated;
739 }
740
741 function feedback_response($question_wrap) {
742 var goNext = false;
743
744 var feedBackMode = $question_wrap.attr('data-quiz-feedback-mode');
745 $('.wrong-right-text').remove();
746 $('.quiz-answer-input-bottom').removeClass('wrong-answer right-answer');
747
748 var validatedTrue = true;
749 var $inputs = $question_wrap.find('input');
750 var $checkedInputs = $question_wrap.find('input[type="radio"]:checked, input[type="checkbox"]:checked');
751
752 if (feedBackMode === 'retry') {
753 $checkedInputs.each(function () {
754 var $input = $(this);
755
756 var $type = $input.attr('type');
757 if ($type === 'radio' || $type === 'checkbox') {
758 var isTrue = $input.attr('data-is-correct') == '1';
759 if ( !isTrue) {
760 if ($input.prop("checked")) {
761 $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>');
762 }
763 validatedTrue = false;
764 }
765 }
766 });
767
768 $inputs.each(function () {
769 var $input = $(this);
770 var $type = $input.attr('type');
771 if ($type === 'checkbox') {
772 var isTrue = $input.attr('data-is-correct') == '1';
773 var checked = $input.is(':checked');
774
775 if (isTrue && !checked) {
776 $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">More answer for this question is required</p>');
777 validatedTrue = false;
778 }
779 }
780 });
781
782 } else if (feedBackMode === 'reveal') {
783 $checkedInputs.each(function () {
784 var $input = $(this);
785 var isTrue = $input.attr('data-is-correct') == '1';
786 if (!isTrue) {
787 validatedTrue = false;
788 }
789 });
790
791 $inputs.each(function () {
792 var $input = $(this);
793
794 var $type = $input.attr('type');
795 if ($type === 'radio' || $type === 'checkbox') {
796 var isTrue = $input.attr('data-is-correct') == '1';
797 var checked = $input.is(':checked');
798
799 if (isTrue) {
800 $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>');
801 } else {
802 if ($input.prop("checked")) {
803 $input.closest('.quiz-answer-input-bottom').addClass('wrong-answer');
804 }
805 }
806
807 if (isTrue && !checked) {
808 validatedTrue = false;
809 }
810 }
811 });
812 }
813
814 if (validatedTrue) {
815 goNext = true;
816 }
817
818 return goNext;
819 }
820
821
822 /**
823 * Add to cart in guest mode, show login form
824 *
825 * @since v.1.0.4
826 */
827
828 $(document).on('submit click', '.cart-required-login, .cart-required-login a, .cart-required-login form', function (e) {
829 e.preventDefault();
830
831 $('.tutor-cart-box-login-form').fadeIn(100);
832 });
833
834 $('.tutor-popup-form-close, .login-overlay-close').on('click', function () {
835 $('.tutor-cart-box-login-form').fadeOut(100);
836 });
837
838 $(document).on('keyup', function (e) {
839 if (e.keyCode === 27) {
840 $('.tutor-frontend-modal').hide();
841 $('.tutor-cart-box-login-form').fadeOut(100);
842 }
843 });
844 /**
845 * Share Link enable
846 *
847 * @since v.1.0.4
848 */
849 if ($.fn.ShareLink) {
850 var $social_share_wrap = $('.tutor-social-share-wrap');
851 if ($social_share_wrap.length) {
852 var share_config = JSON.parse($social_share_wrap.attr('data-social-share-config'));
853
854 $('.tutor_share').ShareLink({
855 title: share_config.title,
856 text: share_config.text,
857 image: share_config.image,
858 class_prefix: 's_',
859 width: 640,
860 height: 480,
861 });
862 }
863 }
864
865 /**
866 * Datepicker initiate
867 *
868 * @since v.1.1.2
869 */
870 if (jQuery.datepicker) {
871 $(".tutor_report_datepicker").datepicker({ "dateFormat": 'yy-mm-dd' });
872 }
873
874
875 /**
876 * Withdraw Form Tab/Toggle
877 *
878 * @since v.1.1.2
879 */
880
881 $(".withdraw-method-select-input").on('change', function (e) {
882 var $that = $(this);
883 $('.withdraw-method-form').hide();
884 $('#withdraw-method-form-' + $that.closest('.withdraw-method-select').attr('data-withdraw-method')).show();
885 });
886
887 $('.withdraw-method-select-input').each(function () {
888 var $that = $(this);
889 if ($that.is(":checked")) {
890 $('.withdraw-method-form').hide();
891 $('#withdraw-method-form-' + $that.closest('.withdraw-method-select').attr('data-withdraw-method')).show();
892 }
893 });
894
895
896
897 /**
898 * Setting account for withdraw earning
899 *
900 * @since v.1.2.0
901 */
902 $(document).on('submit', '#tutor-withdraw-account-set-form', function (e) {
903 e.preventDefault();
904
905 var $form = $(this);
906 var $btn = $form.find('.tutor_set_withdraw_account_btn');
907 var data = $form.serialize();
908
909 $.ajax({
910 url: _tutorobject.ajaxurl,
911 type: 'POST',
912 data: data,
913 beforeSend: function () {
914 $form.find('.tutor-success-msg').remove();
915 $btn.addClass('updating-icon');
916 },
917 success: function (data) {
918 if (data.success) {
919 var successMsg = '<div class="tutor-success-msg" style="display: none;"><i class="tutor-icon-mark"></i> ' + data.data.msg + ' </div>';
920 $btn.closest('.withdraw-account-save-btn-wrap').append(successMsg);
921 if ($form.find('.tutor-success-msg').length) {
922 $form.find('.tutor-success-msg').slideDown();
923 }
924 setTimeout(function () {
925 $form.find('.tutor-success-msg').slideUp();
926 }, 5000)
927 }
928 },
929 complete: function () {
930 $btn.removeClass('updating-icon');
931 }
932 });
933 });
934
935 /**
936 * Make Withdraw Form
937 *
938 * @since v.1.2.0
939 */
940
941 $(document).on('click', 'a.open-withdraw-form-btn', function (e) {
942 e.preventDefault();
943 $('.tutor-earning-withdraw-form-wrap').slideToggle();
944 });
945
946 $(document).on('submit', '#tutor-earning-withdraw-form', function (e) {
947 e.preventDefault();
948
949 var $form = $(this);
950 var $btn = $('#tutor-earning-withdraw-btn');
951 var $responseDiv = $('#tutor-withdraw-form-response');
952 var data = $form.serialize();
953
954 $.ajax({
955 url: _tutorobject.ajaxurl,
956 type: 'POST',
957 data: data,
958 beforeSend: function () {
959 $form.find('.tutor-success-msg').remove();
960 $btn.addClass('updating-icon');
961 },
962 success: function (data) {
963 var Msg;
964 if (data.success) {
965
966 if (data.data.available_balance !== 'undefined') {
967 $('.withdraw-balance-col .available_balance').html(data.data.available_balance);
968 }
969 Msg = '<div class="tutor-success-msg"><i class="tutor-icon-mark"></i> ' + data.data.msg + ' </div>';
970
971 } else {
972 Msg = '<div class="tutor-error-msg"><i class="tutor-icon-line-cross"></i> ' + data.data.msg + ' </div>';
973 }
974
975 $responseDiv.html(Msg);
976 setTimeout(function () {
977 $responseDiv.html('');
978 }, 5000)
979 },
980 complete: function () {
981 $btn.removeClass('updating-icon');
982 }
983 });
984 });
985
986 var frontEndModal = $('.tutor-frontend-modal');
987 frontEndModal.each(function () {
988 var modal = $(this),
989 action = $(this).data('popup-rel');
990 $('[href="' + action + '"]').on('click', function (e) {
991 modal.fadeIn();
992 e.preventDefault();
993 });
994 });
995 $(document).on('click', '.tm-close, .tutor-frontend-modal-overlay, .tutor-modal-btn-cancel', function () {
996 frontEndModal.fadeOut();
997 });
998
999 /**
1000 * Delete Course
1001 */
1002 $(document).on('click', '.tutor-dashboard-element-delete-btn', function (e) {
1003 e.preventDefault();
1004 var element_id = $(this).attr('data-id');
1005 $('#tutor-dashboard-delete-element-id').val(element_id);
1006 });
1007 $(document).on('submit', '#tutor-dashboard-delete-element-form', function (e) {
1008 e.preventDefault();
1009
1010 var element_id = $('#tutor-dashboard-delete-element-id').val();
1011 var $btn = $('.tutor-modal-element-delete-btn');
1012 var data = $(this).serialize();
1013
1014 $.ajax({
1015 url: _tutorobject.ajaxurl,
1016 type: 'POST',
1017 data: data,
1018 beforeSend: function () {
1019 $btn.addClass('updating-icon');
1020 },
1021 success: function (res) {
1022 if (res.success) {
1023 $('#tutor-dashboard-' + res.data.element + '-' + element_id).remove();
1024 }
1025 },
1026 complete: function () {
1027 $btn.removeClass('updating-icon');
1028 $('.tutor-frontend-modal').hide();
1029 }
1030 });
1031 });
1032
1033 /**
1034 * Frontend Profile
1035 */
1036
1037 if (!$('#tutor_profile_photo_id').val()) {
1038 $('.tutor-profile-photo-delete-btn').hide();
1039 }
1040
1041 $(document).on('click', '.tutor-profile-photo-delete-btn', function () {
1042 $('.tutor-profile-photo-upload-wrap').find('img').attr('src', _tutorobject.placeholder_img_src);
1043 $('#tutor_profile_photo_id').val('');
1044 $('.tutor-profile-photo-delete-btn').hide();
1045
1046 $.ajax({
1047 url: _tutorobject.ajaxurl,
1048 type: 'POST',
1049 data: { 'action': 'tutor_profile_photo_remove' },
1050 });
1051
1052 return false;
1053 });
1054
1055 /**
1056 * Assignment
1057 *
1058 * @since v.1.3.3
1059 */
1060 $(document).on('submit', '#tutor_assignment_start_form', function (e) {
1061 e.preventDefault();
1062
1063 var $that = $(this);
1064 var form_data = $that.serialize() + '&action=tutor_start_assignment';
1065
1066 $.ajax({
1067 url: _tutorobject.ajaxurl,
1068 type: 'POST',
1069 data: form_data,
1070 beforeSend: function () {
1071 $('#tutor_assignment_start_btn').addClass('updating-icon');
1072 },
1073 success: function (data) {
1074 if (data.success) {
1075 location.reload();
1076 }
1077 },
1078 complete: function () {
1079 $('#tutor_assignment_start_btn').removeClass('updating-icon');
1080 }
1081 });
1082 });
1083
1084 /**
1085 * Assignment answer validation
1086 */
1087 $(document).on('submit', '#tutor_assignment_submit_form', function (e) {
1088 var assignment_answer = $('textarea[name="assignment_answer"]').val();
1089 if (assignment_answer.trim().length < 1) {
1090 $('#form_validation_response').html('<div class="tutor-error-msg">' + _tutorobject.text.assignment_text_validation_msg + '</div>');
1091 e.preventDefault();
1092 }
1093 });
1094
1095 /**
1096 * Course builder video
1097 * @since v.1.3.4
1098 */
1099
1100
1101 $(document).on('click', '.video_source_upload_wrap_html5 .video_upload_btn', function (event) {
1102 event.preventDefault();
1103
1104 var $that = $(this);
1105 var frame;
1106 // If the media frame already exists, reopen it.
1107 if (frame) {
1108 frame.open();
1109 return;
1110 }
1111 frame = wp.media({
1112 title: 'Select or Upload Media Of Your Chosen Persuasion',
1113 button: {
1114 text: 'Use this media'
1115 },
1116 library: { type: 'video' },
1117 multiple: false // Set to true to allow multiple files to be selected
1118 });
1119 frame.on('select', function () {
1120 // Get media attachment details from the frame state
1121 var attachment = frame.state().get('selection').first().toJSON();
1122 $that.closest('.video_source_upload_wrap_html5').find('span.video_media_id').text(attachment.id).closest('p').show();
1123 $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id);
1124 });
1125 frame.open();
1126 });
1127
1128
1129 /**
1130 * Course and lesson sorting
1131 */
1132
1133 function enable_sorting_topic_lesson() {
1134 if (jQuery().sortable) {
1135 $(".course-contents").sortable({
1136 handle: ".course-move-handle",
1137 start: function (e, ui) {
1138 ui.placeholder.css('visibility', 'visible');
1139 },
1140 stop: function (e, ui) {
1141 tutor_sorting_topics_and_lesson();
1142 },
1143 });
1144 $(".tutor-lessons:not(.drop-lessons)").sortable({
1145 connectWith: ".tutor-lessons",
1146 items: "div.course-content-item",
1147 start: function (e, ui) {
1148 ui.placeholder.css('visibility', 'visible');
1149 },
1150 stop: function (e, ui) {
1151 tutor_sorting_topics_and_lesson();
1152 },
1153 });
1154 }
1155 }
1156 enable_sorting_topic_lesson();
1157 function tutor_sorting_topics_and_lesson() {
1158 var topics = {};
1159 $('.tutor-topics-wrap').each(function (index, item) {
1160 var $topic = $(this);
1161 var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10);
1162 var lessons = {};
1163
1164 $topic.find('.course-content-item').each(function (lessonIndex, lessonItem) {
1165 var $lesson = $(this);
1166 var lesson_id = parseInt($lesson.attr('id').match(/\d+/)[0], 10);
1167
1168 lessons[lessonIndex] = lesson_id;
1169 });
1170 topics[index] = { 'topic_id': topics_id, 'lesson_ids': lessons };
1171 });
1172 $('#tutor_topics_lessons_sorting').val(JSON.stringify(topics));
1173 }
1174
1175 /**
1176 * Lesson Update or Create Modal
1177 */
1178 $(document).on('click', '.update_lesson_modal_btn', function (event) {
1179 event.preventDefault();
1180
1181 var $that = $(this);
1182 var content;
1183 var editor = tinyMCE.get('tutor_lesson_modal_editor');
1184 if (editor) {
1185 content = editor.getContent();
1186 } else {
1187 content = $('#' + inputid).val();
1188 }
1189
1190 var form_data = $(this).closest('form').serialize();
1191 form_data += '&lesson_content=' + encodeURIComponent(content);
1192
1193 $.ajax({
1194 url: ajaxurl,
1195 type: 'POST',
1196 data: form_data,
1197 beforeSend: function () {
1198 $that.addClass('tutor-updating-message');
1199 },
1200 success: function (data) {
1201 if (data.success) {
1202 $('#tutor-course-content-wrap').html(data.data.course_contents);
1203 enable_sorting_topic_lesson();
1204
1205 //Close the modal
1206 $('.tutor-lesson-modal-wrap').removeClass('show');
1207 }
1208 },
1209 complete: function () {
1210 $that.removeClass('tutor-updating-message');
1211 }
1212 });
1213 });
1214
1215 /**
1216 * END: Tutor Course builder JS
1217 */
1218
1219 /**
1220 * Attachment in forntend course builder
1221 * @since v.1.3.4
1222 */
1223 $(document).on('click', 'a.tutor-delete-attachment', function (e) {
1224 e.preventDefault();
1225 $(this).closest('.tutor-added-attachment').remove();
1226 });
1227 $(document).on('click', '.tutorUploadAttachmentBtn', function (e) {
1228 e.preventDefault();
1229
1230 var $that = $(this);
1231 var frame;
1232 if (frame) {
1233 frame.open();
1234 return;
1235 }
1236 frame = wp.media({
1237 title: 'Select or Upload Media Of Your Chosen Persuasion',
1238 button: {
1239 text: 'Use this media'
1240 },
1241 multiple: true // Set to true to allow multiple files to be selected
1242 });
1243 frame.on('select', function () {
1244 var attachments = frame.state().get('selection').toJSON();
1245 if (attachments.length) {
1246 for (var i = 0; i < attachments.length; i++) {
1247 var attachment = attachments[i];
1248
1249 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>';
1250 $that.closest('.tutor-lesson-attachments-metabox').find('.tutor-added-attachments-wrap').append(inputHtml);
1251 }
1252 }
1253 });
1254 frame.open();
1255 });
1256
1257
1258 /**
1259 * Single Assignment Upload Button
1260 * @since v.1.3.4
1261 */
1262 $('form').on('change', '.tutor-assignment-file-upload', function () {
1263 $(this).siblings("label").find('span').html($(this).val().replace(/.*(\/|\\)/, ''));
1264 });
1265
1266 /**
1267 * Lesson Sidebar Topic Toggle
1268 * @since v.1.3.4
1269 */
1270
1271 $(document).on('click', '.tutor-topics-in-single-lesson .tutor-topics-title h3, .tutor-single-lesson-topic-toggle', function (e) {
1272 var $that = $(this);
1273 var $parent = $that.closest('.tutor-topics-in-single-lesson');
1274 $parent.toggleClass('tutor-topic-active');
1275 $parent.find('.tutor-lessons-under-topic').slideToggle();
1276 });
1277
1278 $('.tutor-single-lesson-items.active').closest('.tutor-lessons-under-topic').show();
1279 $('.tutor-single-lesson-items.active').closest('.tutor-topics-in-single-lesson').addClass('tutor-topic-active');
1280 $('.tutor-course-lesson.active').closest('.tutor-lessons-under-topic').show();
1281
1282
1283 /**
1284 * Assignments Addons
1285 * @backend Support
1286 *
1287 */
1288
1289
1290 /**
1291 * Tutor Assignments JS
1292 * @since v.1.3.3
1293 */
1294 $(document).on('click', '.tutor-create-assignments-btn', function (e) {
1295 e.preventDefault();
1296
1297 var $that = $(this);
1298 var topic_id = $(this).attr('data-topic-id');
1299 var course_id = $('#post_ID').val();
1300
1301 $.ajax({
1302 url: ajaxurl,
1303 type: 'POST',
1304 data: { topic_id: topic_id, course_id: course_id, action: 'tutor_load_assignments_builder_modal' },
1305 beforeSend: function () {
1306 $that.addClass('tutor-updating-message');
1307 },
1308 success: function (data) {
1309 $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output);
1310 $('.tutor-lesson-modal-wrap').attr('data-topic-id', topic_id).addClass('show');
1311
1312 $(document).trigger('assignment_modal_loaded', { topic_id: topic_id, course_id: course_id });
1313
1314 tinymce.init(tinyMCEPreInit.mceInit.course_description);
1315 tinymce.execCommand('mceRemoveEditor', false, 'tutor_assignments_modal_editor');
1316 tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor");
1317 },
1318 complete: function () {
1319 quicktags({ id: "tutor_assignments_modal_editor" });
1320 $that.removeClass('tutor-updating-message');
1321 }
1322 });
1323 });
1324
1325 $(document).on('click', '.open-tutor-assignment-modal', function (e) {
1326 e.preventDefault();
1327
1328 var $that = $(this);
1329 var assignment_id = $that.attr('data-assignment-id');
1330 var topic_id = $that.attr('data-topic-id');
1331 var course_id = $('#post_ID').val();
1332
1333 $.ajax({
1334 url: ajaxurl,
1335 type: 'POST',
1336 data: { assignment_id: assignment_id, topic_id: topic_id, course_id: course_id, action: 'tutor_load_assignments_builder_modal' },
1337 beforeSend: function () {
1338 $that.addClass('tutor-updating-message');
1339 },
1340 success: function (data) {
1341 $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output);
1342 $('.tutor-lesson-modal-wrap').attr({ 'data-assignment-id': assignment_id, 'data-topic-id': topic_id }).addClass('show');
1343
1344 $(document).trigger('assignment_modal_loaded', { assignment_id: assignment_id, topic_id: topic_id, course_id: course_id });
1345
1346 tinymce.init(tinyMCEPreInit.mceInit.course_description);
1347 tinymce.execCommand('mceRemoveEditor', false, 'tutor_assignments_modal_editor');
1348 tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor");
1349 },
1350 complete: function () {
1351 quicktags({ id: "tutor_assignments_modal_editor" });
1352 $that.removeClass('tutor-updating-message');
1353 }
1354 });
1355 });
1356
1357 /**
1358 * Update Assignment Data
1359 */
1360 $(document).on('click', '.update_assignment_modal_btn', function (event) {
1361 event.preventDefault();
1362
1363 var $that = $(this);
1364 var content;
1365 var editor = tinyMCE.get('tutor_assignments_modal_editor');
1366 if (editor) {
1367 content = editor.getContent();
1368 } else {
1369 content = $('#' + inputid).val();
1370 }
1371
1372 var form_data = $(this).closest('form').serialize();
1373 form_data += '&assignment_content=' + content;
1374
1375 $.ajax({
1376 url: ajaxurl,
1377 type: 'POST',
1378 data: form_data,
1379 beforeSend: function () {
1380 $that.addClass('tutor-updating-message');
1381 },
1382 success: function (data) {
1383 if (data.success) {
1384 $('#tutor-course-content-wrap').html(data.data.course_contents);
1385 enable_sorting_topic_lesson();
1386
1387 //Close the modal
1388 $('.tutor-lesson-modal-wrap').removeClass('show');
1389 }
1390 },
1391 complete: function () {
1392 $that.removeClass('tutor-updating-message');
1393 }
1394 });
1395 });
1396
1397 /**
1398 * Add Assignment
1399 */
1400 $(document).on('click', '.add-assignment-attachments', function (event) {
1401 event.preventDefault();
1402
1403 var $that = $(this);
1404 var frame;
1405 // If the media frame already exists, reopen it.
1406 if (frame) {
1407 frame.open();
1408 return;
1409 }
1410
1411 // Create a new media frame
1412 frame = wp.media({
1413 title: 'Select or Upload Media Of Your Chosen Persuasion',
1414 button: {
1415 text: 'Use this media'
1416 },
1417 multiple: false // Set to true to allow multiple files to be selected
1418 });
1419
1420 // When an image is selected in the media frame...
1421 frame.on('select', function () {
1422 // Get media attachment details from the frame state
1423 var attachment = frame.state().get('selection').first().toJSON();
1424
1425 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>';
1426
1427 $('#assignment-attached-file').append(field_markup);
1428 $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id);
1429 });
1430 // Finally, open the modal on click
1431 frame.open();
1432 });
1433
1434 $(document).on('click', '.remove-assignment-attachment-a', function (event) {
1435 event.preventDefault();
1436 $(this).closest('.tutor-individual-attachment-file').remove();
1437 });
1438
1439
1440 /**
1441 *
1442 * @type {jQuery}
1443 *
1444 * Course builder auto draft save
1445 *
1446 * @since v.1.3.4
1447 */
1448 var tutor_course_builder = $('input[name="tutor_action"]').val();
1449 if (tutor_course_builder === 'tutor_add_course_builder') {
1450 setInterval(auto_draft_save_course_builder, 30000);
1451 }
1452
1453 function auto_draft_save_course_builder() {
1454 var form_data = $('form#tutor-frontend-course-builder').serialize();
1455 $.ajax({
1456 //url : _tutorobject.ajaxurl,
1457 type: 'POST',
1458 data: form_data + '&tutor_ajax_action=tutor_course_builder_draft_save',
1459 beforeSend: function () {
1460 $('.tutor-dashboard-builder-draft-btn span').text('Saving...');
1461 },
1462 success: function (data) {
1463
1464 },
1465 complete: function () {
1466 $('.tutor-dashboard-builder-draft-btn span').text('Save');
1467 }
1468 });
1469 }
1470
1471 /**
1472 *
1473 * @type {jQuery}
1474 *
1475 * Course builder section toggle
1476 *
1477 * @since v.1.3.5
1478 */
1479
1480 $('.tutor-course-builder-section-title').on('click', function () {
1481 if ($(this).find('i').hasClass("tutor-icon-up")) {
1482 $(this).find('i').removeClass('tutor-icon-up').addClass('tutor-icon-down');
1483 } else {
1484 $(this).find('i').removeClass('tutor-icon-down').addClass('tutor-icon-up');
1485 }
1486 $(this).next('div').slideToggle();
1487 });
1488
1489 /**
1490 * Open Tutor Modal to edit review
1491 * @since v.1.4.0
1492 */
1493 $(document).on('click', '.open-tutor-edit-review-modal', function (e) {
1494 e.preventDefault();
1495
1496 var $that = $(this);
1497 var review_id = $that.attr('data-review-id');
1498
1499 var nonce_key = _tutorobject.nonce_key;
1500
1501 var json_data = { review_id: review_id, action: 'tutor_load_edit_review_modal' };
1502 json_data[nonce_key] = _tutorobject[nonce_key];
1503
1504 $.ajax({
1505 url: _tutorobject.ajaxurl,
1506 type: 'POST',
1507 data: json_data,
1508 beforeSend: function () {
1509 $that.addClass('tutor-updating-message');
1510 },
1511 success: function (data) {
1512 if (typeof data.data !== 'undefined') {
1513 $('.tutor-edit-review-modal-wrap .modal-container').html(data.data.output);
1514 $('.tutor-edit-review-modal-wrap').attr('data-review-id', review_id).addClass('show');
1515 }
1516 },
1517 complete: function () {
1518 $that.removeClass('tutor-updating-message');
1519 }
1520 });
1521 });
1522
1523 /**
1524 * Update the rating
1525 * @since v.1.4.0
1526 */
1527 $(document).on('submit', '#tutor_update_review_form', function (e) {
1528 e.preventDefault();
1529
1530 var $that = $(this);
1531 var review_id = $that.closest('.tutor-edit-review-modal-wrap ').attr('data-review-id');
1532
1533 var nonce_key = _tutorobject.nonce_key;
1534
1535 var rating = $that.find('input[name="tutor_rating_gen_input"]').val();
1536 var review = $that.find('textarea[name="review"]').val();
1537 review = review.trim();
1538
1539 var json_data = { review_id: review_id, rating: rating, review: review, action: 'tutor_update_review_modal' };
1540 json_data[nonce_key] = _tutorobject[nonce_key];
1541
1542 $.ajax({
1543 url: _tutorobject.ajaxurl,
1544 type: 'POST',
1545 data: json_data,
1546 beforeSend: function () {
1547 $that.find('button[type="submit"]').addClass('tutor-updating-message');
1548 },
1549 success: function (data) {
1550 if (data.success) {
1551 //Close the modal
1552 $('.tutor-edit-review-modal-wrap').removeClass('show');
1553 location.reload(true);
1554 }
1555 },
1556 complete: function () {
1557 $that.find('button[type="submit"]').removeClass('tutor-updating-message');
1558 }
1559 });
1560 });
1561
1562 /**
1563 * Profile photo upload
1564 * @since v.1.4.5
1565 */
1566
1567 $(document).on('click', '#tutor_profile_photo_button', function (e) {
1568 e.preventDefault();
1569
1570 $('#tutor_profile_photo_file').trigger('click');
1571 });
1572
1573 $(document).on('change', '#tutor_profile_photo_file', function (event) {
1574 event.preventDefault();
1575
1576 var $file = this;
1577 if ($file.files && $file.files[0]) {
1578 var reader = new FileReader();
1579 reader.onload = function (e) {
1580 $('.tutor-profile-photo-upload-wrap').find('img').attr('src', e.target.result);
1581 }
1582 reader.readAsDataURL($file.files[0]);
1583 }
1584 });
1585
1586 /**
1587 * Addon, Tutor BuddyPress
1588 * Retrieve MetaInformation on BuddyPress message system
1589 * @for TutorLMS Pro
1590 * @since v.1.4.8
1591 */
1592
1593 $(document).on('click', '.thread-content .subject', function (e) {
1594 var $btn = $(this);
1595
1596 var thread_id = parseInt($btn.closest('.thread-content').attr('data-thread-id'));
1597
1598 var nonce_key = _tutorobject.nonce_key;
1599 var json_data = { thread_id: thread_id, action: 'tutor_bp_retrieve_user_records_for_thread' };
1600 json_data[nonce_key] = _tutorobject[nonce_key];
1601
1602 $.ajax({
1603 type: 'POST',
1604 url: ajaxurl,
1605 data: json_data,
1606 beforeSend: function () {
1607 $('#tutor-bp-thread-wrap').html('');
1608 },
1609 success: function (data) {
1610 if (data.success) {
1611 $('#tutor-bp-thread-wrap').html(data.data.thread_head_html);
1612 tutor_bp_setting_enrolled_courses_list();
1613 }
1614 }
1615 });
1616
1617 });
1618
1619
1620 function tutor_bp_setting_enrolled_courses_list() {
1621 $('ul.tutor-bp-enrolled-course-list').each(function () {
1622 var $that = $(this);
1623 var $li = $that.find(' > li');
1624 var itemShow = 3;
1625
1626 if ($li.length > itemShow) {
1627 var plusCourseCount = $li.length - itemShow;
1628 $li.each(function (liIndex, liItem) {
1629 var $liItem = $(this);
1630
1631 if (liIndex >= itemShow) {
1632 $liItem.hide();
1633 }
1634 });
1635
1636 var infoHtml = '<a href="javascript:;" class="tutor_bp_plus_courses"><strong>+' + plusCourseCount + ' More </strong></a> Courses';
1637 $that.closest('.tutor-bp-enrolled-courses-wrap').find('.thread-participant-enrolled-info').html(infoHtml);
1638 }
1639
1640 $that.show();
1641 });
1642 }
1643 tutor_bp_setting_enrolled_courses_list();
1644
1645 $(document).on('click', 'a.tutor_bp_plus_courses', function (e) {
1646 e.preventDefault();
1647
1648 var $btn = $(this);
1649 $btn.closest('.tutor-bp-enrolled-courses-wrap').find('.tutor-bp-enrolled-course-list li').show();
1650 $btn.closest('.thread-participant-enrolled-info').html('');
1651 });
1652
1653
1654 /**
1655 * Addon, Tutor Certificate
1656 * Certificate dropdown content and copy link
1657 * @for TutorLMS Pro
1658 * @since v.1.5.1
1659 */
1660 $(document).on('click', '.tutor-dropbtn', function (e) {
1661 var $content = $(this).parent().find(".tutor-dropdown-content");
1662 $content.slideToggle(100);
1663 });
1664 $(document).on('click', '.tutor-copy-link', function (e) {
1665 var $btn = $(this);
1666 var copy = '<i class="tutor-icon-copy"></i> Copy Link';
1667 var copied = '<i class="tutor-icon-mark"></i> Copied';
1668 var dummy = document.createElement('input'),
1669 text = window.location.href;
1670 document.body.appendChild(dummy);
1671 dummy.value = text;
1672 dummy.select();
1673 document.execCommand('copy');
1674 document.body.removeChild(dummy);
1675 $btn.html(copied);
1676 setTimeout(function () {
1677 $btn.html(copy);
1678 }, 2500);
1679 });
1680 $(document).on('click', function (e) {
1681 var container = $(".tutor-dropdown");
1682 var $content = container.find('.tutor-dropdown-content');
1683 // if the target of the click isn't the container nor a descendant of the container
1684 if (!container.is(e.target) && container.has(e.target).length === 0) {
1685 $content.slideUp(100);
1686 }
1687 });
1688
1689
1690 /**
1691 * Tutor ajax login
1692 *
1693 * @since v.1.6.3
1694 */
1695 $(document).on('submit', '.tutor-login-form-wrap #loginform', function (e) {
1696 e.preventDefault();
1697 var $that = $(this);
1698 var $form_wrapper = $('.tutor-login-form-wrap');
1699 var form_data = $that.serialize() + '&action=tutor_user_login';
1700 $.ajax({
1701 url: _tutorobject.ajaxurl,
1702 type: 'POST',
1703 data: form_data,
1704 success: function (response) {
1705 if (response.success) {
1706 location.href = response.data.redirect;
1707 } else {
1708 if ($form_wrapper.find('.tutor-alert').length) {
1709 $form_wrapper.find('.tutor-alert').html(response.data);
1710 } else {
1711 $form_wrapper.prepend('<div class="tutor-alert tutor-alert-warning">' + response.data + '</div>');
1712 }
1713 }
1714 },
1715 });
1716 });
1717
1718 });