var geekSort = {};
geekSort.tool = {};
function debounce(fn,wait,immediate){
var timeout;
return function(){
var _this = this;
var args = arguments;
if(timeout)clearTimeout(timeout)
if(immediate){
var callNow = !timeout;
timeout = setTimeout(function(){
timeout = null;
},wait)
if(callNow){
fn.apply(_this,args);
}
}else{
timeout = setTimeout(function(){
fn.apply(_this,args);
},wait)
}
}
}
geekSort.tool.leftProperty = function() {
var select_left = $("#selectLeft");
var select_attrs = select_left.find(".select_attrs");
var select_radio = select_left.find(".select_radio");
if (select_attrs.length > 4) {
var attrs_show = true;
select_attrs
.filter(":lt(4)")
.show()
.end()
.filter(":gt(3)")
.hide();
$(".attrs_more").show();
$(".attrs_more").click(function() {
if (attrs_show) {
select_attrs.show();
$(".attrs_more").addClass("down_icon");
attrs_show = false;
} else {
$(".attrs_more").removeClass("down_icon");
select_attrs
.filter(":lt(4)")
.show()
.end()
.filter(":gt(3)")
.hide();
attrs_show = true;
}
});
}
select_attrs.each(function() {
var select_more = $(this).find(".select_more");
var select_radio = $(this).find(".select_radio");
var select_check = $(this).find(".select_check");
var select_btn = $(this).find(".select_btn");
var is_select = true;
select_more.click(function(e) {
if (is_select) {
select_more.addClass("actived");
select_radio.hide();
select_check.show();
select_btn.show();
if (select_check.length > 0) {
var select_check_li = select_check.find("li");
select_check_li.unbind("click").click(function() {
var _index = $(this).index();
if (!select_check_li.eq(_index).hasClass("actived")) {
select_check_li.eq(_index).addClass("actived");
} else {
select_check_li.eq(_index).removeClass("actived");
}
});
$(".select_cancel").click(function(e) {
select_check_li.removeClass("actived");
select_more.removeClass("actived");
select_check.hide();
select_btn.hide();
select_radio.show();
e.stopPropagation();
});
}
return is_select = false;
} else {
var select_check_li = select_check.find("li");
select_check_li.removeClass("actived");
select_more.removeClass("actived");
select_check.hide();
select_btn.hide();
select_radio.show();
return is_select = true;
}
e.stopPropagation();
})
});
select_radio.each(function() {
var view_more = $(this).find(".view_more");
var select_radio_ul = $(this).find("ul");
var select_radio_li = $(this).find("li");
select_radio_li
.filter(":lt(4)")
.show()
.end()
.filter(":gt(3)")
.hide();
var isShow = true;
view_more.click(function() {
if (isShow) {
select_radio_li.show();
view_more.addClass("down_icon").html("View Less");
isShow = false;
} else {
view_more.removeClass("down_icon").html("View More");
select_radio_li
.filter(":lt(4)")
.show()
.end()
.filter(":gt(3)")
.hide();
isShow = true;
}
});
});
$(".select_ok").each(function(i, e) {
$(this).click(function() {
var _url = $(this).data("url"); //.toLowerCase()
var _value1 = $(this).data("value1");
var _value2 = $(this).data("value2");
var _isSearch = 0;
if(_url.indexOf("search?") >=0) _isSearch = 1;
var _selectVal = "";
var _selectLi = $(this)
.parent()
.parent()
.find(".select_check li");
for (var i = 0; i <= _selectLi.length; i++) {
var _class = _selectLi.eq(i).attr("class");
if (_class != undefined && _class.indexOf("actived") >= 0) {
if(_isSearch == 1)
_selectVal += _selectLi.eq(i).attr("value") + ",";
else
_selectVal += _selectLi.eq(i).attr("value") + "v";
}
}
if (_selectVal.length > 0)
{
_selectVal = _selectVal.substring(0, _selectVal.length - 1);
}
if (_selectVal == "") {
alert("Please select Property.");
return;
}
var _newUrl = _url;
//搜索页的处理
if(_isSearch == 1)
{
if (_url.indexOf("," + _value2) >= 0) {
_newUrl = _url.replace("," + _value2, "," + _selectVal);
}
else
{
_newUrl = _url.replace("v=" + _value2, "v=" + _selectVal);
}
}
else
{
if (_url.indexOf("v" + _value2) >= 0) {
_newUrl = _url.replace("v" + _value2, "v" + _selectVal);
}
if (_url.indexOf("v-" + _value2) >= 0) {
_newUrl = _url.replace("v-" + _value2, "v-" + _selectVal);
}
}
location.href = _newUrl;
});
});
};
geekSort.tool.brandList = function() {
$.lazyLoad.loadImgs(".lazy_brand");
var isShow = true;
var filterBrandUlH = $(".filter_brands ul").height();
if ($(".filter_brands ul").height() == 50) {
$(".brand_more").hide();
}
$(window).resize(function() {
var filterBrandH = $(".filter_brands").height();
filterBrandUlH = $(".filter_brands ul").height();
if(filterBrandH > 42){
$(".filter_brands").height(filterBrandUlH);
}else{
$(".filter_brands").height(42);
}
})
$(".brand_more").click(function() {
if (filterBrandUlH > 50 && isShow) {
$(".filter_brands").height(filterBrandUlH);
$(".brand_more").html("View less ").addClass("down_icon");
return isShow = false;
} else {
$(".filter_brands").height(42);
$(".brand_more").html("View more ").removeClass("down_icon");
return isShow = true;
}
});
};
geekSort.tool.awareh = function() {
$('#aWareh').mouseenter(function() {
$(this).find('.ship_title').css('border-bottom', '1px solid #fff');
$('#ul_wareh').show();
$(this).find('i').addClass('actived');
}).mouseleave(function() {
$('#ul_wareh').hide();
$(this).find('i').removeClass('actived');
$(this).find('.ship_title').css('border-bottom', '1px solid #eee');
});
$("#ul_wareh li").click(function() {
window.location.href = $(this).attr("data-href");
});
}
geekSort.tool.aprice = function() {
var timerout;
$('.search_price').each(function() {
$(this).focus(function() {
clearInterval(timerout);
$('#filterGo').show();
}).blur(function() {
timerout = setInterval(function() {
$('#filterGo').hide();
}, 2000);
});
});
$("#filterGo").click(function() {
var reg = /^[1-9]\d*\.*\d*|0\.\d*[1-9]\d*$/;
var minPrice = $("#minPrice").val();
if (minPrice != "" && reg.test(minPrice)) {
$("#minPrice").val(parseFloat($("#minPrice").val()));
} else {
$("#minPrice").val("");
}
var maxPrice = $("#maxPrice").val();
if (maxPrice != "" && reg.test(maxPrice)) {
$("#maxPrice").val(parseFloat($("#maxPrice").val()));
} else {
$("#maxPrice").val("");
}
return true;
})
}
geekSort.tool.brandLength = function(){
var brandLen = $(".filter_brands .filter_brands_li").length;
function brandLenW(){
var winW = $(window).width();
if(brandLen < 12 && winW > 1584){
$(".brand_more").hide();
}else if(brandLen < 9 && winW >1424){
$(".brand_more").hide();
}else if(brandLen < 8 && winW>1350){
$(".brand_more").hide();
} else if(brandLen < 7 && winW<1350){
$(".brand_more").hide();
}else{
$(".brand_more").show();
}
}
brandLenW();
$(window).resize(function(){
brandLenW();
})
}
geekSort.tool.copyCoupon = function(){
function copyCode(){
var i_coupon = $(this).data("coupon");
$('#copyCouponTop').val(i_coupon);
$('#copyCouponTop')[0].select();
document.execCommand("Copy");
$.curContent.gkAlert("The coupon code has been copied successfully",true,"340px","20px");
}
$(".copy_code").on("click",debounce(copyCode,1000,true));
}