• Blogs (9)
    • 📱 236 - 992 - 3846

      📧 jxjwilliam@gmail.com

    • Version: ‍🚀 1.1.0
  • Some JS examples

    Blogs20132013-05-26


    Some JS examples

    Here are some of my JS/jQuery examples for quick retrieving:

    //1. set _debug flag to auto switch log future in different envs:
    _debug: /(williamjiang|localhost)/i.test(document.location.hostname),
    
    //2.
    this
     .filter(":has(>ul):not(:has(>a))")
     .find(">span")
     .unbind("click.tree")
     .bind("click.tree", function(event) {
       if ( this == event.target )
        toggler.apply($(this).next());
      }).add( $("a", this) ).hoverClass();
    
    branches.each(function(i, e) {
      data[i] = $(e).is(":has(>ul:visible)") ? 1 : 0;
    });
    
    $('li.third-item').nextAll().andSelf()
      .css('background-color', 'red');
    
    //3.on(), off()
    var switchListHandler=function(e){
        if (typeof (e) == "undefined")
            e = window.event;
        if (typeof (e) == "undefined")
            return false;
        var srcEle = e.srcElement;
        if (!srcEle) srcEle = e.target;
        if(srcEle.tagName.toUpperCase()=='A') {...}
    };
    
    $(document).on('click', 'body', CountList.switchListHandler);
    
    $(document).off('click', 'body', CountList.switchListHandler);