PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 1.6.3
Tutor LMS – eLearning and online course solution v1.6.3
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 6 years ago gutenberg_blocks.js 6 years ago mce-button.js 6 years ago tutor-admin.js 6 years ago tutor-front.js 6 years ago tutor-setup.js 6 years ago tutor.js 6 years ago
tutor-front.js
1629 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 // tutor course content accordion
387 $('.tutor-course-topic.tutor-active').find('.tutor-course-lessons').slideDown();
388 $('.tutor-course-title').on('click', function () {
389 var lesson = $(this).siblings('.tutor-course-lessons');
390 $(this).closest('.tutor-course-topic').toggleClass('tutor-active');
391 lesson.slideToggle();
392 });
393
394 $(document).on('click', '.tutor-topics-title h3 .toogle-informaiton-icon', function (e) {
395 $(this).closest('.tutor-topics-in-single-lesson').find('.tutor-topics-summery').slideToggle();
396 e.stopPropagation();
397 });
398
399 $(document).on('click', '.tutor-course-wishlist-btn', function (e) {
400 e.preventDefault();
401
402 var $that = $(this);
403 var course_id = $that.attr('data-course-id');
404
405 $.ajax({
406 url: _tutorobject.ajaxurl,
407 type: 'POST',
408 data: { course_id: course_id, 'action': 'tutor_course_add_to_wishlist' },
409 beforeSend: function () {
410 $that.addClass('updating-icon');
411 },
412 success: function (data) {
413 if (data.success) {
414 if (data.data.status === 'added') {
415 $that.addClass('has-wish-listed');
416 } else {
417 $that.removeClass('has-wish-listed');
418 }
419 } else {
420 window.location = data.data.redirect_to;
421 }
422 },
423 complete: function () {
424 $that.removeClass('updating-icon');
425 }
426 });
427 });
428
429 /**
430 * Check if lesson has classic editor support
431 * If classic editor support, stop ajax load on the lesson page.
432 *
433 * @since v.1.0.0
434 *
435 * @updated v.1.4.0
436 */
437 if (!_tutorobject.enable_lesson_classic_editor) {
438
439 $(document).on('click', '.tutor-single-lesson-a', function (e) {
440 e.preventDefault();
441
442 var $that = $(this);
443 var lesson_id = $that.attr('data-lesson-id');
444 var $wrap = $('#tutor-single-entry-content');
445
446 $.ajax({
447 url: _tutorobject.ajaxurl,
448 type: 'POST',
449 data: { lesson_id: lesson_id, 'action': 'tutor_render_lesson_content' },
450 beforeSend: function () {
451 var page_title = $that.find('.lesson_title').text();
452 $('head title').text(page_title);
453 window.history.pushState('obj', page_title, $that.attr('href'));
454 $wrap.addClass('loading-lesson');
455 $('.tutor-single-lesson-items').removeClass('active');
456 $that.closest('.tutor-single-lesson-items').addClass('active');
457 },
458 success: function (data) {
459 $wrap.html(data.data.html);
460 videoPlayer.init();
461 $('.tutor-lesson-sidebar').css('display', '');
462 },
463 complete: function () {
464 $wrap.removeClass('loading-lesson');
465 }
466 });
467 });
468
469 $(document).on('click', '.sidebar-single-quiz-a', function (e) {
470 e.preventDefault();
471
472 var $that = $(this);
473 var quiz_id = $that.attr('data-quiz-id');
474 var page_title = $that.find('.lesson_title').text();
475 var $wrap = $('#tutor-single-entry-content');
476
477 $.ajax({
478 url: _tutorobject.ajaxurl,
479 type: 'POST',
480 data: { quiz_id: quiz_id, 'action': 'tutor_render_quiz_content' },
481 beforeSend: function () {
482 $('head title').text(page_title);
483 window.history.pushState('obj', page_title, $that.attr('href'));
484 $wrap.addClass('loading-lesson');
485 $('.tutor-single-lesson-items').removeClass('active');
486 $that.closest('.tutor-single-lesson-items').addClass('active');
487 },
488 success: function (data) {
489 $wrap.html(data.data.html);
490 init_quiz_builder();
491 $('.tutor-lesson-sidebar').css('display', '');
492 },
493 complete: function () {
494 $wrap.removeClass('loading-lesson');
495 }
496 });
497 });
498 }
499
500 /**
501 * @date 05 Feb, 2019
502 */
503
504 $(document).on('click', '.tutor-lesson-sidebar-hide-bar', function (e) {
505 e.preventDefault();
506 $('.tutor-lesson-sidebar').toggle();
507 $('#tutor-single-entry-content').toggleClass("sidebar-hidden");
508
509 });
510
511 $(".tutor-tabs-btn-group a").on('click touchstart', function (e) {
512 e.preventDefault();
513 var $that = $(this);
514 var tabSelector = $that.attr('href');
515 $('.tutor-lesson-sidebar-tab-item').hide();
516 $(tabSelector).show();
517
518 $('.tutor-tabs-btn-group a').removeClass('active');
519 $that.addClass('active');
520 });
521 /**
522 * @date 18 Feb, 2019
523 * @since v.1.0.0
524 */
525
526 function init_quiz_builder() {
527 if (jQuery().sortable) {
528 $(".tutor-quiz-answers-wrap").sortable({
529 handle: ".answer-sorting-bar",
530 start: function (e, ui) {
531 ui.placeholder.css('visibility', 'visible');
532 },
533 stop: function (e, ui) {
534 //Sorting Stopped...
535 },
536 }).disableSelection();
537
538 $(".quiz-draggable-rand-answers, .quiz-answer-matching-droppable").sortable({
539 connectWith: ".quiz-answer-matching-droppable",
540 placeholder: "drop-hover",
541 }).disableSelection();
542 }
543 }
544 init_quiz_builder();
545 /**
546 * Quiz view
547 * @date 22 Feb, 2019
548 * @since v.1.0.0
549 */
550
551 $(document).on('click', '.tutor-quiz-answer-next-btn', function (e) {
552 e.preventDefault();
553
554 var $that = $(this);
555 var $question_wrap = $that.closest('.quiz-attempt-single-question');
556 /**
557 * Validating required answer
558 * @type {jQuery}
559 *
560 * @since v.1.6.1
561 */
562
563 var validated = tutor_quiz_validation($question_wrap);
564 if (!validated) {
565 return;
566 }
567
568 var question_id = parseInt($that.closest('.quiz-attempt-single-question').attr('id').match(/\d+/)[0], 10);
569
570 var next_question_id = $that.closest('.quiz-attempt-single-question').attr('data-next-question-id');
571
572 if (next_question_id) {
573 var $nextQuestion = $(next_question_id);
574 if ($nextQuestion && $nextQuestion.length) {
575 $('.quiz-attempt-single-question').hide();
576 $nextQuestion.show();
577
578 /**
579 * If pagination exists, set active class
580 */
581
582 if ($('.tutor-quiz-questions-pagination').length) {
583 $('.tutor-quiz-question-paginate-item').removeClass('active');
584 $('.tutor-quiz-questions-pagination a[href="' + next_question_id + '"]').addClass('active');
585 }
586
587 }
588 }
589 });
590
591
592 $(document).on('submit', '#tutor-answering-quiz', function (e) {
593 var $questions_wrap = $('.quiz-attempt-single-question');
594 var validated = true;
595 if ($questions_wrap.length) {
596 $questions_wrap.each(function (index, question) {
597 validated = tutor_quiz_validation($(question));
598 });
599 }
600
601 if (!validated) {
602 e.preventDefault();
603 }
604
605 });
606
607
608 $(document).on('click', '.tutor-quiz-question-paginate-item', function (e) {
609 e.preventDefault();
610 var $that = $(this);
611 var $question = $($that.attr('href'));
612 $('.quiz-attempt-single-question').hide();
613 $question.show();
614
615 //Active Class
616 $('.tutor-quiz-question-paginate-item').removeClass('active');
617 $that.addClass('active');
618 });
619
620 /**
621 * Limit Short Answer Question Type
622 */
623 $(document).on('keyup', 'textarea.question_type_short_answer, textarea.question_type_open_ended', function (e) {
624 var $that = $(this);
625 var value = $that.val();
626 var limit = $that.hasClass('question_type_short_answer') ? _tutorobject.quiz_options.short_answer_characters_limit : _tutorobject.quiz_options.open_ended_answer_characters_limit;
627 var remaining = limit - value.length;
628
629 if (remaining < 1) {
630 $that.val(value.substr(0, limit));
631 remaining = 0;
632 }
633 $that.closest('.tutor-quiz-answers-wrap').find('.characters_remaining').html(remaining);
634 });
635
636 /**
637 *
638 * @type {jQuery}
639 *
640 * Improved Quiz draggable answers drop accessibility
641 * Answers draggable wrap will be now same height.
642 *
643 * @since v.1.4.4
644 */
645 var countDraggableAnswers = $('.quiz-draggable-rand-answers').length;
646 if (countDraggableAnswers) {
647 $('.quiz-draggable-rand-answers').each(function () {
648 var $that = $(this);
649 var draggableDivHeight = $that.height();
650
651 $that.css({ "height": draggableDivHeight });
652 });
653 }
654
655
656 /**
657 * Quiz Validation Helper
658 *
659 * @since v.1.6.1
660 */
661
662 function tutor_quiz_validation($question_wrap) {
663 var validated = true;
664
665 var $required_answer_wrap = $question_wrap.find('.quiz-answer-required');
666
667
668 if ($required_answer_wrap.length) {
669
670 /**
671 * Radio field validation
672 *
673 * @type {jQuery}
674 *
675 * @since v.1.6.1
676 */
677 var $inputs = $required_answer_wrap.find('input');
678 if ($inputs.length) {
679 var $type = $inputs.attr('type');
680 if ($type === 'radio') {
681 if ($required_answer_wrap.find('input[type="radio"]:checked').length == 0) {
682 $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">Please select an option to answer</p>');
683 validated = false;
684 }
685 } else if ($type === 'checkbox') {
686 if ($required_answer_wrap.find('input[type="checkbox"]:checked').length == 0) {
687 $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">Please select at least one option to answer.</p>');
688 validated = false;
689 }
690 } else if ($type === 'text') {
691 //Fill in the gaps if many, validation all
692 $inputs.each(function (index, input) {
693 if (!$(input).val().trim().length) {
694 $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">The answer for this question is required</p>');
695 validated = false;
696 }
697 });
698 }
699
700 }
701 if ($required_answer_wrap.find('textarea').length) {
702 if ($required_answer_wrap.find('textarea').val().trim().length < 1) {
703 $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">The answer for this question is required</p>');
704 validated = false;
705 }
706 }
707
708 /**
709 * Matching Question
710 */
711 var $matchingDropable = $required_answer_wrap.find('.quiz-answer-matching-droppable');
712 if ($matchingDropable.length) {
713
714 $matchingDropable.each(function (index, matching) {
715 if (!$(matching).find('.quiz-draggable-answer-item').length) {
716 $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">Please match all the items</p>');
717 validated = false;
718 }
719
720 });
721
722 }
723
724
725
726 }
727
728 return validated;
729 }
730
731
732
733 /**
734 * Add to cart in guest mode, show login form
735 *
736 * @since v.1.0.4
737 */
738
739 $(document).on('submit click', '.cart-required-login, .cart-required-login a, .cart-required-login form', function (e) {
740 e.preventDefault();
741
742 $('.tutor-cart-box-login-form').fadeIn(100);
743 });
744
745 $('.tutor-popup-form-close, .login-overlay-close').on('click', function () {
746 $('.tutor-cart-box-login-form').fadeOut(100);
747 });
748
749 $(document).on('keyup', function (e) {
750 if (e.keyCode === 27) {
751 $('.tutor-frontend-modal').hide();
752 $('.tutor-cart-box-login-form').fadeOut(100);
753 }
754 });
755 /**
756 * Share Link enable
757 *
758 * @since v.1.0.4
759 */
760 if ($.fn.ShareLink) {
761 var $social_share_wrap = $('.tutor-social-share-wrap');
762 if ($social_share_wrap.length) {
763 var share_config = JSON.parse($social_share_wrap.attr('data-social-share-config'));
764
765 $('.tutor_share').ShareLink({
766 title: share_config.title,
767 text: share_config.text,
768 image: share_config.image,
769 class_prefix: 's_',
770 width: 640,
771 height: 480,
772 });
773 }
774 }
775
776 /**
777 * Datepicker initiate
778 *
779 * @since v.1.1.2
780 */
781 if (jQuery.datepicker) {
782 $(".tutor_report_datepicker").datepicker({ "dateFormat": 'yy-mm-dd' });
783 }
784
785
786 /**
787 * Withdraw Form Tab/Toggle
788 *
789 * @since v.1.1.2
790 */
791
792 $(".withdraw-method-select-input").on('change', function (e) {
793 var $that = $(this);
794 $('.withdraw-method-form').hide();
795 $('#withdraw-method-form-' + $that.closest('.withdraw-method-select').attr('data-withdraw-method')).show();
796 });
797
798 $('.withdraw-method-select-input').each(function () {
799 var $that = $(this);
800 if ($that.is(":checked")) {
801 $('.withdraw-method-form').hide();
802 $('#withdraw-method-form-' + $that.closest('.withdraw-method-select').attr('data-withdraw-method')).show();
803 }
804 });
805
806
807
808 /**
809 * Setting account for withdraw earning
810 *
811 * @since v.1.2.0
812 */
813 $(document).on('submit', '#tutor-withdraw-account-set-form', function (e) {
814 e.preventDefault();
815
816 var $form = $(this);
817 var $btn = $form.find('.tutor_set_withdraw_account_btn');
818 var data = $form.serialize();
819
820 $.ajax({
821 url: _tutorobject.ajaxurl,
822 type: 'POST',
823 data: data,
824 beforeSend: function () {
825 $form.find('.tutor-success-msg').remove();
826 $btn.addClass('updating-icon');
827 },
828 success: function (data) {
829 if (data.success) {
830 var successMsg = '<div class="tutor-success-msg" style="display: none;"><i class="tutor-icon-mark"></i> ' + data.data.msg + ' </div>';
831 $btn.closest('.withdraw-account-save-btn-wrap').append(successMsg);
832 if ($form.find('.tutor-success-msg').length) {
833 $form.find('.tutor-success-msg').slideDown();
834 }
835 setTimeout(function () {
836 $form.find('.tutor-success-msg').slideUp();
837 }, 5000)
838 }
839 },
840 complete: function () {
841 $btn.removeClass('updating-icon');
842 }
843 });
844 });
845
846 /**
847 * Make Withdraw Form
848 *
849 * @since v.1.2.0
850 */
851
852 $(document).on('click', 'a.open-withdraw-form-btn', function (e) {
853 e.preventDefault();
854 $('.tutor-earning-withdraw-form-wrap').slideToggle();
855 });
856
857 $(document).on('submit', '#tutor-earning-withdraw-form', function (e) {
858 e.preventDefault();
859
860 var $form = $(this);
861 var $btn = $('#tutor-earning-withdraw-btn');
862 var $responseDiv = $('#tutor-withdraw-form-response');
863 var data = $form.serialize();
864
865 $.ajax({
866 url: _tutorobject.ajaxurl,
867 type: 'POST',
868 data: data,
869 beforeSend: function () {
870 $form.find('.tutor-success-msg').remove();
871 $btn.addClass('updating-icon');
872 },
873 success: function (data) {
874 var Msg;
875 if (data.success) {
876
877 if (data.data.available_balance !== 'undefined') {
878 $('.withdraw-balance-col .available_balance').html(data.data.available_balance);
879 }
880 Msg = '<div class="tutor-success-msg"><i class="tutor-icon-mark"></i> ' + data.data.msg + ' </div>';
881
882 } else {
883 Msg = '<div class="tutor-error-msg"><i class="tutor-icon-line-cross"></i> ' + data.data.msg + ' </div>';
884 }
885
886 $responseDiv.html(Msg);
887 setTimeout(function () {
888 $responseDiv.html('');
889 }, 5000)
890 },
891 complete: function () {
892 $btn.removeClass('updating-icon');
893 }
894 });
895 });
896
897 var frontEndModal = $('.tutor-frontend-modal');
898 frontEndModal.each(function () {
899 var modal = $(this),
900 action = $(this).data('popup-rel');
901 $('[href="' + action + '"]').on('click', function (e) {
902 modal.fadeIn();
903 e.preventDefault();
904 });
905 });
906 $(document).on('click', '.tm-close, .tutor-frontend-modal-overlay, .tutor-modal-btn-cancel', function () {
907 frontEndModal.fadeOut();
908 });
909
910 /**
911 * Delete Course
912 */
913 $(document).on('click', '.tutor-mycourse-delete-btn', function (e) {
914 e.preventDefault();
915 var course_id = $(this).attr('data-course-id');
916 $('#tutor-course-delete-id').val(course_id);
917 });
918 $(document).on('submit', '#tutor-delete-course-form', function (e) {
919 e.preventDefault();
920
921 var course_id = $('#tutor-course-delete-id').val();
922 var $btn = $('.tutor-modal-course-delete-btn');
923 var data = $(this).serialize();
924
925 $.ajax({
926 url: _tutorobject.ajaxurl,
927 type: 'POST',
928 data: data,
929 beforeSend: function () {
930 $btn.addClass('updating-icon');
931 },
932 success: function (data) {
933 if (data.success) {
934 $('#tutor-dashboard-course-' + course_id).remove();
935 }
936 },
937 complete: function () {
938 $btn.removeClass('updating-icon');
939 $('.tutor-frontend-modal').hide();
940 }
941 });
942 });
943
944 /**
945 * Frontend Profile
946 */
947
948 if (!$('#tutor_profile_photo_id').val()) {
949 $('.tutor-profile-photo-delete-btn').hide();
950 }
951
952 $(document).on('click', '.tutor-profile-photo-delete-btn', function () {
953 $('.tutor-profile-photo-upload-wrap').find('img').attr('src', _tutorobject.placeholder_img_src);
954 $('#tutor_profile_photo_id').val('');
955 $('.tutor-profile-photo-delete-btn').hide();
956
957 $.ajax({
958 url: _tutorobject.ajaxurl,
959 type: 'POST',
960 data: { 'action': 'tutor_profile_photo_remove' },
961 });
962
963 return false;
964 });
965
966 /**
967 * Assignment
968 *
969 * @since v.1.3.3
970 */
971 $(document).on('submit', '#tutor_assignment_start_form', function (e) {
972 e.preventDefault();
973
974 var $that = $(this);
975 var form_data = $that.serialize() + '&action=tutor_start_assignment';
976
977 $.ajax({
978 url: _tutorobject.ajaxurl,
979 type: 'POST',
980 data: form_data,
981 beforeSend: function () {
982 $('#tutor_assignment_start_btn').addClass('updating-icon');
983 },
984 success: function (data) {
985 if (data.success) {
986 location.reload();
987 }
988 },
989 complete: function () {
990 $('#tutor_assignment_start_btn').removeClass('updating-icon');
991 }
992 });
993 });
994
995 /**
996 * Assignment answer validation
997 */
998 $(document).on('submit', '#tutor_assignment_submit_form', function (e) {
999 var assignment_answer = $('textarea[name="assignment_answer"]').val();
1000 if (assignment_answer.trim().length < 1) {
1001 $('#form_validation_response').html('<div class="tutor-error-msg">' + _tutorobject.text.assignment_text_validation_msg + '</div>');
1002 e.preventDefault();
1003 }
1004 });
1005
1006 /**
1007 * Course builder video
1008 * @since v.1.3.4
1009 */
1010
1011
1012 $(document).on('click', '.video_source_upload_wrap_html5 .video_upload_btn', function (event) {
1013 event.preventDefault();
1014
1015 var $that = $(this);
1016 var frame;
1017 // If the media frame already exists, reopen it.
1018 if (frame) {
1019 frame.open();
1020 return;
1021 }
1022 frame = wp.media({
1023 title: 'Select or Upload Media Of Your Chosen Persuasion',
1024 button: {
1025 text: 'Use this media'
1026 },
1027 library: { type: 'video' },
1028 multiple: false // Set to true to allow multiple files to be selected
1029 });
1030 frame.on('select', function () {
1031 // Get media attachment details from the frame state
1032 var attachment = frame.state().get('selection').first().toJSON();
1033 $that.closest('.video_source_upload_wrap_html5').find('span.video_media_id').text(attachment.id).closest('p').show();
1034 $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id);
1035 });
1036 frame.open();
1037 });
1038
1039
1040 /**
1041 * Course and lesson sorting
1042 */
1043
1044 function enable_sorting_topic_lesson() {
1045 if (jQuery().sortable) {
1046 $(".course-contents").sortable({
1047 handle: ".course-move-handle",
1048 start: function (e, ui) {
1049 ui.placeholder.css('visibility', 'visible');
1050 },
1051 stop: function (e, ui) {
1052 tutor_sorting_topics_and_lesson();
1053 },
1054 });
1055 $(".tutor-lessons:not(.drop-lessons)").sortable({
1056 connectWith: ".tutor-lessons",
1057 items: "div.course-content-item",
1058 start: function (e, ui) {
1059 ui.placeholder.css('visibility', 'visible');
1060 },
1061 stop: function (e, ui) {
1062 tutor_sorting_topics_and_lesson();
1063 },
1064 });
1065 }
1066 }
1067 enable_sorting_topic_lesson();
1068 function tutor_sorting_topics_and_lesson() {
1069 var topics = {};
1070 $('.tutor-topics-wrap').each(function (index, item) {
1071 var $topic = $(this);
1072 var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10);
1073 var lessons = {};
1074
1075 $topic.find('.course-content-item').each(function (lessonIndex, lessonItem) {
1076 var $lesson = $(this);
1077 var lesson_id = parseInt($lesson.attr('id').match(/\d+/)[0], 10);
1078
1079 lessons[lessonIndex] = lesson_id;
1080 });
1081 topics[index] = { 'topic_id': topics_id, 'lesson_ids': lessons };
1082 });
1083 $('#tutor_topics_lessons_sorting').val(JSON.stringify(topics));
1084 }
1085
1086 /**
1087 * Lesson Update or Create Modal
1088 */
1089 $(document).on('click', '.update_lesson_modal_btn', function (event) {
1090 event.preventDefault();
1091
1092 var $that = $(this);
1093 var content;
1094 var editor = tinyMCE.get('tutor_lesson_modal_editor');
1095 if (editor) {
1096 content = editor.getContent();
1097 } else {
1098 content = $('#' + inputid).val();
1099 }
1100
1101 var form_data = $(this).closest('form').serialize();
1102 form_data += '&lesson_content=' + encodeURIComponent(content);
1103
1104 $.ajax({
1105 url: ajaxurl,
1106 type: 'POST',
1107 data: form_data,
1108 beforeSend: function () {
1109 $that.addClass('tutor-updating-message');
1110 },
1111 success: function (data) {
1112 if (data.success) {
1113 $('#tutor-course-content-wrap').html(data.data.course_contents);
1114 enable_sorting_topic_lesson();
1115
1116 //Close the modal
1117 $('.tutor-lesson-modal-wrap').removeClass('show');
1118 }
1119 },
1120 complete: function () {
1121 $that.removeClass('tutor-updating-message');
1122 }
1123 });
1124 });
1125
1126 /**
1127 * END: Tutor Course builder JS
1128 */
1129
1130 /**
1131 * Attachment in forntend course builder
1132 * @since v.1.3.4
1133 */
1134 $(document).on('click', 'a.tutor-delete-attachment', function (e) {
1135 e.preventDefault();
1136 $(this).closest('.tutor-added-attachment').remove();
1137 });
1138 $(document).on('click', '.tutorUploadAttachmentBtn', function (e) {
1139 e.preventDefault();
1140
1141 var $that = $(this);
1142 var frame;
1143 if (frame) {
1144 frame.open();
1145 return;
1146 }
1147 frame = wp.media({
1148 title: 'Select or Upload Media Of Your Chosen Persuasion',
1149 button: {
1150 text: 'Use this media'
1151 },
1152 multiple: true // Set to true to allow multiple files to be selected
1153 });
1154 frame.on('select', function () {
1155 var attachments = frame.state().get('selection').toJSON();
1156 if (attachments.length) {
1157 for (var i = 0; i < attachments.length; i++) {
1158 var attachment = attachments[i];
1159
1160 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>';
1161 $that.closest('.tutor-lesson-attachments-metabox').find('.tutor-added-attachments-wrap').append(inputHtml);
1162 }
1163 }
1164 });
1165 frame.open();
1166 });
1167
1168
1169 /**
1170 * Single Assignment Upload Button
1171 * @since v.1.3.4
1172 */
1173 $('form').on('change', '.tutor-assignment-file-upload', function () {
1174 $(this).siblings("label").find('span').html($(this).val().replace(/.*(\/|\\)/, ''));
1175 });
1176
1177 /**
1178 * Lesson Sidebar Topic Toggle
1179 * @since v.1.3.4
1180 */
1181
1182 $(document).on('click', '.tutor-topics-in-single-lesson .tutor-topics-title h3, .tutor-single-lesson-topic-toggle', function (e) {
1183 var $that = $(this);
1184 var $parent = $that.closest('.tutor-topics-in-single-lesson');
1185 $parent.toggleClass('tutor-topic-active');
1186 $parent.find('.tutor-lessons-under-topic').slideToggle();
1187 });
1188
1189 $('.tutor-single-lesson-items.active').closest('.tutor-lessons-under-topic').show();
1190 $('.tutor-single-lesson-items.active').closest('.tutor-topics-in-single-lesson').addClass('tutor-topic-active');
1191 $('.tutor-course-lesson.active').closest('.tutor-lessons-under-topic').show();
1192
1193
1194 /**
1195 * Assignments Addons
1196 * @backend Support
1197 *
1198 */
1199
1200
1201 /**
1202 * Tutor Assignments JS
1203 * @since v.1.3.3
1204 */
1205 $(document).on('click', '.tutor-create-assignments-btn', function (e) {
1206 e.preventDefault();
1207
1208 var $that = $(this);
1209 var topic_id = $(this).attr('data-topic-id');
1210 var course_id = $('#post_ID').val();
1211
1212 $.ajax({
1213 url: ajaxurl,
1214 type: 'POST',
1215 data: { topic_id: topic_id, course_id: course_id, action: 'tutor_load_assignments_builder_modal' },
1216 beforeSend: function () {
1217 $that.addClass('tutor-updating-message');
1218 },
1219 success: function (data) {
1220 $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output);
1221 $('.tutor-lesson-modal-wrap').attr('data-topic-id', topic_id).addClass('show');
1222
1223 $(document).trigger('assignment_modal_loaded', { topic_id: topic_id, course_id: course_id });
1224
1225 tinymce.init(tinyMCEPreInit.mceInit.course_description);
1226 tinymce.execCommand('mceRemoveEditor', false, 'tutor_assignments_modal_editor');
1227 tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor");
1228 },
1229 complete: function () {
1230 quicktags({ id: "tutor_assignments_modal_editor" });
1231 $that.removeClass('tutor-updating-message');
1232 }
1233 });
1234 });
1235
1236 $(document).on('click', '.open-tutor-assignment-modal', function (e) {
1237 e.preventDefault();
1238
1239 var $that = $(this);
1240 var assignment_id = $that.attr('data-assignment-id');
1241 var topic_id = $that.attr('data-topic-id');
1242 var course_id = $('#post_ID').val();
1243
1244 $.ajax({
1245 url: ajaxurl,
1246 type: 'POST',
1247 data: { assignment_id: assignment_id, topic_id: topic_id, course_id: course_id, action: 'tutor_load_assignments_builder_modal' },
1248 beforeSend: function () {
1249 $that.addClass('tutor-updating-message');
1250 },
1251 success: function (data) {
1252 $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output);
1253 $('.tutor-lesson-modal-wrap').attr({ 'data-assignment-id': assignment_id, 'data-topic-id': topic_id }).addClass('show');
1254
1255 $(document).trigger('assignment_modal_loaded', { assignment_id: assignment_id, topic_id: topic_id, course_id: course_id });
1256
1257 tinymce.init(tinyMCEPreInit.mceInit.course_description);
1258 tinymce.execCommand('mceRemoveEditor', false, 'tutor_assignments_modal_editor');
1259 tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor");
1260 },
1261 complete: function () {
1262 quicktags({ id: "tutor_assignments_modal_editor" });
1263 $that.removeClass('tutor-updating-message');
1264 }
1265 });
1266 });
1267
1268 /**
1269 * Update Assignment Data
1270 */
1271 $(document).on('click', '.update_assignment_modal_btn', function (event) {
1272 event.preventDefault();
1273
1274 var $that = $(this);
1275 var content;
1276 var editor = tinyMCE.get('tutor_assignments_modal_editor');
1277 if (editor) {
1278 content = editor.getContent();
1279 } else {
1280 content = $('#' + inputid).val();
1281 }
1282
1283 var form_data = $(this).closest('form').serialize();
1284 form_data += '&assignment_content=' + content;
1285
1286 $.ajax({
1287 url: ajaxurl,
1288 type: 'POST',
1289 data: form_data,
1290 beforeSend: function () {
1291 $that.addClass('tutor-updating-message');
1292 },
1293 success: function (data) {
1294 if (data.success) {
1295 $('#tutor-course-content-wrap').html(data.data.course_contents);
1296 enable_sorting_topic_lesson();
1297
1298 //Close the modal
1299 $('.tutor-lesson-modal-wrap').removeClass('show');
1300 }
1301 },
1302 complete: function () {
1303 $that.removeClass('tutor-updating-message');
1304 }
1305 });
1306 });
1307
1308 /**
1309 * Add Assignment
1310 */
1311 $(document).on('click', '.add-assignment-attachments', function (event) {
1312 event.preventDefault();
1313
1314 var $that = $(this);
1315 var frame;
1316 // If the media frame already exists, reopen it.
1317 if (frame) {
1318 frame.open();
1319 return;
1320 }
1321
1322 // Create a new media frame
1323 frame = wp.media({
1324 title: 'Select or Upload Media Of Your Chosen Persuasion',
1325 button: {
1326 text: 'Use this media'
1327 },
1328 multiple: false // Set to true to allow multiple files to be selected
1329 });
1330
1331 // When an image is selected in the media frame...
1332 frame.on('select', function () {
1333 // Get media attachment details from the frame state
1334 var attachment = frame.state().get('selection').first().toJSON();
1335
1336 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>';
1337
1338 $('#assignment-attached-file').append(field_markup);
1339 $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id);
1340 });
1341 // Finally, open the modal on click
1342 frame.open();
1343 });
1344
1345 $(document).on('click', '.remove-assignment-attachment-a', function (event) {
1346 event.preventDefault();
1347 $(this).closest('.tutor-individual-attachment-file').remove();
1348 });
1349
1350
1351 /**
1352 *
1353 * @type {jQuery}
1354 *
1355 * Course builder auto draft save
1356 *
1357 * @since v.1.3.4
1358 */
1359 var tutor_course_builder = $('input[name="tutor_action"]').val();
1360 if (tutor_course_builder === 'tutor_add_course_builder') {
1361 setInterval(auto_draft_save_course_builder, 30000);
1362 }
1363
1364 function auto_draft_save_course_builder() {
1365 var form_data = $('form#tutor-frontend-course-builder').serialize();
1366 $.ajax({
1367 //url : _tutorobject.ajaxurl,
1368 type: 'POST',
1369 data: form_data + '&tutor_ajax_action=tutor_course_builder_draft_save',
1370 beforeSend: function () {
1371 $('.tutor-dashboard-builder-draft-btn span').text('Saving...');
1372 },
1373 success: function (data) {
1374
1375 },
1376 complete: function () {
1377 $('.tutor-dashboard-builder-draft-btn span').text('Save');
1378 }
1379 });
1380 }
1381
1382 /**
1383 *
1384 * @type {jQuery}
1385 *
1386 * Course builder section toggle
1387 *
1388 * @since v.1.3.5
1389 */
1390
1391 $('.tutor-course-builder-section-title').on('click', function () {
1392 if ($(this).find('i').hasClass("tutor-icon-up")) {
1393 $(this).find('i').removeClass('tutor-icon-up').addClass('tutor-icon-down');
1394 } else {
1395 $(this).find('i').removeClass('tutor-icon-down').addClass('tutor-icon-up');
1396 }
1397 $(this).next('div').slideToggle();
1398 });
1399
1400 /**
1401 * Open Tutor Modal to edit review
1402 * @since v.1.4.0
1403 */
1404 $(document).on('click', '.open-tutor-edit-review-modal', function (e) {
1405 e.preventDefault();
1406
1407 var $that = $(this);
1408 var review_id = $that.attr('data-review-id');
1409
1410 var nonce_key = _tutorobject.nonce_key;
1411
1412 var json_data = { review_id: review_id, action: 'tutor_load_edit_review_modal' };
1413 json_data[nonce_key] = _tutorobject[nonce_key];
1414
1415 $.ajax({
1416 url: _tutorobject.ajaxurl,
1417 type: 'POST',
1418 data: json_data,
1419 beforeSend: function () {
1420 $that.addClass('tutor-updating-message');
1421 },
1422 success: function (data) {
1423 if (typeof data.data !== 'undefined') {
1424 $('.tutor-edit-review-modal-wrap .modal-container').html(data.data.output);
1425 $('.tutor-edit-review-modal-wrap').attr('data-review-id', review_id).addClass('show');
1426 }
1427 },
1428 complete: function () {
1429 $that.removeClass('tutor-updating-message');
1430 }
1431 });
1432 });
1433
1434 /**
1435 * Update the rating
1436 * @since v.1.4.0
1437 */
1438 $(document).on('submit', '#tutor_update_review_form', function (e) {
1439 e.preventDefault();
1440
1441 var $that = $(this);
1442 var review_id = $that.closest('.tutor-edit-review-modal-wrap ').attr('data-review-id');
1443
1444 var nonce_key = _tutorobject.nonce_key;
1445
1446 var rating = $that.find('input[name="tutor_rating_gen_input"]').val();
1447 var review = $that.find('textarea[name="review"]').val();
1448 review = review.trim();
1449
1450 var json_data = { review_id: review_id, rating: rating, review: review, action: 'tutor_update_review_modal' };
1451 json_data[nonce_key] = _tutorobject[nonce_key];
1452
1453 $.ajax({
1454 url: _tutorobject.ajaxurl,
1455 type: 'POST',
1456 data: json_data,
1457 beforeSend: function () {
1458 $that.find('button[type="submit"]').addClass('tutor-updating-message');
1459 },
1460 success: function (data) {
1461 if (data.success) {
1462 //Close the modal
1463 $('.tutor-edit-review-modal-wrap').removeClass('show');
1464 location.reload(true);
1465 }
1466 },
1467 complete: function () {
1468 $that.find('button[type="submit"]').removeClass('tutor-updating-message');
1469 }
1470 });
1471 });
1472
1473 /**
1474 * Profile photo upload
1475 * @since v.1.4.5
1476 */
1477
1478 $(document).on('click', '#tutor_profile_photo_button', function (e) {
1479 e.preventDefault();
1480
1481 $('#tutor_profile_photo_file').trigger('click');
1482 });
1483
1484 $(document).on('change', '#tutor_profile_photo_file', function (event) {
1485 event.preventDefault();
1486
1487 var $file = this;
1488 if ($file.files && $file.files[0]) {
1489 var reader = new FileReader();
1490 reader.onload = function (e) {
1491 $('.tutor-profile-photo-upload-wrap').find('img').attr('src', e.target.result);
1492 }
1493 reader.readAsDataURL($file.files[0]);
1494 }
1495 });
1496
1497 /**
1498 * Addon, Tutor BuddyPress
1499 * Retrieve MetaInformation on BuddyPress message system
1500 * @for TutorLMS Pro
1501 * @since v.1.4.8
1502 */
1503
1504 $(document).on('click', '.thread-content .subject', function (e) {
1505 var $btn = $(this);
1506
1507 var thread_id = parseInt($btn.closest('.thread-content').attr('data-thread-id'));
1508
1509 var nonce_key = _tutorobject.nonce_key;
1510 var json_data = { thread_id: thread_id, action: 'tutor_bp_retrieve_user_records_for_thread' };
1511 json_data[nonce_key] = _tutorobject[nonce_key];
1512
1513 $.ajax({
1514 type: 'POST',
1515 url: ajaxurl,
1516 data: json_data,
1517 beforeSend: function () {
1518 $('#tutor-bp-thread-wrap').html('');
1519 },
1520 success: function (data) {
1521 if (data.success) {
1522 $('#tutor-bp-thread-wrap').html(data.data.thread_head_html);
1523 tutor_bp_setting_enrolled_courses_list();
1524 }
1525 }
1526 });
1527
1528 });
1529
1530
1531 function tutor_bp_setting_enrolled_courses_list() {
1532 $('ul.tutor-bp-enrolled-course-list').each(function () {
1533 var $that = $(this);
1534 var $li = $that.find(' > li');
1535 var itemShow = 3;
1536
1537 if ($li.length > itemShow) {
1538 var plusCourseCount = $li.length - itemShow;
1539 $li.each(function (liIndex, liItem) {
1540 var $liItem = $(this);
1541
1542 if (liIndex >= itemShow) {
1543 $liItem.hide();
1544 }
1545 });
1546
1547 var infoHtml = '<a href="javascript:;" class="tutor_bp_plus_courses"><strong>+' + plusCourseCount + ' More </strong></a> Courses';
1548 $that.closest('.tutor-bp-enrolled-courses-wrap').find('.thread-participant-enrolled-info').html(infoHtml);
1549 }
1550
1551 $that.show();
1552 });
1553 }
1554 tutor_bp_setting_enrolled_courses_list();
1555
1556 $(document).on('click', 'a.tutor_bp_plus_courses', function (e) {
1557 e.preventDefault();
1558
1559 var $btn = $(this);
1560 $btn.closest('.tutor-bp-enrolled-courses-wrap').find('.tutor-bp-enrolled-course-list li').show();
1561 $btn.closest('.thread-participant-enrolled-info').html('');
1562 });
1563
1564
1565 /**
1566 * Addon, Tutor Certificate
1567 * Certificate dropdown content and copy link
1568 * @for TutorLMS Pro
1569 * @since v.1.5.1
1570 */
1571 $(document).on('click', '.tutor-dropbtn', function (e) {
1572 var $content = $(this).parent().find(".tutor-dropdown-content");
1573 $content.slideToggle(100);
1574 });
1575 $(document).on('click', '.tutor-copy-link', function (e) {
1576 var $btn = $(this);
1577 var copy = '<i class="tutor-icon-copy"></i> Copy Link';
1578 var copied = '<i class="tutor-icon-mark"></i> Copied';
1579 var dummy = document.createElement('input'),
1580 text = window.location.href;
1581 document.body.appendChild(dummy);
1582 dummy.value = text;
1583 dummy.select();
1584 document.execCommand('copy');
1585 document.body.removeChild(dummy);
1586 $btn.html(copied);
1587 setTimeout(function () {
1588 $btn.html(copy);
1589 }, 2500);
1590 });
1591 $(document).on('click', function (e) {
1592 var container = $(".tutor-dropdown");
1593 var $content = container.find('.tutor-dropdown-content');
1594 // if the target of the click isn't the container nor a descendant of the container
1595 if (!container.is(e.target) && container.has(e.target).length === 0) {
1596 $content.slideUp(100);
1597 }
1598 });
1599
1600
1601 /**
1602 * Tutor ajax login
1603 *
1604 * @since v.1.6.3
1605 */
1606 $(document).on('submit', '.tutor-login-form-wrap #loginform', function (e) {
1607 e.preventDefault();
1608 var $that = $(this);
1609 var $form_wrapper = $('.tutor-login-form-wrap');
1610 var form_data = $that.serialize() + '&action=tutor_user_login';
1611 $.ajax({
1612 url: _tutorobject.ajaxurl,
1613 type: 'POST',
1614 data: form_data,
1615 success: function (response) {
1616 if (response.success) {
1617 location.href = response.data.redirect;
1618 } else {
1619 if ($form_wrapper.find('.tutor-alert').length) {
1620 $form_wrapper.find('.tutor-alert').html(response.data);
1621 } else {
1622 $form_wrapper.prepend('<div class="tutor-alert tutor-alert-warning">'+response.data+'</div>');
1623 }
1624 }
1625 },
1626 });
1627 });
1628
1629 });