PageSourceSearch

https://salon.mainichi-kotoba.jp/wp-content/plugins/bsel/assets/js/bsel-front.js?ver=1.8.1

js mainichi-kotoba.jp collected 2026-10-02 15:31:15 UTC 85,630 bytes, 2,378 lines download raw bytes

1jQuery(document).ready(function ($) {
2    'use strict';
3
4    /**
5     * Initiate Select2
6     * @since v.1.3.4
7     */
8    if (jQuery().select2) {
9        $('.bsel_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', '.bsel-course-filter-form', function (e) {
36        e.preventDefault();
37        $(this).closest('form').submit();
38    }); */
39
40    const videoPlayer = {
41        ajaxurl: _bselobject.ajaxurl,
42        nonce_key: _bselobject.nonce_key,
43        video_data: function () {
44            const video_track_data = $('#bsel_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('#bselPlayer');
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 bsel 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            //BSEL 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] = _bselobject[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] = _bselobject[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 BSEL video
112     * @since v.1.0.0
113     */
114    if ($('#bselPlayer').length) {
115        videoPlayer.init();
116    }
117
118    $(document).on('change keyup paste', '.bsel_user_name', function () {
119        $(this).val(bsel_slugify($(this).val()));
120    });
121
122    function bsel_slugify(text) {
123        return text.toString().toLowerCase()
124            .replace(/\s+/g, '-')           // Replace spaces with -
125            .replace(/[^\w\-]+/g, '')       // Remove all non-word chars
126            .replace(/\-\-+/g, '-')         // Replace multiple - with single -
127            .replace(/^-+/, '')             // Trim - from start of text
128            .replace(/-+$/, '');            // Trim - from end of text
129    }
130
131    function toggle_star_(star){
132        star.add(star.prevAll()).filter('i').addClass('bsel-icon-star-full').removeClass('bsel-icon-star-line');
133        star.nextAll().filter('i').removeClass('bsel-icon-star-full').addClass('bsel-icon-star-line');
134    }
135
136    /**
137     * Hover bsel rating and set value
138     */
139    $(document).on('mouseover', '.bsel-write-review-box .bsel-star-rating-group i', function () {
140        toggle_star_($(this));
141    });
142
143    $(document).on('click', '.bsel-write-review-box .bsel-star-rating-group i', function () {
144        var rating = $(this).attr('data-rating-value');
145        $(this).closest('.bsel-star-rating-group').find('input[name="bsel_rating_gen_input"]').val(rating);
146        
147        toggle_star_($(this));
148    });
149
150    $(document).on('mouseout', '.bsel-write-review-box .bsel-star-rating-group', function(){
151        var value = $(this).find('input[name="bsel_rating_gen_input"]').val();
152        var rating = parseInt(value);
153        
154        var selected = $(this).find('[data-rating-value="'+rating+'"]');
155        (rating && selected && selected.length>0) ? toggle_star_(selected) : $(this).find('i').removeClass('bsel-icon-star-full').addClass('bsel-icon-star-line');
156    });
157
158    $(document).on('click', '.bsel_submit_review_btn', function (e) {
159        e.preventDefault();
160        var $that = $(this);
161        var rating = $that.closest('form').find('input[name="bsel_rating_gen_input"]').val();
162        var review = $that.closest('form').find('textarea[name="review"]').val();
163        review = review.trim();
164
165        var course_id = $('input[name="bsel_course_id"]').val();
166        var data = { course_id: course_id, rating: rating, review: review, action: 'bsel_place_rating' };
167
168        if (review) {
169            $.ajax({
170                url: _bselobject.ajaxurl,
171                type: 'POST',
172                data: data,
173                beforeSend: function () {
174                    $that.addClass('updating-icon');
175                },
176                success: function (data) {
177                    var review_id = data.data.review_id;
178                    var review = data.data.review;
179                    $('.bsel-review-' + review_id + ' .review-content').html(review);
180                    location.reload();
181                }
182            });
183        }
184    });
185
186    $(document).on('click', '.write-course-review-link-btn', function (e) {
187        e.preventDefault();
188        $(this).siblings('.bsel-write-review-form').slideToggle();
189    });
190
191    $(document).on('click', '.bsel-ask-question-btn', function (e) {
192        e.preventDefault();
193        $('.bsel-add-question-wrap').slideToggle();
194    });
195    $(document).on('click', '.bsel_question_cancel', function (e) {
196        e.preventDefault();
197        $('.bsel-add-question-wrap').toggle();
198    });
199
200    $(document).on('submit', '#bsel-ask-question-form', function (e) {
201        e.preventDefault();
202
203        var $form = $(this);
204
205        var data = $(this).serializeObject();
206        data.action = 'bsel_ask_question';
207
208        $.ajax({
209            url: _bselobject.ajaxurl,
210            type: 'POST',
211            data: data,
212            beforeSend: function () {
213                $form.find('.bsel_ask_question_btn').addClass('updating-icon');
214            },
215            success: function (data) {
216                if (data.success) {
217                    $('.bsel-add-question-wrap').hide();
218                    window.location.reload();
219                }
220            },
221            complete: function () {
222                $form.find('.bsel_ask_question_btn').removeClass('updating-icon');
223            }
224        });
225    });
226
227    $(document).on('submit', '.bsel-add-answer-form', function (e) {
228        e.preventDefault();
229
230        var $form = $(this);
231        var data = $(this).serializeObject();
232        data.action = 'bsel_add_answer';
233
234        $.ajax({
235            url: _bselobject.ajaxurl,
236            type: 'POST',
237            data: data,
238            beforeSend: function () {
239                $form.find('.bsel_add_answer_btn').addClass('updating-icon');
240            },
241            success: function (data) {
242                if (data.success) {
243                    window.location.reload();
244                }
245            },
246            complete: function () {
247                $form.find('.bsel_add_answer_btn').removeClass('updating-icon');
248            }
249        });
250    });
251
252    $(document).on('focus', '.bsel_add_answer_textarea', function (e) {
253        e.preventDefault();
254
255        var question_id = $(this).closest('.bsel_add_answer_wrap').attr('data-question-id');
256        var conf = {
257            tinymce: {
258                wpautop: true,
259                //plugins : 'charmap colorpicker compat3x directionality fullscreen hr image lists media paste tabfocus textcolor wordpress wpautoresize wpdialogs wpeditimage wpemoji wpgallery wplink wptextpattern wpview',
260                toolbar1: 'bold italic underline bullist strikethrough numlist  blockquote  alignleft aligncenter alignright undo redo link unlink spellchecker fullscreen'
261            },
262        };
263        wp.editor.initialize('bsel_answer_' + question_id, conf);
264    });
265
266    $(document).on('click', '.bsel_cancel_wp_editor', function (e) {
267        e.preventDefault();
268        $(this).closest('.bsel_wp_editor_wrap').toggle();
269        $(this).closest('.bsel_add_answer_wrap').find('.bsel_wp_editor_show_btn_wrap').toggle();
270        var question_id = $(this).closest('.bsel_add_answer_wrap').attr('data-question-id');
271        wp.editor.remove('bsel_answer_' + question_id);
272    });
273
274    $(document).on('click', '.bsel_wp_editor_show_btn', function (e) {
275        e.preventDefault();
276        $(this).closest('.bsel_add_answer_wrap').find('.bsel_wp_editor_wrap').toggle();
277        $(this).closest('.bsel_wp_editor_show_btn_wrap').toggle();
278    });
279
280    /**
281     * Quiz attempt
282     */
283    var $bsel_quiz_time_update = $('#bsel-quiz-time-update');
284    var attempt_settings = null;
285    if ($bsel_quiz_time_update.length) {
286        attempt_settings = JSON.parse($bsel_quiz_time_update.attr('data-attempt-settings'));
287        var attempt_meta = JSON.parse($bsel_quiz_time_update.attr('data-attempt-meta'));
288
289        if (attempt_meta.time_limit.time_limit_seconds > 0) {
290            //No time Zero limit for
291            var countDownDate = new Date(attempt_settings.attempt_started_at).getTime() + (attempt_meta.time_limit.time_limit_seconds * 1000);
292            var time_now = new Date(attempt_meta.date_time_now).getTime();
293
294            var bsel_quiz_interval = setInterval(function () {
295                var distance = countDownDate - time_now;
296
297                var days = Math.floor(distance / (1000 * 60 * 60 * 24));
298                var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
299                var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
300                var seconds = Math.floor((distance % (1000 * 60)) / 1000);
301
302                var countdown_human = '';
303
304                if (days) {
305                    countdown_human += days + "d ";
306                }
307                if (hours) {
308                    countdown_human += hours + "h ";
309                }
310                if (minutes) {
311                    countdown_human += minutes + "m ";
312                }
313                if (seconds) {
314                    countdown_human += seconds + "s ";
315                }
316
317                if (distance < 0) {
318                    clearInterval(bsel_quiz_interval);
319                    countdown_human = "EXPIRED";
320                    //Set the quiz attempt to timeout in ajax
321
322                    if (_bselobject.quiz_options.quiz_when_time_expires === 'autosubmit') {
323                        /**
324                         * Auto Submit
325                         */
326                        $('form#bsel-answering-quiz').submit();
327
328                    } else if (_bselobject.quiz_options.quiz_when_time_expires === 'autoabandon') {
329                        /**
330                         *
331                         * @type {jQuery}
332                         *
333                         * Current attempt will be cancel with attempt status attempt_timeout
334                         */
335
336                        var quiz_id = $('#bsel_quiz_id').val();
337                        var bsel_quiz_remaining_time_secs = $('#bsel_quiz_remaining_time_secs').val();
338                        var quiz_timeout_data = { quiz_id: quiz_id, action: 'bsel_quiz_timeout' };
339
340                        $.ajax({
341                            url: _bselobject.ajaxurl,
342                            type: 'POST',
343                            data: quiz_timeout_data,
344                            success: function (data) {
345                                if (data.success) {
346                                    window.location.reload(true);
347                                }
348                            },
349                            complete: function () {
350                                $('#bsel-quiz-body').html('');
351                                window.location.reload(true);
352                            }
353                        });
354                    }
355
356                }
357                time_now = time_now + 1000;
358                $bsel_quiz_time_update.html(countdown_human);
359            }, 1000);
360        } else {
361            $bsel_quiz_time_update.closest('.time-remaining').remove();
362        }
363    }
364
365    var $quiz_start_form = $('#bsel-quiz-body form#bsel-start-quiz');
366    if ($quiz_start_form.length) {
367        if (_bselobject.quiz_options.quiz_auto_start === '1') {
368            $quiz_start_form.submit();
369        }
370    }
371
372    /**
373     * Quiz Frontend Review Action
374     * @since 1.4.0
375     */
376    $(document).on('click', '.quiz-manual-review-action', function (e) {
377        e.preventDefault();
378        var $that = $(this),
379            attempt_id = $that.attr('data-attempt-id'),
380            attempt_answer_id = $that.attr('data-attempt-answer-id'),
381            mark_as = $that.attr('data-mark-as');
382
383        $.ajax({
384            url: _bselobject.ajaxurl,
385            type: 'GET',
386            data: { action: 'review_quiz_answer', attempt_id: attempt_id, attempt_answer_id: attempt_answer_id, mark_as: mark_as },
387            beforeSend: function () {
388                $that.find('i').addClass('updating-icon');
389            },
390            success: function (data) {
391                location.reload();
392            },
393            complete: function () {
394                $that.find('i').removeClass('updating-icon');
395            }
396        });
397    });
398
399    // Quiz Review : Tooltip
400    $(".tooltip-btn").on("hover", function (e) {
401        $(this).toggleClass("active");
402    });
403
404    // bsel course content accordion
405
406    /**
407	 * Toggle topic summery
408	 * @since v.1.6.9
409	 */
410    $('.bsel-course-title h4 .toogle-informaiton-icon').on('click', function (e) {
411        $(this).closest('.bsel-topics-in-single-lesson').find('.bsel-topics-summery').slideToggle();
412        e.stopPropagation();
413    });
414
415    $('.bsel-course-topic.bsel-active').find('.bsel-course-lessons').slideDown();
416    $('.bsel-course-title').on('click', function () {
417        var lesson = $(this).siblings('.bsel-course-lessons');
418        $(this).closest('.bsel-course-topic').toggleClass('bsel-active');
419        lesson.slideToggle();
420    });
421
422    $(document).on('click', '.bsel-topics-title h3 .toogle-informaiton-icon', function (e) {
423        $(this).closest('.bsel-topics-in-single-lesson').find('.bsel-topics-summery').slideToggle();
424        e.stopPropagation();
425    });
426
427    $(document).on('click', '.bsel-course-wishlist-btn', function (e) {
428        e.preventDefault();
429
430        var $that = $(this);
431        var course_id = $that.attr('data-course-id');
432
433        $.ajax({
434            url: _bselobject.ajaxurl,
435            type: 'POST',
436            data: { course_id: course_id, 'action': 'bsel_course_add_to_wishlist' },
437            beforeSend: function () {
438                $that.addClass('updating-icon');
439            },
440            success: function (data) {
441                if (data.success) {
442                    if (data.data.status === 'added') {
443                        $that.addClass('has-wish-listed');
444                    } else {
445                        $that.removeClass('has-wish-listed');
446                    }
447                } else {
448                    window.location = data.data.redirect_to;
449                }
450            },
451            complete: function () {
452                $that.removeClass('updating-icon');
453            }
454        });
455    });
456
457    /**
458     * Check if lesson has classic editor support
459     * If classic editor support, stop ajax load on the lesson page.
460     *
461     * @since v.1.0.0
462     *
463     * @updated v.1.4.0
464     */
465    if (!_bselobject.enable_lesson_classic_editor) {
466
467        $(document).on('click', '.bsel-single-lesson-a', function (e) {
468            e.preventDefault();
469            
470            var $that = $(this);
471            var lesson_id = $that.attr('data-lesson-id');
472            var $wrap = $('#bsel-single-entry-content');
473
474            $.ajax({
475                url: _bselobject.ajaxurl,
476                type: 'POST',
477                data: { lesson_id: lesson_id, 'action': 'bsel_render_lesson_content' },
478                beforeSend: function () {
479                    var page_title = $that.find('.lesson_title').text();
480                    $('head title').text(page_title);
481                    window.history.pushState('obj', page_title, $that.attr('href'));
482                    $wrap.addClass('loading-lesson');
483                    $('.bsel-single-lesson-items').removeClass('active');
484                    $that.closest('.bsel-single-lesson-items').addClass('active');
485                },
486                success: function (data) {
487                    $wrap.html(data.data.html);
488                    videoPlayer.init();
489                    $('.bsel-lesson-sidebar').css('display', '');
490                    window.dispatchEvent(new window.Event('bsel_ajax_lesson_loaded')); // Some plugins like h5p needs notification on ajax load
491                },
492                complete: function () {
493                    $wrap.removeClass('loading-lesson');
494                }
495            });
496        });   
497
498        if($('#bsel_video_tracking_information').length) { // fix video size by reloading ajax data
499            $('.bsel-single-lesson-items.active .bsel-single-lesson-a').trigger('click');
500        }
501
502        $(document).on('click', '.sidebar-single-quiz-a', function (e) {
503            e.preventDefault();
504
505            var $that = $(this);
506            var quiz_id = $that.attr('data-quiz-id');
507            var page_title = $that.find('.lesson_title').text();
508            var $wrap = $('#bsel-single-entry-content');
509
510            $.ajax({
511                url: _bselobject.ajaxurl,
512                type: 'POST',
513                data: { quiz_id: quiz_id, 'action': 'bsel_render_quiz_content' },
514                beforeSend: function () {
515                    $('head title').text(page_title);
516                    window.history.pushState('obj', page_title, $that.attr('href'));
517                    $wrap.addClass('loading-lesson');
518                    $('.bsel-single-lesson-items').removeClass('active');
519                    $that.closest('.bsel-single-lesson-items').addClass('active');
520                },
521                success: function (data) {
522                    if(data.success) {
523                        $wrap.html(data.data.html);
524                    } else {
525                        // $wrap.html('<p style="text-align:center;margin: 40px;">すべてのレッスンの完了後に可能です。</p>');
526                    }
527                    init_quiz_builder();
528                    $('.bsel-lesson-sidebar').css('display', '');
529                },
530                complete: function () {
531                    $wrap.removeClass('loading-lesson');
532                }
533            });
534        });
535    }
536
537    /**
538     * @date 05 Feb, 2019
539     */
540
541    $(document).on('click', '.bsel-lesson-sidebar-hide-bar', function (e) {
542        e.preventDefault();
543        $('.bsel-lesson-sidebar').toggle();
544        $('#bsel-single-entry-content').toggleClass("sidebar-hidden");
545
546    });
547
548    $(".bsel-tabs-btn-group a").on('click touchstart', function (e) {
549        e.preventDefault();
550        var $that = $(this);
551        var tabSelector = $that.attr('href');
552        $('.bsel-lesson-sidebar-tab-item').hide();
553        $(tabSelector).show();
554
555        $('.bsel-tabs-btn-group a').removeClass('active');
556        $that.addClass('active');
557
558        if(tabSelector == "#bsel-lesson-sidebar-qa-tab-content") {
559            var course_id = $that.attr('data-course_id');
560            $.ajax({
561                url : _bselobject.ajaxurl,
562                type : 'POST',
563                data : {
564                    action : 'bsel_announcement_reset_unread_count',
565                    course_id: course_id
566                },
567                beforeSend: function() {
568                
569                },
570                success: function(data) {
571                    
572                },
573                error: function(){
574
575                }
576            })
577        }
578    });
579    /**
580     * @date 18 Feb, 2019
581     * @since v.1.0.0
582     */
583
584    function init_quiz_builder() {
585        if (jQuery().sortable) {
586            $(".bsel-quiz-answers-wrap").sortable({
587                handle: ".answer-sorting-bar",
588                start: function (e, ui) {
589                    ui.placeholder.css('visibility', 'visible');
590                },
591                stop: function (e, ui) {
592                    //Sorting Stopped...
593                },
594            }).disableSelection();
595
596            $(".quiz-draggable-rand-answers, .quiz-answer-matching-droppable").sortable({
597                connectWith: ".quiz-answer-matching-droppable",
598                placeholder: "drop-hover",
599            }).disableSelection();
600        }
601    }
602    init_quiz_builder();
603    /**
604     * Quiz view
605     * @date 22 Feb, 2019
606     * @since v.1.0.0
607     */
608
609    $(document).on('click', '.bsel-quiz-answer-next-btn', function (e) {
610        e.preventDefault();
611
612        var $that = $(this);
613        var $question_wrap = $that.closest('.quiz-attempt-single-question');
614        /**
615         * Validating required answer
616         * @type {jQuery}
617         *
618         * @since v.1.6.1
619         */
620
621        var validated = bsel_quiz_validation($question_wrap);
622        if (!validated) {
623            return;
624        }
625
626        var feedBackNext = feedback_response($question_wrap);
627        if (!feedBackNext) {
628            return;
629        }
630
631        var question_id = parseInt($that.closest('.quiz-attempt-single-question').attr('id').match(/\d+/)[0], 10);
632
633        var next_question_id = $that.closest('.quiz-attempt-single-question').attr('data-next-question-id');
634
635        if (next_question_id) {
636            var $nextQuestion = $(next_question_id);
637            if ($nextQuestion && $nextQuestion.length) {
638                $('.quiz-attempt-single-question').hide();
639                $nextQuestion.show();
640
641                /**
642                 * If pagination exists, set active class
643                 */
644
645                if ($('.bsel-quiz-questions-pagination').length) {
646                    $('.bsel-quiz-question-paginate-item').removeClass('active');
647                    $('.bsel-quiz-questions-pagination a[href="' + next_question_id + '"]').addClass('active');
648                }
649
650            }
651        }
652    });
653
654
655    $(document).on('click', '.bsel-quiz-answer-next-btn', function (e) {
656        e.preventDefault();
657
658    });
659
660    $(document).on('click', '.bsel-quiz-answer-prev-btn', function (e) {
661        e.preventDefault();
662
663        var $that = $(this);
664
665        var prev_question_id = $that.closest('.quiz-attempt-single-question').attr('data-prev-question-id');
666
667        if (prev_question_id) {
668            var $prevQuestion = $(prev_question_id);
669            if ($prevQuestion && $prevQuestion.length) {
670                $('.quiz-attempt-single-question').hide();
671                $prevQuestion.show();
672
673                /**
674                 * If pagination exists, set active class
675                 */
676
677                if ($('.bsel-quiz-questions-pagination').length) {
678                    $('.bsel-quiz-question-paginate-item').removeClass('active');
679                    $('.bsel-quiz-questions-pagination a[href="' + prev_question_id + '"]').addClass('active');
680                }
681            }
682        }
683    });
684    
685    $(document).on('submit', '#bsel-answering-quiz', function (e) {
686        var $questions_wrap = $('.quiz-attempt-single-question');
687        var validated = true;
688        if ($questions_wrap.length) {
689            $questions_wrap.each(function (index, question) {
690                validated = bsel_quiz_validation($(question));
691                validated = feedback_response($(question));
692            });
693        }
694
695        if (!validated) {
696            e.preventDefault();
697        }
698
699    });
700
701
702    $(document).on('click', '.bsel-quiz-question-paginate-item', function (e) {
703        e.preventDefault();
704        var $that = $(this);
705        var $question = $($that.attr('href'));
706        $('.quiz-attempt-single-question').hide();
707        $question.show();
708
709        //Active Class
710        $('.bsel-quiz-question-paginate-item').removeClass('active');
711        $that.addClass('active');
712    });
713
714    /**
715     * Limit Short Answer Question Type
716     */
717    $(document).on('keyup', 'textarea.question_type_short_answer, textarea.question_type_open_ended', function (e) {
718        var $that = $(this);
719        var value = $that.val();
720        var limit = $that.hasClass('question_type_short_answer') ? _bselobject.quiz_options.short_answer_characters_limit : _bselobject.quiz_options.open_ended_answer_characters_limit;
721        var remaining = limit - value.length;
722
723        if (remaining < 1) {
724            $that.val(value.substr(0, limit));
725            remaining = 0;
726        }
727        $that.closest('.bsel-quiz-answers-wrap').find('.characters_remaining').html(remaining);
728    });
729
730    /**
731     *
732     * @type {jQuery}
733     *
734     * Improved Quiz draggable answers drop accessibility
735     * Answers draggable wrap will be now same height.
736     *
737     * @since v.1.4.4
738     */
739    var countDraggableAnswers = $('.quiz-draggable-rand-answers').length;
740    if (countDraggableAnswers) {
741        $('.quiz-draggable-rand-answers').each(function () {
742            var $that = $(this);
743            var draggableDivHeight = $that.height();
744
745            $that.css({ "height": draggableDivHeight });
746        });
747    }
748
749
750    /**
751     * Quiz Validation Helper
752     *
753     * @since v.1.6.1
754     */
755
756    function bsel_quiz_validation($question_wrap) {
757        var validated = true;
758
759        var $required_answer_wrap = $question_wrap.find('.quiz-answer-required');
760
761        if ($required_answer_wrap.length) {
762            /**
763             * Radio field validation
764             *
765             * @type {jQuery}
766             *
767             * @since v.1.6.1
768             */
769            var $inputs = $required_answer_wrap.find('input');
770            if ($inputs.length) {
771                var $type = $inputs.attr('type');
772                if ($type === 'radio') {
773                    if ($required_answer_wrap.find('input[type="radio"]:checked').length == 0) {
774                        $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">答えを選んでください</p>');
775                        validated = false;
776                    }
777                } else if ($type === 'checkbox') {
778                    if ($required_answer_wrap.find('input[type="checkbox"]:checked').length == 0) {
779                        $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">答えを1つ以上選択してください</p>');
780                        validated = false;
781                    }
782                } else if ($type === 'text') {
783                    //Fill in the gaps if many, validation all
784                    $inputs.each(function (index, input) {
785                        if (!$(input).val().trim().length) {
786                            $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">この質問に対する回答が必要です。</p>');
787                            validated = false;
788                        }
789                    });
790                }
791
792            }
793            if ($required_answer_wrap.find('textarea').length) {
794                if ($required_answer_wrap.find('textarea').val().trim().length < 1) {
795                    $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">この質問に対する答えが必要です</p>');
796                    validated = false;
797                }
798            }
799
800            /**
801             * Matching Question
802             */
803            var $matchingDropable = $required_answer_wrap.find('.quiz-answer-matching-droppable');
804            if ($matchingDropable.length) {
805
806                $matchingDropable.each(function (index, matching) {
807                    if (!$(matching).find('.quiz-draggable-answer-item').length) {
808                        $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">すべての項目を一致させてください</p>');
809                        validated = false;
810                    }
811                });
812            }
813        }
814
815        return validated;
816    }
817
818    function feedback_response($question_wrap) {
819        var goNext = false;
820
821
822        var feedBackMode = $question_wrap.attr('data-quiz-feedback-mode');
823        $('.wrong-right-text').remove();
824        $('.quiz-answer-input-bottom').removeClass('wrong-answer right-answer');
825
826        var validatedTrue = true;
827        var $inputs = $question_wrap.find('input');
828        var $checkedInputs = $question_wrap.find('input[type="radio"]:checked, input[type="checkbox"]:checked');
829
830        if (feedBackMode === 'retry') {
831            $checkedInputs.each(function () {
832                var $input = $(this);
833
834                var $type = $input.attr('type');
835                if ($type === 'radio' || $type === 'checkbox') {
836                    var isTrue = $input.attr('data-is-correct') == '1';
837                    if ( !isTrue) {
838                        if ($input.prop("checked")) {
839                            $input.closest('.quiz-answer-input-bottom').addClass('wrong-answer').append('<span class="wrong-right-text"><i class="bsel-icon-line-cross"></i> 正しくありません。もう一度お試しください</span>');
840                        }
841                        validatedTrue = false;
842                    }
843                }
844            });
845
846            $inputs.each(function () {
847                var $input = $(this);
848                var $type = $input.attr('type');
849                if ($type === 'checkbox') {
850                    var isTrue = $input.attr('data-is-correct') == '1';
851                    var checked = $input.is(':checked');
852                
853                    if (isTrue && !checked) {
854                        $question_wrap.find('.answer-help-block').html('<p style="color: #dc3545">この質問に対する詳細な回答が必要です。</p>');
855                        validatedTrue = false;
856                    }
857                }
858            });
859
860        } else if (feedBackMode === 'reveal') {
861            $checkedInputs.each(function () {
862                var $input = $(this);
863                var isTrue = $input.attr('data-is-correct') == '1';
864                if (!isTrue) {
865                    validatedTrue = false;
866                }
867            });
868
869            $inputs.each(function () {
870                var $input = $(this);
871
872                var $type = $input.attr('type');
873                if ($type === 'radio' || $type === 'checkbox') {
874                    var isTrue = $input.attr('data-is-correct') == '1';
875                    var checked = $input.is(':checked');
876
877                    if (isTrue) {
878                        $input.closest('.quiz-answer-input-bottom').addClass('right-answer').append('<span class="wrong-right-text"><i class="bsel-icon-checkbox-pen-outline"></i> 正解です</span>');
879                    } else {
880                        if ($input.prop("checked")) {
881                            $input.closest('.quiz-answer-input-bottom').addClass('wrong-answer');
882                        }
883                    }
884
885                    if (isTrue && !checked) {
886                        validatedTrue = false;
887                    }
888                }
889            });
890        }
891        
892        if (validatedTrue) {
893            goNext = true;
894        }
895
896        return goNext;
897    }
898
899
900    /**
901     * Add to cart in guest mode, show login form
902     *
903     * @since v.1.0.4
904     */
905
906    $(document).on('submit click', '.cart-required-login, .cart-required-login a, .cart-required-login form', function (e) {
907        e.preventDefault();
908
909        var login_url = $(this).data('login_page_url');
910        login_url ? window.location.assign(login_url) : $('.bsel-cart-box-login-form').fadeIn(100);
911    });
912
913    $('.bsel-popup-form-close, .login-overlay-close').on('click', function () {
914        $('.bsel-cart-box-login-form').fadeOut(100);
915    });
916
917    $(document).on('keyup', function (e) {
918        if (e.keyCode === 27) {
919            $('.bsel-frontend-modal').hide();
920            $('.bsel-cart-box-login-form').fadeOut(100);
921        }
922    });
923    /**
924     * Share Link enable
925     *
926     * @since v.1.0.4
927     */
928    if ($.fn.ShareLink) {
929        var $social_share_wrap = $('.bsel-social-share-wrap');
930        if ($social_share_wrap.length) {
931            var share_config = JSON.parse($social_share_wrap.attr('data-social-share-config'));
932
933            $('.bsel_share').ShareLink({
934                title: share_config.title,
935                text: share_config.text,
936                image: share_config.image,
937                class_prefix: 's_',
938                width: 640,
939                height: 480,
940            });
941        }
942    }
943
944    /**
945     * Datepicker initiate
946     *
947     * @since v.1.1.2
948     */
949    if (jQuery.datepicker) {
950        $(".bsel_report_datepicker").datepicker({ "dateFormat": 'yy-mm-dd' });
951    }
952
953
954    /**
955     * Withdraw Form Tab/Toggle
956     *
957     * @since v.1.1.2
958     */
959
960    $(".withdraw-method-select-input").on('change', function (e) {
961        var $that = $(this);
962        $('.withdraw-method-form').hide();
963        $('#withdraw-method-form-' + $that.closest('.withdraw-method-select').attr('data-withdraw-method')).show();
964    });
965
966    $('.withdraw-method-select-input').each(function () {
967        var $that = $(this);
968        if ($that.is(":checked")) {
969            $('.withdraw-method-form').hide();
970            $('#withdraw-method-form-' + $that.closest('.withdraw-method-select').attr('data-withdraw-method')).show();
971        }
972    });
973
974
975
976    /**
977     * Setting account for withdraw earning
978     *
979     * @since v.1.2.0
980     */
981    $(document).on('submit', '#bsel-withdraw-account-set-form', function (e) {
982        e.preventDefault();
983
984        var $form = $(this);
985        var $btn = $form.find('.bsel_set_withdraw_account_btn');
986        var data = $form.serializeObject();
987
988        $.ajax({
989            url: _bselobject.ajaxurl,
990            type: 'POST',
991            data: data,
992            beforeSend: function () {
993                $form.find('.bsel-success-msg').remove();
994                $btn.addClass('updating-icon');
995            },
996            success: function (data) {
997                if (data.success) {
998                    var successMsg = '<div class="bsel-success-msg" style="display: none;"><i class="bsel-icon-mark"></i> ' + data.data.msg + ' </div>';
999                    $btn.closest('.withdraw-account-save-btn-wrap').append(successMsg);
1000                    if ($form.find('.bsel-success-msg').length) {
1001                        $form.find('.bsel-success-msg').slideDown();
1002                    }
1003                    setTimeout(function () {
1004                        $form.find('.bsel-success-msg').slideUp();
1005                    }, 5000)
1006                }
1007            },
1008            complete: function () {
1009                $btn.removeClass('updating-icon');
1010            }
1011        });
1012    });
1013
1014    /**
1015     * Make Withdraw Form
1016     *
1017     * @since v.1.2.0
1018     */
1019
1020    $(document).on('click', 'a.open-withdraw-form-btn, .close-withdraw-form-btn', function (e) {
1021        e.preventDefault();
1022
1023        if($(this).data('reload')=='yes'){
1024            window.location.reload();
1025            return;
1026        }
1027
1028        $('.bsel-earning-withdraw-form-wrap').toggle().find('[name="bsel_withdraw_amount"]').val('');
1029        $('.bsel-withdrawal-pop-up-success').hide().next().show();
1030        $('html, body').css('overflow', ($('.bsel-earning-withdraw-form-wrap').is(':visible') ? 'hidden' : 'auto'));
1031    });
1032
1033    $(document).on('submit', '#bsel-earning-withdraw-form', function (e) {
1034        e.preventDefault();
1035
1036        var $form = $(this);
1037        var $btn = $('#bsel-earning-withdraw-btn');
1038        var $responseDiv = $('.bsel-withdraw-form-response');
1039        var data = $form.serializeObject();
1040
1041        $.ajax({
1042            url: _bselobject.ajaxurl,
1043            type: 'POST',
1044            data: data,
1045            beforeSend: function () {
1046                $form.find('.bsel-success-msg').remove();
1047                $btn.addClass('updating-icon');
1048            },
1049            success: function (data) {
1050                var Msg;
1051                if (data.success) {
1052
1053                    if (data.data.available_balance !== 'undefined') {
1054                        $('.withdraw-balance-col .available_balance').html(data.data.available_balance);
1055                    }
1056
1057                    $('.bsel-withdrawal-pop-up-success').show().next().hide();
1058
1059                } else {
1060                    Msg = '<div class="bsel-error-msg inline-image-text is-inline-block">\
1061                            <img src="'+window.bsel_url_base+'assets/images/icon-cross.svg"/> \
1062                            <div>\
1063                                <b>Error</b><br/>\
1064                                <span>'+ data.data.msg + '</span>\
1065                            </div>\
1066                        </div>';
1067
1068                    $responseDiv.html(Msg);
1069                    setTimeout(function () {
1070                        $responseDiv.html('');
1071                    }, 5000)
1072                }
1073            },
1074            complete: function () {
1075                $btn.removeClass('updating-icon');
1076            }
1077        });
1078    });
1079
1080    var frontEndModal = $('.bsel-frontend-modal');
1081    frontEndModal.each(function () {
1082        var modal = $(this),
1083            action = $(this).data('popup-rel');
1084        $('[href="' + action + '"]').on('click', function (e) {
1085            modal.fadeIn();
1086            e.preventDefault();
1087        });
1088    });
1089    $(document).on('click', '.tm-close, .bsel-frontend-modal-overlay, .bsel-modal-btn-cancel', function () {
1090        frontEndModal.fadeOut();
1091    });
1092
1093    /**
1094     * Delete Course
1095     */
1096    $(document).on('click', '.bsel-dashboard-element-delete-btn', function (e) {
1097        e.preventDefault();
1098        var element_id = $(this).attr('data-id');
1099        $('#bsel-dashboard-delete-element-id').val(element_id);
1100    });
1101    $(document).on('submit', '#bsel-dashboard-delete-element-form', function (e) {
1102        e.preventDefault();
1103
1104        var element_id = $('#bsel-dashboard-delete-element-id').val();
1105        var $btn = $('.bsel-modal-element-delete-btn');
1106        var data = $(this).serializeObject();
1107
1108        $.ajax({
1109            url: _bselobject.ajaxurl,
1110            type: 'POST',
1111            data: data,
1112            beforeSend: function () {
1113                $btn.addClass('updating-icon');
1114            },
1115            success: function (res) {
1116                if (res.success) {
1117                    $('#bsel-dashboard-' + res.data.element + '-' + element_id).remove();
1118                }
1119            },
1120            complete: function () {
1121                $btn.removeClass('updating-icon');
1122                $('.bsel-frontend-modal').hide();
1123            }
1124        });
1125    });
1126
1127    /**
1128     * Frontend Profile
1129     */
1130
1131    if (!$('#bsel_profile_photo_id').val()) {
1132        $('.bsel-profile-photo-delete-btn').hide();
1133    }
1134
1135    $(document).on('click', '.bsel-profile-photo-delete-btn', function () {
1136        $('.bsel-profile-photo-upload-wrap').find('img').attr('src', _bselobject.placeholder_img_src);
1137        $('#bsel_profile_photo_id').val('');
1138        $('.bsel-profile-photo-delete-btn').hide();
1139
1140        $.ajax({
1141            url: _bselobject.ajaxurl,
1142            type: 'POST',
1143            data: { 'action': 'bsel_profile_photo_remove' },
1144        });
1145
1146        return false;
1147    });
1148
1149    /**
1150     * Assignment
1151     *
1152     * @since v.1.3.3
1153     */
1154    $(document).on('submit', '#bsel_assignment_start_form', function (e) {
1155        e.preventDefault();
1156
1157        var $that = $(this);
1158        var form_data = $that.serializeObject();
1159        form_data.action = 'bsel_start_assignment';
1160
1161        $.ajax({
1162            url: _bselobject.ajaxurl,
1163            type: 'POST',
1164            data: form_data,
1165            beforeSend: function () {
1166                $('#bsel_assignment_start_btn').addClass('updating-icon');
1167            },
1168            success: function (data) {
1169                if (data.success) {
1170                    location.reload();
1171                }
1172            },
1173            complete: function () {
1174                $('#bsel_assignment_start_btn').removeClass('updating-icon');
1175            }
1176        });
1177    });
1178
1179    /**
1180     * Assignment answer validation
1181     */
1182    $(document).on('submit', '#bsel_assignment_submit_form', function (e) {
1183        var assignment_answer = $('textarea[name="assignment_answer"]').val();
1184        if (assignment_answer.trim().length < 1) {
1185            $('#form_validation_response').html('<div class="bsel-error-msg">' + _bselobject.text.assignment_text_validation_msg + '</div>');
1186            e.preventDefault();
1187        }
1188    });
1189
1190    /**
1191     * Course builder video
1192     * @since v.1.3.4
1193     */
1194
1195
1196    $(document).on('click', '.video_source_upload_wrap_html5 .video_upload_btn', function (event) {
1197        event.preventDefault();
1198
1199        var $that = $(this);
1200        var frame;
1201        // If the media frame already exists, reopen it.
1202        if (frame) {
1203            frame.open();
1204            return;
1205        }
1206        frame = wp.media({
1207            title: 'Select or Upload Media Of Your Chosen Persuasion',
1208            button: {
1209                text: 'Use this media'
1210            },
1211            library: { type: 'video' },
1212            multiple: false  // Set to true to allow multiple files to be selected
1213        });
1214        frame.on('select', function () {
1215            // Get media attachment details from the frame state
1216            var attachment = frame.state().get('selection').first().toJSON();
1217            $that.closest('.video_source_upload_wrap_html5').find('span.video_media_id').text(attachment.id).closest('p').show();
1218            $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id);
1219        });
1220        frame.open();
1221    });
1222
1223
1224    /**
1225     * Course and lesson sorting
1226     */
1227
1228    function enable_sorting_topic_lesson() {
1229        if (jQuery().sortable) {
1230            $(".course-contents").sortable({
1231                handle: ".course-move-handle",
1232                start: function (e, ui) {
1233                    ui.placeholder.css('visibility', 'visible');
1234                },
1235                stop: function (e, ui) {
1236                    bsel_sorting_topics_and_lesson();
1237                },
1238            });
1239            $(".bsel-lessons:not(.drop-lessons)").sortable({
1240                connectWith: ".bsel-lessons",
1241                items: "div.course-content-item",
1242                start: function (e, ui) {
1243                    ui.placeholder.css('visibility', 'visible');
1244                },
1245                stop: function (e, ui) {
1246                    bsel_sorting_topics_and_lesson();
1247                },
1248            });
1249        }
1250    }
1251    enable_sorting_topic_lesson();
1252    function bsel_sorting_topics_and_lesson() {
1253        var topics = {};
1254        $('.bsel-topics-wrap').each(function (index, item) {
1255            var $topic = $(this);
1256            var topics_id = parseInt($topic.attr('id').match(/\d+/)[0], 10);
1257            var lessons = {};
1258
1259            $topic.find('.course-content-item').each(function (lessonIndex, lessonItem) {
1260                var $lesson = $(this);
1261                var lesson_id = parseInt($lesson.attr('id').match(/\d+/)[0], 10);
1262
1263                lessons[lessonIndex] = lesson_id;
1264            });
1265            topics[index] = { 'topic_id': topics_id, 'lesson_ids': lessons };
1266        });
1267        $('#bsel_topics_lessons_sorting').val(JSON.stringify(topics));
1268    }
1269
1270    /**
1271     * Lesson Update or Create Modal
1272     */
1273    $(document).on('click', '.update_lesson_modal_btn', function (event) {
1274        event.preventDefault();
1275
1276        var $that = $(this);
1277        var content;
1278        var editor = tinyMCE.get('bsel_lesson_modal_editor');
1279        if (editor) {
1280            content = editor.getContent();
1281        } else {
1282            content = $('#' + inputid).val();
1283        }
1284
1285        var form_data = $(this).closest('form').serializeObject();
1286        form_data.lesson_content = content;
1287
1288        $.ajax({
1289            url: ajaxurl,
1290            type: 'POST',
1291            data: form_data,
1292            beforeSend: function () {
1293                $that.addClass('bsel-updating-message');
1294            },
1295            success: function (data) {
1296                if (data.success) {
1297                    $('#bsel-course-content-wrap').html(data.data.course_contents);
1298                    enable_sorting_topic_lesson();
1299
1300                    //Close the modal
1301                    $('.bsel-lesson-modal-wrap').removeClass('show');
1302                    
1303                    bsel_toast($that.data('toast_success'), $that.data('toast_success_message'), 'success');
1304                }
1305                else {
1306                    bsel_toast($that.data('toast_error'), $that.data('toast_error_message'), 'error');
1307                }
1308            },
1309            error: function() {
1310                bsel_toast($that.data('toast_error'), $that.data('toast_error_message'), 'error');
1311            },
1312            complete: function () {
1313                $that.removeClass('bsel-updating-message');
1314            }
1315        });
1316    });
1317
1318    /**
1319     * END: Bsel Course builder JS
1320     */
1321
1322    /**
1323     * Attachment in forntend course builder
1324     * @since v.1.3.4
1325     */
1326    $(document).on('click', 'a.bsel-delete-attachment', function (e) {
1327        e.preventDefault();
1328        $(this).closest('.bsel-added-attachment').remove();
1329    });
1330    $(document).on('click', '.bselUploadAttachmentBtn', function (e) {
1331        e.preventDefault();
1332
1333        var $that = $(this);
1334        var frame;
1335        if (frame) {
1336            frame.open();
1337            return;
1338        }
1339        frame = wp.media({
1340            title: 'Select or Upload Media Of Your Chosen Persuasion',
1341            button: {
1342                text: 'Use this media'
1343            },
1344            multiple: true  // Set to true to allow multiple files to be selected
1345        });
1346        frame.on('select', function () {
1347            var attachments = frame.state().get('selection').toJSON();
1348            if (attachments.length) {
1349                for (var i = 0; i < attachments.length; i++) {
1350                    var attachment = attachments[i];
1351
1352                    var inputHtml = '<div class="bsel-added-attachment"><i class="bsel-icon-archive"></i><a href="javascript:;" class="bsel-delete-attachment bsel-icon-line-cross"></a> <span> <a href="' + attachment.url + '">' + attachment.filename + '</a> </span> <input type="hidden" name="bsel_attachments[]" value="' + attachment.id + '"></div>';
1353                    $that.closest('.bsel-lesson-attachments-metabox').find('.bsel-added-attachments-wrap').append(inputHtml);
1354                }
1355            }
1356        });
1357        frame.open();
1358    });
1359
1360
1361    /**
1362     * Single Assignment Upload Button
1363     * @since v.1.3.4
1364     */
1365    $('form').on('change', '.bsel-assignment-file-upload', function () {
1366        $(this).siblings("label").find('span').html($(this).val().replace(/.*(\/|\\)/, ''));
1367    });
1368
1369    /**
1370     * Lesson Sidebar Topic Toggle
1371     * @since v.1.3.4
1372     */
1373
1374    $(document).on('click', '.bsel-topics-in-single-lesson .bsel-topics-title h3, .bsel-single-lesson-topic-toggle', function (e) {
1375        var $that = $(this);
1376        var $parent = $that.closest('.bsel-topics-in-single-lesson');
1377        $parent.toggleClass('bsel-topic-active');
1378        $parent.find('.bsel-lessons-under-topic').slideToggle();
1379    });
1380
1381    $('.bsel-single-lesson-items.active').closest('.bsel-lessons-under-topic').show();
1382    $('.bsel-single-lesson-items.active').closest('.bsel-topics-in-single-lesson').addClass('bsel-topic-active');
1383    $('.bsel-course-lesson.active').closest('.bsel-lessons-under-topic').show();
1384
1385
1386    /**
1387     * Assignments Addons
1388     * @backend Support
1389     *
1390     */
1391
1392
1393    /**
1394     * Bsel Assignments JS
1395     * @since v.1.3.3
1396     */
1397    $(document).on('click', '.bsel-create-assignments-btn', function (e) {
1398        e.preventDefault();
1399
1400        var $that = $(this);
1401        var topic_id = $(this).attr('data-topic-id');
1402        var course_id = $('#post_ID').val();
1403
1404        $.ajax({
1405            url: ajaxurl,
1406            type: 'POST',
1407            data: { topic_id: topic_id, course_id: course_id, action: 'bsel_load_assignments_builder_modal' },
1408            beforeSend: function () {
1409                $that.addClass('bsel-updating-message');
1410            },
1411            success: function (data) {
1412                $('.bsel-lesson-modal-wrap .modal-container').html(data.data.output);
1413                $('.bsel-lesson-modal-wrap').attr('data-topic-id', topic_id).addClass('show');
1414
1415                $(document).trigger('assignment_modal_loaded', { topic_id: topic_id, course_id: course_id });
1416
1417                tinymce.init(tinyMCEPreInit.mceInit.course_description);
1418                tinymce.execCommand('mceRemoveEditor', false, 'bsel_assignments_modal_editor');
1419                tinyMCE.execCommand('mceAddEditor', false, "bsel_assignments_modal_editor");
1420            },
1421            complete: function () {
1422                quicktags({ id: "bsel_assignments_modal_editor" });
1423                $that.removeClass('bsel-updating-message');
1424            }
1425        });
1426    });
1427
1428    $(document).on('click', '.open-bsel-assignment-modal', function (e) {
1429        e.preventDefault();
1430
1431        var $that = $(this);
1432        var assignment_id = $that.attr('data-assignment-id');
1433        var topic_id = $that.attr('data-topic-id');
1434        var course_id = $('#post_ID').val();
1435
1436        $.ajax({
1437            url: ajaxurl,
1438            type: 'POST',
1439            data: { assignment_id: assignment_id, topic_id: topic_id, course_id: course_id, action: 'bsel_load_assignments_builder_modal' },
1440            beforeSend: function () {
1441                $that.addClass('bsel-updating-message');
1442            },
1443            success: function (data) {
1444                $('.bsel-lesson-modal-wrap .modal-container').html(data.data.output);
1445                $('.bsel-lesson-modal-wrap').attr({ 'data-assignment-id': assignment_id, 'data-topic-id': topic_id }).addClass('show');
1446
1447                $(document).trigger('assignment_modal_loaded', { assignment_id: assignment_id, topic_id: topic_id, course_id: course_id });
1448
1449                tinymce.init(tinyMCEPreInit.mceInit.course_description);
1450                tinymce.execCommand('mceRemoveEditor', false, 'bsel_assignments_modal_editor');
1451                tinyMCE.execCommand('mceAddEditor', false, "bsel_assignments_modal_editor");
1452            },
1453            complete: function () {
1454                quicktags({ id: "bsel_assignments_modal_editor" });
1455                $that.removeClass('bsel-updating-message');
1456            }
1457        });
1458    });
1459
1460    /**
1461     * Update Assignment Data
1462     */
1463    $(document).on('click', '.update_assignment_modal_btn', function (event) {
1464        event.preventDefault();
1465
1466        var $that = $(this);
1467        var content;
1468        var editor = tinyMCE.get('bsel_assignments_modal_editor');
1469        if (editor) {
1470            content = editor.getContent();
1471        } else {
1472            content = $('#' + inputid).val();
1473        }
1474
1475        var form_data = $(this).closest('form').serializeObject();
1476        form_data.assignment_content = content;
1477        
1478        $.ajax({
1479            url: ajaxurl,
1480            type: 'POST',
1481            data: form_data,
1482            beforeSend: function () {
1483                $that.addClass('bsel-updating-message');
1484            },
1485            success: function (data) {
1486                if (data.success) {
1487                    $('#bsel-course-content-wrap').html(data.data.course_contents);
1488                    enable_sorting_topic_lesson();
1489
1490                    //Close the modal
1491                    $('.bsel-lesson-modal-wrap').removeClass('show');
1492
1493                    bsel_toast($that.data('toast_success'), $that.data('toast_success_message'), 'success');
1494                }
1495                else {
1496                    bsel_toast($that.data('toast_error'), $that.data('toast_error_message'), 'error');
1497                }
1498            },
1499            error: function() {
1500                bsel_toast($that.data('toast_error'), $that.data('toast_error_message'), 'error');
1501            },
1502            complete: function () {
1503                $that.removeClass('bsel-updating-message');
1504            }
1505        });
1506    });
1507
1508    /**
1509     * Add Assignment
1510     */
1511    $(document).on('click', '.add-assignment-attachments', function (event) {
1512        event.preventDefault();
1513
1514        var $that = $(this);
1515        var frame;
1516        // If the media frame already exists, reopen it.
1517   
1517     if (frame) {
1518            frame.open();
1519            return;
1520        }
1521
1522        // Create a new media frame
1523        frame = wp.media({
1524            title: 'Select or Upload Media Of Your Chosen Persuasion',
1525            button: {
1526                text: 'Use this media'
1527            },
1528            multiple: false  // Set to true to allow multiple files to be selected
1529        });
1530
1531        // When an image is selected in the media frame...
1532        frame.on('select', function () {
1533            // Get media attachment details from the frame state
1534            var attachment = frame.state().get('selection').first().toJSON();
1535
1536            var field_markup = '<div class="bsel-individual-attachment-file"><p class="attachment-file-name">' + attachment.filename + '</p><input type="hidden" name="bsel_assignment_attachments[]" value="' + attachment.id + '"><a href="javascript:;" class="remove-assignment-attachment-a text-muted"> &times; Remove</a></div>';
1537
1538            $('#assignment-attached-file').append(field_markup);
1539            $that.closest('.video_source_upload_wrap_html5').find('input').val(attachment.id);
1540        });
1541        // Finally, open the modal on click
1542        frame.open();
1543    });
1544
1545    $(document).on('click', '.remove-assignment-attachment-a', function (event) {
1546        event.preventDefault();
1547        $(this).closest('.bsel-individual-attachment-file').remove();
1548    });
1549
1550
1551    /**
1552     *
1553     * @type {jQuery}
1554     *
1555     * Course builder auto draft save
1556     *
1557     * @since v.1.3.4
1558     */
1559    var bsel_course_builder = $('input[name="bsel_action"]').val();
1560    if (bsel_course_builder === 'bsel_add_course_builder') {
1561        setInterval(auto_draft_save_course_builder, 30000);
1562    }
1563
1564    function auto_draft_save_course_builder() {
1565        
1566        var form_data = $('form#bsel-frontend-course-builder').serializeObject();
1567        form_data.bsel_ajax_action = 'bsel_course_builder_draft_save';
1568
1569        $.ajax({
1570            //url : _bselobject.ajaxurl,
1571            type: 'POST',
1572            data: form_data,
1573            beforeSend: function () {
1574                $('.bsel-dashboard-builder-draft-btn span').text('保存中...');
1575            },
1576            success: function (data) {
1577
1578            },
1579            complete: function () {
1580                $('.bsel-dashboard-builder-draft-btn span').text('保存');
1581            }
1582        });
1583    }
1584
1585    /**
1586     *
1587     * @type {jQuery}
1588     *
1589     * Course builder section toggle
1590     *
1591     * @since v.1.3.5
1592     */
1593
1594    $('.bsel-course-builder-section-title').on('click', function () {
1595        if ($(this).find('i').hasClass("bsel-icon-up")) {
1596            $(this).find('i').removeClass('bsel-icon-up').addClass('bsel-icon-down');
1597        } else {
1598            $(this).find('i').removeClass('bsel-icon-down').addClass('bsel-icon-up');
1599        }
1600        $(this).next('div').slideToggle();
1601    });
1602
1603    /**
1604     * Open Bsel Modal to edit review
1605     * @since v.1.4.0
1606     */
1607    $(document).on('click', '.open-bsel-edit-review-modal', function (e) {
1608        e.preventDefault();
1609
1610        var $that = $(this);
1611        var review_id = $that.attr('data-review-id');
1612
1613        var nonce_key = _bselobject.nonce_key;
1614
1615        var json_data = { review_id: review_id, action: 'bsel_load_edit_review_modal' };
1616        json_data[nonce_key] = _bselobject[nonce_key];
1617
1618        $.ajax({
1619            url: _bselobject.ajaxurl,
1620            type: 'POST',
1621            data: json_data,
1622            beforeSend: function () {
1623                $that.addClass('bsel-updating-message');
1624            },
1625            success: function (data) {
1626                if (typeof data.data !== 'undefined') {
1627                    $('.bsel-edit-review-modal-wrap .modal-container').html(data.data.output);
1628                    $('.bsel-edit-review-modal-wrap').attr('data-review-id', review_id).addClass('show');
1629                }
1630            },
1631            complete: function () {
1632                $that.removeClass('bsel-updating-message');
1633            }
1634        });
1635    });
1636
1637    /**
1638     * Update the rating
1639     * @since v.1.4.0
1640     */
1641    $(document).on('submit', '#bsel_update_review_form', function (e) {
1642        e.preventDefault();
1643
1644        var $that = $(this);
1645        var review_id = $that.closest('.bsel-edit-review-modal-wrap ').attr('data-review-id');
1646
1647        var nonce_key = _bselobject.nonce_key;
1648
1649        var rating = $that.find('input[name="bsel_rating_gen_input"]').val();
1650        var review = $that.find('textarea[name="review"]').val();
1651        review = review.trim();
1652
1653        var json_data = { review_id: review_id, rating: rating, review: review, action: 'bsel_update_review_modal' };
1654        json_data[nonce_key] = _bselobject[nonce_key];
1655
1656        $.ajax({
1657            url: _bselobject.ajaxurl,
1658            type: 'POST',
1659            data: json_data,
1660            beforeSend: function () {
1661                $that.find('button[type="submit"]').addClass('bsel-updating-message');
1662            },
1663            success: function (data) {
1664                if (data.success) {
1665                    //Close the modal
1666                    $('.bsel-edit-review-modal-wrap').removeClass('show');
1667                    location.reload(true);
1668                }
1669            },
1670            complete: function () {
1671                $that.find('button[type="submit"]').removeClass('bsel-updating-message');
1672            }
1673        });
1674    });
1675
1676    /**
1677     * Profile photo upload
1678     * @since v.1.4.5
1679     */
1680
1681    $(document).on('click', '#bsel_profile_photo_button', function (e) {
1682        e.preventDefault();
1683
1684        $('#bsel_profile_photo_file').trigger('click');
1685    });
1686
1687    $(document).on('change', '#bsel_profile_photo_file', function (event) {
1688        event.preventDefault();
1689
1690        var $file = this;
1691        if ($file.files && $file.files[0]) {
1692            var reader = new FileReader();
1693            reader.onload = function (e) {
1694                $('.bsel-profile-photo-upload-wrap').find('img').attr('src', e.target.result);
1695            }
1696            reader.readAsDataURL($file.files[0]);
1697        }
1698    });
1699
1700    /**
1701     * Addon, Bsel BuddyPress
1702     * Retrieve MetaInformation on BuddyPress message system
1703     * @for BseL
1704     * @since v.1.4.8
1705     */
1706
1707    $(document).on('click', '.thread-content .subject', function (e) {
1708        var $btn = $(this);
1709
1710        var thread_id = parseInt($btn.closest('.thread-content').attr('data-thread-id'));
1711
1712        var nonce_key = _bselobject.nonce_key;
1713        var json_data = { thread_id: thread_id, action: 'bsel_bp_retrieve_user_records_for_thread' };
1714        json_data[nonce_key] = _bselobject[nonce_key];
1715
1716        $.ajax({
1717            type: 'POST',
1718            url: ajaxurl,
1719            data: json_data,
1720            beforeSend: function () {
1721                $('#bsel-bp-thread-wrap').html('');
1722            },
1723            success: function (data) {
1724                if (data.success) {
1725                    $('#bsel-bp-thread-wrap').html(data.data.thread_head_html);
1726                    bsel_bp_setting_enrolled_courses_list();
1727                }
1728            }
1729        });
1730
1731    });
1732
1733
1734    function bsel_bp_setting_enrolled_courses_list() {
1735        $('ul.bsel-bp-enrolled-course-list').each(function () {
1736            var $that = $(this);
1737            var $li = $that.find(' > li');
1738            var itemShow = 3;
1739
1740            if ($li.length > itemShow) {
1741                var plusCourseCount = $li.length - itemShow;
1742                $li.each(function (liIndex, liItem) {
1743                    var $liItem = $(this);
1744
1745                    if (liIndex >= itemShow) {
1746                        $liItem.hide();
1747                    }
1748                });
1749
1750                var infoHtml = '<a href="javascript:;" class="bsel_bp_plus_courses"><strong>+' + plusCourseCount + ' More </strong></a> Courses';
1751                $that.closest('.bsel-bp-enrolled-courses-wrap').find('.thread-participant-enrolled-info').html(infoHtml);
1752            }
1753
1754            $that.show();
1755        });
1756    }
1757    bsel_bp_setting_enrolled_courses_list();
1758
1759    $(document).on('click', 'a.bsel_bp_plus_courses', function (e) {
1760        e.preventDefault();
1761
1762        var $btn = $(this);
1763        $btn.closest('.bsel-bp-enrolled-courses-wrap').find('.bsel-bp-enrolled-course-list li').show();
1764        $btn.closest('.thread-participant-enrolled-info').html('');
1765    });
1766
1767
1768    /**
1769     * Addon, Bsel Certificate
1770     * Certificate dropdown content and copy link
1771     * @for BseL
1772     * @since v.1.5.1
1773     */
1774    //$(document).on('click', '.bsel-dropbtn', function (e) {
1775    $('.bsel-dropbtn').click(function(){
1776       
1777        var $content = $(this).parent().find(".bsel-dropdown-content");
1778        $content.slideToggle(100);
1779    })
1780
1781
1782    //$(document).on('click', '.bsel-copy-link', function (e) {
1783    $('.bsel-copy-link').click(function (e) {
1784        var $btn = $(this);
1785        var copy = '<i class="bsel-icon-copy"></i> Copy Link';
1786        var copied = '<i class="bsel-icon-mark"></i> Copied';
1787        var dummy = document.createElement('input'),
1788            text = window.location.href;
1789        document.body.appendChild(dummy);
1790        dummy.value = text;
1791        dummy.select();
1792        document.execCommand('copy');
1793        document.body.removeChild(dummy);
1794        $btn.html(copied);
1795        setTimeout(function () {
1796            $btn.html(copy);
1797        }, 2500);
1798    });
1799    
1800    $(document).on('click', function (e) {
1801        var container = $(".bsel-dropdown");
1802        var $content = container.find('.bsel-dropdown-content');
1803        // if the target of the click isn't the container nor a descendant of the container
1804        if (!container.is(e.target) && container.has(e.target).length === 0) {
1805            $content.slideUp(100);
1806        }
1807    });
1808
1809
1810    /**
1811     * Bsel ajax login
1812     *
1813     * @since v.1.6.3
1814     */
1815    $(document).on('submit', '.bsel-login-form-wrap #loginform', function (e) {
1816        e.preventDefault();
1817        
1818        var $that = $(this);
1819        var $form_wrapper = $('.bsel-login-form-wrap');
1820
1821        var form_data = $that.serializeObject();
1822        form_data.action = 'bsel_user_login';
1823        
1824        $.ajax({
1825            url: _bselobject.ajaxurl,
1826            type: 'POST',
1827            data: form_data,
1828            success: function (response) {
1829                if (response.success) {
1830                    location.assign(response.data.redirect);
1831                    location.reload();
1832                } else {
1833                    if ($form_wrapper.find('.bsel-alert').length) {
1834                        $form_wrapper.find('.bsel-alert').html(response.data);
1835                    } else {
1836                        $form_wrapper.prepend('<div class="bsel-alert bsel-alert-warning">' + response.data + '</div>');
1837                    }
1838                }
1839            },
1840        });
1841    });
1842
1843    /**
1844     * Show hide is course public checkbox (frontend dashboard editor)
1845     * 
1846     * @since  v.1.7.2
1847    */
1848    var price_type = $('.bsel-frontend-builder-course-price [name="bsel_course_price_type"]');
1849    if(price_type.length==0){
1850        $('#_bsel_is_course_public_meta_checkbox').show();
1851    }
1852    else{
1853        price_type.change(function(){
1854            if($(this).prop('checked')){
1855                var method = $(this).val()=='paid' ? 'hide' : 'show';
1856                $('#_bsel_is_course_public_meta_checkbox')[method]();
1857            }
1858        }).trigger('change');
1859    }
1860    
1861    /**
1862     * Withdrawal page tooltip
1863     * 
1864     * @since  v.1.7.4
1865    */
1866    // Fully accessible tooltip jQuery plugin with delegation.
1867    // Ideal for view containers that may re-render content.
1868    (function ($) {
1869        $.fn.bsel_tooltip = function () {
1870        this
1871    
1872        // Delegate to tooltip, Hide if tooltip receives mouse or is clicked (tooltip may 
1872stick if parent has focus)
1873            .on('mouseenter click', '.tooltip', function (e) {
1874            e.stopPropagation();
1875            $(this).removeClass('isVisible');
1876            })
1877            // Delegate to parent of tooltip, Show tooltip if parent receives mouse or focus
1878            .on('mouseenter focus', ':has(>.tooltip)', function (e) {
1879            if (!$(this).prop('disabled')) { // IE 8 fix to prevent tooltip on `disabled` elements
1880                $(this)
1881                .find('.tooltip')
1882                .addClass('isVisible');
1883            }
1884            })
1885            // Delegate to parent of tooltip, Hide tooltip if parent loses mouse or focus
1886            .on('mouseleave blur keydown', ':has(>.tooltip)', function (e) {
1887            if (e.type === 'keydown') {
1888                if(e.which === 27) {
1889                $(this)
1890                    .find('.tooltip')
1891                    .removeClass('isVisible');
1892                }
1893            } else {
1894                $(this)
1895                .find('.tooltip')
1896                .removeClass('isVisible');
1897            }
1898            });
1899        return this;
1900        };
1901    }(jQuery));
1902    
1903    // Bind event listener to container element
1904    jQuery('.bsel-tooltip-inside').bsel_tooltip();
1905    
1906
1907    
1908    /**
1909     * Manage course filter
1910     * 
1911     * @since  v.1.7.2
1912    */
1913    var filter_criteria = {action:'bsel_course_filter_ajax'};
1914    var filter_container = $('.bsel-course-filter-container');
1915    var loop_container = $('.bsel-course-filter-loop-container');
1916    var toggle_criteria = function(name, value, is_checked){
1917
1918        if(is_checked===undefined){
1919            
1920            if(!value){
1921                delete filter_criteria[name];
1922            }
1923            else{
1924                filter_criteria[name]=value;
1925            }
1926        }
1927        else{
1928            !filter_criteria[name] ? filter_criteria[name]=[] : 0;
1929            var index = filter_criteria[name].indexOf(value);
1930
1931            if(is_checked){
1932                index==-1 ? filter_criteria[name].push(value) : 0;
1933            }
1934            else{
1935                filter_criteria[name].splice(index, 1);
1936            }
1937        }
1938        
1939        push_state();
1940    }
1941
1942    var push_state=function(){
1943        var exclude = ['column_per_row', 'course_per_page'];
1944        
1945        var str = Object.keys(filter_criteria).map(function(key){
1946            var val = filter_criteria[key];
1947            var str = Array.isArray(val) ? val.join(',') : val;
1948
1949            return (key=='action' || !str || exclude.indexOf(key)>-1) ? null : key+'='+str;
1950
1951        }).filter(q=>q!==null).join('&');
1952        
1953        window.history.replaceState({'id':'bsel_courses'}, 'Courses', (str ? '?'+str : ''));
1954    }
1955
1956    // Sidebar checkbox value change
1957    filter_container.find('[type=checkbox]').change(function(e){
1958        /**
1959         * check if checkbox is checked
1960         */
1961        var is_checked = filter_container.find('[type=checkbox]').is(":checked");
1962        is_checked ? $(".bsel-clear-all-filter").show() : $(".bsel-clear-all-filter").hide();
1963
1964        e.originalEvent ? toggle_criteria($(this).attr('name'), $(this).val(), $(this).prop('checked')) : 0;
1965        filter_criteria.column_per_row = loop_container.data('column_per_row');
1966        filter_criteria.course_per_page = loop_container.data('course_per_page');
1967        filter_criteria.course_shortcode = loop_container.data('course_shortcode');
1968        loop_container.html('<div style="text-align:center"><img src="'+window.bsel_loading_icon_url+'"/></div>').show();
1969
1970        $.ajax({
1971            url:window._bselobject.ajaxurl+(filter_criteria.page ? '?paged='+filter_criteria.page : ''),
1972            type:'POST',
1973            data:filter_criteria,
1974            success:function(r){
1975                loop_container.html(r).find('.bsel-pagination-wrap a').each(function(){
1976                    $(this).attr('data-href', $(this).attr('href')).attr('href', '#');
1977                });
1978                $('select:not(.none-select2)').select2({
1979                    width: '100%'
1980                });
1981            },
1982            error:function(){
1983                alert('Request Failed!');
1984            }
1985        })
1986    });
1987
1988    // Search field 
1989    var time_out;
1990    filter_container.on('input', '[name="bsel-course-filter-keyword"]', function(){
1991        window.clearTimeout(time_out);
1992
1993        var value = $(this).val();
1994        value = value.trim();
1995
1996        time_out=window.setTimeout(function(){
1997            
1998            toggle_criteria('keyword', value);
1999
2000            filter_container.find('[type="checkbox"]:first').trigger('change');
2001        }, 500);
2002    });
2003
2004    // Alter pagination
2005    loop_container.on('click', '.bsel-pagination-wrap a', function(e){
2006        var url = $(this).data('href') || $(this).attr('href');
2007
2008        if(url){
2009            url = new URL(url);
2010            var page = url.searchParams.get("paged");
2011
2012            if(page){
2013                e.preventDefault();
2014                toggle_criteria('page', page);
2015                
2016                filter_container.find('[type="checkbox"]:first').trigger('change');
2017            }
2018        }
2019    });
2020
2021    // Alter sort filter
2022    loop_container.on('change', 'select[name="bsel_course_filter"]', function(){
2023        toggle_criteria('bsel_course_filter', $(this).val());
2024        filter_container.find('[type="checkbox"]:first').trigger('change');
2025    });
2026
2027    // Alter category filter
2028    loop_container.on('change', 'select[name="bsel-course-filter-category[]"]', function(){
2029        toggle_criteria('bsel-course-filter-category[]', $(this).val());
2030        filter_container.find('[type="checkbox"]:first').trigger('change');
2031    });
2032
2033    // show type filter
2034    loop_container.on('click', '#bsel_show_list', function(){
2035        toggle_criteria('bsel-course-filter-show-type', 'list');
2036
2037        // $(this).addClass("active");
2038        // $("#bsel_show_blocks").removeClass("active");
2039        
2040        filter_container.find('[type="checkbox"]:first').trigger('change');
2041    });
2042    loop_container.on('click', '#bsel_show_blocks', function(){
2043        toggle_criteria('bsel-course-filter-show-type', 'blocks');
2044
2045        // $(this).addClass("active");
2046        // $("#bsel_show_list").removeClass("active");
2047
2048        filter_container.find('[type="checkbox"]:first').trigger('change');
2049    });
2050
2051    // Parse filter from URL
2052    var url = new URL(window.location.href);
2053    var trigger_load=false;
2054    filter_container.find('[type="checkbox"]').each(function(){
2055        var name = $(this).attr('name');
2056        var value = $(this).val();
2057        var checked = $(this).prop('checked');
2058
2059        var arg = url.searchParams.get(name);
2060        arg = arg ? arg.split(',') : [];
2061        
2062
2063        if(arg.indexOf(value)>-1 || checked){
2064            $(this).prop('checked', true);
2065            toggle_criteria(name, value, true, false);
2066        }
2067    });
2068
2069    ['page', 'keyword', 'bsel_course_filter', 'bsel-course-filter-category[]'].forEach(function(name){
2070        var value = url.searchParams.get(name);
2071
2072        if(value){
2073            toggle_criteria(name, value, undefined, false);
2074            name=='keyword' ? filter_container.find('[name="bsel-course-filter-keyword"]').val(value) : 0;
2075            name=='bsel_course_filter' ? loop_container.find('select[name="bsel_course_filter"]').val(value) : 0;
2076            name=='bsel-course-filter-category[]' ? loop_container.find('select[name="bsel-course-filter-category[]"]').val(value) : 0;
2077            trigger_load=true;
2078        }
2079    });
2080
2081    if(trigger_load || filter_container.find('input:checked').length>0){
2082        filter_container.find('[type="checkbox"]:first').trigger('change');
2083    }
2084    else{
2085        loop_container.show();
2086    }
2087   
2088    // Refresh page after coming back to course archive page from cart
2089    var archive_loop = $('.bsel-course-loop');
2090    if(archive_loop.length>0){
2091        window.sessionStorage.getItem('bsel_refresh_archive')==='yes' ? window.location.reload() : 0;
2092        window.sessionStorage.removeItem('bsel_refresh_archive');
2093        archive_loop.on('click', '.bsel-loop-cart-btn-wrap', function(){
2094            window.sessionStorage.setItem('bsel_refresh_archive', 'yes');
2095        });
2096    }
2097    
2098    /**
2099     * Profile Photo and Cover Photo editor
2100     * 
2101     * @since  v.1.7.5
2102    */
2103    var PhotoEditor=function(photo_editor){
2104
2105        this.dialogue_box = photo_editor.find('#bsel_photo_dialogue_box');
2106
2107        
2108        this.open_dialogue_box = function(name){
2109            this.dialogue_box.attr('name', name);
2110            this.dialogue_box.trigger('click');
2111        }
2112
2113        this.validate_image = function(file){
2114            return true;
2115        }
2116
2117        this.upload_selected_image = function(name, file){
2118            if(!file || !this.validate_image(file)){
2119                return;
2120            }
2121
2122            var nonce = bsel_get_nonce_data(true);
2123
2124            var context = this;
2125            context.toggle_loader(name, true);
2126
2127            // Prepare payload to upload
2128            var form_data = new FormData();
2129            form_data.append('action', 'bsel_user_photo_upload');
2130            form_data.append('photo_type', name);
2131            form_data.append('photo_file', file, file.name);
2132            form_data.append(nonce.key, nonce.value);
2133            
2134            $.ajax({
2135                url:window._bselobject.ajaxurl,
2136                data:form_data,
2137                type:'POST',
2138                processData: false,
2139                contentType: false,
2140                error:context.error_alert,
2141                complete:function(){
2142                    context.toggle_loader(name, false);
2143                }
2144            })
2145        }
2146
2147        this.accept_upload_image=function(context, e){
2148            var file = e.currentTarget.files[0] || null;
2149            context.update_preview(e.currentTarget.name, file);
2150            context.upload_selected_image(e.currentTarget.name, file);
2151            $(e.currentTarget).val('');
2152        }
2153
2154        this.delete_image=function(name){
2155            var context = this;
2156            context.toggle_loader(name, true);
2157            
2158            $.ajax({
2159                url:window._bselobject.ajaxurl,
2160                data:{action:'bsel_user_photo_remove', photo_type:name},
2161                type:'POST',
2162                error:context.error_alert,
2163                complete:function(){
2164                    context.toggle_loader(name, false);
2165                }
2166            });
2167        }
2168
2169        this.update_preview=function(name, file){
2170            var renderer = photo_editor.find(name=='cover_photo' ? '#bsel_cover_area' : '#bsel_profile_area');
2171
2172            if(!file){
2173                renderer.css('background-image', 'url('+renderer.data('fallback')+')');
2174                this.delete_image(name);
2175                return;
2176            }
2177            
2178            var reader = new FileReader();
2179            reader.onload = function(e) {
2180                renderer.css('background-image', 'url('+e.target.result+')');
2181            }
2182            
2183            reader.readAsDataURL(file); 
2184        }
2185
2186        this.toggle_profile_pic_action=function(show){
2187            var method = show===undefined ? 'toggleClass' : (show ? 'addClass' : 'removeClass');
2188            photo_editor[method]('pop-up-opened');
2189        }
2190
2191        this.error_alert=function(){
2192            alert('Something Went Wrong.');
2193        }
2194
2195        this.toggle_loader = function(name, show){
2196            photo_editor.find('#bsel_photo_meta_area .loader-area').css('display', (show ? 'block' : 'none'));
2197        }
2198
2199        this.initialize = function(){
2200            var context = this;
2201
2202            this.dialogue_box.change(function(e){context.accept_upload_image(context, e)});
2203
2204            photo_editor.find('#bsel_profile_area .bsel_overlay, #bsel_pp_option>div:last-child').click(function(){context.toggle_profile_pic_action()});
2205
2206            // Upload new
2207            photo_editor.find('.bsel_cover_uploader').click(function(){context.open_dialogue_box('cover_photo')});
2208            photo_editor.find('.bsel_pp_uploader').click(function(){context.open_dialogue_box('profile_photo')});
2209
2210            // Delete existing
2211            photo_editor.find('.bsel_cover_deleter').click(function(){context.update_preview('cover_photo', null)});
2212            photo_editor.find('.bsel_pp_deleter').click(function(){context.update_preview('profile_photo', null)});
2213        }
2214    }
2215
2216    var photo_editor = $('#bsel_profile_cover_photo_editor');
2217    photo_editor.length>0 ? new PhotoEditor(photo_editor).initialize() : 0;
2218
2219
2220    /**
2221     * 
2222     * Instructor list filter
2223     * 
2224     * @since  v.1.8.4
2225    */
2226    // Get values on course category selection
2227    $('.bsel-instructor-filter').each(function() {
2228
2229        var root = $(this);
2230        var filter_args = {}; 
2231        var time_out;
2232
2233        function run_instructor_filter(name, value, page_number) {
2234
2235            // Prepare http payload
2236            var result_container = root.find('.filter-result-container');
2237            var html_cache = result_container.html();
2238            var attributes = root.data();
2239            attributes.current_page = page_number || 1;
2240
2241            name ? filter_args[name] = value : filter_args = {};
2242            filter_args.attributes = attributes;
2243            filter_args.action = 'load_filtered_instructor';
2244            
2245            // Show loading icon
2246            result_container.html('<div style="text-align:center"><img src="'+window.bsel_loading_icon_url+'"/></div>');
2247
2248            $.ajax({
2249                url: window._bselobject.ajaxurl,
2250                data: filter_args,
2251                type: 'POST',
2252                success: function(r) {
2253                    result_container.html(r);
2254                },
2255                error: function() {
2256                    result_container.html(html_cache);
2257                    bsel_toast('Error', 'Request Error', 'error');
2258                }
2259            })
2260        }
2261
2262        root.on('change', '.course-category-filter [type="checkbox"]', function() {
2263
2264            var values = {};
2265
2266            $(this).closest('.course-category-filter').find('input:checked').each(function() {
2267                values[$(this).val()] = $(this).parent().text();
2268            });
2269
2270            // Show selected cat list
2271            var cat_parent = root.find('.selected-cate-list').empty();
2272            var cat_ids = Object.keys(values);
2273
2274            cat_ids.forEach(function(value) {
2275                cat_parent.append('<span>'+values[value]+' <span class="bsel-icon-line-cross" data-cat_id="'+value+'"></span></span>');
2276            });
2277
2278            cat_ids.length ? cat_parent.append('<span data-cat_id="0">Clear All</span>') : 0;
2279
2280            run_instructor_filter($(this).attr('name'), cat_ids);
2281        })
2282        .on('click', '.selected-cate-list [data-cat_id]', function() {
2283
2284            var id = $(this).data('cat_id');
2285            var inputs = root.find('.mobile-filter-popup [type="checkbox"]');
2286            id ? inputs = inputs.filter('[value="'+id+'"]') : 0;
2287            
2288            inputs.prop('checked', false).trigger('change');
2289        })
2290        .on('input', '.filter-pc [name="keyword"]', function() {
2291            // Get values on search keyword change
2292            
2293            var val = $(this).val();
2294
2295            time_out ? window.clearTimeout(time_out) : 0;
2296
2297            time_out = window.setTimeout(function() {
2298
2299                run_instructor_filter('keyword', val);
2300                time_out = null;
2301
2302            }, 500);
2303        })
2304        .on('click', '[data-page_number]', function(e) {
2305
2306            // On pagination click
2307            e.preventDefault();
2308            
2309            run_instructor_filter(null, null, $(this).data( 'page_number' ) );
2310
2311        }).on('click', '.clear-instructor-filter', function() {
2312
2313            // Clear filter
2314            var root = $(this).closest('.bsel-instructor-filter');
2315            
2316            root.find('input[type="checkbox"]').prop('checked', false);
2317
2318            root.find('[name="keyword"]').val('');
2319            
2320            run_instructor_filter();
2321        })
2322        .on('click', '.mobile-filter-container i', function () {
2323            // Open mobile screen filter
2324            $(this).parent().next().addClass('is-opened');
2325        })
2326        .on('click', '.mobile-filter-popup button', function() {
2327            
2328            $('.mobile-filter-popup [type="checkbox"]').trigger('change');
2329            
2330            // Close mobile screen filter
2331            $(this).closest('.mobile-filter-popup').removeClass('is-opened');
2332
2333        }).on('input', '.filter-mobile [name="keyword"]', function() {
2334
2335            // Sync keyword with two screen
2336            
2337            root.find('.filter-pc [name="keyword"]').val($(this).val()).trigger('input');
2338
2339        }).on('change', '.mobile-filter-popup [type="checkbox"]', function(e) {
2340
2341            if(e.originalEvent) {
2342                return;
2343            }
2344
2345            // Sync category with two screen
2346            var name = $(this).attr('name');
2347            var val = $(this).val();
2348            var checked = $(this).prop('checked');
2349
2350            root.find('.course-category-filter [name="'+name+'"]').filter('[value="'+val+'"]').prop('checked', checked).trigger('change');
2351        
2352        }).on('mousedown touchstart', '.expand-instructor-filter', function(e) {
2353            
2354            var window_height = $(window).height();
2355            var el = root.find('.mobile-filter-popup>div');
2356            var el_top = window_height-el.height();
2357            var plus = ((e.originalEvent.touches || [])[0] || e).clientY - el_top;
2358
2359            root.on('mousemove touchmove', function(e){
2360
2361                var y = ((e.originalEvent.touches || [])[0] || e).clientY;
2362
2363                var height = (window_height-y)+plus;
2364                
2365                (height>200 && height<=window_height) ? el.css('height', height+'px') : 0;
2366            });
2367        
2368        }).on('mouseup touchend', function(){
2369
2370            root.off('mousemove touchmove');
2371        })
2372        .on('click', '.mobile-filter-popup>div', function(e) {
2373            e.stopImmediatePropagation();
2374        }).on('click', '.mobile-filter-popup', function(e) {
2375            $(this).removeClass('is-opened');;
2376        });
2377    });
2378});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.