Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

/** 
  * Author                      : Raj Kumar Bharti
  * Creation Date       : 06 Dec 2010
  * Project             : Shop2020
  * Copyright 2010 Evon Technologies
*/

$(document).ready(function(){
        
        // Variables for pagination result of browse, other tab content and search result
        x = y = z = 0;
        var arrBrowsePaginationResult = [];
        arrBrowsePaginationResult.push([0, 0]);
        
        var arrOtherPaginationResult = [];
        arrOtherPaginationResult.push([0, 0]);
        
        var arrSearchPaginationResult = [];
        arrSearchPaginationResult.push([0, 0]);
        
        
        // Setting tab button id attr to empty
        $('#tabButton div').each(function(){
                $("a", this).attr("id", "");
        });
        
        // Activating Browse tab
        activeTab("catTab1");
        
        // Hide other tab common content for best deals, latest arrivals, best sellers
        hideShowTabContent("otherTabContent", "hide");
        
        
        // Filter by heading slideup and slidedown
        filterByOptionSlide();
        
        // Filter by values selection
        filterByValues();
        
        // Sort Search Results
        sortSearchResult();
        
        // Align properly new icon in search result pages for a product
        var newIconLeft = $("#searchResult #productListCenter .productItem .productImg img").css("left");
        $("#searchResult #productListCenter .productItem .productImg .newIcon").css("left", newIconLeft);
});

/*
 *  sort search results
*/
function sortSearchResult(){
        $("#sortBy a").click(function(){
                id = $(this).attr("id");
                
                if(id == "sortByPrice"){
                        $(this).removeClass('active').addClass('active');
                        $("#sortByRelevance, #sortByPopularity").removeClass('active');
                        // Ajax call to fecth data in page class
                        
                }else if(id == "sortByRelevance"){
                        $(this).removeClass('active').addClass('active');
                        $("#sortByPrice, #sortByPopularity").removeClass('active');
                        // Ajax call to fecth data in page class
                }else if (id =="sortByPopularity"){
                        $(this).removeClass('active').addClass('active');
                        $("#sortByPrice,#sortByRelevance").removeClass('active');
                }
        });
}

/*
 *  Filter by values selection
*/
function filterByValues(){
        // Data Connectivity
        $("#filterByDataConnectivity .filterOption a").click(function(){
                var v =  $(this).text();
        });
        
        // Note for price slider value see priceSlider.js
}

/*
 * Filter by heading slideup and slidedown
*/
function filterByOptionSlide(){
        $("#filterBy .filterHeading").click(function(){
                
                // Image angle change
                if($(this).parent().find(".filterArrow").length == 1){
                        $(this).parent().find(".filterArrow").removeClass('filterArrow').addClass('filterArrowRotate');
                }else if($(this).parent().find(".filterArrowRotate").length == 1){
                        $(this).parent().find(".filterArrowRotate").removeClass('filterArrowRotate').addClass('filterArrow');
                }
                
                // Content slideup and slide down
                if($(this).parent().find(".filterOption").length == 1){
                        $(this).parent().find(".filterOption").slideToggle();
                }else{
                        $(this).parent().find("#priceSlider").slideToggle();
                }
        });
}

/*
 * Browse content
*/
function browseContentCallback(page_index, jq){
        
        // Show page content
        $('#browseContent #productListCenter1 div.page:visible').hide();
        $('#browseContent #productListCenter1 div.page:eq(' + page_index + ')').show(); 

        x = arrBrowsePaginationResult[page_index][0];
        y = arrBrowsePaginationResult[page_index][1];
        z = $('#browseContent #productListCenter1 div.page .productItem').length; 
        
        result = x + ' to ' + y + ' of <span class="resultLimit">' + z + '</span> <span class="style1">results</span>';
        
        $("#browseContent .productListResult").html(result);
        
        return false;
}

/*
 * Browse content
*/
function otherTabContentCallback(page_index, jq){

        // Show page content
        $('#otherTabContent #productListCenter2 div.page:visible').hide();
        $('#otherTabContent #productListCenter2 div.page:eq(' + page_index + ')').show(); 

        x = arrOtherPaginationResult[page_index][0];
        y = arrOtherPaginationResult[page_index][1];
        z = $('#otherTabContent #productListCenter2 div.page .productItem').length; 
        
        result = x + ' to ' + y + ' of <span class="resultLimit">' + z + '</span> ' + $("#otherTabContent .productListHeading").text();
        
        $("#otherTabContent .productListResult").html(result);
        
        return false;
}

