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