Soft Reject new item need help !!

themeforest

#1

hello guys i don’t understand what say reviewer…
here the reviewer mention reason…

  1. CACHE JQUERY OBJECTS: Please cache the jQuery objects that are used more than once when it’s possible, this will help a lot with performance of the site. --> http://envato.d.pr/7xEJ

  2. STRICT EQUALITY COMPARISON: For better performance please use Strict Equality Comparison. --> http://envato.d.pr/7xEJ

plz help me how can i solve it…and see my code it is right or wrong

my previous code is

    /*----------------------------
        OPEN SEARCH FORM
    ----------------------------*/
    $('.search-form-trigger').on('click', function (event) {
        event.preventDefault();
        toggleSearch();
    });

    function toggleSearch(type) {
        if (type == "close") {
            //close serach 
            $('.search-form').removeClass('is-visible');
            $('.search-form-trigger').removeClass('search-is-visible');
        } else {
            //toggle search visibility
            $('.search-form').toggleClass('is-visible');
            $('.search-form-trigger').toggleClass('search-is-visible');
            if ($('.search-form').hasClass('is-visible')) $('.search-form').find('input[type="search"]').focus();
            $('.search-form').hasClass('is-visible') ? $('.search-form-overlay').addClass('is-visible') : $('.search-form-overlay').removeClass('is-visible');
        }
    }

and i am right now fix it…look see blew…and tell me it’s right or wrong

    /*----------------------------
        OPEN SEARCH FORM
    ----------------------------*/
    $('.search-form-trigger').on('click', function (event) {
        event.preventDefault();
        toggleSearch();
    });

    var searchForm = $('.search-form');
    var searchFormTrigger = $('.search-form-trigger');

    function toggleSearch(type) {
        if (type === "close") {
            //close serach 
            $searchForm.removeClass('is-visible');
            $searchFormTrigger.removeClass('search-is-visible');
        } else {
            //toggle search visibility
            $searchForm.toggleClass('is-visible');
            $searchFormTrigger.toggleClass('search-is-visible');
            if ($searchForm.hasClass('is-visible')) $searchForm.find('input[type="search"]').focus();
            $searchForm.hasClass('is-visible') ? $('.search-form-overlay').addClass('is-visible') : $('.search-form-overlay').removeClass('is-visible');
        }
    }

if find here any wrong plz tell me how can i solve it…


#2

Hi,

1) What he means by caching the jquery object is this $(’.selector’) you should have less of these instead you can have something like this.

var someContainer = $(’.some-selector’);

then you can use like this someContainer.find or someContainer.on(‘click’, ‘.some-selector’, callback );

in your case it should be something like this:

var form = $(’.search-form’);

then use form.on(‘click’, ‘.search-form-trigger’, toggleSearch );

2) You need to use triple === sign for comparison in this case. See more about this here.

Your fixed version is better for the click event you should use ‘searchFormTrigger’ variable, also if you are in strict mode put the variables before any bind events, move your vars to the top.

searchFormTrigger.on(‘click’, function (event) {
event.preventDefault();
toggleSearch();
});


#3

thanks for your help @hawk95 I think this time it will be approved.