yoho_common_new.js 5.6 KB
$(document).ready(function() {
    colorPopupCreate();
});

function colorPopupCreate() {
    popID = "#colorPopBox";
    THUMBWIDTH = 64;
    OPENSPEED = 250;
    COLORSPEED = 200;
    var l = 0;
    if (jQuery.browser.version == "6.0" || jQuery.browser.version == "7.0") {
        var j = "old"
    }
    if (j == "old") {
        COLORSPEED = 0
    }
    if (!$(".popstatus").val()) {
        $(popID).after('<input type="hidden" class="popstatus" value="off" />')
    }
    $(".list").unbind();
    $(".list").hover(function() {
        thisBox = this;
        if ($(thisBox).find(".colorList").html()) {
            idx = $(".list").index(thisBox);
            $(thisBox).mousemove(function(a) {
                if ($(".popstatus").val() == "off") {
                    clearTimeout(l);
                    l = setTimeout(h, OPENSPEED)
                }
            });
            $(popID).hover(function() {
                $(".popstatus").val("on")
            }, function() {
                g("over")
            })
        } else {
            g("over")
        }
    }, function() {
        if ($(".popstatus").val() == "off") {
            g("over")
        } else {
            g()
        }
    });
    function h() {
        clearTimeout(l);
        $(thisBox).children().each(
            function() {
                if ($(this).attr("class") == "expansion") {
                    $(popID + " ." + $(this).attr("class") + " a").hide();
                    $(
                        popID + " ." + $(this).attr("class") + " a:eq("
                        + idx + ")").show()
                } else {
                    $(popID + " ." + $(this).attr("class")).html(
                        $(this).html())
                }
            });
        $(popID + " .color").html(
            k($(thisBox).find(".colorList img:first").attr("alt"))).hide();
        $(popID + " .colorList").html($(thisBox).find(".colorList").html());
        i = 0;
        row = 4;
        var a = thumb = new Array();
        $(popID + " .colorList").find("a").each(function(b) {
            a[b] = new Image();
            a[b].src = $(this).attr("rel");
            thumb[b] = new Image();
            thumb[b].src = $(this).find("img").attr("src");
            $(this).wrap("<li></li>")
        });
        for (i = 0; i < $(popID + " .colorList").find("li").size(); i = i + row) {
            $(popID + " .colorList").find("li").slice(i, i + row).wrapAll(
                '<ul style="float: left; width: ' + (THUMBWIDTH + 1)
                + 'px;"></ul>')
        }
        $(popID + " .colorList")
        .html(
            '<div class="cf">' + $(popID + " .colorList").html()
            + "</div>");
        ulSize = $(popID + " .colorList").find("ul").size(); 
        colorListWidth = ulSize * (THUMBWIDTH) + ulSize; 
        if (j == "old") {
            windowSize = $(thisBox).width() + colorListWidth + 16;
            $(popID).width(windowSize)
        }
        $(popID + " .colorList").width(0);
        $(popID + " .colorList > div").width(colorListWidth);
        pos = $(thisBox).offset();
        spw = 60; 
        /*mdodify by csj at 20130128
		$(popID + " .innerDetail").width($(thisBox).width()).height(
            $(thisBox).height());
		*/
		$(popID + " .innerDetail").width($(thisBox).width()+1).height(
            $(thisBox).height());
        if ($("body").width() < ($(thisBox).width() + pos.left + colorListWidth + spw)) {
            pos.left = $("body").width() - $(thisBox).width() - colorListWidth
            - spw
        }
		/*end*/
		/*add by csj at 20130128*/ 
		//pos.left = pos.left - 1;
		/*end*/

        /*add by csj at 20130528*/ 
        pos.top = pos.top - $("#searchResultList").offset().top;
        pos.left = pos.left - $("#searchResultList").offset().left;

        var popDivWidth = $(thisBox).width()+ 1 + colorListWidth + 20;
        $(popID).width(popDivWidth);
        //end 20130528

        $(popID).css({
            top : pos.top + "px",
            left : pos.left + "px"
        });
        $(".popstatus").val("on");
        $(popID).show();
        $(popID + " .color").fadeIn(COLORSPEED);
        $(popID + " .colorList")
        .animate(
        {
            width : colorListWidth + "px"
        },
        COLORSPEED,
        function() {
            $(popID + " .colorList ul")
            .find("li")
            .each(
                function() {
                    $(this)
                    .find("a")
                    .mouseover(
                        function() {
                            $(
                                popID
                                + " .thumb img")
                            .attr(
                                "src",
                                $(
                                    this)
                                .attr(
                                    "rel"));
                            $(
                                popID
                                + " .color")
                            .html(
                                k($(
                                    this)
                                .find(
                                    "img")
                                .attr(
                                    "alt")))
                        })
                })
        })
    }
    function g(a) {
        $(".popstatus").val("off");
        clearTimeout(l);
        $(popID + " .color").clearQueue();
        $(popID + " .colorList").clearQueue();
        if (a) {
            $(popID + " .colorList").width(0);
            $(popID + " .color").html("").hide();
            $(popID).hide()
        }
    }
    function k(a) {

        return a
    }
}