You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

491 lines
16 KiB
JavaScript

(function(win, UI, undefined) {
if (win[UI] === undefined) {
win[UI] = {};
} else {
return;
}
UI = win[UI];
$.extend(UI, {
laterEvent: function(fn, times, me) {
if (me.sleepid) {
clearTimeout(me.sleepid);
}
me.sleepid = setTimeout(fn, times);
},
popWinA: function(s, op) {
op = $.extend(op || {}, {
opener: ".opener",
openerC: ".openerC",
addClass: "now"
});
$(s).each(function() {
var objOpner = $(this).find(op.opener),
objC = $(this).find(op.openerC);
$(this).hover(function() {
objOpner.addClass(op.addClass);
objC.show();
}, function() {
objOpner.removeClass(op.removeClass || op.addClass);
objC.hide();
});
});
},
popWinB: function(s, hover) {
var objOpner = $("." + s + " .opener");
var objShuter = $("." + s + " .shuter");
if (hover == false) {
if (objOpner.length) {
objOpner.click(function() {
if ($(this).parents(".over").length) {
$(this).parents("." + s).removeClass("over");
}
else {
$("." + s).removeClass("over");
$(this).parents("." + s).addClass("over");
}
});
}
if (objShuter.length) {
objShuter.click(function() {
$(this).parents("." + s).removeClass("over");
});
}
}
if (hover == true) {
if ($.browser.msie) {
objOpner.parents("." + s).hover(
function() {
$(this).addClass("over");
}, function() {
$(this).removeClass("over");
});
} else {
objOpner.parents("." + s).mouseover(
function() {
$(this).addClass("over");
}).mouseout(function() {
$(this).removeClass("over");
});
}
}
},
childUntil: function(expr, obj) {
if (obj.length == 0) return null;
var child = obj.children(expr);
if (child.length == 0) {
return arguments.callee(expr, obj.children());
} else {
return child;
}
},
defaultText: function(op) {
op = $.extend(op || {}, {
hasDefaultText: ".hasDefaultText",
removeClass: "hasDefaultText",
addClass: "hasDefaultText"
});
var obj = $(op.hasDefaultText);
var tmpText = new Array();
var objIndex = 0;
for (i = 1; i <= obj.length; i++) {
tmpText[i - 1] = obj.eq(i - 1).attr("tip") ? obj.eq(i - 1).attr("tip") : obj.eq(i - 1).val();
obj.eq(i - 1).attr("tip", tmpText[i - 1]);
}
obj.focus(function() {
objIndex = obj.index($(this));
if ($(this).val() == $(this).attr("tip")) {
$(this).val("");
}
$(this).removeClass(op.removeClass);
});
obj.blur(function() {
objIndex = obj.index($(this));
if ($(this).val() == "") {
$(this).val($(this).attr("tip"));
$(this).addClass(op.addClass);
}
});
}
});
})(window, "UI");
var tabPanel = function(obj) {
obj.each(function() {
var $this = $(this),
tabc = UI.childUntil(".tabc", $this.parent());
$this.children("a:not([rel*='link'])").add($this.find(".tabitem")).each(function(n) {
$(this).attr("rel", n);
}).mouseenter(function() {
if ($this.attr("trigger") == "click") { return false; }
$(this).addClass("now").siblings().removeClass("now");
$(this).siblings("b[class*=hide]").removeClass("hide");
$(this).prev("b").addClass("hide").andSelf().next("b").addClass("hide");
tabc.hide().eq(parseInt($(this).attr("rel"))).show();
if ($(this).attr("command")) {
eval($(this).attr('command') + "(this)");
}
}).click(function() {
if ($this.attr("trigger") != "click") { return true; }
$(this).addClass("now").siblings().removeClass("now");
tabc.hide().eq(parseInt($(this).attr("rel"))).show();
//if($(this).prev().is("input")){$(this).prev().attr("checked","checked")}
if ($(this).attr("command")) {
eval($(this).attr('command') + "(this)");
}
//return false;
});
});
}
tabPanel($(".tab"));
/***
* Customized Select Menu
* Version: 0.0.1
* Last Update: 2013.05.30
* Author: Sean Huang
* Modified By: Teller Shen, Dan Yang
* JQuery Requires: 1.6.2+
* JS Method Requires: UI.laterEvent()
* CSS Style Requires: .select
* Call Method: bindSelect() or bindSelect("#id .select") or bindSelect($("#id .select"))
***/
var bindSelect = function(_obj) {
var obj = (arguments.length != 0) ? $(_obj) : $(".select");
obj.mouseenter(function() {
if (this.sleepid) {
clearTimeout(this.sleepid);
}
}).mouseleave(function() {
var me = $(this);
UI.laterEvent(function() {
me.css({ zIndex: 0 }).removeClass("select_expand").find("dd").hide();
me.parents("li").css({ zIndex: 0 });
$("object").show();
}, 200, this);
}).delegate("dd a", "click", function() {
var curselect = $(this).parents(".select");
if (this.selected == "selected") {
curselect.parents("li").css({ zIndex: 0 });
$(this).parents("dd").hide();
return;
}
var text = $(this).html();
$(this).parents("dd").prev("dt").find("a").html(text);
$(this).parents("dd").find("a").each(function() {
this.selected = "";
});
this.selected = "selected";
$(this).parent().addClass("selected").siblings("li").removeClass("selected");
curselect.parents("li").css({ zIndex: 0 });
curselect.siblings("input[name='" + curselect.attr("name") + "']").val($(this).attr("value"));
curselect.removeClass("select_expand").trigger("change");
$(this).parents("dd").hide();
$("object").show();
}).end().find("dt").click(function() {
var curselect = $(this).parent(".select");
if (curselect.is(".disabled")) { return false; }
curselect.css({ zIndex: 1 }).find("dd").toggle();
curselect.toggleClass("select_expand");
curselect.parents("li").css({ zIndex: 1 });
$("object").hide();
//Start: Options Width & Height Fix
var ul_w = curselect.find("ul").width();
var ul_h = curselect.find("ul").height();
var dt_w = curselect.width();
if (ul_h > 300) {
ul_w += 15;
ul_h = 300;
}
if (ul_w < dt_w) {
curselect.find("ul").css({ width: dt_w });
ul_w = dt_w;
}
curselect.find("dd").css({ width: ul_w, heigth: ul_h });
//End: Options Width & Height Fix
});
obj.each(function() {
var val = $(this).find("dt a").html();
$(this).find("dd a").each(function() {
if ($(this).html() == val) {
this.selected = "selected";
var curselect = $(this).parents(".select");
$(this).parent().addClass("selected");
curselect.siblings("input[name='" + curselect.attr("name") + "']").val($(this).attr("value"));
}
});
});
}
$(function() {
/* Default Input Place Holder */
UI.defaultText();
$("#header .searchbar .intxt").focusin(function() {
$("#header .searchbar").addClass("searchbar_now");
if ($.browser.msie && $.browser.version != "6.0") {
$("#header .searchbar .intxt").animate({
width: 138
}, 200);
}
}).focusout(function() {
if ($(this).val() == "") {
$("#header .searchbar").removeClass("searchbar_now");
if ($.browser.msie && $.browser.version != "6.0") {
$("#header .searchbar .intxt").animate({
width: 107
}, 200);
}
}
});
//mycart;
$(".mycart").hover(function() {
var $this = $(this);
UI.laterEvent(function() {
$this.addClass("expand");
/*if ($this.find("li").length == 0) {
$this.find("dd").hide();
} else {
$this.find("dd").show();
}*/
}, 200, this);
}, function() {
var $this = $(this);
UI.laterEvent(function() {
$this.removeClass("expand");
}, 200, this);
});
var init_mycart = function(obj) {
var mycartpage = 1;
var mycartcur = 1;
var $this = $(obj),
totalnum = $this.find("li").length,
numperpage = 5,
temp = $this.find("ul");
mycartpage = Math.ceil(totalnum / numperpage)
var app = function() {
temp = $("<ul />").append(temp.find("li:gt(" + (numperpage - 1) + ")")).appendTo($this.find(".mover"));
if (temp.find("li").length > numperpage) {
app();
}
}
mycartpage > 1 && app();
$this.find(".navi .num").text(mycartcur + "/" + mycartpage);
if (mycartpage > 1) {
$this.find(".inner").css({
height: 305
});
}
$this.find("li").hover(function() {
$(this).addClass("hover");
}, function() {
$(this).removeClass("hover");
});
UI.Xslider(obj, {
numtoMove: 1,
unitLen: 343,
viewedSize: 343,
scrollObj: ".mover",
scrollunits: "ul",
beforeStart: function(e) {
if ($(e.eventTrigger).is(".aleft")) {
mycartcur--;
} else {
mycartcur++;
};
$this.find(".navi .num").text(mycartcur + "/" + mycartpage);
}
});
}
init_mycart(".mycart");
//category;
var category = $(".category"),
categoryTop = category.length && category.offset().top,
categoryH = 390;
$(".category").hover(function() {
if (category.find(".innerwrap").length == 0) { return false; }
var $this = $(this);
UI.laterEvent(function() {
$this.addClass("now");
}, 200, this);
}, function() {
if (category.find(".innerwrap").length == 0) { return false; }
var $this = $(this);
UI.laterEvent(function() {
$this.removeClass("now");
}, 200, this);
});
$(".category").not(".categoryall").find(".item").hover(function() {
var $this = $(this);
UI.laterEvent(function() {
$this.addClass("expand");
//fix position;
if ($this.data("inited")) { return; }
var oftop = $this.offset().top,
ddH = $this.find("dd").outerHeight(),
absTop = oftop - categoryTop,
top;
if (ddH > categoryH) {
top = -absTop
} else if (absTop + ddH > categoryH) {
top = categoryH - (absTop + ddH) - 1
}
$this.find("dd").css({
top: top
});
$this.data("inited", true);
}, 200, this);
}, function() {
var $this = $(this);
UI.laterEvent(function() {
$this.removeClass("expand");
}, 120, this);
});
$(".topnav").find(".expand").hover(function() {
$(this).addClass("ex_hover");
}, function() {
$(this).removeClass("ex_hover");
});
//back to the top;
var toRight = ($(window).width() - 980) / 2 - 60;
toRight = toRight > 0 ? toRight : 0;
$(".toTop").click(function() {
$($.browser.safari || document.compatMode == 'BackCompat' ? document.body : document.documentElement).animate({
scrollTop: 0
}, 200);
return false;
}).css({
right: toRight
});
$(window).bind("scroll resize", function() {
var sctop = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
toRight = ($(window).width() - 980) / 2 - 60;
toRight = toRight > 0 ? toRight : 0;
if (sctop > 130) {
$(".toTop").css({
right: toRight
}).fadeIn(300);
} else {
$(".toTop").fadeOut(400);
}
});
$(".fadeSiblings").children().css({
"background-color": "#000",
"display": "block"
}).hover(function() {
$(this).siblings().find("img").stop().animate({ opacity: 0.5 }, 600);
}, function() {
$(this).siblings().find("img").stop().animate({ opacity: 1 }, 400);
});
$(".pageNav").find(".intxt").focusin(function() {
$(this).siblings(".btn_confirm").css("display", "inline-block");
}).focusout(function() {
if ($.trim($(this).val()) != "") {
return false;
}
$(this).siblings(".btn_confirm").css("display", "none");
});
contH = $("#topbar").height() + $("#header").height() + 10 + $("#main").height() + $("#footer").outerHeight() + 77;
setFmargin = function() {
var winH = $(window).height();
var margin = winH > contH ? winH - contH : 0;
$("#footer").css({
"margin-top": 77 + margin
});
}
setFmargin();
$(window).bind("resize", function() {
setFmargin();
});
$(".inputhover").live("focusin", function() {
$(this).addClass("intxtfocus");
}).live("focusout", function() {
$(this).removeClass("intxtfocus");
});
//select;
$(".select").click(function() {
if ($(this).is(".disable")) { return false; }
$(this).find("dd").toggle();
$(this).parents("li").andSelf().css({ zIndex: 1 });
}).mouseleave(function() {
$(this).find("dd").hide();
$(this).parents("li").andSelf().css({ zIndex: 0 });
}).find("dd a").click(function() {
var text = $(this).html();
var val = $(this).attr('val');
var temp = $(this).parents("dd").prev("dt").find("a");
temp.html(text);
temp.attr('val', val);
});
//prolist hover effect;
$(".prolist").find(".pro").hover(function() {
$(this).addClass("hover");
}, function() {
$(this).removeClass("hover");
});
if (typeof PopWin != "undefined") {
var youke = PopWin("#youke", {
animate: true,
olOpacity: 0.5,
callback: function() {
try {
DD_belatedPNG.fix('#youke .ie6png2');
} catch (e) { }
}
});
$(".btn_youke").click(function() {
youke.fn.popIn();
return false;
});
}
$("#searchtype dd a").click(function() {
var me = $(this);
if (me.attr("value") == 0) {
$(".searchbar .formsel2").hide();
$(".searchbar .formtext").show();
} else {
$(".searchbar .formsel2").show();
$(".searchbar .formtext").hide();
}
})
});