navigation.js
5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/**
* 专题页导航
* @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();
}
}
});
};