PluginProbe ʕ •ᴥ•ʔ
Tutor LMS – eLearning and online course solution / 1.6.2
Tutor LMS – eLearning and online course solution v1.6.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 6 years ago gutenberg_blocks.js 6 years ago mce-button.js 6 years ago tutor-admin.js 6 years ago tutor-front.js 6 years ago tutor-setup.js 6 years ago tutor.js 6 years ago
tutor-front.js
1604 lines
1 jQuery(document).ready(function($){
2 'use strict';
3
4 /**
5 * Initiate Select2
6 * @since v.1.3.4
7 */
8 if (jQuery().select2){
9 $('.tutor_select2').select2({
10 escapeMarkup : function(markup) {
11 return markup;
12 }
13 });
14 }
15 //END: select2
16
17
18 /*!
19 * jQuery UI Touch Punch 0.2.3
20 *
21 * Copyright 2011–2014, Dave Furfero
22 * Dual licensed under the MIT or GPL Version 2 licenses.
23 *
24 * Depends:
25 * jquery.ui.widget.js
26 * jquery.ui.mouse.js
27 */
28 !function(a){function f(a,b){if(!(a.originalEvent.touches.length>1)){a.preventDefault();var c=a.originalEvent.changedTouches[0],d=document.createEvent("MouseEvents");d.initMouseEvent(b,!0,!0,window,1,c.screenX,c.screenY,c.clientX,c.clientY,!1,!1,!1,!1,0,null),a.target.dispatchEvent(d)}}if(a.support.touch="ontouchend"in document,a.support.touch){var e,b=a.ui.mouse.prototype,c=b._mouseInit,d=b._mouseDestroy;b._touchStart=function(a){var b=this;!e&&b._mouseCapture(a.originalEvent.changedTouches[0])&&(e=!0,b._touchMoved=!1,f(a,"mouseover"),f(a,"mousemove"),f(a,"mousedown"))},b._touchMove=function(a){e&&(this._touchMoved=!0,f(a,"mousemove"))},b._touchEnd=function(a){e&&(f(a,"mouseup"),f(a,"mouseout"),this._touchMoved||f(a,"click"),e=!1)},b._mouseInit=function(){var b=this;b.element.bind({touchstart:a.proxy(b,"_touchStart"),touchmove:a.proxy(b,"_touchMove"),touchend:a.proxy(b,"_touchEnd")}),c.call(b)},b._mouseDestroy=function(){var b=this;b.element.unbind({touchstart:a.proxy(b,"_touchStart"),touchmove:a.proxy(b,"_touchMove"),touchend:a.proxy(b,"_touchEnd")}),d.call(b)}}}(jQuery);
29
30 /**
31 * END jQuery UI Touch Punch
32 */
33
34
35 $(document).on('change', '.tutor-course-filter-form', function(e){
36 e.preventDefault();
37 $(this).closest('form').submit();
38 });
39
40 const videoPlayer = {
41 ajaxurl: _tutorobject.ajaxurl,
42 nonce_key: _tutorobject.nonce_key,
43 video_data: function() {
44 const video_track_data = $('#tutor_video_tracking_information').val();
45 return video_track_data ? JSON.parse(video_track_data) : {};
46 },
47 track_player: function() {
48 const that = this;
49 if (typeof Plyr !== 'undefined') {
50 const player = new Plyr('#tutorPlayer');
51 const video_data = that.video_data();
52 player.on('ready', function(event){
53 const instance = event.detail.plyr;
54 const { best_watch_time } = video_data;
55 if (best_watch_time > 0 && instance.duration > Math.round(best_watch_time)) {
56 instance.media.currentTime = best_watch_time;
57 }
58 that.sync_time(instance);
59 });
60
61 let tempTimeNow = 0;
62 let intervalSeconds = 30; //Send to tutor backend about video playing time in this interval
63 player.on('timeupdate', function(event) {
64 const instance = event.detail.plyr;
65 const tempTimeNowInSec = (tempTimeNow / 4); //timeupdate firing 250ms interval
66 if (tempTimeNowInSec >= intervalSeconds){
67 that.sync_time(instance);
68 tempTimeNow = 0;
69 }
70 tempTimeNow++;
71 });
72
73 player.on('ended', function(event) {
74 const video_data = that.video_data();
75 const instance = event.detail.plyr;
76 const data = {is_ended:true};
77 that.sync_time(instance, data);
78 if(video_data.autoload_next_course_content) {
79 that.autoload_content();
80 }
81 });
82 }
83 },
84 sync_time: function(instance, options) {
85 const post_id = this.video_data().post_id;
86 //TUTOR is sending about video playback information to server.
87 let data = {action: 'sync_video_playback', currentTime: instance.currentTime, duration:instance.duration, post_id};
88 data[this.nonce_key] = _tutorobject[this.nonce_key];
89 let data_send = data;
90 if(options){
91 data_send = Object.assign(data, options);
92 }
93 $.post(this.ajaxurl, data_send);
94 },
95 autoload_content: function() {
96 const post_id = this.video_data().post_id;
97 const data = {action: 'autoload_next_course_content', post_id};
98 data[this.nonce_key] = _tutorobject[this.nonce_key];
99 $.post(this.ajaxurl, data).done(function(response) {
100 if(response.success && response.data.next_url) {
101 location.href = response.data.next_url;
102 }
103 });
104 },
105 init: function() {
106 this.track_player();
107 }
108 };
109
110 /**
111 * Fire TUTOR video
112 * @since v.1.0.0
113 */
114 if ($('#tutorPlayer').length){
115 videoPlayer.init();
116 }
117
118 $(document).on('change keyup paste', '.tutor_user_name', function(){
119 $(this).val(tutor_slugify($(this).val()));
120 });
121
122 function tutor_slugify(text) {
123 return text.toString().toLowerCase()
124 .replace(/\s+/g, '-') // Replace spaces with -
125 .replace(/[^\w\-]+/g, '') // Remove all non-word chars
126 .replace(/\-\-+/g, '-') // Replace multiple - with single -
127 .replace(/^-+/, '') // Trim - from start of text
128 .replace(/-+$/, ''); // Trim - from end of text
129 }
130
131 /**
132 * Hover tutor rating and set value
133 */
134 $(document).on('hover', '.tutor-write-review-box .tutor-star-rating-group i', function(){
135 $(this).closest('.tutor-star-rating-group').find('i').removeClass('tutor-icon-star-full').addClass('tutor-icon-star-line');
136 var currentRateValue = $(this).attr('data-rating-value');
137 for (var i = 1; i<= currentRateValue; i++){
138 $(this).closest('.tutor-star-rating-group').find('i[data-rating-value="'+i+'"]').removeClass('tutor-icon-star-line').addClass('tutor-icon-star-full');
139 }
140 $(this).closest('.tutor-star-rating-group').find('input[name="tutor_rating_gen_input"]').val(currentRateValue);
141 });
142
143 $(document).on('click', '.tutor-star-rating-group i', function(){
144 var rating = $(this).attr('data-rating-value');
145 $(this).closest('.tutor-star-rating-group').find('input[name="tutor_rating_gen_input"]').val(rating);
146 });
147
148 $(document).on('click', '.tutor_submit_review_btn', function (e) {
149 e.preventDefault();
150 var $that = $(this);
151 var rating = $that.closest('form').find('input[name="tutor_rating_gen_input"]').val();
152 var review = $that.closest('form').find('textarea[name="review"]').val();
153 review = review.trim();
154
155 var course_id = $('input[name="tutor_course_id"]').val();
156 var data = {course_id : course_id, rating : rating, review:review, action: 'tutor_place_rating' };
157
158 if (review) {
159 $.ajax({
160 url: _tutorobject.ajaxurl,
161 type: 'POST',
162 data: data,
163 beforeSend: function () {
164 $that.addClass('updating-icon');
165 },
166 success: function (data) {
167 var review_id = data.data.review_id;
168 var review = data.data.review;
169 $('.tutor-review-'+review_id+' .review-content').html(review);
170 location.reload();
171 }
172 });
173 }
174 });
175
176 $(document).on('click', '.write-course-review-link-btn', function(e){
177 e.preventDefault();
178 $(this).siblings('.tutor-write-review-form').slideToggle();
179 });
180
181 $(document).on('click', '.tutor-ask-question-btn', function(e){
182 e.preventDefault();
183 $('.tutor-add-question-wrap').slideToggle();
184 });
185 $(document).on('click', '.tutor_question_cancel', function(e){
186 e.preventDefault();
187 $('.tutor-add-question-wrap').toggle();
188 });
189
190 $(document).on('submit', '#tutor-ask-question-form', function(e){
191 e.preventDefault();
192
193 var $form = $(this);
194 var data = $(this).serialize()+'&action=tutor_ask_question';
195
196 $.ajax({
197 url: _tutorobject.ajaxurl,
198 type: 'POST',
199 data: data,
200 beforeSend: function () {
201 $form.find('.tutor_ask_question_btn').addClass('updating-icon');
202 },
203 success: function (data) {
204 if (data.success){
205 $('.tutor-add-question-wrap').hide();
206 window.location.reload();
207 }
208 },
209 complete: function () {
210 $form.find('.tutor_ask_question_btn').removeClass('updating-icon');
211 }
212 });
213 });
214
215 $(document).on('submit', '.tutor-add-answer-form', function(e){
216 e.preventDefault();
217
218 var $form = $(this);
219 var data = $(this).serialize()+'&action=tutor_add_answer';
220
221 $.ajax({
222 url: _tutorobject.ajaxurl,
223 type: 'POST',
224 data: data,
225 beforeSend: function () {
226 $form.find('.tutor_add_answer_btn').addClass('updating-icon');
227 },
228 success: function (data) {
229 if (data.success){
230 window.location.reload();
231 }
232 },
233 complete: function () {
234 $form.find('.tutor_add_answer_btn').removeClass('updating-icon');
235 }
236 });
237 });
238
239 $(document).on('focus', '.tutor_add_answer_textarea', function(e){
240 e.preventDefault();
241
242 var question_id = $(this).closest('.tutor_add_answer_wrap').attr('data-question-id');
243 var conf = {
244 tinymce: {
245 wpautop:true,
246 //plugins : 'charmap colorpicker compat3x directionality fullscreen hr image lists media paste tabfocus textcolor wordpress wpautoresize wpdialogs wpeditimage wpemoji wpgallery wplink wptextpattern wpview',
247 toolbar1: 'bold italic underline bullist strikethrough numlist blockquote alignleft aligncenter alignright undo redo link unlink spellchecker fullscreen'
248 },
249 };
250 wp.editor.initialize('tutor_answer_'+question_id, conf);
251 });
252
253 $(document).on('click', '.tutor_cancel_wp_editor', function(e){
254 e.preventDefault();
255 $(this).closest('.tutor_wp_editor_wrap').toggle();
256 $(this).closest('.tutor_add_answer_wrap').find('.tutor_wp_editor_show_btn_wrap').toggle();
257 var question_id = $(this).closest('.tutor_add_answer_wrap').attr('data-question-id');
258 wp.editor.remove('tutor_answer_'+question_id);
259 });
260
261 $(document).on('click', '.tutor_wp_editor_show_btn', function(e){
262 e.preventDefault();
263 $(this).closest('.tutor_add_answer_wrap').find('.tutor_wp_editor_wrap').toggle();
264 $(this).closest('.tutor_wp_editor_show_btn_wrap').toggle();
265 });
266
267 /**
268 * Quiz attempt
269 */
270 var $tutor_quiz_time_update = $('#tutor-quiz-time-update');
271 var attempt_settings = null;
272 if ($tutor_quiz_time_update.length){
273 attempt_settings = JSON.parse($tutor_quiz_time_update.attr('data-attempt-settings'));
274 var attempt_meta = JSON.parse($tutor_quiz_time_update.attr('data-attempt-meta'));
275
276 if (attempt_meta.time_limit.time_limit_seconds > 0) {
277 //No time Zero limit for
278 var countDownDate = new Date(attempt_settings.attempt_started_at).getTime() + (attempt_meta.time_limit.time_limit_seconds * 1000);
279 var time_now = new Date(attempt_meta.date_time_now).getTime();
280
281 var tutor_quiz_interval = setInterval(function () {
282 var distance = countDownDate - time_now;
283
284 var days = Math.floor(distance / (1000 * 60 * 60 * 24));
285 var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
286 var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
287 var seconds = Math.floor((distance % (1000 * 60)) / 1000);
288
289 var countdown_human = '';
290
291 if (days) {
292 countdown_human += days + "d ";
293 }
294 if (hours) {
295 countdown_human += hours + "h ";
296 }
297 if (minutes) {
298 countdown_human += minutes + "m ";
299 }
300 if (seconds) {
301 countdown_human += seconds + "s ";
302 }
303
304 if (distance < 0) {
305 clearInterval(tutor_quiz_interval);
306 countdown_human = "EXPIRED";
307 //Set the quiz attempt to timeout in ajax
308
309 if (_tutorobject.quiz_options.quiz_when_time_expires === 'autosubmit') {
310 /**
311 * Auto Submit
312 */
313 $('form#tutor-answering-quiz').submit();
314
315 } else if (_tutorobject.quiz_options.quiz_when_time_expires === 'autoabandon') {
316 /**
317 *
318 * @type {jQuery}
319 *
320 * Current attempt will be cancel with attempt status attempt_timeout
321 */
322
323 var quiz_id = $('#tutor_quiz_id').val();
324 var tutor_quiz_remaining_time_secs = $('#tutor_quiz_remaining_time_secs').val();
325 var quiz_timeout_data = {quiz_id: quiz_id, action: 'tutor_quiz_timeout'};
326
327 $.ajax({
328 url: _tutorobject.ajaxurl,
329 type: 'POST',
330 data: quiz_timeout_data,
331 success: function (data) {
332 if (data.success) {
333 window.location.reload(true);
334 }
335 },
336 complete: function () {
337 $('#tutor-quiz-body').html('');
338 window.location.reload(true);
339 }
340 });
341 }
342
343 }
344 time_now = time_now + 1000;
345 $tutor_quiz_time_update.html(countdown_human);
346 }, 1000);
347 }else{
348 $tutor_quiz_time_update.closest('.time-remaining').remove();
349 }
350 }
351
352 var $quiz_start_form = $('#tutor-quiz-body form#tutor-start-quiz');
353 if ($quiz_start_form.length){
354 if (_tutorobject.quiz_options.quiz_auto_start === '1'){
355 $quiz_start_form.submit();
356 }
357 }
358
359 /**
360 * Quiz Frontend Review Action
361 * @since 1.4.0
362 */
363 $(document).on('click', '.quiz-manual-review-action', function(e){
364 e.preventDefault();
365 var $that = $(this),
366 attempt_id = $that.attr('data-attempt-id'),
367 attempt_answer_id = $that.attr('data-attempt-answer-id'),
368 mark_as = $that.attr('data-mark-as');
369
370 $.ajax({
371 url : _tutorobject.ajaxurl,
372 type : 'GET',
373 data : {action:'review_quiz_answer', attempt_id: attempt_id, attempt_answer_id : attempt_answer_id, mark_as : mark_as },
374 beforeSend: function () {
375 $that.find('i').addClass('updating-icon');
376 },
377 success: function (data) {
378 location.reload();
379 },
380 complete: function () {
381 $that.find('i').removeClass('updating-icon');
382 }
383 });
384 });
385
386 // tutor course content accordion
387 $('.tutor-course-topic.tutor-active').find('.tutor-course-lessons').slideDown();
388 $('.tutor-course-title').on('click', function () {
389 var lesson = $(this).siblings('.tutor-course-lessons');
390 $(this).closest('.tutor-course-topic').toggleClass('tutor-active');
391 lesson.slideToggle();
392 });
393
394 $(document).on('click', '.tutor-topics-title h3 .toogle-informaiton-icon', function (e) {
395 $(this).closest('.tutor-topics-in-single-lesson').find('.tutor-topics-summery').slideToggle();
396 e.stopPropagation();
397 });
398
399 $(document).on('click', '.tutor-course-wishlist-btn', function (e) {
400 e.preventDefault();
401
402 var $that = $(this);
403 var course_id = $that.attr('data-course-id');
404
405 $.ajax({
406 url: _tutorobject.ajaxurl,
407 type: 'POST',
408 data: {course_id : course_id, 'action': 'tutor_course_add_to_wishlist'},
409 beforeSend: function () {
410 $that.addClass('updating-icon');
411 },
412 success: function (data) {
413 if (data.success){
414 if (data.data.status === 'added'){
415 $that.addClass('has-wish-listed');
416 }else{
417 $that.removeClass('has-wish-listed');
418 }
419 }else{
420 window.location = data.data.redirect_to;
421 }
422 },
423 complete: function () {
424 $that.removeClass('updating-icon');
425 }
426 });
427 });
428
429 /**
430 * Check if lesson has classic editor support
431 * If classic editor support, stop ajax load on the lesson page.
432 *
433 * @since v.1.0.0
434 *
435 * @updated v.1.4.0
436 */
437 if ( ! _tutorobject.enable_lesson_classic_editor) {
438
439 $(document).on('click', '.tutor-single-lesson-a', function (e) {
440 e.preventDefault();
441
442 var $that = $(this);
443 var lesson_id = $that.attr('data-lesson-id');
444 var $wrap = $('#tutor-single-entry-content');
445
446 $.ajax({
447 url: _tutorobject.ajaxurl,
448 type: 'POST',
449 data: {lesson_id : lesson_id, 'action': 'tutor_render_lesson_content'},
450 beforeSend: function () {
451 var page_title = $that.find('.lesson_title').text();
452 $('head title').text(page_title);
453 window.history.pushState('obj', page_title, $that.attr('href'));
454 $wrap.addClass('loading-lesson');
455 $('.tutor-single-lesson-items').removeClass('active');
456 $that.closest('.tutor-single-lesson-items').addClass('active');
457 },
458 success: function (data) {
459 $wrap.html(data.data.html);
460 videoPlayer.init();
461 $('.tutor-lesson-sidebar').css('display', '');
462 },
463 complete: function () {
464 $wrap.removeClass('loading-lesson');
465 }
466 });
467 });
468
469 $(document).on('click', '.sidebar-single-quiz-a', function (e) {
470 e.preventDefault();
471
472 var $that = $(this);
473 var quiz_id = $that.attr('data-quiz-id');
474 var page_title = $that.find('.lesson_title').text();
475 var $wrap = $('#tutor-single-entry-content');
476
477 $.ajax({
478 url: _tutorobject.ajaxurl,
479 type: 'POST',
480 data: {quiz_id : quiz_id, 'action': 'tutor_render_quiz_content'},
481 beforeSend: function () {
482 $('head title').text(page_title);
483 window.history.pushState('obj', page_title, $that.attr('href'));
484 $wrap.addClass('loading-lesson');
485 $('.tutor-single-lesson-items').removeClass('active');
486 $that.closest('.tutor-single-lesson-items').addClass('active');
487 },
488 success: function (data) {
489 $wrap.html(data.data.html);
490 init_quiz_builder();
491 $('.tutor-lesson-sidebar').css('display', '');
492 },
493 complete: function () {
494 $wrap.removeClass('loading-lesson');
495 }
496 });
497 });
498 }
499
500 /**
501 * @date 05 Feb, 2019
502 */
503
504 $(document).on('click', '.tutor-lesson-sidebar-hide-bar', function(e){
505 e.preventDefault();
506 $('.tutor-lesson-sidebar').toggle();
507 $('#tutor-single-entry-content').toggleClass("sidebar-hidden");
508
509 });
510
511 $(".tutor-tabs-btn-group a").on('click touchstart', function (e) {
512 e.preventDefault();
513 var $that = $(this);
514 var tabSelector = $that.attr('href');
515 $('.tutor-lesson-sidebar-tab-item').hide();
516 $(tabSelector).show();
517
518 $('.tutor-tabs-btn-group a').removeClass('active');
519 $that.addClass('active');
520 });
521 /**
522 * @date 18 Feb, 2019
523 * @since v.1.0.0
524 */
525
526 function init_quiz_builder() {
527 if (jQuery().sortable) {
528 $(".tutor-quiz-answers-wrap").sortable({
529 handle: ".answer-sorting-bar",
530 start: function (e, ui) {
531 ui.placeholder.css('visibility', 'visible');
532 },
533 stop: function (e, ui) {
534 //Sorting Stopped...
535 },
536 }).disableSelection();
537
538 $(".quiz-draggable-rand-answers, .quiz-answer-matching-droppable").sortable({
539 connectWith: ".quiz-answer-matching-droppable",
540 placeholder: "drop-hover",
541 }).disableSelection();
542 }
543 }
544 init_quiz_builder();
545 /**
546 * Quiz view
547 * @date 22 Feb, 2019
548 * @since v.1.0.0
549 */
550
551 $(document).on('click', '.tutor-quiz-answer-next-btn', function (e) {
552 e.preventDefault();
553
554 var $that = $(this);
555 var $question_wrap = $that.closest('.quiz-attempt-single-question');
556 /**
557 * Validating required answer
558 * @type {jQuery}
559 *
560 * @since v.1.6.1
561 */
562
563 var validated = tutor_quiz_validation($question_wrap);
564 if ( ! validated){
565 return;
566 }
567
568 var question_id = parseInt($that.closest('.quiz-attempt-single-question').attr('id').match(/\d+/)[0], 10);
569
570 var next_question_id = $that.closest('.quiz-attempt-single-question').attr('data-next-question-id');
571
572 if (next_question_id) {
573 var $nextQuestion = $(next_question_id);
574 if ($nextQuestion && $nextQuestion.length) {
575 $('.quiz-attempt-single-question').hide();
576 $nextQuestion.show();
577
578 /**
579 * If pagination exists, set active class
580 */
581
582 if ($('.tutor-quiz-questions-pagination').length){
583 $('.tutor-quiz-question-paginate-item').removeClass('active');
584 $('.tutor-quiz-questions-pagination a[href="'+next_question_id+'"]').addClass('active');
585 }
586
587 }
588 }
589 });
590
591
592 $(document).on('submit', '#tutor-answering-quiz', function (e) {
593 var $questions_wrap = $('.quiz-attempt-single-question');
594 var validated = true;
595 if ($questions_wrap.length){
596 $questions_wrap.each(function(index, question){
597 validated = tutor_quiz_validation($(question));
598 });
599 }
600
601 if ( ! validated){
602 e.preventDefault();
603 }
604
605 });
606
607
608 $(document).on('click', '.tutor-quiz-question-paginate-item', function (e) {
609 e.preventDefault();
610 var $that = $(this);
611 var $question = $($that.attr('href'));
612 $('.quiz-attempt-single-question').hide();
613 $question.show();
614
615 //Active Class
616 $('.tutor-quiz-question-paginate-item').removeClass('active');
617 $that.addClass('active');
618 });
619
620 /**
621 * Limit Short Answer Question Type
622 */
623 $(document).on('keyup', 'textarea.question_type_short_answer', function (e) {
624 var $that = $(this);
625 var value = $that.val();
626 var limit = _tutorobject.quiz_options.short_answer_characters_limit;
627 var remaining = limit - value.length;
628
629 if (remaining < 1){
630 $that.val(value.substr(0, limit));
631 remaining = 0;
632 }
633 $that.closest('.tutor-quiz-answers-wrap').find('.characters_remaining').html(remaining);
634 });
635
636 /**
637 *
638 * @type {jQuery}
639 *
640 * Improved Quiz draggable answers drop accessibility
641 * Answers draggable wrap will be now same height.
642 *
643 * @since v.1.4.4
644 */
645 var countDraggableAnswers = $('.quiz-draggable-rand-answers').length;
646 if (countDraggableAnswers){
647 $('.quiz-draggable-rand-answers').each(function(){
648 var $that = $(this);
649 var draggableDivHeight = $that.height();
650
651 $that.css({"height": draggableDivHeight});
652 });
653 }
654
655
656 /**
657 * Quiz Validation Helper
658 *
659 * @since v.1.6.1
660 */
661
662 function tutor_quiz_validation($question_wrap){
663 var validated = true;
664
665 var $required_answer_wrap = $question_wrap.find('.quiz-answer-required');
666
667
668 if ($required_answer_wrap.length){
669
670 /**
671 * Radio field validation
672 *
673 * @type {jQuery}
674 *
675 * @since v.1.6.1
676 */
677 var $inputs = $required_answer_wrap.find('input');
678 if ($inputs.length){
679 var $type = $inputs.attr('type');
680 if ($type === 'radio') {
681 if ($required_answer_wrap.find('input[type="radio"]:checked').length == 0) {
682 $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">Please select an option to answer</p>');
683 validated = false;
684 }
685 }else if ($type === 'checkbox'){
686 if ($required_answer_wrap.find('input[type="checkbox"]:checked').length == 0) {
687 $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">Please select at least one option to answer.</p>');
688 validated = false;
689 }
690 }else if($type === 'text'){
691 //Fill in the gaps if many, validation all
692 $inputs.each(function(index, input){
693 if ( ! $(input).val().trim().length){
694 $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">The answer for this question is required</p>');
695 validated = false;
696 }
697 });
698 }
699
700 }
701 if ($required_answer_wrap.find('textarea').length) {
702 if ($required_answer_wrap.find('textarea').val().trim().length < 1){
703 $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">The answer for this question is required</p>');
704 validated = false;
705 }
706 }
707
708 /**
709 * Matching Question
710 */
711 var $matchingDropable = $required_answer_wrap.find('.quiz-answer-matching-droppable');
712 if ($matchingDropable.length){
713
714 $matchingDropable.each(function(index, matching){
715 if ( ! $(matching).find('.quiz-draggable-answer-item').length){
716 $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">Please match all the items</p>');
717 validated = false;
718 }
719
720 });
721
722 }
723
724
725
726 }
727
728 return validated;
729 }
730
731
732
733 /**
734 * Add to cart in guest mode, show login form
735 *
736 * @since v.1.0.4
737 */
738
739 $(document).on('submit click', '.cart-required-login, .cart-required-login a, .cart-required-login form', function (e) {
740 e.preventDefault();
741
742 $('.tutor-cart-box-login-form').fadeIn(100);
743 });
744
745 $('.tutor-popup-form-close, .login-overlay-close').on('click', function () {
746 $('.tutor-cart-box-login-form').fadeOut(100);
747 });
748
749 $(document).on('keyup', function (e) {
750 if (e.keyCode === 27) {
751 $('.tutor-frontend-modal').hide();
752 $('.tutor-cart-box-login-form').fadeOut(100);
753 }
754 });
755 /**
756 * Share Link enable
757 *
758 * @since v.1.0.4
759 */
760 if($.fn.ShareLink){
761 var $social_share_wrap = $('.tutor-social-share-wrap');
762 if ($social_share_wrap.length) {
763 var share_config = JSON.parse($social_share_wrap.attr('data-social-share-config'));
764
765 $('.tutor_share').ShareLink({
766 title: share_config.title,
767 text: share_config.text,
768 image: share_config.image,
769 class_prefix: 's_',
770 width: 640,
771 height: 480,
772 });
773 }
774 }
775
776 /**
777 * Datepicker initiate
778 *
779 * @since v.1.1.2
780 */
781 if (jQuery.datepicker){
782 $( ".tutor_report_datepicker" ).datepicker({"dateFormat" : 'yy-mm-dd'});
783 }
784
785
786 /**
787 * Withdraw Form Tab/Toggle
788 *
789 * @since v.1.1.2
790 */
791
792 $(".withdraw-method-select-input").on('change', function(e){
793 var $that = $(this);
794 $('.withdraw-method-form').hide();
795 $('#withdraw-method-form-'+$that.closest('.withdraw-method-select').attr('data-withdraw-method')).show();
796 });
797
798 $('.withdraw-method-select-input').each(function () {
799 var $that = $(this);
800 if($that.is(":checked")){
801 $('.withdraw-method-form').hide();
802 $('#withdraw-method-form-'+$that.closest('.withdraw-method-select').attr('data-withdraw-method')).show();
803 }
804 });
805
806
807
808 /**
809 * Setting account for withdraw earning
810 *
811 * @since v.1.2.0
812 */
813 $(document).on('submit', '#tutor-withdraw-account-set-form', function(e){
814 e.preventDefault();
815
816 var $form = $(this);
817 var $btn = $form.find('.tutor_set_withdraw_account_btn');
818 var data = $form.serialize();
819
820 $.ajax({
821 url: _tutorobject.ajaxurl,
822 type: 'POST',
823 data: data,
824 beforeSend: function () {
825 $form.find('.tutor-success-msg').remove();
826 $btn.addClass('updating-icon');
827 },
828 success: function (data) {
829 if (data.success){
830 var successMsg = '<div class="tutor-success-msg" style="display: none;"><i class="tutor-icon-mark"></i> '+data.data.msg+' </div>';
831 $btn.closest('.withdraw-account-save-btn-wrap').append(successMsg);
832 if ($form.find('.tutor-success-msg').length) {
833 $form.find('.tutor-success-msg').slideDown();
834 }
835 setTimeout(function () {
836 $form.find('.tutor-success-msg').slideUp();
837 }, 5000)
838 }
839 },
840 complete: function () {
841 $btn.removeClass('updating-icon');
842 }
843 });
844 });
845
846 /**
847 * Make Withdraw Form
848 *
849 * @since v.1.2.0
850 */
851
852 $(document).on('click', 'a.open-withdraw-form-btn', function(e){
853 e.preventDefault();
854 $('.tutor-earning-withdraw-form-wrap').slideToggle();
855 });
856
857 $(document).on('submit', '#tutor-earning-withdraw-form', function(e){
858 e.preventDefault();
859
860 var $form = $(this);
861 var $btn = $('#tutor-earning-withdraw-btn');
862 var $responseDiv = $('#tutor-withdraw-form-response');
863 var data = $form.serialize();
864
865 $.ajax({
866 url: _tutorobject.ajaxurl,
867 type: 'POST',
868 data: data,
869 beforeSend: function () {
870 $form.find('.tutor-success-msg').remove();
871 $btn.addClass('updating-icon');
872 },
873 success: function (data) {
874 var Msg;
875 if (data.success){
876
877 if (data.data.available_balance !== 'undefined') {
878 $('.withdraw-balance-col .available_balance').html(data.data.available_balance);
879 }
880 Msg = '<div class="tutor-success-msg"><i class="tutor-icon-mark"></i> '+data.data.msg+' </div>';
881
882 }else{
883 Msg = '<div class="tutor-error-msg"><i class="tutor-icon-line-cross"></i> '+data.data.msg+' </div>';
884 }
885
886 $responseDiv.html(Msg);
887 setTimeout(function () {
888 $responseDiv.html('');
889 }, 5000)
890 },
891 complete: function () {
892 $btn.removeClass('updating-icon');
893 }
894 });
895 });
896
897 var frontEndModal = $('.tutor-frontend-modal');
898 frontEndModal.each(function () {
899 var modal = $(this),
900 action = $(this).data('popup-rel');
901 $('[href="'+action+'"]').on('click', function (e) {
902 modal.fadeIn();
903 e.preventDefault();
904 });
905 });
906 $(document).on('click', '.tm-close, .tutor-frontend-modal-overlay, .tutor-modal-btn-cancel', function () {
907 frontEndModal.fadeOut();
908 });
909
910 /**
911 * Delete Course
912 */
913 $(document).on('click', '.tutor-mycourse-delete-btn', function (e) {
914 e.preventDefault();
915 var course_id = $(this).attr('data-course-id');
916 $('#tutor-course-delete-id').val(course_id);
917 });
918 $(document).on('submit', '#tutor-delete-course-form', function (e) {
919 e.preventDefault();
920
921 var course_id = $('#tutor-course-delete-id').val();
922 var $btn = $('.tutor-modal-course-delete-btn');
923 var data = $(this).serialize();
924
925 $.ajax({
926 url: _tutorobject.ajaxurl,
927 type: 'POST',
928 data: data,
929 beforeSend: function () {
930 $btn.addClass('updating-icon');
931 },
932 success: function (data) {
933 if (data.success){
934 $('#tutor-dashboard-course-'+course_id).remove();
935 }
936 },
937 complete: function () {
938 $btn.removeClass('updating-icon');
939 $('.tutor-frontend-modal').hide();
940 }
941 });
942 });
943
944 /**
945 * Frontend Profile
946 */
947
948 if (! $('#tutor_profile_photo_id').val()) {
949 $('.tutor-profile-photo-delete-btn').hide();
950 }
951
952 $( document ).on( 'click', '.tutor-profile-photo-delete-btn', function() {
953 $( '.tutor-profile-photo-upload-wrap' ).find( 'img' ).attr( 'src', _tutorobject.placeholder_img_src );
954 $( '#tutor_profile_photo_id' ).val( '' );
955 $( '.tutor-profile-photo-delete-btn' ).hide();
956
957 $.ajax({
958 url: _tutorobject.ajaxurl,
959 type: 'POST',
960 data: {'action' : 'tutor_profile_photo_remove'},
961 });
962
963 return false;
964 });
965
966
967
968 /**
969 * Assignment
970 *
971 * @since v.1.3.3
972 */
973
974 $( document ).on( 'submit', '#tutor_assignment_start_form', function(e) {
975 e.preventDefault();
976
977 var $that = $(this);
978 var form_data = $that.serialize()+'&action=tutor_start_assignment';
979
980 $.ajax({
981 url: _tutorobject.ajaxurl,
982 type: 'POST',
983 data: form_data,
984 beforeSend: function () {
985 $('#tutor_assignment_start_btn').addClass('updating-icon');
986 },
987 success: function (data) {
988 if (data.success){
989 location.reload();
990 }
991 },
992 complete : function () {
993 $('#tutor_assignment_start_btn').removeClass('updating-icon');
994 }
995 });
996 });
997
998 /**
999 * Assignment answer validation
1000 */
1001 $( document ).on( 'submit', '#tutor_assignment_submit_form', function(e) {
1002 var assignment_answer = $('textarea[name="assignment_answer"]').val();
1003 if (assignment_answer.trim().length < 1) {
1004 $('#form_validation_response').html('<div class="tutor-error-msg">'+_tutorobject.text.assignment_text_validation_msg+'</div>');
1005 e.preventDefault();
1006 }
1007 });
1008
1009 /**
1010 * Course builder video
1011 * @since v.1.3.4
1012 */
1013
1014
1015 $(document).on( 'click', '.video_source_upload_wrap_html5 .video_upload_btn', function( event ){
1016 event.preventDefault();
1017
1018 var $that = $(this);
1019 var frame;
1020 // If the media frame already exists, reopen it.
1021 if ( frame ) {
1022 frame.open();
1023 return;
1024 }
1025 frame = wp.media({
1026 title: 'Select or Upload Media Of Your Chosen Persuasion',
1027 button: {
1028 text: 'Use this media'
1029 },
1030 library: { type: 'video' },
1031 multiple: false // Set to true to allow multiple files to be selected
1032 });
1033 frame.on( 'select', function() {
1034 // Get media attachment details from the frame state
1035 var attachment = frame.state().get('selection').first().toJSON();
1036 $that.closest('.video_source_upload_wrap_html5').find('span.video_media_id').text(attachment.id).closest('p').show();
1037 $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id);
1038 });
1039 frame.open();
1040 });
1041
1042
1043 /**
1044 * Course and lesson sorting
1045 */
1046
1047 function enable_sorting_topic_lesson(){
1048 if (jQuery().sortable) {
1049 $(".course-contents").sortable({
1050 handle: ".course-move-handle",
1051 start: function (e, ui) {
1052 ui.placeholder.css('visibility', 'visible');
1053 },
1054 stop: function (e, ui) {
1055 tutor_sorting_topics_and_lesson();
1056 },
1057 });
1058 $(".tutor-lessons:not(.drop-lessons)").sortable({
1059 connectWith: ".tutor-lessons",
1060 items: "div.course-content-item",
1061 start: function (e, ui) {
1062 ui.placeholder.css('visibility', 'visible');
1063 },
1064 stop: function (e, ui) {
1065 tutor_sorting_topics_and_lesson();
1066 },
1067 });
1068 }
1069 }
1070 enable_sorting_topic_lesson();
1071 function tutor_sorting_topics_and_lesson(){
1072 var topics = {};
1073 $('.tutor-topics-wrap').each(function(index, item){
1074 var $topic = $(this);
1075 var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10);
1076 var lessons = {};
1077
1078 $topic.find('.course-content-item').each(function(lessonIndex, lessonItem){
1079 var $lesson = $(this);
1080 var lesson_id = parseInt($lesson.attr('id').match(/\d+/)[0], 10);
1081
1082 lessons[lessonIndex] = lesson_id;
1083 });
1084 topics[index] = { 'topic_id' : topics_id, 'lesson_ids' : lessons };
1085 });
1086 $('#tutor_topics_lessons_sorting').val(JSON.stringify(topics));
1087 }
1088
1089 /**
1090 * Lesson Update or Create Modal
1091 */
1092 $(document).on( 'click', '.update_lesson_modal_btn', function( event ){
1093 event.preventDefault();
1094
1095 var $that = $(this);
1096 var content;
1097 var editor = tinyMCE.get('tutor_lesson_modal_editor');
1098 if (editor) {
1099 content = editor.getContent();
1100 } else {
1101 content = $('#'+inputid).val();
1102 }
1103
1104 var form_data = $(this).closest('form').serialize();
1105 form_data += '&lesson_content='+encodeURIComponent(content);
1106
1107 $.ajax({
1108 url : ajaxurl,
1109 type : 'POST',
1110 data : form_data,
1111 beforeSend: function () {
1112 $that.addClass('tutor-updating-message');
1113 },
1114 success: function (data) {
1115 if (data.success){
1116 $('#tutor-course-content-wrap').html(data.data.course_contents);
1117 enable_sorting_topic_lesson();
1118
1119 //Close the modal
1120 $('.tutor-lesson-modal-wrap').removeClass('show');
1121 }
1122 },
1123 complete: function () {
1124 $that.removeClass('tutor-updating-message');
1125 }
1126 });
1127 });
1128
1129 /**
1130 * END: Tutor Course builder JS
1131 */
1132
1133 /**
1134 * Attachment in forntend course builder
1135 * @since v.1.3.4
1136 */
1137 $(document).on('click', 'a.tutor-delete-attachment', function(e){
1138 e.preventDefault();
1139 $(this).closest('.tutor-added-attachment').remove();
1140 });
1141 $(document).on('click', '.tutorUploadAttachmentBtn', function(e){
1142 e.preventDefault();
1143
1144 var $that = $(this);
1145 var frame;
1146 if ( frame ) {
1147 frame.open();
1148 return;
1149 }
1150 frame = wp.media({
1151 title: 'Select or Upload Media Of Your Chosen Persuasion',
1152 button: {
1153 text: 'Use this media'
1154 },
1155 multiple: true // Set to true to allow multiple files to be selected
1156 });
1157 frame.on( 'select', function() {
1158 var attachments = frame.state().get('selection').toJSON();
1159 if (attachments.length){
1160 for (var i=0; i < attachments.length; i++){
1161 var attachment = attachments[i];
1162
1163 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>';
1164 $that.closest('.tutor-lesson-attachments-metabox').find('.tutor-added-attachments-wrap').append(inputHtml);
1165 }
1166 }
1167 });
1168 frame.open();
1169 });
1170
1171
1172 /**
1173 * Single Assignment Upload Button
1174 * @since v.1.3.4
1175 */
1176 $('form').on('change', '.tutor-assignment-file-upload', function () {
1177 $(this).siblings("label").find('span').html($(this).val().replace(/.*(\/|\\)/, ''));
1178 });
1179
1180 /**
1181 * Lesson Sidebar Topic Toggle
1182 * @since v.1.3.4
1183 */
1184
1185 $(document).on('click', '.tutor-topics-in-single-lesson .tutor-topics-title h3, .tutor-single-lesson-topic-toggle', function (e) {
1186 var $that = $(this);
1187 var $parent = $that.closest('.tutor-topics-in-single-lesson');
1188 $parent.toggleClass('tutor-topic-active');
1189 $parent.find('.tutor-lessons-under-topic').slideToggle();
1190 });
1191
1192 $('.tutor-single-lesson-items.active').closest('.tutor-lessons-under-topic').show();
1193 $('.tutor-single-lesson-items.active').closest('.tutor-topics-in-single-lesson').addClass('tutor-topic-active');
1194 $('.tutor-course-lesson.active').closest('.tutor-lessons-under-topic').show();
1195
1196
1197 /**
1198 * Assignments Addons
1199 * @backend Support
1200 *
1201 */
1202
1203
1204 /**
1205 * Tutor Assignments JS
1206 * @since v.1.3.3
1207 */
1208 $(document).on('click', '.tutor-create-assignments-btn', function(e){
1209 e.preventDefault();
1210
1211 var $that = $(this);
1212 var topic_id = $(this).attr('data-topic-id');
1213 var course_id = $('#post_ID').val();
1214
1215 $.ajax({
1216 url : ajaxurl,
1217 type : 'POST',
1218 data : {topic_id : topic_id, course_id : course_id, action: 'tutor_load_assignments_builder_modal'},
1219 beforeSend: function () {
1220 $that.addClass('tutor-updating-message');
1221 },
1222 success: function (data) {
1223 $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output);
1224 $('.tutor-lesson-modal-wrap').attr('data-topic-id', topic_id).addClass('show');
1225
1226 $(document).trigger('assignment_modal_loaded', {topic_id : topic_id, course_id : course_id});
1227
1228 tinymce.init(tinyMCEPreInit.mceInit.course_description);
1229 tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_assignments_modal_editor' );
1230 tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor");
1231 },
1232 complete: function () {
1233 quicktags({id : "tutor_assignments_modal_editor"});
1234 $that.removeClass('tutor-updating-message');
1235 }
1236 });
1237 });
1238
1239 $(document).on('click', '.open-tutor-assignment-modal', function(e){
1240 e.preventDefault();
1241
1242 var $that = $(this);
1243 var assignment_id = $that.attr('data-assignment-id');
1244 var topic_id = $that.attr('data-topic-id');
1245 var course_id = $('#post_ID').val();
1246
1247 $.ajax({
1248 url : ajaxurl,
1249 type : 'POST',
1250 data : {assignment_id : assignment_id, topic_id : topic_id, course_id : course_id, action: 'tutor_load_assignments_builder_modal'},
1251 beforeSend: function () {
1252 $that.addClass('tutor-updating-message');
1253 },
1254 success: function (data) {
1255 $('.tutor-lesson-modal-wrap .modal-container').html(data.data.output);
1256 $('.tutor-lesson-modal-wrap').attr({'data-assignment-id' : assignment_id, 'data-topic-id':topic_id}).addClass('show');
1257
1258 $(document).trigger('assignment_modal_loaded', {assignment_id : assignment_id, topic_id : topic_id, course_id : course_id});
1259
1260 tinymce.init(tinyMCEPreInit.mceInit.course_description);
1261 tinymce.execCommand( 'mceRemoveEditor', false, 'tutor_assignments_modal_editor' );
1262 tinyMCE.execCommand('mceAddEditor', false, "tutor_assignments_modal_editor");
1263 },
1264 complete: function () {
1265 quicktags({id : "tutor_assignments_modal_editor"});
1266 $that.removeClass('tutor-updating-message');
1267 }
1268 });
1269 });
1270
1271 /**
1272 * Update Assignment Data
1273 */
1274 $(document).on( 'click', '.update_assignment_modal_btn', function( event ){
1275 event.preventDefault();
1276
1277 var $that = $(this);
1278 var content;
1279 var editor = tinyMCE.get('tutor_assignments_modal_editor');
1280 if (editor) {
1281 content = editor.getContent();
1282 } else {
1283 content = $('#'+inputid).val();
1284 }
1285
1286 var form_data = $(this).closest('form').serialize();
1287 form_data += '&assignment_content='+content;
1288
1289 $.ajax({
1290 url : ajaxurl,
1291 type : 'POST',
1292 data : form_data,
1293 beforeSend: function () {
1294 $that.addClass('tutor-updating-message');
1295 },
1296 success: function (data) {
1297 if (data.success){
1298 $('#tutor-course-content-wrap').html(data.data.course_contents);
1299 enable_sorting_topic_lesson();
1300
1301 //Close the modal
1302 $('.tutor-lesson-modal-wrap').removeClass('show');
1303 }
1304 },
1305 complete: function () {
1306 $that.removeClass('tutor-updating-message');
1307 }
1308 });
1309 });
1310
1311 /**
1312 * Add Assignment
1313 */
1314 $(document).on( 'click', '.add-assignment-attachments', function( event ){
1315 event.preventDefault();
1316
1317 var $that = $(this);
1318 var frame;
1319 // If the media frame already exists, reopen it.
1320 if ( frame ) {
1321 frame.open();
1322 return;
1323 }
1324
1325 // Create a new media frame
1326 frame = wp.media({
1327 title: 'Select or Upload Media Of Your Chosen Persuasion',
1328 button: {
1329 text: 'Use this media'
1330 },
1331 multiple: false // Set to true to allow multiple files to be selected
1332 });
1333
1334 // When an image is selected in the media frame...
1335 frame.on( 'select', function() {
1336 // Get media attachment details from the frame state
1337 var attachment = frame.state().get('selection').first().toJSON();
1338
1339 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>';
1340
1341 $('#assignment-attached-file').append(field_markup);
1342 $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id);
1343 });
1344 // Finally, open the modal on click
1345 frame.open();
1346 });
1347
1348 $(document).on( 'click', '.remove-assignment-attachment-a', function( event ){
1349 event.preventDefault();
1350 $(this).closest('.tutor-individual-attachment-file').remove();
1351 });
1352
1353
1354 /**
1355 *
1356 * @type {jQuery}
1357 *
1358 * Course builder auto draft save
1359 *
1360 * @since v.1.3.4
1361 */
1362 var tutor_course_builder = $('input[name="tutor_action"]').val();
1363 if (tutor_course_builder === 'tutor_add_course_builder'){
1364 setInterval(auto_draft_save_course_builder, 30000);
1365 }
1366
1367 function auto_draft_save_course_builder(){
1368 var form_data = $('form#tutor-frontend-course-builder').serialize();
1369 $.ajax({
1370 //url : _tutorobject.ajaxurl,
1371 type : 'POST',
1372 data : form_data+'&tutor_ajax_action=tutor_course_builder_draft_save',
1373 beforeSend: function () {
1374 $('.tutor-dashboard-builder-draft-btn span').text('Saving...');
1375 },
1376 success: function (data) {
1377
1378 },
1379 complete: function () {
1380 $('.tutor-dashboard-builder-draft-btn span').text('Save');
1381 }
1382 });
1383 }
1384
1385 /**
1386 *
1387 * @type {jQuery}
1388 *
1389 * Course builder section toggle
1390 *
1391 * @since v.1.3.5
1392 */
1393
1394 $('.tutor-course-builder-section-title').on('click', function () {
1395 if($(this).find('i').hasClass("tutor-icon-up")){
1396 $(this).find('i').removeClass('tutor-icon-up').addClass('tutor-icon-down');
1397 }else{
1398 $(this).find('i').removeClass('tutor-icon-down').addClass('tutor-icon-up');
1399 }
1400 $(this).next('div').slideToggle();
1401 });
1402
1403 /**
1404 * Open Tutor Modal to edit review
1405 * @since v.1.4.0
1406 */
1407 $(document).on('click', '.open-tutor-edit-review-modal', function(e){
1408 e.preventDefault();
1409
1410 var $that = $(this);
1411 var review_id = $that.attr('data-review-id');
1412
1413 var nonce_key = _tutorobject.nonce_key;
1414
1415 var json_data = {review_id : review_id, action: 'tutor_load_edit_review_modal'};
1416 json_data[nonce_key] = _tutorobject[nonce_key];
1417
1418 $.ajax({
1419 url : _tutorobject.ajaxurl,
1420 type : 'POST',
1421 data : json_data,
1422 beforeSend: function () {
1423 $that.addClass('tutor-updating-message');
1424 },
1425 success: function (data) {
1426 if (typeof data.data !== 'undefined') {
1427 $('.tutor-edit-review-modal-wrap .modal-container').html(data.data.output);
1428 $('.tutor-edit-review-modal-wrap').attr('data-review-id', review_id).addClass('show');
1429 }
1430 },
1431 complete: function () {
1432 $that.removeClass('tutor-updating-message');
1433 }
1434 });
1435 });
1436
1437 /**
1438 * Update the rating
1439 * @since v.1.4.0
1440 */
1441 $(document).on('submit', '#tutor_update_review_form', function(e){
1442 e.preventDefault();
1443
1444 var $that = $(this);
1445 var review_id = $that.closest('.tutor-edit-review-modal-wrap ').attr('data-review-id');
1446
1447 var nonce_key = _tutorobject.nonce_key;
1448
1449 var rating = $that.find('input[name="tutor_rating_gen_input"]').val();
1450 var review = $that.find('textarea[name="review"]').val();
1451 review = review.trim();
1452
1453 var json_data = {review_id : review_id, rating : rating, review : review, action: 'tutor_update_review_modal'};
1454 json_data[nonce_key] = _tutorobject[nonce_key];
1455
1456 $.ajax({
1457 url : _tutorobject.ajaxurl,
1458 type : 'POST',
1459 data : json_data,
1460 beforeSend: function () {
1461 $that.find('button[type="submit"]').addClass('tutor-updating-message');
1462 },
1463 success: function (data) {
1464 if (data.success){
1465 //Close the modal
1466 $('.tutor-edit-review-modal-wrap').removeClass('show');
1467 location.reload(true);
1468 }
1469 },
1470 complete: function () {
1471 $that.find('button[type="submit"]').removeClass('tutor-updating-message');
1472 }
1473 });
1474 });
1475
1476 /**
1477 * Profile photo upload
1478 * @since v.1.4.5
1479 */
1480
1481 $(document).on('click', '#tutor_profile_photo_button', function(e){
1482 e.preventDefault();
1483
1484 $('#tutor_profile_photo_file').trigger('click');
1485 });
1486
1487 $(document).on('change', '#tutor_profile_photo_file', function(event){
1488 event.preventDefault();
1489
1490 var $file = this;
1491 if ($file.files && $file.files[0]) {
1492 var reader = new FileReader();
1493 reader.onload = function(e) {
1494 $( '.tutor-profile-photo-upload-wrap' ).find( 'img' ).attr( 'src', e.target.result);
1495 }
1496 reader.readAsDataURL($file.files[0]);
1497 }
1498 });
1499
1500 /**
1501 * Addon, Tutor BuddyPress
1502 * Retrieve MetaInformation on BuddyPress message system
1503 * @for TutorLMS Pro
1504 * @since v.1.4.8
1505 */
1506
1507 $(document).on('click', '.thread-content .subject', function(e){
1508 var $btn = $(this);
1509
1510 var thread_id = parseInt($btn.closest('.thread-content').attr('data-thread-id'));
1511
1512 var nonce_key = _tutorobject.nonce_key;
1513 var json_data = {thread_id : thread_id, action: 'tutor_bp_retrieve_user_records_for_thread'};
1514 json_data[nonce_key] = _tutorobject[nonce_key];
1515
1516 $.ajax({
1517 type: 'POST',
1518 url: ajaxurl,
1519 data: json_data,
1520 beforeSend: function(){
1521 $('#tutor-bp-thread-wrap').html('');
1522 },
1523 success: function (data) {
1524 if (data.success){
1525 $('#tutor-bp-thread-wrap').html(data.data.thread_head_html);
1526 tutor_bp_setting_enrolled_courses_list();
1527 }
1528 }
1529 });
1530
1531 });
1532
1533
1534 function tutor_bp_setting_enrolled_courses_list(){
1535 $('ul.tutor-bp-enrolled-course-list').each(function(){
1536 var $that = $(this);
1537 var $li = $that.find(' > li');
1538 var itemShow = 3;
1539
1540 if ($li.length > itemShow){
1541 var plusCourseCount = $li.length - itemShow;
1542 $li.each(function(liIndex, liItem){
1543 var $liItem = $(this);
1544
1545 if (liIndex >= itemShow){
1546 $liItem.hide();
1547 }
1548 });
1549
1550 var infoHtml = '<a href="javascript:;" class="tutor_bp_plus_courses"><strong>+'+plusCourseCount+' More </strong></a> Courses';
1551 $that.closest('.tutor-bp-enrolled-courses-wrap').find('.thread-participant-enrolled-info').html(infoHtml);
1552 }
1553
1554 $that.show();
1555 });
1556 }
1557 tutor_bp_setting_enrolled_courses_list();
1558
1559 $(document).on('click', 'a.tutor_bp_plus_courses', function(e){
1560 e.preventDefault();
1561
1562 var $btn = $(this);
1563 $btn.closest('.tutor-bp-enrolled-courses-wrap').find('.tutor-bp-enrolled-course-list li').show();
1564 $btn.closest('.thread-participant-enrolled-info').html('');
1565 });
1566
1567
1568
1569 /**
1570 * Addon, Tutor Certificate
1571 * Certificate dropdown content and copy link
1572 * @for TutorLMS Pro
1573 * @since v.1.5.1
1574 */
1575 $(document).on('click', '.tutor-dropbtn', function (e) {
1576 var $content = $(this).parent().find(".tutor-dropdown-content");
1577 $content.slideToggle(100);
1578 });
1579 $(document).on('click', '.tutor-copy-link', function (e) {
1580 var $btn = $(this);
1581 var copy = '<i class="tutor-icon-copy"></i> Copy Link';
1582 var copied = '<i class="tutor-icon-mark"></i> Copied';
1583 var dummy = document.createElement('input'),
1584 text = window.location.href;
1585 document.body.appendChild(dummy);
1586 dummy.value = text;
1587 dummy.select();
1588 document.execCommand('copy');
1589 document.body.removeChild(dummy);
1590 $btn.html(copied);
1591 setTimeout( function() {
1592 $btn.html(copy);
1593 }, 2500);
1594 });
1595 $(document).on('click', function(e) {
1596 var container = $(".tutor-dropdown");
1597 var $content = container.find('.tutor-dropdown-content');
1598 // if the target of the click isn't the container nor a descendant of the container
1599 if (!container.is(e.target) && container.has(e.target).length === 0) {
1600 $content.slideUp(100);
1601 }
1602 });
1603
1604 });