Tuesday 22 August 2017

menu selected on scroll and click

 $(document).on("scroll", onScroll);
    $('.mobile-nav').click(function () {
        $(this).toggleClass('nav-open');
        $(this).next().slideToggle();
        $('.header').toggleClass('fixed');
    });

    $(".header-menu li a").click(function (evn) {
        evn.preventDefault();
        if (!evn.detail || evn.detail == 1) {
            $(document).off("scroll");

            var curobj = $(this).attr('href');
            $(this).parent().siblings().removeClass('active');
            $(this).parent().addClass('active');
            var topOffsetVal = $(curobj).offset().top - $('#header').outerHeight();
            $('html,body').animate({scrollTop: topOffsetVal}, 1000, function () {
                $(document).on("scroll");
                $(document).on("scroll", onScroll);
            });
        }
    });

    $(".footer-nav li a").click(function (evn) {
        evn.preventDefault();

        var curobj = $(this).attr('href');
        var curobj1 = $(this).attr('data-id');
        $(".header-menu li").removeClass('active');
        $("#" + curobj1).addClass('active');
        var topOffsetVal = $(curobj).offset().top - $('#header').outerHeight();
        $('html,body').animate({scrollTop: topOffsetVal}, 1000, function () {
            $(document).on("scroll");
            $(document).on("scroll", onScroll);
        });
        ;
    });

    $(".down-bottom a").on('click', function (event) {
        event.preventDefault();
        var curobj = $(this).attr('href');
        var curobj1 = $(this).attr('data-id');
        $(".header-menu li").removeClass('active');
        $("#" + curobj1).addClass('active');
        var topOffsetVal = $(curobj).offset().top - $('#header').outerHeight();
        $('html,body').animate({scrollTop: topOffsetVal}, 1000, function () {
            $(document).on("scroll");
            $(document).on("scroll", onScroll);
        });
        ;
    });




    function onScroll(event) {
        var scrollPos = $(document).scrollTop();
        $('.header-menu a').each(function () {
            var currLink = $(this);
            var refElement = $(currLink.attr("href"));
            if (refElement.position().top - 88 <= scrollPos) {
                $('.header-menu li').removeClass("active");
                $('.header-menu li.active a').attr("href")
                currLink.parent().addClass("active");
            }
            else {
                currLink.parent().removeClass("active");
            }


        });
    }





    $(window).scroll(function () {
        if ($(this).scrollTop() > 100) {
            $('.scrollToTop').fadeIn();
        } else {
            $('.scrollToTop').fadeOut();
        }
    });
//Click event to scroll to top
    $('.scrollToTop').click(function (evn) {
        $('html, body').animate({scrollTop: 0}, 1000);
    });



    $(".panel-heading").click(function () {
        $(this).next().slideToggle();
    });
})

Sunday 20 August 2017

jquery add error placement

 errorPlacement: function (error, element) {
            if (element.attr("name") == "hear_about[]") {
                error.insertAfter(".checkboxerror3");
            }
}

jquery validation cumtom


$(document).ready(function () {

    /*
     *  Check initial space
     */
    $.validator.addMethod("noInitiallSpace", function (value, element) {
        return this.optional(element) || $.trim(value) != '';
    }, ("No space please and don't leave it empty"));



    /********check space starting and end ***********/
    $.validator.addMethod("noSpace",
            function (value, element) {
                return value.indexOf(" ") < 0 && value != "";
            }, ("No space please and don't leave it empty"));

    function getWordCount(wordString) {
        var words = wordString.split(" ");
        words = words.filter(function (words) {
            return words.length > 0
        }).length;
        return words;
    }

//add the custom validation method
    $.validator.addMethod("wordCount",
            function (value, element, params) {
                var count = getWordCount(value);
                if (count < 500) {
                    return true;
                }
            },
            ("Please enter no more than  {0} characters.")
            );


    /*********add validation for latter only *****/
    $.validator.addMethod("letter",
            function (value, element) {
                return this.optional(element) || /^[a-z-.,()'\"\s]+$/i.test(value);
            }, ('Only letters allowed!'));



    /***********check password 8 char 1 numeric 1 char*********/

    $.validator.addMethod("pwdcheck",
            function (value, element) {
                return /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9]).{8,50}$/i.test(value);

            }, ('Password should be alphanumeric with minimum 8 characters.'));


    /***********check password 8 char 1 numeric 1 char*********/

    $.validator.addMethod("custom_number", function (value, element) {
        return this.optional(element) || value === "NA" ||
                value.match(/^[0-9]+$/);
    }, ("Please enter a valid number"));

    $.validator.addMethod("extension", function (value, element, param) {
        var ext = value.split('.').pop().toLowerCase();
        if ($.inArray(ext, param) == -1 && ext != '') {
            return false;
        }
        return true;
    }, ("Upload only pdf"));



})