Subversion Repositories SmartDukaan

Rev

Rev 1235 | Blame | Compare with Previous | Last modification | View Log | RSS feed

$(document).ready(function(){

        /* Home */
        if($("#products:visible").length == 1){
                
                // Product Title
                $(".productItem .productDetails .title a").each(function(){
                        var str = charLimit($(this), $(this).text(), 2, 20);
                        $(this).text(str);
                });
                
                // Product Description
                $(".productItem .productDetails .productDesp").each(function(){
                        if($("ul", this).length != 1){
                                var str = charLimit($(this), $(this).text(), 5, 24);
                                $(this).text(str);
                        }
                });
        }
        
        /* Product Category : Browse Tab */
        if($("#browseContent:visible").length == 1){
                
                // Product Title
                $(".productItem .productDetails .title a").each(function(){
                        var str = charLimit($(this), $(this).text(), 2, 20);
                        $(this).text(str);
                });
                
                // Product Description
                $(".productItem .productDetails .productDesp").each(function(){
                        if($("ul", this).length != 1){
                                var str = charLimit($(this), $(this).text(), 5, 24);
                                $(this).text(str);
                        }
                });
        }
        
        /* Product Category : Other Tab */
        if($("#otherTabContent:visible").length == 1){
                
                // Product Title
                $(".productItem .productDetails .title a").each(function(){
                        var str = charLimit($(this), $(this).text(), 2, 20);
                        $(this).text(str);
                });
                
                // Product Description
                $(".productItem .productDetails .productDesp").each(function(){
                        if($("ul", this).length != 1){
                                var str = charLimit($(this), $(this).text(), 5, 24);
                                $(this).text(str);
                        }
                });
        }
        
        /* Search Result */
        if($("#searchResult:visible").length == 1){
                
                // Product Title
                $(".productItem .productDetails .title a").each(function(){
                        var str = charLimit($(this), $(this).text(), 2, 32);
                        $(this).text(str);
                });
                
                // Product Description
                $(".productItem .productDetails .productDesp").each(function(){
                        if($("ul", this).length != 1){
                                var str = charLimit($(this), $(this).text(), 4, 40);
                                $(this).text(str);
                        }
                });
        }
        
        
});

/*
 * param : selector, characters, no. of lines, each line char limit
*/
function charLimit(selector, chars, line, limit){
        var temp = "";
        var str  = jQuery.trim(chars);
        var len  = str.length;
        
        limit = line * limit;
        
        if(len > limit){
                $(selector).attr("title", str);
                temp = str.substr(0, limit-3) + "...";
                
                return temp;
        }else{
                return str;
        }       
}