/*
 * Search Result content pagination
*/
function initSearchResultPagination(){
        if($('#searchResult:visible').length == 1){
                // Total page length
                totalPages = $('#searchResult #searchResultContent div.page').length;   
                
                if(totalPages > 0){
                        defaultPaginationLen = 6;       // Length of pages to show in pagination
                        
                        // Whether to show ellipse or not, if yes then how many
                        edgePaginationLen = (totalPages >= defaultPaginationLen) ? 1 : 0;
                        
                        // Number of pages to display in pagination
                        numOfPageDisplay = (totalPages >= defaultPaginationLen) ? defaultPaginationLen : totalPages;    
                        
                        // Select current page in pagination
                        curPageSelection = 0;
                        
                        $("#searchResult #searchResultContent .pagination1").pagination(totalPages, {
                                num_display_entries : numOfPageDisplay,
                                num_edge_entries        : edgePaginationLen,
                                current_page            : curPageSelection,
                                items_per_page          : 1,
                                callback                : searchContentCallback,
                                link_to                 : 'javascript: void(0);'
                        });
                        
                        // Show result no
                        curPageItemNo = $('#searchResult #searchResultContent div.page:eq(0) .productItem').length;
                        
                        x = 1;
                        y = curPageItemNo;
                        z = $('#searchResult #searchResultContent div.page .productItem').length;
                        result = x + ' to ' + y + ' of <span class="resultLimit">' + z + '</span> <span class="style1">results</span>';
                        
                        len = arrSearchPaginationResult.length;
                        for(var i=0; i<len; i++){
                                arrSearchPaginationResult.pop();
                        }
                        
                        $('#searchResult #searchResultContent div.page').each(function(){
                                arrSearchPaginationResult.push([x, y]);
                                
                                x = y + 1;
                                y = x + ($('.productItem', this).length - 1);
                        });
        
                        $("#searchResult #searchResultContent .productListResult").html(result);
                }else{
                        result = '0 to 0 of <span class="resultLimit"> 0 </span> <span class="style1">results</span>';
                        
                        $("#searchResult #searchResultContent .productListResult").html(result);
                }
        }
}

/*
 * Search result content
*/
function searchContentCallback(page_index, jq){
        
        // Show page content
        $('#searchResult #searchResultContent div.page:visible').hide();
        $('#searchResult #searchResultContent div.page:eq(' + page_index + ')').show(); 

        x = arrSearchPaginationResult[page_index][0];
        y = arrSearchPaginationResult[page_index][1];
        z = $('#searchResult #searchResultContent div.page .productItem').length; 
        
        result = x + ' to ' + y + ' of <span class="resultLimit">' + z + '</span> <span class="style1">results</span>';
        
        $("#searchResult #searchResultContent .productListResult").html(result);
        
        return false;
}

/*
 * Remove last active tab state
*/
function removeLastActiveState(){
        if($('#tabButton a#activeTab').length == 1){
                
                $('#tabButton div').each(function(){
                        if($("a", this).attr("id") == "activeTab"){
                                $("a", this).attr("id", "");
                        }
                });

        }
}

/*
 * Make active tab
*/
function activeTab(id){
        $("#" + id + " a").attr("class","category-tabs activeTab");
}

/*
 * Hide tab content
*/
function hideShowTabContent(id, state){ 
        if(state == "hide"){
                $("#" + id).hide();
        }else if(state == "show"){
                $("#" + id).show();
        }
        
        if(id == "multifacetedSearch"){
                if(state == "hide"){
                        $("#productCat .top .left").css("background", "#fff");
                        $("#productCat .bottom .left").css("background", "url(/images/product-detail-bottom-left.jpg) no-repeat");
                        $("#productCat .middle .content").css("background-image", "none");
                        
                        $("#productList").css("width", "100%");
                        $("#productList").css("margin-left", "0");
                        
                        $("#productList #productListCenter .floatLeft").css("margin-left", "70px");
                        $("#productList #productListCenter .floatRight").css("margin-right", "70px");
                }else if(state == "show"){
                        $("#productCat .top .left").css("background", "#efeff0");
                        $("#productCat .bottom .left").css("background", "url(/images/product-cat-bottom-left.jpg) no-repeat");
                        $("#productCat .middle .content").css("background", "#ffffff url(/images/grey-ver-bar.gif) repeat-y");
                        
                        $("#productList").css("width", "515px");
                        $("#productList").css("margin-left", "1px");
                        
                        $("#productList #productListCenter .floatLeft").css("margin-left", "16px");
                        $("#productList #productListCenter .floatRight").css("margin-right", "16px");
                }
        }
}

/*
 * Set content heading on tab click
*/
function setContentHeading(str){
        if($("#otherTabContent:visible").length == 1){
                $("#otherTabContent .productListHeading").text(str);
        }
}