navigation.js 5.9 KB
/**
 * 专题页导航
 * @author jiangchengyong
 */
$(function() {
	// 渲染头部导航
	jQuery.ajax({
		url : DiliPath.homePath + "common/navigation.html",
		type : "POST",
		dataType : "jsonp",
		jsonp:'callFn',
		success : function(result) {
			if(result){
				var navigationHtml = [];
				for ( var i = 0; i < result.length; i++) {
					navigationHtml.push("<li id='navigation" + (i+1) + "'><a href='" + result[i].link
							+ "' target='_blank'>" + result[i].text + "</a></li>");
				}
				$("#navigationli").append(navigationHtml.join(""));
				
				if (window.pageConfig) {
					productCategory();
					$("#"+pageConfig.navId).addClass("on");
				}else{
					productCategory();
				}
			}
		}
	});
	
	/**
	//获取右侧标题
	jQuery.ajax({
		url : DiliPath.homePath + "common/navRightTitle.html",
		type : "POST",
		dataType : "jsonp",
		jsonp:'callFn',
		success : function(result) {
			if(result&&result.length>0){
				$("#navRightTitle").html(result[0].text);
			}
		}
	});
	//获取右侧内容
	jQuery.ajax({
		url : DiliPath.homePath + "common/navRightContent.html",
		type : "POST",
		dataType : "jsonp",
		jsonp:'callFn',
		success : function(result) {
			if(result&&result.length>0){
				var html='';
				for (var i = 0; i < result.length; i++) {
					if(i>4){
						break;
					}
					html += '<a href="'+result[i].link+'" target="_blank">'+result[i].text+'</a>'
				}
				$("#navRight").append(html);
			}
		}
	});
	**/
	
});

var bindCategoryEvent = function(){
	 //导航菜单
    var Nav = {
        open:function( target ){ 
            var _target = $( target );
            _target.addClass( 'current' ).siblings().removeClass( 'current' );

        },
        close:function( target ){
            var _target = $( target );

        },
        closeAll:function( ){
            $( '#menu-box' ).find( '>li.current' ).removeClass( 'current' );

        }
    }
    if(  $( '#menu-box' ).length > 0 ){
        $( '#menu-box' ).menuAim({
            // enter: Nav.open,
            activate: Nav.open,
            deactivate:Nav.close,
            exitMenu:Nav.closeAll
        });
        var _timer = null;
        
        $( '.multistage-menu' ).hover(function(){
			var _this = $( this );
			var menuList = $(this).find(".menu-list");
			
			if( menuList.is( ':hidden' ) && !$( _this ).hasClass( 'indexNav' ) ){
				 menuList.show();
				 $( _this ).addClass( 'selected' );
			}
		},function(){
			var _this = $( this );
			var menuList = $(this).find(".menu-list");
			
			if( !menuList.is( ':hidden' ) && !$( _this ).hasClass( 'indexNav' ) ){
				 menuList.hide();
				 $( _this ).removeClass( 'selected' );
			}
		});
        
    }
}

var productCategory = function(){
	jQuery.ajax({
		url : DiliPath.homePath + "common/categoryInfo.html",
		type : "POST",
		data : {type:1},//1:首页分类标题 2:产地直供产地标题
		dataType : "jsonp",
		jsonp:'callFn',
		success : function(result) {
			if(result && result.length>0){
				$(".col-fff").html("<a class='col-fff' href='"+result[0].link+"' target='_blank'>"+result[0].text+"</a>");
			}
		}
	});
	
	var categoryUrl = function(category){
		if(category.contentType == 0){
			return "http://www.nong12.com/search.html?category="+category.content;
		}else if(category.contentType == 1){
			return "http://www.nong12.com/search.html?key="+encodeURI(encodeURI(category.content));
		}else if(category.contentType == 2){
			return category.content;
		}
	}
	
	// 渲染商品分类
	jQuery.ajax({
		url : DiliPath.homePath + "common/category.html",
		type : "POST",
		dataType : "jsonp",
		jsonp:'callFn',
		success : function(first_category) {
			if(first_category && first_category.length>0){
				var html = [];
				// 遍历一级分类
				for ( var i = 0; i < first_category.length; i++) {
					if(i < 6){
						var cat_dl_html = [];
						// 二级分类扩展字段
						var second_category = first_category[i].subNode;
						html[i] = '<li><div class="menu-title clearfix">';
						html[i] += '<span class="menu-icon ll"><img src="'+first_category[i].icon+'" isoriginal="true" alt="'+first_category[i].name+'"></span>';
						html[i] += '<div class="titles"><a href="'+categoryUrl(first_category[i])+'" class="b-title" title="'+first_category[i].name+'">'+first_category[i].name+'</a><p>';
						if (second_category != null) {
							// 遍历二级分类
							for ( var j = 0; j < second_category.length; j++) {
								html[i] += '<a href="'+categoryUrl(second_category[j])+'" target="_blank" title="'+second_category[j].name+'">'+second_category[j].name+'</a>';
							}
						}
						html[i] += '</p></div><span class="icon-arrow"></span></div>';
						html[i] += "<div class='menu-lists'>";
						if (second_category != null) {
							// 遍历二级分类
							for ( var j = 0; j < second_category.length; j++) {
									cat_dl_html[j] = "<dl><dt><a href='" + categoryUrl(second_category[j]) + "'  target='_blank' title='"+second_category[j].name+"'>" + second_category[j].name + "</a></dt><dd>";
									var cat_dt_html = [];
									// 三级分类扩展字段
									var third_category = second_category[j].subNode;
									// 遍历三级分类
									for ( var k = 0; k < third_category.length; k++) {
										// 遍历三级分类内容
										for ( var h = 0; h < third_category.length; h++) {
											if(h == third_category.length-1){
												cat_dt_html[h] = "<a class='last' href='"+ categoryUrl(third_category[h])+ "' target='_blank' title='"+third_category[h].name+"'>"+ third_category[h].name+ "</a>";
											}else{
												cat_dt_html[h] = "<a href='"+ categoryUrl(third_category[h])+ "' target='_blank' title='"+third_category[h].name+"'>"+ third_category[h].name+ "</a>";
											}
										}
									}
									cat_dl_html[j] += cat_dt_html.join("");
									cat_dl_html[j] += "</dd></dl>";

							}
						}
						html[i] += cat_dl_html.join(""); 

						html[i] += "</li>";
					}
				}
				$(".menu-list ul").append(html.join(""));
				bindCategoryEvent();
			}
		}
	});
	
};