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