Subversion Repositories SmartDukaan

Rev

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

$(function() {
        
        $("#query").autocomplete({  autoFocus: true, minLength: 3,
        source: "/auto-suggest",
        select: function( event, ui ) {
                this.value = ui.item.value;
                        $('#formSearch').submit();
                        return false;
                }
    });
        
        $('.imageThumbnail_li ').mouseover(function(){
                $(this).css({"border-color":"#000000"});
                $(".default-thumbnail").find("img").attr("src",$(this).find("img").attr("src"));
                });
                $('.imageThumbnail_li ').mouseleave(function(){
                $(this).css({"border-color":"#CCCCCC"});
        });
        
        $('input.filterList_checkBox').change(function(){
                var search = window.location.search;
                if(window.location.search=="") {
                        search = "?";
                }
                var currenturl = (window.location.pathname + search);
                console.log(currenturl);
                console.log(this.checked + this.value);
                if(this.checked) {
                        currenturl = (currenturl) + this.value;
                } else {
                        currenturl = (currenturl).replace(this.value, "");
                }
                window.location = currenturl.replace(/&page=./,"");
        });
        
        $('a.mk_filter').click(function(){
                //first remove all fqs except category and sub category when 
                //any of the category links are clicked
                var search = window.location.search;
                if(window.location.search=="") {
                        search = "?";
                }
                var currenturl = window.location.pathname + search;
                classNames = $(this).attr("class");
                if(classNames.indexOf("mk_bold") >= 0) {
                        //if this is selected category filter, remove subcategory filter from url
                        currenturl = currenturl.replace($(this).closest('ul').find('.mk_bold.mk_subcategory').attr("value"), "");
                }else {
                        //check if sub-category is changed, if yes then remove the previous sub-category and add this sub-category
                        if(classNames.indexOf("mk_subcategory") >= 0) {
                                currenturl = currenturl.replace($(this).closest('ul').find('.mk_bold.mk_subcategory').attr("value"), "") + $(this).attr("value");
                        }else {
                                currenturl = (currenturl).replace($(this).closest('ul').find('.mk_bold.mk_category').attr("value"), "").replace($(this).closest('ul').find('.mk_bold.mk_subcategory').attr("value"),"") + $(this).attr("value");
                        } 
                }
                window.location = currenturl.replace(/&page=./,"");
        });
        
        //also now remove unwanted filters
        $('a.mk_filter_close').click(function(){
                var rootFacets = ["F_50010","F_50011","F_50002", "F_50001", "F_50028"];
                var search = window.location.search;
                if(window.location.search=="") {
                        search = "?";
                }
                var newurl = window.location.pathname + search;
                var filterValue = $(this).attr("value");
                console.log("newurl "+newurl);
                console.log("filtervalue "+filterValue);
                if(filterValue.indexOf("F_50010")>-1){
                        $(this).closest('div').find('.mk_filter_close').each(function(index,value){
                                newurl = newurl.replace($(value).attr("value"), "");
                        });
                } else if(filterValue.indexOf("F_50011")>-1){
                        $(this).closest('#currentFilters').find('.mk_filter_close').each(function(index,value){
                                var regexS = "fq=(.*)%3A";
                                var regex = new RegExp(regexS);
                                var results = regex.exec($(value).attr("value"));
                                if(rootFacets.indexOf(results[1]) == -1){
                                        newurl = newurl.replace($(value).attr("value"), "");
                                }
                        });
                        newurl = newurl.replace($(this).attr("value"), "");
                } else {
                        newurl = newurl.replace($(this).attr("value"), "");
                }
                window.location = newurl.replace(/&page=./,"");
        });
        

        
});