Sh3ll
OdayForums


Server : LiteSpeed
System : Linux premium84.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
User : claqxcrl ( 523)
PHP Version : 8.1.32
Disable Function : NONE
Directory :  /home/claqxcrl/confenda.com/wp-content/plugins/poll-maker/public/js/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //home/claqxcrl/confenda.com/wp-content/plugins/poll-maker/public/js/poll-maker-ays-public.js
(function($) {
    window.FontAwesomeConfig = {
        autoReplaceSvg: false
    }
    window.fbAsyncInit = function() {
        FB.init({
            appId: '1204514392893219',
            xfbml: true,
            version: 'v3.0'
        });
    };
    (function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return;
        js = d.createElement(s);
        js.id = id;
        js.src = '//connect.facebook.net/en_US/sdk.js';
        fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));

    $.fn.serializeFormJSON = function () {
        var o = {},
            a = this.serializeArray();
        $.each(a, function () {
            if (o[this.name]) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    };

    $(document).ready(function() {
        var active = false;
        var emailValivatePattern = /^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+\.\w{2,}$/;
        $(document).on('mouseleave', '.rating-poll .apm-answers', function() {
            if ($(this).find('label:not(.emoji)').length > 0) {
                var allRateLabels = $(this).find('label');
                if (active) {
                    var index = -1;
                    allRateLabels.each(function() {
                        if ($(this).hasClass('active-answer')) {
                            index = allRateLabels.index(this);
                        }
                    });
                    for (var i = 0; i < allRateLabels.length; i++) {
                        if (i > index) {
                            allRateLabels.eq(i).find('i').removeClass('ays_poll_fas').addClass('ays_poll_far');
                        } else {
                            allRateLabels.eq(i).find('i').removeClass('ays_poll_far').addClass('ays_poll_fas');
                        }
                    }
                } else {
                    allRateLabels.each(function() {
                        $(this).find('i').removeClass('ays_poll_fas').addClass('ays_poll_far');
                    });
                }
            }
        });

        $(document).on('click', '.rating-poll label:not(.emoji)', function(){
            $(this).parent().parent().find('label').each(function() {
                $(this).removeClass('active-answer');
            });
            $(this).addClass('active-answer');
            active = true;
        });

        $(document).on('mouseover', '.rating-poll label:not(.emoji)', function(){
            var allRateLabels = $(this).parent().parent().find('label');
            var index = allRateLabels.index(this);
            allRateLabels.each(function() {
                $(this).find('i').removeClass('ays_poll_fas').addClass('ays_poll_far');
            });
            for (var i = 0; i <= index; i++) {
                allRateLabels.eq(i).find('i').removeClass('ays_poll_far').addClass('ays_poll_fas');
            }
        });

        $(document).on('mouseleave', '.rating-poll .apm-answers', function() {
            if ($(this).find('label.emoji').length > 0) {
                var $this = $(this);
                if (active) {
                    var index = -1;
                    $this.find('label.emoji').each(function() {
                        if ($(this).hasClass('active-answer')) {
                            index = $this.find('label.emoji').index(this);
                        }
                    });
                    for (var i = 0; i < $this.find('label.emoji').length; i++) {
                        if (i != index) {
                            $this.find('label.emoji').eq(i).find('i').removeClass('ays_poll_fas').addClass('ays_poll_far');
                        } else {
                            $this.find('label.emoji').eq(i).find('i').removeClass('ays_poll_far').addClass('ays_poll_fas');
                        }
                    }
                } else {
                    $this.find('label.emoji').each(function() {
                        $(this).find('i').removeClass('ays_poll_fas').addClass('ays_poll_far');
                    });
                }
            }
        });

        $(document).on('mouseover', '.rating-poll label.emoji', function() {
            var $this = $(this);
            var thisLabels = $this.parent().parent().find('label.emoji');
            var index = thisLabels.index(this);

            thisLabels.each(function() {
                $(this).find('i').removeClass('ays_poll_fas').addClass('ays_poll_far');
            });
            thisLabels.eq(index).find('i').removeClass('ays_poll_far').addClass('ays_poll_fas');
        });

        $(document).on('click', '.rating-poll label.emoji', function() {
            var thisLabels = $(this).parent().parent().find('label.emoji');
            thisLabels.each(function() {
                $(this).removeClass('active-answer');
            });
            $(this).addClass('active-answer');
            active = true;
        });

        // Voting poll Start
        $(document).on('mouseleave', '.voting-poll .apm-answers', function() {
            var index = -1;
            var labels = $(this).find('label');
            if (active) {
                labels.each(function() {
                    if ($(this).hasClass('active-answer')) {
                        index = labels.index(this);
                    }
                });
                for (var i = 0; i < labels.length; i++) {
                    if (i != index) {
                        labels.eq(i).find('i').removeClass('fas').addClass('far');
                    } else {
                        labels.eq(i).find('i').removeClass('far').addClass('fas');
                    }
                }
            } else {
                labels.each(function() {
                    $(this).find('i').removeClass('fas').addClass('far');
                });
            }
        });

        $(document).on('mouseover', '.voting-poll label', function() {
            var $this = $(this);
            var index = $this.parent().parent().find('label').index(this);
            $this.parent().parent().find('label').each(function() {
                $(this).find('i').removeClass('fas').addClass('far');
            });
            $this.parent().parent().find('label').eq(index).find('i').removeClass('far').addClass('fas');
        });

        $(document).on('click', '.voting-poll label', function() {
            var $this = $(this);
            $this.parent().parent().find('label').each(function() {
                $(this).removeClass('active-answer');
            });
            $(this).addClass('active-answer');
            active = true;
        });

        // $(document).on('mouseleave', '.voting-poll .apm-answers', function() {
        //     var index = -1;
        //     var labels = $(this).find('label');
        //     if (active) {
        //         labels.each(function() {
        //             if ($(this).hasClass('active-answer')) {
        //                 index = labels.index(this);
        //             }
        //         });
        //         for (var i = 0; i < labels.length; i++) {
        //             if (i != index) {
        //                 labels.eq(i).find('i').removeClass('ays_poll_fas').addClass('ays_poll_far')
        //             } else {
        //                 labels.eq(i).find('i').removeClass('ays_poll_far').addClass('ays_poll_fas')
        //             }
        //         }
        //     } else {
        //         labels.each(function() {
        //             $(this).find('i').removeClass('ays_poll_fas').addClass('ays_poll_far');
        //         });
        //     }
        // });
       
        // $(document).on('mouseover', '.voting-poll label', function() {
        //     var $this = $(this);
        //     var index = $this.parent().parent().find('label').index(this);
        //     $this.parent().parent().find('label').each(function(index) {
        //         $(this).find('i').removeClass('fas').addClass('far');
        //     });
        //     $this.parent().parent().find('label').eq(index).find('i').removeClass('ays_poll_far').addClass('ays_poll_fas');
        //     $this.parent().parent().find('label').eq(index).find('i').removeClass('far').addClass('fas');
        // });

        // $(document).on('click', '.voting-poll label', function() {
        //     var $this = $(this);
        //     $this.parent().parent().find('label').each(function() {
        //         $(this).removeClass('active-answer');
        //     });
        //     $(this).addClass('active-answer');
        //     active = true;
        // });
        // Voting poll END

        // Versus poll Start
        $(document).on('mouseover', '.versus-poll label', function() {
            var $this = $(this);
            $this.parent().addClass('hover-answer');
            $this.parent().parent().addClass('apm-no-after').children().not('.hover-answer').addClass('apm-w-0');
        });

        $(document).on('click', '.versus-poll label', function() {
            var $this = $(this);
            // $this.parent().parent().find('label').css({"border": "unset"});
            // $this.css({"border": "1px solid"});
            $this.parent().parent().children().removeClass('active-answer');
            $this.parent().addClass('active-answer');
        });

        $(document).on('mouseleave', '.versus-poll label', function() {
            var $this = $(this);
            $this.parent().parent().removeClass('apm-no-after').children().removeClass('apm-w-0');
            $this.parent().removeClass('hover-answer');
        });
        // Versus poll End

        $(document).on('change', '.apm-choosing' , function(){
            var numberOfChecked = $(this).parent().find("input:checkbox:checked").length;
            var multivote_answer_count = $(this).parent().find("#multivot_answer_count").val();
            var pollMultivoteMinCount = $(this).parent().find("#ays_poll_multivote_min_count").val();
            var numberNotChecked = $(this).parent().find('input:checkbox:not(":checked")');
            var numberAllAnswers = $(this).parents("form").find('input:checkbox').length;
            var voteButton = $(this).parents("form").find("input[name='ays_finish_poll']");
            var otherAnswer = $(this).parent().find('input.ays-poll-new-answer-apply-text');
            var otherAnswerVal = otherAnswer.val();
            if(otherAnswer.length > 0 && otherAnswerVal != ""){
                numberOfChecked++;
            }
            if(numberOfChecked >= multivote_answer_count){
                numberNotChecked.prop( "disabled", true );
            }else{
                numberNotChecked.prop( "disabled", false );
            }
            if(numberAllAnswers < pollMultivoteMinCount){
                pollMultivoteMinCount = numberAllAnswers;
            }
            
            if(pollMultivoteMinCount > numberOfChecked){
                voteButton.css("opacity" , "0.5");
                // voteButton.prop( "disabled", true );
            }
            else{
                voteButton.css("opacity" , "1");
                // voteButton.prop( "disabled", false );
            }
        });

        var allow_multivote_answer = $(document).find('.multivote_answer_on').val();
        $(document).on('change', '#apm_dropdown_answers', function(){
            if(allow_multivote_answer == 'on'){
              var selected = $(this).val();
              var selected_str = selected.toString();
    
              var multivote_answer_count_select = $(this).parents('.apm-answers').find("#multivote_answer_count_select").val();
                if($(this).parents('.apm-answers').find("#apm_dropdown_answers option:selected").length > multivote_answer_count_select){
                    if(selected != null){
                        selected_str =  $(this).parents('.apm-answers').find('.multivote_answer_selected_val').val();
                        selected_arr =  selected_str.split(',');
                        $(this).val(selected_arr).select2();
                    }
                }else{
                    $(this).parents('.apm-answers').find('.multivote_answer_selected_val').val(selected_str);
                }
            }
        });

        $(document).on('input','.apm_range_answer',function(){
            var rangeInpVal = $(this).parents('.ays-poll-main').find('.apm-range>.apm_range_answer').val();
            $(this).parents('.ays-poll-main').find('.apm-range .range_value_span').empty().append(rangeInpVal);
        });

        $('.redirect-after-vote-url').on('click', function(e) {
            var x = $(this).attr('answers-url');
            if (x !== "") {
                var url = $(this).parent().parent().parent().attr('data-url-href', x);
            }
        });

        $('.poll_answers_sound').on('click', function(e) {
            var answers_sound = $(this).parents('.ays-poll-main').find('.ays_poll_ans_sound').get(0);            
            if(answers_sound){
                resetPlaying(answers_sound);
                setTimeout(function(){
                    answers_sound.play();
                }, 10);
            }
        });

        $(document).on('click','.ays-poll-view-more-button', function(e) {
            var $this = $(this);
            var parent = $this.parents('.ays-poll-main ');
            var pollAnswers = parent.find('.apm-answers .apm-choosing');

            pollAnswers.each(function(e) {
                if ($(this).hasClass('ays_poll_display_none')) {
                    $(this).removeClass('ays_poll_display_none');
                }
            });

            $this.parents('.ays-poll-view-more-button-box').addClass('ays_poll_display_none');
        });

        //Users limitations 
        if ($('.apm-redirection').length > 0) {
            $('.apm-redirection').each(function(e) {
                var url = $(this).find('p').attr('data-href');
                var delay = +$(this).find('p').attr('data-delay');
                setTimeout( function() {
                    var interval = setInterval( function() {
                        if (delay > 0) {
                            delay--;
                            $(this).find('p b').text(secsToText(delay));
                        } else {
                            clearInterval(interval);
                            location.href = url;
                        }
                    }, 1000);
                }, 1500);
            })
        }

        function secsToText(sec) {
            /*** get the hours ***/
            var hours = ((sec / 3600) % 24).toFixed(0);
            if (hours > 0) hours = hours < 10 ? '0'+hours : hours;
            else hours = '00';
            /*** get the minutes ***/
            var minutes = ((sec / 60) % 60).toFixed(0);
            if (minutes > 0) minutes = minutes < 10 ? '0'+minutes : minutes;
            else minutes = '00';
            /*** get the seconds ***/
            var seconds = (sec % 60).toFixed(0);
            if (seconds > 0) seconds = seconds < 10 ? '0'+seconds : seconds;
            else seconds = '00';

            return hours+':'+minutes+':'+seconds;
        }

        //AV Countdown date
        $(document).find('.show_timer_countdown').each(function(e){
            // Countdown date
            var countDownEndDate = $(this).data('timer_countdown');
            var this_poll_id = $(this).parents(".ays-poll-main").attr("id");
            var refreshButton = "<input type='button' id='ays_refresh_btn_"+this_poll_id+"' class='btn ays-poll-btn btn-restart' style='text-align:center;' value='"+ poll_maker_ajax_public.refresh +"'>";
            if (countDownEndDate != '' && countDownEndDate != undefined) {
                ays_countdown_datetime(countDownEndDate, this_poll_id);
            }
        });
        
        function ays_countdown_datetime(sec, poll_id) {
            var distance = sec*1000;
            var x_int;

            // Update the count down every 1 second
            x_int = setInterval(function() {
                // Time calculations for days, hours, minutes and seconds
                var days = Math.floor(distance / (1000 * 60 * 60 * 24));
                var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
                var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
                var seconds = Math.floor((distance % (1000 * 60)) / 1000);

                // Output the result in an element with id="demo"
                var text = "";

                if(days > 0){
                    text += days + " ";
                    if(days == 1){
                        text += poll_maker_ajax_public.day + " ";
                    }else{
                        text += poll_maker_ajax_public.days + " ";
                    }
                }

                if(hours > 0){
                    text += hours + " ";
                    if(hours == 1){
                        text += poll_maker_ajax_public.hour + " ";
                    }else{
                        text += poll_maker_ajax_public.hours + " ";
                    }
                }

                if(minutes > 0){
                    text += minutes + " ";
                    if(minutes == 1){
                        text += poll_maker_ajax_public.minute + " ";
                    }else{
                        text += poll_maker_ajax_public.minutes + " ";
                    }
                }

                text += seconds + " " + poll_maker_ajax_public.seconds;

                jQuery(document).find( "#"+ poll_id +" .show_timer_countdown" ).html(text);

                // If the count down is over, write some text
                if (distance > 0) {
                    distance -= 1000;
                }
                if (distance <= 0) {
                    clearInterval(x_int);
                    jQuery(document).find( "#"+ poll_id +" .show_timer_countdown" ).html('');
                }
                if(distance == 0){
                    location.reload();
                }
            }, 1000);
        }

        $(document).on('input', '.ays_animated_xms:not([phone_type_id])', function(){
            $(document).find('.user-form input[name]').each(function () {
                $(this).removeClass('ays_poll_shake');
            });
            $(this).removeClass('ays_red_border');
            $(this).removeClass('ays_green_border');
            if ($(this).attr('type') !== 'hidden' && $(this).attr('name') != 'user-form-apm-email') {
                if($(this).val() == '' && $(this).attr('required')){
                    $(this).addClass('ays_red_border');
                }else{
                    $(this).addClass('ays_green_border');
                }                
            }else if($(this).attr('type') !== 'hidden'){
                if($(this).val() != ''){
                    if (!(emailValivatePattern.test($(this).val()))) {
                        $(this).addClass('ays_red_border');
                    }else{
                        $(this).addClass('ays_green_border');
                    }
                }
            }
        });

        $(document).on('input', '.user-form input[phone_type_id]', function(){            
            if ($(this).attr('type') !== 'hidden') {
                if($(this).val() != ''){
                    if (!(/^[+ 0-9-]+$/.test($(this).val()))) {
                        $(this).addClass('ays_red_border');
                    }else{
                        $(this).addClass('ays_green_border');
                    }
                }
            }
        });

        function resetPlaying(audelems) {
            audelems.pause();
            audelems.currentTime = 0;
        }

        //Aro GLB
        if( typeof pollLangDataTableObj != "undefined"){
            $(document).find('.ays_poll_glb_table').DataTable({
                "language": {
                    "sEmptyTable":     pollLangDataTableObj.sEmptyTable,
                    "sInfo":           pollLangDataTableObj.sInfo,
                    "sInfoEmpty":      pollLangDataTableObj.sInfoEmpty,
                    "sInfoFiltered":   pollLangDataTableObj.sInfoFiltered,
                    "sInfoPostFix":    "",
                    "sInfoThousands":  ",",
                    "sLengthMenu":     pollLangDataTableObj.sLengthMenu,
                    "sLoadingRecords": pollLangDataTableObj.sLoadingRecords,
                    "sProcessing":     pollLangDataTableObj.sProcessing,
                    "sSearch":         pollLangDataTableObj.sSearch,
                    "sUrl":            "",
                    "sZeroRecords":    pollLangDataTableObj.sZeroRecords,
                    "oPaginate": {
                        "sFirst":    pollLangDataTableObj.sFirst,
                        "sLast":     pollLangDataTableObj.sLast,
                        "sNext":     pollLangDataTableObj.sNext,
                        "sPrevious": pollLangDataTableObj.sPrevious,
                    },
                    "oAria": {
                        "sSortAscending":  pollLangDataTableObj.sSortAscending,
                        "sSortDescending": pollLangDataTableObj.sSortDescending
                    }
                } 
            });
        }

        $(document).on( 'click', '.ays_poll_remove_answer', function() {
            var answersCount = $(this).parents('.ays_poll_answers_table').find('.ays_poll_answers_td').length;
            if(answersCount == 2){
                swal.fire({
                    type: 'warning',
                    text: poll_maker_ajax_public.pollMInAnswer
                });
                return false;
            }
            var item = $(this).parents().eq(0);
            $(this).parents('tr').addClass('animated fadeOutLeft');
            setTimeout(function () {
                item.remove();
            }, 400);
        });

        $(document).on( 'click', '.ays_poll_add_answer', function() {
            var html = '';

            html += '<tr class="ays_poll_answers_td">';
                html += '<td>';
                    html += '<input type="text" class="ays_poll_answer ays-poll-request-modal-body-answer-texts" name="ays_poll_answers[]" placeholder="'+ poll_maker_ajax_public.answerText +'">';
                html += '</td>';

                html += '<td class="ays_poll_remove_answer">';
                    html += '<i class="ays_poll_fas ays_poll_fa-times" aria-hidden="true"></i>';
                html += '</td>';
            html += '</tr>';

            var tableTr = $(this).parents('.ays_poll_answers_table').find('tr');
            var childLength = tableTr.length;
            var postPreviousChild = childLength - 2;
            
            tableTr.eq(postPreviousChild).after(html);
            // tableTr.eq(postPreviousChild).find('.ays_poll_answer').select();
        });

        $(document).find('.ays_request_submit_button').on( 'click', function(e) {
            var pollTitle =  $(this).parents('.ays_poll_modal').find('.ays_poll_title');
            if(pollTitle.val() == ''){            
                swal.fire({
                    type: 'error',
                    text: poll_maker_ajax_public.pollTitle
                });
                return false;
            }

            var question =  $(this).parents('.ays_poll_modal').find('.ays_poll_question');
            if(question.val() == ''){            
                swal.fire({
                    type: 'error',
                    text: poll_maker_ajax_public.pollQuestion
                });
                return false;
            }

            var answers = $(this).parents('.ays_poll_modal').find('.ays_poll_answer');
            var emptyAnswers = 0;
            for(var j = 0; j < answers.length; j++){
                if(answers.eq(j).val() == ''){
                    emptyAnswers++;
                    break;
                }
            }
            if(emptyAnswers > 0){
                swal.fire({
                    type: 'error',
                    text: poll_maker_ajax_public.pollAnswer
                });
                return false;
            }
        });

        $(document).find("form[id='ays_poll_request_form']").submit(function() {
            $(this).submit(function() {
                return false;
            });
            return true;
        });
        
        $(document).find('#apm_dropdown_answers').select2({
            minimumResultsForSearch: -1
        });

        // ==== ADDED NEW ====

        // Answer Sound Muter
        $(document).on('click', '.ays_music_sound', function() {
            var $this = $(this);
            var pollCoutainer = $this.parents('.ays-poll-main');
            var audioEl = pollCoutainer.find('.ays_poll_ans_sound').get(0);
            if($this.hasClass('ays_sound_active')){
                audioEl.volume = 0;
                $this.find('.ays_poll_far').addClass('ays_poll_fa-volume_off').removeClass('ays_poll_fa-volume_up');
                $this.removeClass('ays_sound_active');
            } else {
                audioEl.volume = 1;
                $this.find('.ays_poll_far').addClass('ays_poll_fa-volume_up').removeClass('ays_poll_fa-volume_off');
                $this.addClass('ays_sound_active');
            }
        });        
        // ==== ====
        
        // = Social buttons in see results directly
        $(document).on('click', 'div.apm-social-btn a.ays-d-res-share-btn', function () {
            var detectLink = $(this).data("id");
            var url = "";
            var dataUrl = "";
            var dataCss = 'width=650,height=450';
            if(detectLink == "fb"){
                url = 'https://www.facebook.com/sharer/sharer.php?u=' + window.location.href;
                dataUrl = 'facebook-share-dialog';
            }
            else if(detectLink == "twt"){
                url = 'https://twitter.com/intent/tweet?url=' + window.location.href;
                dataUrl = 'twitter-share-dialog';
            }
            else if(detectLink == "ln"){
                url = 'https://www.linkedin.com/shareArticle?mini=true&url=' + window.location.href;
                dataUrl = 'linkedin-share-dialog';
            }
            window.open(url,dataUrl,dataCss);
            return false;
        });
        // ==
        if( typeof pollLangDataTableObj != "undefined"){
            $(document).find('#ays-poll-user-history-result-page').DataTable({
                "language": {
                    "sEmptyTable":     pollLangDataTableObj.sEmptyTable,
                    "sInfo":           pollLangDataTableObj.sInfo,
                    "sInfoEmpty":      pollLangDataTableObj.sInfoEmpty,
                    "sInfoFiltered":   pollLangDataTableObj.sInfoFiltered,
                    "sInfoPostFix":    "",
                    "sInfoThousands":  ",",
                    "sLengthMenu":     pollLangDataTableObj.sLengthMenu,
                    "sLoadingRecords": pollLangDataTableObj.sLoadingRecords,
                    "sProcessing":     pollLangDataTableObj.sProcessing,
                    "sSearch":         pollLangDataTableObj.sSearch,
                    "sUrl":            "",
                    "sZeroRecords":    pollLangDataTableObj.sZeroRecords,
                    "oPaginate": {
                        "sFirst":    pollLangDataTableObj.sFirst,
                        "sLast":     pollLangDataTableObj.sLast,
                        "sNext":     pollLangDataTableObj.sNext,
                        "sPrevious": pollLangDataTableObj.sPrevious,
                    },
                    "oAria": {
                        "sSortAscending":  pollLangDataTableObj.sSortAscending,
                        "sSortDescending": pollLangDataTableObj.sSortDescending
                    }
                } 
            });
        }

        // Avatars on see res directly option
        if(typeof idChecker !== 'undefined'){
            var checkResShow = $(document).find("#"+idChecker);
            if(checkResShow.data("loadMethod")){
                var checkModal = $(document).find(".ays-poll-avatars-modal-main");
                if(checkModal.length < 1){
                    var avatarsModal = "<div class='ays-poll-avatars-modal-main'>" +
                                            "<div class='ays-poll-avatars-modal-content'>" +
                                                "<div class='ays-poll-avatars-preloader'>" +
                                                "<img class='ays-poll-avatar-pic-loader' src="+resLoader+">" +
                                                "</div>" +
                                                "<div class='ays-poll-avatars-modal-header'>" +
                                                    "<span class='ays-close' id='ays-poll-close-avatars-modal'>&times;</span>" +
                                                    "<span style='font-weight: bold;'></span>" +
                                                "</div>" +
                                                "<div class='ays-poll-modal-body' id='ays-poll-avatars-body'></div>" +
                                            "</div>" +
                                        "</div>";
                    $(document.body).append(avatarsModal);
                }
            }
        }

        var questionTypeText = $(document).find('textarea.ays-poll-text-types-inputs-only-textarea');
        autosize(questionTypeText);

        $(document).find('textarea.ays_poll_question_limit_length, input.ays_poll_question_limit_length').on('keyup keypress', function(e) {
            var $this = $(this);
            var limitType = $this.data("limitType");
            var limitMaxLength = $this.data("maxLength");
            var limitTextMessage = $this.parents(".ays-poll-maker-text-answer-main").find('.ays_poll_question_text_message_span');

            var remainder = '';
            if(limitMaxLength != '' && limitMaxLength != 0){
                switch ( limitType ) {
                    case 'characters':
                        var tval = $this.val();
                        var tlength = tval.length;
                        var set = limitMaxLength;
                        var remain = parseInt(set - tlength);
                        if (remain <= 0 && e.which !== 0 && e.charCode !== 0) {
                            $this.val((tval).substring(0, tlength - 1));
                        }
                        if (e.type=="keyup") {
                            var tval = $this.val().trim();
                            if(tval.length > 0 && tval != null){
                                var wordsLength = this.value.split('').length;
                                if (wordsLength > limitMaxLength) {
                                    var trimmed = tval.split('', limitMaxLength).join("");
                                    $this.val(trimmed);
                                }
                            }
                        }
                        remainder = remain;
                        break;
                    case 'words':
                        if (e.type=="keyup") {
                            var tval = $this.val().trim();
                            if(tval.length > 0 && tval != null){
                                var wordsLength = this.value.match(/\S+/g).length;
                                if (wordsLength > limitMaxLength) {
                                    var trimmed = tval.split(/\s+/, limitMaxLength).join(" ");
                                    $this.val(trimmed + " ");
                                }
                                remainder = limitMaxLength - wordsLength;
                            }
                        }
                        break;
                    default:
                        break;
                }
                if (e.type=="keyup") {
                    if ( limitTextMessage ) {
                        if(limitMaxLength != '' && limitMaxLength != 0){
                            if (remainder <= 0) {
                                remainder = 0;
                            }
                            if (tval.length == 0 || tval == null) {
                                remainder = limitMaxLength;
                            }
                        }
                        limitTextMessage.html( remainder );
                    }
                }
            }
        });

        // Allow other answer
        $(document).find(".ays-poll-new-answer-apply-text").on("input" , function(){
            var _this = $(this);
            var voteButton = _this.parents("form").find("input[name='ays_finish_poll']");
            var allowMultivoteCheck = _this.parents("form").find('input#ays_poll_multivote_min_count').data("allow");
            var pollMultivoteMinCount = _this.parents(".apm-answers").find("#ays_poll_multivote_min_count").val();
            var CheckedBoxes = _this.parents(".apm-answers").find("input:checkbox:checked");
            var numberOfChecked = CheckedBoxes.length;
            if(_this.val() != ""){
                numberOfChecked++;
            }
            var noteBox = _this.parents(".apm-add-answer").next();
            if(noteBox.hasClass('ays-poll-add-answer-note-enable')){
                noteBox.slideDown(200);
                noteBox.removeClass("ays-poll-add-answer-note-enable");
            }
            else if(_this.val() == ''){
                noteBox.addClass("ays-poll-add-answer-note-enable");
                noteBox.slideUp(200);
            }
            if(allowMultivoteCheck){
                if(pollMultivoteMinCount > numberOfChecked){
                    voteButton.css("opacity" , "0.5");
                }
                else{
                    voteButton.css("opacity" , "1");
                }
            }
        });

        $(document).on('click', '.ays-poll-password-toggle', function(e){
            var $this  = $(this);
            
            var parent = $this.parents('.ays-poll-password-input-box-visibility');
            var passwordInput = parent.find('.ays-poll-password-input');

            var visibilityOn  = parent.find('.ays-poll-password-toggle-visibility');
            var visibilityOff = parent.find('.ays-poll-password-toggle-visibility-off');

            if( $this.hasClass('ays-poll-password-toggle-visibility-off') ) {
                passwordInput.attr('type', 'text');
                    
                if ( visibilityOn.hasClass('ays_poll_display_none') ) {
                    visibilityOn.removeClass('ays_poll_display_none');
                }

                if ( ! visibilityOff.hasClass('ays_poll_display_none') ) {
                    visibilityOff.addClass('ays_poll_display_none');
                }

            } else if( $this.hasClass('ays-poll-password-toggle-visibility') ) {
                passwordInput.attr('type', 'password');

                if ( ! visibilityOn.hasClass('ays_poll_display_none') ) {
                    visibilityOn.addClass('ays_poll_display_none');
                }

                if ( visibilityOff.hasClass('ays_poll_display_none') ) {
                    visibilityOff.removeClass('ays_poll_display_none');
                }                
            }
        });


    })

})(jQuery);

ZeroDay Forums Mini