PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 1.7.9
Tutor LMS – eLearning and online course solution v1.7.9
4.0.4 4.0.3 4.0.2 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
2116 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 },
1250 complete: function () {
1251 $that.removeClass('tutor-updating-message');
1252 }
1253 });
1254 });
1255
1256 /**
1257 * END: Tutor Course builder JS
1258 */
1259
1260 /**
1261 * Attachment in forntend course builder
1262 * @since v.1.3.4
1263 */
1264 $(document).on('click', 'a.tutor-delete-attachment', function (e) {
1265 e.preventDefault();
1266 $(this).closest('.tutor-added-attachment').remove();
1267 });
1268 $(document).on('click', '.tutorUploadAttachmentBtn', function (e) {
1269 e.preventDefault();
1270
1271 var $that = $(this);
1272 var frame;
1273 if (frame) {
1274 frame.open();
1275 return;
1276 }
1277 frame = wp.media({
1278 title: 'Select or Upload Media Of Your Chosen Persuasion',
1279 button: {
1280 text: 'Use this media'
1281 },
1282 multiple: true // Set to true to allow multiple files to be selected
1283 });
1284 frame.on('select', function () {
1285 var attachments = frame.state().get('selection').toJSON();
1286 if (attachments.length) {
1287 for (var i = 0; i < attachments.length; i++) {
1288 var attachment = attachments[i];
1289
1290 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>';
1291 $that.closest('.tutor-lesson-attachments-metabox').find('.tutor-added-attachments-wrap').append(inputHtml);
1292 }
1293 }
1294 });
1295 frame.open();
1296 });
1297
1298
1299 /**
1300 * Single Assignment Upload Button
1301 * @since v.1.3.4
1302 */
1303 $('form').on('change', '.tutor-assignment-file-upload', function () {
1304 $(this).siblings("label").find('span').html($(this).val().replace(/.*(\/|\\)/, ''));
1305 });
1306
1307 /**
1308 * Lesson Sidebar Topic Toggle
1309 * @since v.1.3.4
1310 */
1311
1312 $(document).on('click', '.tutor-topics-in-single-lesson .tutor-topics-title h3, .tutor-single-lesson-topic-toggle', function (e) {
1313 var $that = $(this);
1314 var $parent = $that.closest('.tutor-topics-in-single-lesson');
1315 $parent.toggleClass('tutor-topic-active');
1316 $parent.find('.tutor-lessons-under-topic').slideToggle();
1317 });
1318
1319 $('.tutor-single-lesson-items.active').closest('.tutor-lessons-under-topic').show();
1320 $('.tutor-single-lesson-items.active').closest('.tutor-topics-in-single-lesson').addClass('tutor-topic-active');
1321 $('.tutor-course-lesson.active').closest('.tutor-lessons-under-topic').show();
1322
1323
1324 /**
1325 * Assignments Addons
1326 * @backend Support
1327 *
1328 */
1329
1330
1331 /**
1332 * Tutor Assignments JS
1333 * @since v.1.3.3
1334 */
1335 $(document).on('click', '.tutor-create-assignments-btn', function (e) {
1336 e.preventDefault();
1337
1338 var $that = $(this);
1339 var topic_id = $(this).attr('data-topic-id');
1340 var course_id = $('#post_ID').val();
1341
1342 $.ajax({
1343 url: ajaxurl,
1344 type: 'POST',
1345 data: { topic_id: topic_id, course_id: course_id, action: 'tutor_load_assignments_builder_modal' },
1346 beforeSend: function () {
1347 $that.addClass('tutor-updating-message');
1348 },
1349 success: function (data) {
1350 $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output);
1351 $('.tutor-lesson-modal-wrap').attr('data-topic-id', topic_id).addClass('show');
1352
1353 $(document).trigger('assignment_modal_loaded', { topic_id: topic_id, course_id: course_id });
1354
1355 tinymce.init(tinyMCEPreInit.mceInit.course_description);
1356 tinymce.execCommand('mceRemoveEditor', false, 'tutor_assignments_modal_editor');
1357 tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor");
1358 },
1359 complete: function () {
1360 quicktags({ id: "tutor_assignments_modal_editor" });
1361 $that.removeClass('tutor-updating-message');
1362 }
1363 });
1364 });
1365
1366 $(document).on('click', '.open-tutor-assignment-modal', function (e) {
1367 e.preventDefault();
1368
1369 var $that = $(this);
1370 var assignment_id = $that.attr('data-assignment-id');
1371 var topic_id = $that.attr('data-topic-id');
1372 var course_id = $('#post_ID').val();
1373
1374 $.ajax({
1375 url: ajaxurl,
1376 type: 'POST',
1377 data: { assignment_id: assignment_id, topic_id: topic_id, course_id: course_id, action: 'tutor_load_assignments_builder_modal' },
1378 beforeSend: function () {
1379 $that.addClass('tutor-updating-message');
1380 },
1381 success: function (data) {
1382 $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output);
1383 $('.tutor-lesson-modal-wrap').attr({ 'data-assignment-id': assignment_id, 'data-topic-id': topic_id }).addClass('show');
1384
1385 $(document).trigger('assignment_modal_loaded', { assignment_id: assignment_id, topic_id: topic_id, course_id: course_id });
1386
1387 tinymce.init(tinyMCEPreInit.mceInit.course_description);
1388 tinymce.execCommand('mceRemoveEditor', false, 'tutor_assignments_modal_editor');
1389 tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor");
1390 },
1391 complete: function () {
1392 quicktags({ id: "tutor_assignments_modal_editor" });
1393 $that.removeClass('tutor-updating-message');
1394 }
1395 });
1396 });
1397
1398 /**
1399 * Update Assignment Data
1400 */
1401 $(document).on('click', '.update_assignment_modal_btn', function (event) {
1402 event.preventDefault();
1403
1404 var $that = $(this);
1405 var content;
1406 var editor = tinyMCE.get('tutor_assignments_modal_editor');
1407 if (editor) {
1408 content = editor.getContent();
1409 } else {
1410 content = $('#' + inputid).val();
1411 }
1412
1413 var form_data = $(this).closest('form').serializeObject();
1414 form_data.assignment_content = content;
1415
1416 $.ajax({
1417 url: ajaxurl,
1418 type: 'POST',
1419 data: form_data,
1420 beforeSend: function () {
1421 $that.addClass('tutor-updating-message');
1422 },
1423 success: function (data) {
1424 if (data.success) {
1425 $('#tutor-course-content-wrap').html(data.data.course_contents);
1426 enable_sorting_topic_lesson();
1427
1428 //Close the modal
1429 $('.tutor-lesson-modal-wrap').removeClass('show');
1430 }
1431 },
1432 complete: function () {
1433 $that.removeClass('tutor-updating-message');
1434 }
1435 });
1436 });
1437
1438 /**
1439 * Add Assignment
1440 */
1441 $(document).on('click', '.add-assignment-attachments', function (event) {
1442 event.preventDefault();
1443
1444 var $that = $(this);
1445 var frame;
1446 // If the media frame already exists, reopen it.
1447 if (frame) {
1448 frame.open();
1449 return;
1450 }
1451
1452 // Create a new media frame
1453 frame = wp.media({
1454 title: 'Select or Upload Media Of Your Chosen Persuasion',
1455 button: {
1456 text: 'Use this media'
1457 },
1458 multiple: false // Set to true to allow multiple files to be selected
1459 });
1460
1461 // When an image is selected in the media frame...
1462 frame.on('select', function () {
1463 // Get media attachment details from the frame state
1464 var attachment = frame.state().get('selection').first().toJSON();
1465
1466 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>';
1467
1468 $('#assignment-attached-file').append(field_markup);
1469 $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id);
1470 });
1471 // Finally, open the modal on click
1472 frame.open();
1473 });
1474
1475 $(document).on('click', '.remove-assignment-attachment-a', function (event) {
1476 event.preventDefault();
1477 $(this).closest('.tutor-individual-attachment-file').remove();
1478 });
1479
1480
1481 /**
1482 *
1483 * @type {jQuery}
1484 *
1485 * Course builder auto draft save
1486 *
1487 * @since v.1.3.4
1488 */
1489 var tutor_course_builder = $('input[name="tutor_action"]').val();
1490 if (tutor_course_builder === 'tutor_add_course_builder') {
1491 setInterval(auto_draft_save_course_builder, 30000);
1492 }
1493
1494 function auto_draft_save_course_builder() {
1495
1496 var form_data = $('form#tutor-frontend-course-builder').serializeObject();
1497 form_data.tutor_ajax_action = 'tutor_course_builder_draft_save';
1498
1499 $.ajax({
1500 //url : _tutorobject.ajaxurl,
1501 type: 'POST',
1502 data: form_data,
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 $('.tutor-dropbtn').click(function(){
1706
1707 var $content = $(this).parent().find(".tutor-dropdown-content");
1708 $content.slideToggle(100);
1709 })
1710
1711
1712 //$(document).on('click', '.tutor-copy-link', function (e) {
1713 $('.tutor-copy-link').click(function (e) {
1714 var $btn = $(this);
1715 var copy = '<i class="tutor-icon-copy"></i> Copy Link';
1716 var copied = '<i class="tutor-icon-mark"></i> Copied';
1717 var dummy = document.createElement('input'),
1718 text = window.location.href;
1719 document.body.appendChild(dummy);
1720 dummy.value = text;
1721 dummy.select();
1722 document.execCommand('copy');
1723 document.body.removeChild(dummy);
1724 $btn.html(copied);
1725 setTimeout(function () {
1726 $btn.html(copy);
1727 }, 2500);
1728 });
1729
1730 $(document).on('click', function (e) {
1731 var container = $(".tutor-dropdown");
1732 var $content = container.find('.tutor-dropdown-content');
1733 // if the target of the click isn't the container nor a descendant of the container
1734 if (!container.is(e.target) && container.has(e.target).length === 0) {
1735 $content.slideUp(100);
1736 }
1737 });
1738
1739
1740 /**
1741 * Tutor ajax login
1742 *
1743 * @since v.1.6.3
1744 */
1745 $(document).on('submit', '.tutor-login-form-wrap #loginform', function (e) {
1746 e.preventDefault();
1747
1748 var $that = $(this);
1749 var $form_wrapper = $('.tutor-login-form-wrap');
1750
1751 var form_data = $that.serializeObject();
1752 form_data.action = 'tutor_user_login';
1753
1754 $.ajax({
1755 url: _tutorobject.ajaxurl,
1756 type: 'POST',
1757 data: form_data,
1758 success: function (response) {
1759 if (response.success) {
1760 location.assign(response.data.redirect);
1761 location.reload();
1762 } else {
1763 if ($form_wrapper.find('.tutor-alert').length) {
1764 $form_wrapper.find('.tutor-alert').html(response.data);
1765 } else {
1766 $form_wrapper.prepend('<div class="tutor-alert tutor-alert-warning">' + response.data + '</div>');
1767 }
1768 }
1769 },
1770 });
1771 });
1772
1773 /**
1774 * Show hide is course public checkbox (frontend dashboard editor)
1775 *
1776 * @since v.1.7.2
1777 */
1778 var price_type = $('.tutor-frontend-builder-course-price [name="tutor_course_price_type"]');
1779 if(price_type.length==0){
1780 $('#_tutor_is_course_public_meta_checkbox').show();
1781 }
1782 else{
1783 price_type.change(function(){
1784 if($(this).prop('checked')){
1785 var method = $(this).val()=='paid' ? 'hide' : 'show';
1786 $('#_tutor_is_course_public_meta_checkbox')[method]();
1787 }
1788 }).trigger('change');
1789 }
1790
1791 /**
1792 * Withdrawal page tooltip
1793 *
1794 * @since v.1.7.4
1795 */
1796 // Fully accessible tooltip jQuery plugin with delegation.
1797 // Ideal for view containers that may re-render content.
1798 (function ($) {
1799 $.fn.tutor_tooltip = function () {
1800 this
1801
1802 // Delegate to tooltip, Hide if tooltip receives mouse or is clicked (tooltip may stick if parent has focus)
1803 .on('mouseenter click', '.tooltip', function (e) {
1804 e.stopPropagation();
1805 $(this).removeClass('isVisible');
1806 })
1807 // Delegate to parent of tooltip, Show tooltip if parent receives mouse or focus
1808 .on('mouseenter focus', ':has(>.tooltip)', function (e) {
1809 if (!$(this).prop('disabled')) { // IE 8 fix to prevent tooltip on `disabled` elements
1810 $(this)
1811 .find('.tooltip')
1812 .addClass('isVisible');
1813 }
1814 })
1815 // Delegate to parent of tooltip, Hide tooltip if parent loses mouse or focus
1816 .on('mouseleave blur keydown', ':has(>.tooltip)', function (e) {
1817 if (e.type === 'keydown') {
1818 if(e.which === 27) {
1819 $(this)
1820 .find('.tooltip')
1821 .removeClass('isVisible');
1822 }
1823 } else {
1824 $(this)
1825 .find('.tooltip')
1826 .removeClass('isVisible');
1827 }
1828 });
1829 return this;
1830 };
1831 }(jQuery));
1832
1833 // Bind event listener to container element
1834 $('.tutor-tooltip-inside').tutor_tooltip();
1835
1836
1837
1838 /**
1839 * Manage course filter
1840 *
1841 * @since v.1.7.2
1842 */
1843 var filter_criteria = {action:'tutor_course_filter_ajax'};
1844 var filter_container = $('.tutor-course-filter-container');
1845 var loop_container = $('.tutor-course-filter-loop-container');
1846 var toggle_criteria = function(name, value, is_checked){
1847
1848 if(is_checked===undefined){
1849
1850 if(!value){
1851 delete filter_criteria[name];
1852 }
1853 else{
1854 filter_criteria[name]=value;
1855 }
1856 }
1857 else{
1858 !filter_criteria[name] ? filter_criteria[name]=[] : 0;
1859 var index = filter_criteria[name].indexOf(value);
1860
1861 if(is_checked){
1862 index==-1 ? filter_criteria[name].push(value) : 0;
1863 }
1864 else{
1865 filter_criteria[name].splice(index, 1);
1866 }
1867 }
1868
1869 push_state();
1870 }
1871
1872 var push_state=function(){
1873 var exclude = ['column_per_row', 'course_per_page'];
1874
1875 var str = Object.keys(filter_criteria).map(function(key){
1876 var val = filter_criteria[key];
1877 var str = Array.isArray(val) ? val.join(',') : val;
1878
1879 return (key=='action' || !str || exclude.indexOf(key)>-1) ? null : key+'='+str;
1880
1881 }).filter(q=>q!==null).join('&');
1882
1883 window.history.replaceState({'id':'tutor_courses'}, 'Courses', (str ? '?'+str : ''));
1884 }
1885
1886 // Sidebar checkbox value change
1887 filter_container.find('[type=checkbox]').change(function(e){
1888 /**
1889 * check if checkbox is checked
1890 */
1891 var is_checked = filter_container.find('[type=checkbox]').is(":checked");
1892 is_checked ? $(".tutor-clear-all-filter").show() : $(".tutor-clear-all-filter").hide();
1893
1894 e.originalEvent ? toggle_criteria($(this).attr('name'), $(this).val(), $(this).prop('checked')) : 0;
1895 filter_criteria.column_per_row = loop_container.data('column_per_row');
1896 filter_criteria.course_per_page = loop_container.data('course_per_page');
1897 loop_container.html('<div style="text-align:center"><img src="'+window.tutor_loading_icon_url+'"/></div>').show();
1898
1899 $.ajax({
1900 url:window._tutorobject.ajaxurl+(filter_criteria.page ? '?paged='+filter_criteria.page : ''),
1901 type:'POST',
1902 data:filter_criteria,
1903 success:function(r){
1904 loop_container.html(r).find('.tutor-pagination-wrap a').each(function(){
1905 $(this).attr('data-href', $(this).attr('href')).attr('href', '#');
1906 });
1907 },
1908 error:function(){
1909 alert('Request Failed!');
1910 }
1911 })
1912 });
1913
1914 // Search field
1915 var time_out;
1916 filter_container.on('input', '[name="tutor-course-filter-keyword"]', function(){
1917 window.clearTimeout(time_out);
1918
1919 var value = $(this).val();
1920 value = value.trim();
1921
1922 time_out=window.setTimeout(function(){
1923
1924 toggle_criteria('keyword', value);
1925
1926 filter_container.find('[type="checkbox"]:first').trigger('change');
1927 }, 500);
1928 });
1929
1930 // Alter pagination
1931 loop_container.on('click', '.tutor-pagination-wrap a', function(e){
1932 var url = $(this).data('href') || $(this).attr('href');
1933
1934 if(url){
1935 url = new URL(url);
1936 var page = url.searchParams.get("paged");
1937
1938 if(page){
1939 e.preventDefault();
1940 toggle_criteria('page', page);
1941
1942 filter_container.find('[type="checkbox"]:first').trigger('change');
1943 }
1944 }
1945 });
1946
1947 // Alter sort filter
1948 loop_container.on('change', 'select[name="tutor_course_filter"]', function(){
1949 toggle_criteria('tutor_course_filter', $(this).val());
1950 filter_container.find('[type="checkbox"]:first').trigger('change');
1951 });
1952
1953 // Parse filter from URL
1954 var url = new URL(window.location.href);
1955 var trigger_load=false;
1956 filter_container.find('[type="checkbox"]').each(function(){
1957 var name = $(this).attr('name');
1958 var value = $(this).val();
1959 var checked = $(this).prop('checked');
1960
1961 var arg = url.searchParams.get(name);
1962 arg = arg ? arg.split(',') : [];
1963
1964
1965 if(arg.indexOf(value)>-1 || checked){
1966 $(this).prop('checked', true);
1967 toggle_criteria(name, value, true, false);
1968 }
1969 });
1970
1971 ['page', 'keyword', 'tutor_course_filter'].forEach(function(name){
1972 var value = url.searchParams.get(name);
1973
1974 if(value){
1975 toggle_criteria(name, value, undefined, false);
1976 name=='keyword' ? filter_container.find('[name="tutor-course-filter-keyword"]').val(value) : 0;
1977 name=='tutor_course_filter' ? loop_container.find('select[name="tutor_course_filter"]').val(value) : 0;
1978 trigger_load=true;
1979 }
1980 });
1981
1982 if(trigger_load || filter_container.find('input:checked').length>0){
1983 filter_container.find('[type="checkbox"]:first').trigger('change');
1984 }
1985 else{
1986 loop_container.show();
1987 }
1988
1989 // Refresh page after coming back to course archive page from cart
1990 var archive_loop = $('.tutor-course-loop');
1991 if(archive_loop.length>0){
1992 window.sessionStorage.getItem('tutor_refresh_archive')==='yes' ? window.location.reload() : 0;
1993 window.sessionStorage.removeItem('tutor_refresh_archive');
1994 archive_loop.on('click', '.tutor-loop-cart-btn-wrap', function(){
1995 window.sessionStorage.setItem('tutor_refresh_archive', 'yes');
1996 });
1997 }
1998
1999 /**
2000 * Profile Photo and Cover Photo editor
2001 *
2002 * @since v.1.7.5
2003 */
2004 var PhotoEditor=function(photo_editor){
2005
2006 this.dialogue_box = photo_editor.find('#tutor_photo_dialogue_box');
2007
2008
2009 this.open_dialogue_box = function(name){
2010 this.dialogue_box.attr('name', name);
2011 this.dialogue_box.trigger('click');
2012 }
2013
2014 this.validate_image = function(file){
2015 return true;
2016 }
2017
2018 this.upload_selected_image = function(name, file){
2019 if(!file || !this.validate_image(file)){
2020 return;
2021 }
2022
2023 var context = this;
2024 context.toggle_loader(name, true);
2025
2026 // Prepare payload to upload
2027 var form_data = new FormData();
2028 form_data.append('action', 'tutor_user_photo_upload');
2029 form_data.append('photo_type', name);
2030 form_data.append('photo_file', file, file.name);
2031
2032 $.ajax({
2033 url:window._tutorobject.ajaxurl,
2034 data:form_data,
2035 type:'POST',
2036 processData: false,
2037 contentType: false,
2038 error:context.error_alert,
2039 complete:function(){
2040 context.toggle_loader(name, false);
2041 }
2042 })
2043 }
2044
2045 this.accept_upload_image=function(context, e){
2046 var file = e.currentTarget.files[0] || null;
2047 context.update_preview(e.currentTarget.name, file);
2048 context.upload_selected_image(e.currentTarget.name, file);
2049 $(e.currentTarget).val('');
2050 }
2051
2052 this.delete_image=function(name){
2053 var context = this;
2054 context.toggle_loader(name, true);
2055
2056 $.ajax({
2057 url:window._tutorobject.ajaxurl,
2058 data:{action:'tutor_user_photo_remove', photo_type:name},
2059 type:'POST',
2060 error:context.error_alert,
2061 complete:function(){
2062 context.toggle_loader(name, false);
2063 }
2064 });
2065 }
2066
2067 this.update_preview=function(name, file){
2068 var renderer = photo_editor.find(name=='cover_photo' ? '#tutor_cover_area' : '#tutor_profile_area');
2069
2070 if(!file){
2071 renderer.css('background-image', 'url('+renderer.data('fallback')+')');
2072 this.delete_image(name);
2073 return;
2074 }
2075
2076 var reader = new FileReader();
2077 reader.onload = function(e) {
2078 renderer.css('background-image', 'url('+e.target.result+')');
2079 }
2080
2081 reader.readAsDataURL(file);
2082 }
2083
2084 this.toggle_profile_pic_action=function(show){
2085 var method = show===undefined ? 'toggleClass' : (show ? 'addClass' : 'removeClass');
2086 photo_editor[method]('pop-up-opened');
2087 }
2088
2089 this.error_alert=function(){
2090 alert('Something Went Wrong.');
2091 }
2092
2093 this.toggle_loader = function(name, show){
2094 photo_editor.find('#tutor_photo_meta_area .loader-area').css('display', (show ? 'block' : 'none'));
2095 }
2096
2097 this.initialize = function(){
2098 var context = this;
2099
2100 this.dialogue_box.change(function(e){context.accept_upload_image(context, e)});
2101
2102 photo_editor.find('#tutor_profile_area .tutor_overlay, #tutor_pp_option>div:last-child').click(function(){context.toggle_profile_pic_action()});
2103
2104 // Upload new
2105 photo_editor.find('.tutor_cover_uploader').click(function(){context.open_dialogue_box('cover_photo')});
2106 photo_editor.find('.tutor_pp_uploader').click(function(){context.open_dialogue_box('profile_photo')});
2107
2108 // Delete existing
2109 photo_editor.find('.tutor_cover_deleter').click(function(){context.update_preview('cover_photo', null)});
2110 photo_editor.find('.tutor_pp_deleter').click(function(){context.update_preview('profile_photo', null)});
2111 }
2112 }
2113
2114 var photo_editor = $('#tutor_profile_cover_photo_editor');
2115 photo_editor.length>0 ? new PhotoEditor(photo_editor).initialize() : 0;
2116 });