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