map_pad.js 3.49 KB
/**
 * @fileOverview 首页JS
 * @author wei.wang@yoho.cn
 * @date 2014-05-21
 */

	var $=require("jquery");
	//require("lib/ui/touch");
	//require("lib/util/jquery.hammer");
	require("../public");
	require("jquery.imagesloaded");
	var currentZoom=0.85;
	var OriginalWidth=0,OriginalHeight=0,OriginalMarks={};
	window.onresize=function(){
		initShopListHeight();
		var bodyWidth=document.body.clientWidth;
		 $("#citymap").width(bodyWidth-$(".city-shop-list").width());
		var contentWidth = $(".map-city-content").width();
		var currentLeft=parseFloat(contentWidth-$("#citymap").width());
	
		$("#citymap").css({"left":currentLeft,top:0});
	}
	exports.init=function(){
		initShopListHeight();
	
		$(".city-list").find("div").niceScroll();
		$(document.body).css({overflow:"hidden"});
		var bodyWidth=document.body.clientWidth;
		$("#citymap-img").imagesLoaded(function()
	       {
		   $(this).width("100%").height("100%");
	       });
		$(".shop").hover(
			function(){
				$(".mark-tips").hide();
				var shopId=$(this).id().replace("shoplist-","mark");
				var shopObj=$("#"+shopId);
				var top=0;
				var left=0;
				var _top=parseFloat($("#"+shopId)[0].style.top.replace("%",""));
				var _left=parseFloat($("#"+shopId)[0].style.left.replace("%",""));
				top=_top/100*$("#citymap").height();
				left=_left/100*$("#citymap").width();

				console.log(top,left);
				console.log(bodyWidth-shopObj.offset().left);
				if(top<120&&left<250){
					//显示在右下角
					
					$("#"+shopId).find(".mark-tips").attr("class","mark-tips left-bottom");
				}
				else if(top>120&&left<250)
				{
					//显示在右上角
					
					$("#"+shopId).find(".mark-tips").attr("class","mark-tips left");
				}
				else if(top<120&&left>250&&bodyWidth-shopObj.offset().left>250)
				{
					//显示在左下角
					
					$("#"+shopId).find(".mark-tips").attr("class","mark-tips left-bottom");
				}
				else if (top<120&&left>250&&bodyWidth-shopObj.offset().left<250) {
					$("#"+shopId).find(".mark-tips").attr("class","mark-tips right-bottom");
				}
				else if(top>120&&left>250&&bodyWidth-shopObj.offset().left>250)
				{
					//显示在左角
					$("#"+shopId).find(".mark-tips").attr("class","mark-tips left");
				}
				else if(top>120&&left>250&&bodyWidth-shopObj.offset().left<250)
				{
					//显示在左角
					$("#"+shopId).find(".mark-tips").attr("class","mark-tips right");
				}
				$("#"+shopId).find(".mark-tips").show().unbind().click(function(){
					var href=$("a[val='"+$(this).parent().attr("val")+"']").attr("src");
					window.open(href);
					
				});
				

			},
			function(){
				var shopId=$(this).id().replace("shoplist-","mark");
			}
		);
		$("#citymap-img").width("100%").height("100%");
		
		var bodyHeight = document.body.clientHeight - 177;
        $(".map-city-content").height(bodyHeight);
        $("#citymap").width(bodyWidth-$(".city-shop-list").width());
        var contentWidth = $(".map-city-content").width();
        var currentLeft=parseFloat(contentWidth-$("#citymap").width());

        $("#citymap").css({"left":currentLeft,top:0});
        var currentTop=parseFloat($("#citymap").css("top").replace("px",""));

	};
	
	function initShopListHeight(){
			var currentWidth=document.body.clientWidth;
			
			if(currentWidth>=1190)
			{
				$(".city-list").height(document.body.clientHeight-310);
			}
			else if(currentWidth<1190&&currentWidth>=769)
			{
				$(".city-list").height(document.body.clientHeight-260);
			}
			else if(currentWidth<=768)
			{
				$(".city-list").height(document.body.clientHeight-268);
			}
	}