PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 1.4.6
Tutor LMS – eLearning and online course solution v1.4.6
3.9.14 3.9.13 3.9.12 3.9.11 trunk 1.0.0 1.0.0-alpha 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.11 1.2.12 1.2.13 1.2.20 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.9 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9 1.8.0 1.8.1 1.8.10 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.8.7 1.8.8 1.8.9 1.9.0 1.9.1 1.9.10 1.9.11 1.9.12 1.9.13 1.9.14 1.9.15 1.9.16 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.10 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.3.0 2.4.0 2.5.0 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.1.0 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.7.0 3.7.1 3.7.2 3.7.3 3.7.4 3.8.0 3.8.1 3.8.2 3.8.3 3.9.0 3.9.1 3.9.10 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9
tutor / assets / js / tutor-front.js
tutor / assets / js Last commit date
Chart.bundle.min.js 6 years ago gutenberg_blocks.js 6 years ago mce-button.js 6 years ago tutor-admin.js 6 years ago tutor-front.js 6 years ago tutor.js 6 years ago
tutor-front.js
1377 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 nonce_key : _tutorobject.nonce_key,
42 video_track_data : $('#tutor_video_tracking_information').val(),
43 track_player : function(){
44 var that = this;
45
46 var video_data = this.video_track_data ? JSON.parse(this.video_track_data) : {};
47
48 if (typeof Plyr !== 'undefined') {
49 const player = new Plyr('#tutorPlayer');
50
51 player.on('ready', function(event){
52 const instance = event.detail.plyr;
53 if (video_data.best_watch_time > 0) {
54 instance.media.currentTime = video_data.best_watch_time;
55 }
56 that.sync_time(instance);
57 });
58
59 var tempTimeNow = 0;
60 var intervalSeconds = 60; //Send to tutor backend about video playing time in this interval
61 player.on('timeupdate', function(event){
62 const instance = event.detail.plyr;
63
64 var tempTimeNowInSec = (tempTimeNow / 4); //timeupdate firing 250ms interval
65 if (tempTimeNowInSec >= intervalSeconds){
66 that.sync_time(instance);
67 tempTimeNow = 0;
68 }
69 tempTimeNow++;
70 });
71
72 player.on('ended', function(event){
73 const instance = event.detail.plyr;
74
75 var data = {is_ended:true};
76 that.sync_time(instance, data)
77 });
78 }
79 },
80 sync_time: function(instance, options){
81 /**
82 * TUTOR is sending about video playback information to server.
83 */
84 var video_data = this.video_track_data ? JSON.parse(this.video_track_data) : {};
85 var data = {action: 'sync_video_playback', currentTime : instance.currentTime, duration:instance.duration, post_id : video_data.post_id};
86 data[this.nonce_key] = _tutorobject[this.nonce_key];
87
88 var data_send = data;
89 if(options){
90 data_send = Object.assign(data, options);
91 }
92 $.post(_tutorobject.ajaxurl, data_send);
93 },
94 init: function(){
95 this.track_player();
96 }
97 };
98
99 /**
100 * Fire TUTOR video
101 * @since v.1.0.0
102 */
103 if ($('#tutorPlayer').length){
104 videoPlayer.init();
105 }
106
107 $(document).on('change keyup paste', '.tutor_user_name', function(){
108 $(this).val(tutor_slugify($(this).val()));
109 });
110
111 function tutor_slugify(text) {
112 return text.toString().toLowerCase()
113 .replace(/\s+/g, '-') // Replace spaces with -
114 .replace(/[^\w\-]+/g, '') // Remove all non-word chars
115 .replace(/\-\-+/g, '-') // Replace multiple - with single -
116 .replace(/^-+/, '') // Trim - from start of text
117 .replace(/-+$/, ''); // Trim - from end of text
118 }
119
120 /**
121 * Hover tutor rating and set value
122 */
123 $(document).on('hover', '.tutor-write-review-box .tutor-star-rating-group i', function(){
124 $(this).closest('.tutor-star-rating-group').find('i').removeClass('tutor-icon-star-full').addClass('tutor-icon-star-line');
125 var currentRateValue = $(this).attr('data-rating-value');
126 for (var i = 1; i<= currentRateValue; i++){
127 $(this).closest('.tutor-star-rating-group').find('i[data-rating-value="'+i+'"]').removeClass('tutor-icon-star-line').addClass('tutor-icon-star-full');
128 }
129 $(this).closest('.tutor-star-rating-group').find('input[name="tutor_rating_gen_input"]').val(currentRateValue);
130 });
131
132 $(document).on('click', '.tutor-star-rating-group i', function(){
133 var rating = $(this).attr('data-rating-value');
134 $(this).closest('.tutor-star-rating-group').find('input[name="tutor_rating_gen_input"]').val(rating);
135 });
136
137 $(document).on('click', '.tutor_submit_review_btn', function (e) {
138 e.preventDefault();
139 var $that = $(this);
140 var rating = $that.closest('form').find('input[name="tutor_rating_gen_input"]').val();
141 var review = $that.closest('form').find('textarea[name="review"]').val();
142 review = review.trim();
143
144 var course_id = $('input[name="tutor_course_id"]').val();
145 var data = {course_id : course_id, rating : rating, review:review, action: 'tutor_place_rating' };
146
147 if (review) {
148 $.ajax({
149 url: _tutorobject.ajaxurl,
150 type: 'POST',
151 data: data,
152 beforeSend: function () {
153 $that.addClass('updating-icon');
154 },
155 success: function (data) {
156 var review_id = data.data.review_id;
157 var review = data.data.review;
158 $('.tutor-review-'+review_id+' .review-content').html(review);
159 location.reload();
160 }
161 });
162 }
163 });
164
165 $(document).on('click', '.write-course-review-link-btn', function(e){
166 e.preventDefault();
167 $(this).siblings('.tutor-write-review-form').slideToggle();
168 });
169
170 $(document).on('click', '.tutor-ask-question-btn', function(e){
171 e.preventDefault();
172 $('.tutor-add-question-wrap').slideToggle();
173 });
174 $(document).on('click', '.tutor_question_cancel', function(e){
175 e.preventDefault();
176 $('.tutor-add-question-wrap').toggle();
177 });
178
179 $(document).on('submit', '#tutor-ask-question-form', function(e){
180 e.preventDefault();
181
182 var $form = $(this);
183 var data = $(this).serialize()+'&action=tutor_ask_question';
184
185 $.ajax({
186 url: _tutorobject.ajaxurl,
187 type: 'POST',
188 data: data,
189 beforeSend: function () {
190 $form.find('.tutor_ask_question_btn').addClass('updating-icon');
191 },
192 success: function (data) {
193 if (data.success){
194 $('.tutor-add-question-wrap').hide();
195 window.location.reload();
196 }
197 },
198 complete: function () {
199 $form.find('.tutor_ask_question_btn').removeClass('updating-icon');
200 }
201 });
202 });
203
204 $(document).on('submit', '.tutor-add-answer-form', function(e){
205 e.preventDefault();
206
207 var $form = $(this);
208 var data = $(this).serialize()+'&action=tutor_add_answer';
209
210 $.ajax({
211 url: _tutorobject.ajaxurl,
212 type: 'POST',
213 data: data,
214 beforeSend: function () {
215 $form.find('.tutor_add_answer_btn').addClass('updating-icon');
216 },
217 success: function (data) {
218 if (data.success){
219 window.location.reload();
220 }
221 },
222 complete: function () {
223 $form.find('.tutor_add_answer_btn').removeClass('updating-icon');
224 }
225 });
226 });
227
228 $(document).on('focus', '.tutor_add_answer_textarea', function(e){
229 e.preventDefault();
230
231 var question_id = $(this).closest('.tutor_add_answer_wrap').attr('data-question-id');
232 var conf = {
233 tinymce: {
234 wpautop:true,
235 //plugins : 'charmap colorpicker compat3x directionality fullscreen hr image lists media paste tabfocus textcolor wordpress wpautoresize wpdialogs wpeditimage wpemoji wpgallery wplink wptextpattern wpview',
236 toolbar1: 'bold italic underline bullist strikethrough numlist blockquote alignleft aligncenter alignright undo redo link unlink spellchecker fullscreen'
237 },
238 };
239 wp.editor.initialize('tutor_answer_'+question_id, conf);
240 });
241
242 $(document).on('click', '.tutor_cancel_wp_editor', function(e){
243 e.preventDefault();
244 $(this).closest('.tutor_wp_editor_wrap').toggle();
245 $(this).closest('.tutor_add_answer_wrap').find('.tutor_wp_editor_show_btn_wrap').toggle();
246 var question_id = $(this).closest('.tutor_add_answer_wrap').attr('data-question-id');
247 wp.editor.remove('tutor_answer_'+question_id);
248 });
249
250 $(document).on('click', '.tutor_wp_editor_show_btn', function(e){
251 e.preventDefault();
252 $(this).closest('.tutor_add_answer_wrap').find('.tutor_wp_editor_wrap').toggle();
253 $(this).closest('.tutor_wp_editor_show_btn_wrap').toggle();
254 });
255
256 /**
257 * Quiz attempt
258 */
259 var $tutor_quiz_time_update = $('#tutor-quiz-time-update');
260 var attempt_settings = null;
261 if ($tutor_quiz_time_update.length){
262 attempt_settings = JSON.parse($tutor_quiz_time_update.attr('data-attempt-settings'));
263 var attempt_meta = JSON.parse($tutor_quiz_time_update.attr('data-attempt-meta'));
264
265 if (attempt_meta.time_limit.time_limit_seconds > 0) {
266 //No time Zero limit for
267 var countDownDate = new Date(attempt_settings.attempt_started_at).getTime() + (attempt_meta.time_limit.time_limit_seconds * 1000);
268 var time_now = new Date(attempt_meta.date_time_now).getTime();
269
270 var tutor_quiz_interval = setInterval(function () {
271 var distance = countDownDate - time_now;
272
273 var days = Math.floor(distance / (1000 * 60 * 60 * 24));
274 var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
275 var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
276 var seconds = Math.floor((distance % (1000 * 60)) / 1000);
277
278 var countdown_human = '';
279
280 if (days) {
281 countdown_human += days + "d ";
282 }
283 if (hours) {
284 countdown_human += hours + "h ";
285 }
286 if (minutes) {
287 countdown_human += minutes + "m ";
288 }
289 if (seconds) {
290 countdown_human += seconds + "s ";
291 }
292
293 if (distance < 0) {
294 clearInterval(tutor_quiz_interval);
295 countdown_human = "EXPIRED";
296 //Set the quiz attempt to timeout in ajax
297
298 if (_tutorobject.options.quiz_when_time_expires === 'autosubmit') {
299 /**
300 * Auto Submit
301 */
302 $('form#tutor-answering-quiz').submit();
303
304 } else if (_tutorobject.options.quiz_when_time_expires === 'autoabandon') {
305 /**
306 *
307 * @type {jQuery}
308 *
309 * Current attempt will be cancel with attempt status attempt_timeout
310 */
311
312 var quiz_id = $('#tutor_quiz_id').val();
313 var tutor_quiz_remaining_time_secs = $('#tutor_quiz_remaining_time_secs').val();
314 var quiz_timeout_data = {quiz_id: quiz_id, action: 'tutor_quiz_timeout'};
315
316 $.ajax({
317 url: _tutorobject.ajaxurl,
318 type: 'POST',
319 data: quiz_timeout_data,
320 success: function (data) {
321 if (data.success) {
322 window.location.reload(true);
323 }
324 },
325 complete: function () {
326 $('#tutor-quiz-body').html('');
327 window.location.reload(true);
328 }
329 });
330 }
331
332 }
333 time_now = time_now + 1000;
334 $tutor_quiz_time_update.html(countdown_human);
335 }, 1000);
336 }else{
337 $tutor_quiz_time_update.closest('.time-remaining').remove();
338 }
339 }
340
341 var $quiz_start_form = $('#tutor-quiz-body form#tutor-start-quiz');
342 if ($quiz_start_form.length){
343 if (_tutorobject.quiz_options.quiz_auto_start === '1'){
344 $quiz_start_form.submit();
345 }
346 }
347
348 /**
349 * Quiz Frontend Review Action
350 * @since 1.4.0
351 */
352 $(document).on('click', '.quiz-manual-review-action', function(e){
353 e.preventDefault();
354 var $that = $(this),
355 attempt_id = $that.attr('data-attempt-id'),
356 attempt_answer_id = $that.attr('data-attempt-answer-id'),
357 mark_as = $that.attr('data-mark-as');
358
359 $.ajax({
360 url : _tutorobject.ajaxurl,
361 type : 'GET',
362 data : {action:'review_quiz_answer', attempt_id: attempt_id, attempt_answer_id : attempt_answer_id, mark_as : mark_as },
363 beforeSend: function () {
364 $that.find('i').addClass('updating-icon');
365 },
366 success: function (data) {
367 location.reload();
368 },
369 complete: function () {
370 $that.find('i').removeClass('updating-icon');
371 }
372 });
373 });
374
375 // tutor course content accordion
376 $('.tutor-course-topic.tutor-active').find('.tutor-course-lessons').slideDown();
377 $('.tutor-course-title').on('click', function () {
378 var lesson = $(this).siblings('.tutor-course-lessons');
379 $(this).closest('.tutor-course-topic').toggleClass('tutor-active');
380 lesson.slideToggle();
381 });
382
383 $(document).on('click', '.tutor-topics-title h3 .toogle-informaiton-icon', function (e) {
384 $(this).closest('.tutor-topics-in-single-lesson').find('.tutor-topics-summery').slideToggle();
385 e.stopPropagation();
386 });
387
388 $(document).on('click', '.tutor-course-wishlist-btn', function (e) {
389 e.preventDefault();
390
391 var $that = $(this);
392 var course_id = $that.attr('data-course-id');
393
394 $.ajax({
395 url: _tutorobject.ajaxurl,
396 type: 'POST',
397 data: {course_id : course_id, 'action': 'tutor_course_add_to_wishlist'},
398 beforeSend: function () {
399 $that.addClass('updating-icon');
400 },
401 success: function (data) {
402 if (data.success){
403 if (data.data.status === 'added'){
404 $that.addClass('has-wish-listed');
405 }else{
406 $that.removeClass('has-wish-listed');
407 }
408 }else{
409 window.location = data.data.redirect_to;
410 }
411 },
412 complete: function () {
413 $that.removeClass('updating-icon');
414 }
415 });
416 });
417
418 /**
419 * Check if lesson has classic editor support
420 * If classic editor support, stop ajax load on the lesson page.
421 *
422 * @since v.1.0.0
423 *
424 * @updated v.1.4.0
425 */
426 if ( ! _tutorobject.enable_lesson_classic_editor) {
427
428 $(document).on('click', '.tutor-single-lesson-a', function (e) {
429 e.preventDefault();
430
431 var $that = $(this);
432 var lesson_id = $that.attr('data-lesson-id');
433 var $wrap = $('#tutor-single-entry-content');
434
435 $.ajax({
436 url: _tutorobject.ajaxurl,
437 type: 'POST',
438 data: {lesson_id : lesson_id, 'action': 'tutor_render_lesson_content'},
439 beforeSend: function () {
440 var page_title = $that.find('.lesson_title').text();
441 $('head title').text(page_title);
442 window.history.pushState('obj', page_title, $that.attr('href'));
443 $wrap.addClass('loading-lesson');
444 $('.tutor-single-lesson-items').removeClass('active');
445 $that.closest('.tutor-single-lesson-items').addClass('active');
446 },
447 success: function (data) {
448 $wrap.html(data.data.html);
449 videoPlayer.init();
450 $('.tutor-lesson-sidebar').css('display', '');
451 },
452 complete: function () {
453 $wrap.removeClass('loading-lesson');
454 }
455 });
456 });
457
458 $(document).on('click', '.sidebar-single-quiz-a', function (e) {
459 e.preventDefault();
460
461 var $that = $(this);
462 var quiz_id = $that.attr('data-quiz-id');
463 var page_title = $that.find('.lesson_title').text();
464 var $wrap = $('#tutor-single-entry-content');
465
466 $.ajax({
467 url: _tutorobject.ajaxurl,
468 type: 'POST',
469 data: {quiz_id : quiz_id, 'action': 'tutor_render_quiz_content'},
470 beforeSend: function () {
471 $('head title').text(page_title);
472 window.history.pushState('obj', page_title, $that.attr('href'));
473 $wrap.addClass('loading-lesson');
474 $('.tutor-single-lesson-items').removeClass('active');
475 $that.closest('.tutor-single-lesson-items').addClass('active');
476 },
477 success: function (data) {
478 $wrap.html(data.data.html);
479 init_quiz_builder();
480 $('.tutor-lesson-sidebar').css('display', '');
481 },
482 complete: function () {
483 $wrap.removeClass('loading-lesson');
484 }
485 });
486 });
487 }
488
489 /**
490 * @date 05 Feb, 2019
491 */
492
493 $(document).on('click', '.tutor-lesson-sidebar-hide-bar', function(e){
494 e.preventDefault();
495 $('.tutor-lesson-sidebar').toggle();
496 $('#tutor-single-entry-content').toggleClass("sidebar-hidden");
497
498 });
499
500 $(".tutor-tabs-btn-group a").on('click touchstart', function (e) {
501 e.preventDefault();
502 var $that = $(this);
503 var tabSelector = $that.attr('href');
504 $('.tutor-lesson-sidebar-tab-item').hide();
505 $(tabSelector).show();
506
507 $('.tutor-tabs-btn-group a').removeClass('active');
508 $that.addClass('active');
509 });
510 /**
511 * @date 18 Feb, 2019
512 * @since v.1.0.0
513 */
514
515 function init_quiz_builder() {
516 if (jQuery().sortable) {
517 $(".tutor-quiz-answers-wrap").sortable({
518 handle: ".answer-sorting-bar",
519 start: function (e, ui) {
520 ui.placeholder.css('visibility', 'visible');
521 },
522 stop: function (e, ui) {
523 //Sorting Stopped...
524 },
525 }).disableSelection();
526
527 $(".quiz-draggable-rand-answers, .quiz-answer-matching-droppable").sortable({
528 connectWith: ".quiz-answer-matching-droppable",
529 placeholder: "drop-hover",
530 }).disableSelection();
531 }
532 }
533 init_quiz_builder();
534 /**
535 * Quiz view
536 * @date 22 Feb, 2019
537 * @since v.1.0.0
538 */
539
540 $(document).on('click', '.tutor-quiz-answer-next-btn', function (e) {
541 e.preventDefault();
542 var $that = $(this);
543 var question_id = parseInt($that.closest('.quiz-attempt-single-question').attr('id').match(/\d+/)[0], 10);
544
545 var next_question_id = $that.closest('.quiz-attempt-single-question').attr('data-next-question-id');
546
547 if (next_question_id) {
548 var $nextQuestion = $(next_question_id);
549 if ($nextQuestion && $nextQuestion.length) {
550 $('.quiz-attempt-single-question').hide();
551 $nextQuestion.show();
552
553 /**
554 * If pagination exists, set active class
555 */
556
557 if ($('.tutor-quiz-questions-pagination').length){
558 $('.tutor-quiz-question-paginate-item').removeClass('active');
559 $('.tutor-quiz-questions-pagination a[href="'+next_question_id+'"]').addClass('active');
560 }
561
562 }
563 }
564 });
565 $(document).on('click', '.tutor-quiz-question-paginate-item', function (e) {
566 e.preventDefault();
567 var $that = $(this);
568 var $question = $($that.attr('href'));
569 $('.quiz-attempt-single-question').hide();
570 $question.show();
571
572 //Active Class
573 $('.tutor-quiz-question-paginate-item').removeClass('active');
574 $that.addClass('active');
575 });
576
577 /**
578 * Limit Short Answer Question Type
579 */
580 $(document).on('keyup', 'textarea.question_type_short_answer', function (e) {
581 var $that = $(this);
582 var value = $that.val();
583 var limit = _tutorobject.quiz_options.short_answer_characters_limit;
584 var remaining = limit - value.length;
585
586 if (remaining < 1){
587 $that.val(value.substr(0, limit));
588 remaining = 0;
589 }
590 $that.closest('.tutor-quiz-answers-wrap').find('.characters_remaining').html(remaining);
591 });
592
593 /**
594 *
595 * @type {jQuery}
596 *
597 * Improved Quiz draggable answers drop accessibility
598 * Answers draggable wrap will be now same height.
599 *
600 * @since v.1.4.4
601 */
602 var countDraggableAnswers = $('.quiz-draggable-rand-answers').length;
603 if (countDraggableAnswers){
604 $('.quiz-draggable-rand-answers').each(function(){
605 var $that = $(this);
606 var draggableDivHeight = $that.height();
607
608 $that.css({"height": draggableDivHeight});
609 });
610 }
611
612 /**
613 * Add to cart in guest mode, show login form
614 *
615 * @since v.1.0.4
616 */
617
618 $(document).on('submit click', '.cart-required-login, .cart-required-login a, .cart-required-login form', function (e) {
619 e.preventDefault();
620
621 $('.tutor-cart-box-login-form').fadeIn(100);
622 });
623
624 $('.tutor-popup-form-close, .login-overlay-close').on('click', function () {
625 $('.tutor-cart-box-login-form').fadeOut(100);
626 });
627
628 $(document).on('keyup', function (e) {
629 if (e.keyCode === 27) {
630 $('.tutor-frontend-modal').hide();
631 $('.tutor-cart-box-login-form').fadeOut(100);
632 }
633 });
634 /**
635 * Share Link enable
636 *
637 * @since v.1.0.4
638 */
639 if($.fn.ShareLink){
640 var $social_share_wrap = $('.tutor-social-share-wrap');
641 if ($social_share_wrap.length) {
642 var share_config = JSON.parse($social_share_wrap.attr('data-social-share-config'));
643
644 $('.tutor_share').ShareLink({
645 title: share_config.title,
646 text: share_config.text,
647 image: share_config.image,
648 class_prefix: 's_',
649 width: 640,
650 height: 480,
651 });
652 }
653 }
654
655 /**
656 * Datepicker initiate
657 *
658 * @since v.1.1.2
659 */
660 if (jQuery.datepicker){
661 $( ".tutor_report_datepicker" ).datepicker({"dateFormat" : 'yy-mm-dd'});
662 }
663
664
665 /**
666 * Withdraw Form Tab/Toggle
667 *
668 * @since v.1.1.2
669 */
670
671 $(".withdraw-method-select-input").on('change', function(e){
672 var $that = $(this);
673 $('.withdraw-method-form').hide();
674 $('#withdraw-method-form-'+$that.closest('.withdraw-method-select').attr('data-withdraw-method')).show();
675 });
676
677 $('.withdraw-method-select-input').each(function () {
678 var $that = $(this);
679 if($that.is(":checked")){
680 $('.withdraw-method-form').hide();
681 $('#withdraw-method-form-'+$that.closest('.withdraw-method-select').attr('data-withdraw-method')).show();
682 }
683 });
684
685
686
687 /**
688 * Setting account for withdraw earning
689 *
690 * @since v.1.2.0
691 */
692 $(document).on('submit', '#tutor-withdraw-account-set-form', function(e){
693 e.preventDefault();
694
695 var $form = $(this);
696 var $btn = $form.find('.tutor_set_withdraw_account_btn');
697 var data = $form.serialize();
698
699 $.ajax({
700 url: _tutorobject.ajaxurl,
701 type: 'POST',
702 data: data,
703 beforeSend: function () {
704 $form.find('.tutor-success-msg').remove();
705 $btn.addClass('updating-icon');
706 },
707 success: function (data) {
708 if (data.success){
709 var successMsg = '<div class="tutor-success-msg" style="display: none;"><i class="tutor-icon-mark"></i> '+data.data.msg+' </div>';
710 $btn.closest('.withdraw-account-save-btn-wrap').append(successMsg);
711 if ($form.find('.tutor-success-msg').length) {
712 $form.find('.tutor-success-msg').slideDown();
713 }
714 setTimeout(function () {
715 $form.find('.tutor-success-msg').slideUp();
716 }, 5000)
717 }
718 },
719 complete: function () {
720 $btn.removeClass('updating-icon');
721 }
722 });
723 });
724
725 /**
726 * Make Withdraw Form
727 *
728 * @since v.1.2.0
729 */
730
731 $(document).on('click', 'a.open-withdraw-form-btn', function(e){
732 e.preventDefault();
733 $('.tutor-earning-withdraw-form-wrap').slideToggle();
734 });
735
736 $(document).on('submit', '#tutor-earning-withdraw-form', function(e){
737 e.preventDefault();
738
739 var $form = $(this);
740 var $btn = $('#tutor-earning-withdraw-btn');
741 var $responseDiv = $('#tutor-withdraw-form-response');
742 var data = $form.serialize();
743
744 $.ajax({
745 url: _tutorobject.ajaxurl,
746 type: 'POST',
747 data: data,
748 beforeSend: function () {
749 $form.find('.tutor-success-msg').remove();
750 $btn.addClass('updating-icon');
751 },
752 success: function (data) {
753 var Msg;
754 if (data.success){
755
756 if (data.data.available_balance !== 'undefined') {
757 $('.withdraw-balance-col .available_balance').html(data.data.available_balance);
758 }
759 Msg = '<div class="tutor-success-msg"><i class="tutor-icon-mark"></i> '+data.data.msg+' </div>';
760
761 }else{
762 Msg = '<div class="tutor-error-msg"><i class="tutor-icon-line-cross"></i> '+data.data.msg+' </div>';
763 }
764
765 $responseDiv.html(Msg);
766 setTimeout(function () {
767 $responseDiv.html('');
768 }, 5000)
769 },
770 complete: function () {
771 $btn.removeClass('updating-icon');
772 }
773 });
774 });
775
776 var frontEndModal = $('.tutor-frontend-modal');
777 frontEndModal.each(function () {
778 var modal = $(this),
779 action = $(this).data('popup-rel');
780 $('[href="'+action+'"]').on('click', function (e) {
781 modal.fadeIn();
782 e.preventDefault();
783 });
784 });
785 $(document).on('click', '.tm-close, .tutor-frontend-modal-overlay, .tutor-modal-btn-cancel', function () {
786 frontEndModal.fadeOut();
787 });
788
789 /**
790 * Delete Course
791 */
792 $(document).on('click', '.tutor-mycourse-delete-btn', function (e) {
793 e.preventDefault();
794 var course_id = $(this).attr('data-course-id');
795 $('#tutor-course-delete-id').val(course_id);
796 });
797 $(document).on('submit', '#tutor-delete-course-form', function (e) {
798 e.preventDefault();
799
800 var course_id = $('#tutor-course-delete-id').val();
801 var $btn = $('.tutor-modal-course-delete-btn');
802 var data = $(this).serialize();
803
804 $.ajax({
805 url: _tutorobject.ajaxurl,
806 type: 'POST',
807 data: data,
808 beforeSend: function () {
809 $btn.addClass('updating-icon');
810 },
811 success: function (data) {
812 if (data.success){
813 $('#tutor-dashboard-course-'+course_id).remove();
814 }
815 },
816 complete: function () {
817 $btn.removeClass('updating-icon');
818 $('.tutor-frontend-modal').hide();
819 }
820 });
821 });
822
823 /**
824 * Frontend Profile
825 */
826
827 if (! $('#tutor_profile_photo_id').val()) {
828 $('.tutor-profile-photo-delete-btn').hide();
829 }
830
831 $( document ).on( 'click', '.tutor-profile-photo-delete-btn', function() {
832 $( '.tutor-profile-photo-upload-wrap' ).find( 'img' ).attr( 'src', _tutorobject.placeholder_img_src );
833 $( '#tutor_profile_photo_id' ).val( '' );
834 $( '.tutor-profile-photo-delete-btn' ).hide();
835
836 $.ajax({
837 url: _tutorobject.ajaxurl,
838 type: 'POST',
839 data: {'action' : 'tutor_profile_photo_remove'},
840 });
841
842 return false;
843 });
844
845
846
847 /**
848 * Assignment
849 *
850 * @since v.1.3.3
851 */
852
853 $( document ).on( 'submit', '#tutor_assignment_start_form', function(e) {
854 e.preventDefault();
855
856 var $that = $(this);
857 var form_data = $that.serialize()+'&action=tutor_start_assignment';
858
859 $.ajax({
860 url: _tutorobject.ajaxurl,
861 type: 'POST',
862 data: form_data,
863 beforeSend: function () {
864 $('#tutor_assignment_start_btn').addClass('updating-icon');
865 },
866 success: function (data) {
867 if (data.success){
868 location.reload();
869 }
870 },
871 complete : function () {
872 $('#tutor_assignment_start_btn').removeClass('updating-icon');
873 }
874 });
875 });
876
877 /**
878 * Assignment answer validation
879 */
880 $( document ).on( 'submit', '#tutor_assignment_submit_form', function(e) {
881 var assignment_answer = $('textarea[name="assignment_answer"]').val();
882 if (assignment_answer.trim().length < 1) {
883 $('#form_validation_response').html('<div class="tutor-error-msg">'+_tutorobject.text.assignment_text_validation_msg+'</div>');
884 e.preventDefault();
885 }
886 });
887
888 /**
889 * Course builder video
890 * @since v.1.3.4
891 */
892
893
894 $(document).on( 'click', '.video_source_upload_wrap_html5 .video_upload_btn', function( event ){
895 event.preventDefault();
896
897 var $that = $(this);
898 var frame;
899 // If the media frame already exists, reopen it.
900 if ( frame ) {
901 frame.open();
902 return;
903 }
904 frame = wp.media({
905 title: 'Select or Upload Media Of Your Chosen Persuasion',
906 button: {
907 text: 'Use this media'
908 },
909 multiple: false // Set to true to allow multiple files to be selected
910 });
911 frame.on( 'select', function() {
912 // Get media attachment details from the frame state
913 var attachment = frame.state().get('selection').first().toJSON();
914 $that.closest('.video_source_upload_wrap_html5').find('span.video_media_id').text(attachment.id).closest('p').show();
915 $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id);
916 });
917 frame.open();
918 });
919
920
921 /**
922 * Course and lesson sorting
923 */
924
925 function enable_sorting_topic_lesson(){
926 if (jQuery().sortable) {
927 $(".course-contents").sortable({
928 handle: ".course-move-handle",
929 start: function (e, ui) {
930 ui.placeholder.css('visibility', 'visible');
931 },
932 stop: function (e, ui) {
933 tutor_sorting_topics_and_lesson();
934 },
935 });
936 $(".tutor-lessons:not(.drop-lessons)").sortable({
937 connectWith: ".tutor-lessons",
938 items: "div.course-content-item",
939 start: function (e, ui) {
940 ui.placeholder.css('visibility', 'visible');
941 },
942 stop: function (e, ui) {
943 tutor_sorting_topics_and_lesson();
944 },
945 });
946 }
947 }
948 enable_sorting_topic_lesson();
949 function tutor_sorting_topics_and_lesson(){
950 var topics = {};
951 $('.tutor-topics-wrap').each(function(index, item){
952 var $topic = $(this);
953 var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10);
954 var lessons = {};
955
956 $topic.find('.course-content-item').each(function(lessonIndex, lessonItem){
957 var $lesson = $(this);
958 var lesson_id = parseInt($lesson.attr('id').match(/\d+/)[0], 10);
959
960 lessons[lessonIndex] = lesson_id;
961 });
962 topics[index] = { 'topic_id' : topics_id, 'lesson_ids' : lessons };
963 });
964 $('#tutor_topics_lessons_sorting').val(JSON.stringify(topics));
965 }
966
967 /**
968 * Lesson Update or Create Modal
969 */
970 $(document).on( 'click', '.update_lesson_modal_btn', function( event ){
971 event.preventDefault();
972
973 var $that = $(this);
974 var content;
975 var editor = tinyMCE.get('tutor_lesson_modal_editor');
976 if (editor) {
977 content = editor.getContent();
978 } else {
979 content = $('#'+inputid).val();
980 }
981
982 var form_data = $(this).closest('form').serialize();
983 form_data += '&lesson_content='+content;
984
985 $.ajax({
986 url : ajaxurl,
987 type : 'POST',
988 data : form_data,
989 beforeSend: function () {
990 $that.addClass('tutor-updating-message');
991 },
992 success: function (data) {
993 if (data.success){
994 $('#tutor-course-content-wrap').html(data.data.course_contents);
995 enable_sorting_topic_lesson();
996
997 //Close the modal
998 $('.tutor-lesson-modal-wrap').removeClass('show');
999 }
1000 },
1001 complete: function () {
1002 $that.removeClass('tutor-updating-message');
1003 }
1004 });
1005 });
1006
1007 /**
1008 * END: Tutor Course builder JS
1009 */
1010
1011 /**
1012 * Attachment in forntend course builder
1013 * @since v.1.3.4
1014 */
1015 $(document).on('click', 'a.tutor-delete-attachment', function(e){
1016 e.preventDefault();
1017 $(this).closest('.tutor-added-attachment').remove();
1018 });
1019 $(document).on('click', '.tutorUploadAttachmentBtn', function(e){
1020 e.preventDefault();
1021
1022 var $that = $(this);
1023 var frame;
1024 if ( frame ) {
1025 frame.open();
1026 return;
1027 }
1028 frame = wp.media({
1029 title: 'Select or Upload Media Of Your Chosen Persuasion',
1030 button: {
1031 text: 'Use this media'
1032 },
1033 multiple: true // Set to true to allow multiple files to be selected
1034 });
1035 frame.on( 'select', function() {
1036 var attachments = frame.state().get('selection').toJSON();
1037 if (attachments.length){
1038 for (var i=0; i < attachments.length; i++){
1039 var attachment = attachments[i];
1040
1041 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>';
1042 $that.closest('.tutor-lesson-attachments-metabox').find('.tutor-added-attachments-wrap').append(inputHtml);
1043 }
1044 }
1045 });
1046 frame.open();
1047 });
1048
1049
1050 /**
1051 * Single Assignment Upload Button
1052 * @since v.1.3.4
1053 */
1054 $('form').on('change', '.tutor-assignment-file-upload', function () {
1055 $(this).siblings("label").find('span').html($(this).val().replace(/.*(\/|\\)/, ''));
1056 });
1057
1058 /**
1059 * Lesson Sidebar Topic Toggle
1060 * @since v.1.3.4
1061 */
1062
1063 $(document).on('click', '.tutor-topics-in-single-lesson .tutor-topics-title h3, .tutor-single-lesson-topic-toggle', function (e) {
1064 var $that = $(this);
1065 var $parent = $that.closest('.tutor-topics-in-single-lesson');
1066 $parent.toggleClass('tutor-topic-active');
1067 $parent.find('.tutor-lessons-under-topic').slideToggle();
1068 });
1069
1070 $('.tutor-single-lesson-items.active').closest('.tutor-lessons-under-topic').show();
1071 $('.tutor-single-lesson-items.active').closest('.tutor-topics-in-single-lesson').addClass('tutor-topic-active');
1072
1073
1074 /**
1075 * Assignments Addons
1076 * @backend Support
1077 *
1078 */
1079
1080
1081 /**
1082 * Tutor Assignments JS
1083 * @since v.1.3.3
1084 */
1085 $(document).on('click', '.tutor-create-assignments-btn', function(e){
1086 e.preventDefault();
1087
1088 var $that = $(this);
1089 var topic_id = $(this).attr('data-topic-id');
1090 var course_id = $('#post_ID').val();
1091
1092 $.ajax({
1093 url : ajaxurl,
1094 type : 'POST',
1095 data : {topic_id : topic_id, course_id : course_id, action: 'tutor_load_assignments_builder_modal'},
1096 beforeSend: function () {
1097 $that.addClass('tutor-updating-message');
1098 },
1099 success: function (data) {
1100 $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output);
1101 $('.tutor-lesson-modal-wrap').attr('data-topic-id', topic_id).addClass('show');
1102
1103 $(document).trigger('assignment_modal_loaded', {topic_id : topic_id, course_id : course_id});
1104
1105 tinymce.init(tinyMCEPreInit.mceInit.course_description);
1106 tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_assignments_modal_editor' );
1107 tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor");
1108 },
1109 complete: function () {
1110 quicktags({id : "tutor_assignments_modal_editor"});
1111 $that.removeClass('tutor-updating-message');
1112 }
1113 });
1114 });
1115
1116 $(document).on('click', '.open-tutor-assignment-modal', function(e){
1117 e.preventDefault();
1118
1119 var $that = $(this);
1120 var assignment_id = $that.attr('data-assignment-id');
1121 var topic_id = $that.attr('data-topic-id');
1122 var course_id = $('#post_ID').val();
1123
1124 $.ajax({
1125 url : ajaxurl,
1126 type : 'POST',
1127 data : {assignment_id : assignment_id, topic_id : topic_id, course_id : course_id, action: 'tutor_load_assignments_builder_modal'},
1128 beforeSend: function () {
1129 $that.addClass('tutor-updating-message');
1130 },
1131 success: function (data) {
1132 $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output);
1133 $('.tutor-lesson-modal-wrap').attr({'data-assignment-id' : assignment_id, 'data-topic-id':topic_id}).addClass('show');
1134
1135 $(document).trigger('assignment_modal_loaded', {assignment_id : assignment_id, topic_id : topic_id, course_id : course_id});
1136
1137 tinymce.init(tinyMCEPreInit.mceInit.course_description);
1138 tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_assignments_modal_editor' );
1139 tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor");
1140 },
1141 complete: function () {
1142 quicktags({id : "tutor_assignments_modal_editor"});
1143 $that.removeClass('tutor-updating-message');
1144 }
1145 });
1146 });
1147
1148 /**
1149 * Update Assignment Data
1150 */
1151 $(document).on( 'click', '.update_assignment_modal_btn', function( event ){
1152 event.preventDefault();
1153
1154 var $that = $(this);
1155 var content;
1156 var editor = tinyMCE.get('tutor_assignments_modal_editor');
1157 if (editor) {
1158 content = editor.getContent();
1159 } else {
1160 content = $('#'+inputid).val();
1161 }
1162
1163 var form_data = $(this).closest('form').serialize();
1164 form_data += '&assignment_content='+content;
1165
1166 $.ajax({
1167 url : ajaxurl,
1168 type : 'POST',
1169 data : form_data,
1170 beforeSend: function () {
1171 $that.addClass('tutor-updating-message');
1172 },
1173 success: function (data) {
1174 if (data.success){
1175 $('#tutor-course-content-wrap').html(data.data.course_contents);
1176 enable_sorting_topic_lesson();
1177
1178 //Close the modal
1179 $('.tutor-lesson-modal-wrap').removeClass('show');
1180 }
1181 },
1182 complete: function () {
1183 $that.removeClass('tutor-updating-message');
1184 }
1185 });
1186 });
1187
1188 /**
1189 * Add Assignment
1190 */
1191 $(document).on( 'click', '.add-assignment-attachments', function( event ){
1192 event.preventDefault();
1193
1194 var $that = $(this);
1195 var frame;
1196 // If the media frame already exists, reopen it.
1197 if ( frame ) {
1198 frame.open();
1199 return;
1200 }
1201
1202 // Create a new media frame
1203 frame = wp.media({
1204 title: 'Select or Upload Media Of Your Chosen Persuasion',
1205 button: {
1206 text: 'Use this media'
1207 },
1208 multiple: false // Set to true to allow multiple files to be selected
1209 });
1210
1211 // When an image is selected in the media frame...
1212 frame.on( 'select', function() {
1213 // Get media attachment details from the frame state
1214 var attachment = frame.state().get('selection').first().toJSON();
1215
1216 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>';
1217
1218 $('#assignment-attached-file').append(field_markup);
1219 $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id);
1220 });
1221 // Finally, open the modal on click
1222 frame.open();
1223 });
1224
1225 $(document).on( 'click', '.remove-assignment-attachment-a', function( event ){
1226 event.preventDefault();
1227 $(this).closest('.tutor-individual-attachment-file').remove();
1228 });
1229
1230
1231 /**
1232 *
1233 * @type {jQuery}
1234 *
1235 * Course builder auto draft save
1236 *
1237 * @since v.1.3.4
1238 */
1239 var tutor_course_builder = $('input[name="tutor_action"]').val();
1240 if (tutor_course_builder === 'tutor_add_course_builder'){
1241 setInterval(auto_draft_save_course_builder, 30000);
1242 }
1243
1244 function auto_draft_save_course_builder(){
1245 var form_data = $('form#tutor-frontend-course-builder').serialize();
1246 $.ajax({
1247 //url : _tutorobject.ajaxurl,
1248 type : 'POST',
1249 data : form_data+'&tutor_ajax_action=tutor_course_builder_draft_save',
1250 beforeSend: function () {
1251 $('.tutor-dashboard-builder-draft-btn span').text('Saving...');
1252 },
1253 success: function (data) {
1254
1255 },
1256 complete: function () {
1257 $('.tutor-dashboard-builder-draft-btn span').text('Save');
1258 }
1259 });
1260 }
1261
1262 /**
1263 *
1264 * @type {jQuery}
1265 *
1266 * Course builder section toggle
1267 *
1268 * @since v.1.3.5
1269 */
1270
1271 $('.tutor-course-builder-section-title').on('click', function () {
1272 if($(this).find('i').hasClass("tutor-icon-up")){
1273 $(this).find('i').removeClass('tutor-icon-up').addClass('tutor-icon-down');
1274 }else{
1275 $(this).find('i').removeClass('tutor-icon-down').addClass('tutor-icon-up');
1276 }
1277 $(this).next('div').slideToggle();
1278 });
1279
1280 /**
1281 * Open Tutor Modal to edit review
1282 * @since v.1.4.0
1283 */
1284 $(document).on('click', '.open-tutor-edit-review-modal', function(e){
1285 e.preventDefault();
1286
1287 var $that = $(this);
1288 var review_id = $that.attr('data-review-id');
1289
1290 var nonce_key = _tutorobject.nonce_key;
1291
1292 var json_data = {review_id : review_id, action: 'tutor_load_edit_review_modal'};
1293 json_data[nonce_key] = _tutorobject[nonce_key];
1294
1295 $.ajax({
1296 url : _tutorobject.ajaxurl,
1297 type : 'POST',
1298 data : json_data,
1299 beforeSend: function () {
1300 $that.addClass('tutor-updating-message');
1301 },
1302 success: function (data) {
1303 if (typeof data.data !== 'undefined') {
1304 $('.tutor-edit-review-modal-wrap .modal-container').html(data.data.output);
1305 $('.tutor-edit-review-modal-wrap').attr('data-review-id', review_id).addClass('show');
1306 }
1307 },
1308 complete: function () {
1309 $that.removeClass('tutor-updating-message');
1310 }
1311 });
1312 });
1313
1314 /**
1315 * Update the rating
1316 * @since v.1.4.0
1317 */
1318 $(document).on('submit', '#tutor_update_review_form', function(e){
1319 e.preventDefault();
1320
1321 var $that = $(this);
1322 var review_id = $that.closest('.tutor-edit-review-modal-wrap ').attr('data-review-id');
1323
1324 var nonce_key = _tutorobject.nonce_key;
1325
1326 var rating = $that.find('input[name="tutor_rating_gen_input"]').val();
1327 var review = $that.find('textarea[name="review"]').val();
1328 review = review.trim();
1329
1330 var json_data = {review_id : review_id, rating : rating, review : review, action: 'tutor_update_review_modal'};
1331 json_data[nonce_key] = _tutorobject[nonce_key];
1332
1333 $.ajax({
1334 url : _tutorobject.ajaxurl,
1335 type : 'POST',
1336 data : json_data,
1337 beforeSend: function () {
1338 $that.find('button[type="submit"]').addClass('tutor-updating-message');
1339 },
1340 success: function (data) {
1341 if (data.success){
1342 //Close the modal
1343 $('.tutor-edit-review-modal-wrap').removeClass('show');
1344 location.reload(true);
1345 }
1346 },
1347 complete: function () {
1348 $that.find('button[type="submit"]').removeClass('tutor-updating-message');
1349 }
1350 });
1351 });
1352
1353 /**
1354 * Profile photo upload
1355 * @since v.1.4.5
1356 */
1357
1358 $(document).on('click', '#tutor_profile_photo_button', function(e){
1359 e.preventDefault();
1360
1361 $('#tutor_profile_photo_file').trigger('click');
1362 });
1363
1364 $(document).on('change', '#tutor_profile_photo_file', function(event){
1365 event.preventDefault();
1366
1367 var $file = this;
1368 if ($file.files && $file.files[0]) {
1369 var reader = new FileReader();
1370 reader.onload = function(e) {
1371 $( '.tutor-profile-photo-upload-wrap' ).find( 'img' ).attr( 'src', e.target.result);
1372 }
1373 reader.readAsDataURL($file.files[0]);
1374 }
1375 });
1376
1377 });