$(document).ready(function(){ // whether connect server var wait = null; var wait_time = 1100; // search option var option = { product_count : , page : , keyword : "", brands : "", categories : "", show_num : , page_num : , price_1 : 0, price_2 : 0, order_by : "best" }; // Slider $('#slider').slider({ range: true, min: option.price_1, max: option.price_2, values : [option.price_1, option.price_2], animate : true, slide : function(event, ui) { $("#min_price").val($('#slider').slider('option', 'values')[0]); $("#max_price").val($('#slider').slider('option', 'values')[1]); }, stop : function(event, ui) { init_data(); clearTimeout(wait); option.price_1 = $("#min_price").val(); option.price_2 = $("#max_price").val(); wait = setTimeout(get_products,wait_time); } }); // Brand $("input[name='brand[]']").click(function(){ init_data(); clearTimeout(wait); /* if($(this).attr("checked")) option.brands.push($(this).val()); else option.brands.splice($.inArray($(this).val(),option.brands)); */ wait = setTimeout(get_products,wait_time); }); // Category $("input[name='category[]']").click(function(){ init_data(); clearTimeout(wait); wait = setTimeout(get_products,wait_time); }); // Order By $("#order_by").change(function(){ option.order_by = $(this).val(); get_products(); }); // show all brand $("#show_all_brand").click(function(){ $.each($("input[name='brand[]']"),function(i,item){ $(this).parent().show(); }); }); // show all category $("#show_all_category").click(function(){ $.each($("input[name='category[]']"),function(i,item){ $(this).parent().show(); }); }); // reset li width $(window).resize(function(){ reset_li_width(); }); function reset_li_width(){ var count = parseInt($(".pds").width()/185); var width = (100/count); if(option.product_count<=count) return; $(".pds li").width(width +"%"); } function init_data(){ option.page = 1; } function reset_option(brands,categories,price_1,price_2){ //setter if(price_1!=option.price1 || price_2!=option.price2){ $("#brands").children().hide(); $.each(brands,function(i,item){ $("input[name='brand[]'][value='"+item.brand+"']").parent().show(); }); $("#categories").children().hide(); $.each(categories,function(i,item){ $("input[name='category[]'][value='"+item.category+"']").parent().show(); }); } } function get_search_option(str){ if(str.length>0) return '' + str + ''; return ""; } //Get Porducts function get_products(){ $("#subContent").empty(); finish($("#subContent")); loading($("#subContent")); var keyword = get_search_option($("#barInput").val()); var brands = []; var categories = []; if(keyword.length>0) keyword += " + "+get_search_option("$" + option.price_1 + " ~ $" + option.price_2) + " + "; else keyword += get_search_option("$" + option.price_1 + " ~ $" + option.price_2) + " + "; $.each($("input:checked[name='brand[]']"),function(i,item){ brands.push(item.value); keyword += get_search_option(item.value)+" + "; }); $.each($("input:checked[name='category[]']"),function(i,item){ categories.push(item.value); keyword += get_search_option(item.value)+" + "; }); //search option text keyword = keyword.substr(0,keyword.length-3); $.post( "includes/ajax_product.php", { smode : "get_products", keyword : option.keyword, salePrice_1 : option.price_1, salePrice_2 : option.price_2, brand : brands, category : categories, page : option.page, order_by : option.order_by }, function(data){ //get product count var product_count = data[0][0]; var brands_result = data[0][2]; var categories_result = data[0][3]; var price_1 = parseInt(data[0][4]["p1"]); var price_2 = parseInt(data[0][4]["p2"]); reset_option(brands_result,categories_result,price_1,price_2) if(product_count<=0){ return no_result(keyword); } option.product_count = product_count; // search option var html = '
';
html += 'Your Search: '+keyword+'
';
html += product_count +' Result(s) Found

You Search "+keyword+"
"; $("#subContent").empty(); finish($("#subContent")); $("#subContent").append(html); } /** * page */ function page_list(){ var total = option.product_count; var now = option.page; var page_num = option.page_num; var show_num = option.show_num; var page = total/show_num; if(total%show_num>0) page += 1; var $html = $(''); var url = "advancedSearch.php?keyword="+option.keyword+"&page="; var $i = 0; if(now - page_num <= 0) for($i=1;$i< now;$i++) $html.append(page_link(url+$i,$i)); else for($i=now-page_num;$i< now;$i++) $html.append(page_link(url+$i,$i)); $html.append(""+$i+" "); if(now + page_num >= page) for($i=now+1;$i<=page;$i++) $html.append(page_link(url+$i,$i)); else for($i=now+1;$i<=now+page_num;$i++) $html.append(page_link(url+$i,$i)); if(now<$i-1) $html.append(page_link(url+(now+1),"Next")); if(now*show_num>total) $html.append("("+((now-1)*show_num+1)+"-"+total+" of "+total+")"); else $html.append("("+((now-1)*show_num+1)+"-"+(now*show_num)+" of "+total+")"); return $html; } function page_link(url,i){ var page = parseInt(url.substr(url.lastIndexOf("=")+1)); return $("",{ href : url, text : i + " ", click : function(){ option.page = page; //alert(option.page); get_products(); return false; } }); } $a = $("p[class='rsFont tac']").find("a"); $a.click(function(){ var url = $(this).attr("href"); var page = url.substr(url.lastIndexOf("=")+1); option.page = parseInt(page); get_products(); return false; }); function get_order_by(){ var order_by_list = { price_asc : "Lowest Price", price_desc : "Highest Price", best : "Best Result" }; var $html = $('Sort By:
'); $order_select = $(''); $order_select.change(function(){ option.order_by = $(this).val(); get_products(); }); $.each(order_by_list,function(value,name){ if(value == option.order_by) $order_select.append(''); else $order_select.append(''); }); $html.append($order_select); return $html; } //execute reset width; reset_li_width(); });