header.js
14.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
/**
* 头部
* @author: wangqing<robin.wang@yoho.cn>
* @date: 2015/12/01
*/
var $ = require('yoho.jquery');
var noticeSuccess = false;
function JsonPCallBack(data) {
var topbanner;
if (+data.code === 200) {
if (typeof data.data === 'object') {
topbanner = '<a target="_blank" href="' + data.data.url + '" class="page-top-banner"' +
'style="height:50px;border:none;background-image:url(' + window.unescape(data.data.src) + ');' +
'background-position: center;display:block;background-color:#ff5409;"> </a>';
$('body').prepend(topbanner);
}
}
}
function NoticeCallBack(data) {
if (+data.code === 200) {
noticeSuccess = true;
}
}
window.JsonPCallBack = JsonPCallBack;
window.NoticeCallBack = NoticeCallBack;
/**
* 检测是否获得公告
* @return {[type]} [description]
*/
function checkNotice() {
var noticeinner;
if (!noticeSuccess) {
noticeinner = '<div class="noticewrapper">' +
'<div class="noticecontainer">' +
'<h1 class="noticetitle">关于系统升级的公告</h1>' +
'<div class="noticecontent">' +
'<p class="tips">尊敬的顾客:</p>' +
'<p class="detail">您好!为了向您提供更优质的服务,目前系统正在升级,请耐心等待。</p>' +
'<p class="detail">' +
'系统升级期间,部分地区用户体验会有暂时中断,如遇紧急事宜,欢迎垂询客服热线:400-889-9646 09:00-22:30(周一至周日)。稍后系统将恢复正常' +
'</p>' +
'<p class="detail">使用,欢迎您继续光顾YOHO!BUY有货!带来不便之处深表歉意,请您谅解!</p>' +
'</div>' +
'</div>' +
'</div>';
$('.header-topwrapper').append(noticeinner);
}
}
/**
* 获得banner数据
* @param {[string]} code [banner对应的编码]
* @return {[type]} [description]
*/
function getBannerData(code) {
var script = document.createElement('script');
script.src = 'http://new.yohobuy.com/resource/getbanner?content_code=' +
code + '&client_type=web&callback=JsonPCallBack';
document.getElementsByTagName('head')[0].appendChild(script);
}
/**
* 获取公告的jsonp请求
* @param {[type]} code [description]
* @return {[type]} [description]
*/
function getNoticeData(code) {
var script = document.createElement('script');
script.src = 'http://new.yohobuy.com/resource/getbanner?content_code=' +
code + '&client_type=web&callback=NoticeCallBack';
document.getElementsByTagName('head')[0].appendChild(script);
window.setTimeout(checkNotice, 5000); //5s后检测是否成功
}
/**
* 显示和隐藏
* @param {[type]} sourceClass [description]
* @param {[type]} targetClass [description]
* @return {[type]} [description]
*/
function toggleDisplay(sourceClass, targetClass) {
var $that,
targetobj;
$(sourceClass).hover(function(e) {
e.preventDefault();
$that = $(this);
targetobj = $(targetClass)[0];
if (targetobj.style.display === '') {
$that.addClass('acttags');
targetobj.style.display = 'block';
} else {
$that.removeClass('acttags');
targetobj.style.display = '';
}
});
}
/**
* 执行顶部显示和隐藏
* @return {[type]} [description]
*/
function actionTopTagToggle() {
var tags = [{
sourceClass: '.myyoho',
targetClass: '.myyoho-info'
}, {
sourceClass: '.phone',
targetClass: '.qr'
}],
obj,
i;
for (i = 0; i < tags.length; i++) {
obj = tags[i];
toggleDisplay(obj.sourceClass, obj.targetClass);
}
}
/**
* 执行顶部群组鼠标交互
* @return {[type]} [description]
*/
function actionYoHoGroup() {
var $this;
$('.yohogroup').mouseenter(function() {
$this = $(this);
$this.text($this.attr('cn'));
});
$('.yohogroup').mouseleave(function() {
$this = $(this);
$this.text($this.attr('en'));
});
}
/**
* 检测是否支持css3的动画
* @return {Boolean} [description]
*/
function isSupportCss3Animation() {
var thisFunc,
prefixList = ['webkit', 'moz', 'ms'],
i;
for (i = 0; i < prefixList.length; i++) {
thisFunc = prefixList[i] + 'RequestAnimationFrame';
if (window[thisFunc]) {
return true;
} else {
return false;
}
}
}
/**
* css3动画
* @param {Array} ) { var thisFunc, prefixList [description]
* @return {[type]} [description]
*/
function requestFrameCloser() {
var prefixList = ['webkit', 'moz', 'ms'];
var func1 = prefixList[0] + 'RequestAnimationFrame';
var func2 = prefixList[1] + 'RequestAnimationFrame';
var func3 = prefixList[2] + 'RequestAnimationFrame';
if (window[func1]) {
return function(callback) {
window[func1](callback);
};
}
if (window[func2]) {
return function(callback) {
window[func2](callback);
};
}
if (window[func3]) {
return function(callback) {
window[func3](callback);
};
}
return function(callback) {
window.setTimeout(callback, 67);
};
}
window.requestFrame = requestFrameCloser();
window.start = 0;
window.$logotrans = $('.icon-logo');
window.isen = true;
/**
* css3动画
* @return {[type]} [description]
*/
function tsAnimate() {
window.start += 10;
window.$logotrans.css({
transform: 'rotateX(' + window.start + 'deg)',
'-webkit-transform': 'rotateX(' + window.start + 'deg)',
'-moz-transform': 'rotateX(' + window.start + 'deg)'
});
if (window.start / 90 % 2 === 1) {
if (window.isen) {
window.$logotrans.css('background-image', 'url(http://static.yohobuy.com/newheader/img/logo1.png)');
window.isen = false;
} else {
window.$logotrans.css('background-image', 'url(http://static.yohobuy.com/newheader/img/logo_e.png)');
window.isen = true;
}
}
if (window.start / 90 % 2 === 0 && window.start % 360 !== 0) {
window.setTimeout(tsAnimate, 3000);
} else {
if (window.start % 360 === 0) {
window.setTimeout(tsAnimate, 1 * 60 * 1000);
} else {
window.requestFrame(function() {
tsAnimate();
});
}
}
}
window.loopdurationtime = 500;
window.globaltimeout;
window.onetimeoout;
/**
* 淡出
* @return {[type]} [description]
*/
function fadeAnimate() {
if (window.globaltimeout) {
window.clearTimeout(window.globaltimeout);
}
window.logotrans.fadeOut(window.loopdurationtime, function() {
window.isen = false;
window.logotrans.css('background-image', 'url(http://static.yohobuy.com/newheader/img/logo.png)');
window.logotrans.fadeIn(window.loopdurationtime, function() {
window.onetimeoout = window.setTimeout(function() {
window.logotrans.fadeOut(window.loopdurationtime, function() {
window.clearTimeout(window.onetimeoout);
window.isen = true;
window.logotrans.css('background-image', 'url(http://static.yohobuy.com/newheader/img/logo_e.png)');
window.logotrans.fadeIn(window.loopdurationtime, function() {
window.globaltimeout = window.setTimeout(fadeAnimate, 1 * 60 * 1000);
});
});
}, 3000);
});
});
}
/**
* 执行头部logo动画
* @return {[type]} [description]
*/
function actionTopLogoAnimate() {
if (isSupportCss3Animation()) {
window.setTimeout(tsAnimate, 3000);
} else {
window.setTimeout(fadeAnimate, 3000);
}
}
/**
* 查询跳转后保留关键字
* @return {[type]} [description]
*/
function actionAddKeyWords() {
var $keywords = $('#nav_keyword').text();
var defaultsearch = 'vans';
var $querykey = $('#query_key');
if ($keywords !== '') {
$querykey.css({
color: '#000'
});
$querykey.val($keywords);
} else {
$querykey.css({
color: '#e0e0e0'
});
$querykey.val(defaultsearch);
$querykey.on('focus', function(e) {
$querykey.css({
color: '#000'
});
$querykey.val('');
});
}
}
window.dataLayer = [];
function getSource(column, postition, event) {
try {
window.dataLayer.push({
louceng: column,
weizhi: postition,
event: event
});
} catch (e) {}
}
/**
* 搜寻的时候过滤非法字符(+-/:等非法字符单独出现)
* @type {RegExp}
*/
window.reg = /^[\^\!\+\-\(\)\:\[\]\\\{\}\~\*\?\|\&\;\/\s]{0,}$/g;
window.keyword = '';
window.link = '';
window.submitSearch = function() {
var $keywordinput = $('#query_key').val();
var column = 'Search';
var postition = 'Head Search';
var event = 'Search';
var $formatkeyword,
$formatkeywordinput;
$formatkeyword = $.trim(window.keyword.toLowerCase());
$formatkeywordinput = $.trim($keywordinput.toLowerCase());
getSource(column, postition, event);
if (window.link !== '' && window.keyword !== '' && $formatkeyword === $formatkeywordinput) {
location.href = window.link.replace('\'', '');
} else {
if (window.reg.test($keywordinput)) {
location.href = 'http://search.yohobuy.com/error?query=' + $keywordinput + '&result=error';
} else {
$('#searchForm').submit();
return false;
}
}
};
/**
* banner和地址的映射
* @type {Object}
*/
window.bannerMap = {
listboys: '4f78b0f418fc42314d8b6e791cfb7fa8',
listgirls: '00c1f025a51b6b597dc37925951ea27d',
listkids: 'b02df11184727701ade1b6de9737d08c',
listlifestyle: 'fd35c52dced0c880976ba858346d1fc5',
searchboys: '9fb8986ea700cc27a8057361c3924394',
searchgirls: 'e3e207a1443ca60c8037fe52a5560c18',
searchkids: '620fc77f479da8feaeb06f2324e5d0bb',
searchlifestyle: 'a3c93301c6ffaf3ed0f36a4a451be36d',
uniquebrandboys: '2ebb0810c0d1a67e5229149c9c3aba7d',
uniquebrandgirls: '99e23385f4ba4b65f406b7e2968ac821',
uniquebrandkids: 'a74ebc9b17840c91b9ea46568111fe6b',
uniquebrandlifestyle: '0e8c81ead53f56302baa4d0ad967f527',
brandsboys: '77b352db07129c76a9d532acad149f9f',
brandsgirls: 'bf047f16e52ebc38be5ce9c7623831e6',
brandskids: 'e3ae1ce9b5e13c6d271ef3eccb831652',
brandslifestyle: 'e4ac8029c30f65d7f1af030980d140fe',
newboys: '869d3c5f3b450fb52101d00a61ce87cb',
newgirls: 'd953b6dfdac02483d1dcce8d96055954',
newkids: '0874cb6d75df8e0e78f2d475e53ecc08',
newlifestyle: '43e8fc8e178115c262bbce2bd0012db7',
saleboys: 'c846e3165c994769b4201d8c32f3ae9b',
salegirls: '52b1d389edcbc62d65de71b80c4d6ad0',
salekids: 'ad8b1703c761ba00973868ab5199cc27',
salelifestyle: '7acc64905c70ac91846f43fb2cec4bbd',
homeboys: 'b0856a771ef1b59ab1234c74688fa42d',
homegirls: '2bd61fa12e4933211518f70fe5ce3c48',
homekids: '895c59e8c64b40399c9533509507320c',
homelifestyle: '2e037d4e25d2767352ca3e0a4627f7bd',
indexboys: '0c911d3000f52e8ca7cffb74f5864c29',
indexgirls: 'b645b8980c423ab30485e0a9d08c2ef7',
indexkids: '17f6d5d5d454d2c507bc5fcbc90f7756',
indexlifestyle: '735cd393e841762af8793c346abbbc36'
};
/**
* cookie集合
* @type {Object}
*/
window.cookieMap = {};
function actionExeCookieMap() {
var cookies = document.cookie;
var cookiearr = cookies.split(';');
var i;
var temparr;
var key;
for (i = 0; i < cookiearr.length; i++) {
temparr = cookiearr[i].split('=');
key = temparr[0].replace(/\s/g, '');
window.cookieMap[key] = temparr[1];
}
}
/**
* 获得banner & 异常通知
* @return {[type]} [description]
*/
function actionGetBannerAndNotice() {
var INDEXKIDS = 'indexkids',
INDEXLIFESTYLE = 'indexlifestyle',
INDEXBOYS = 'indexboys',
INDEXWOMAN = 'indexgirls',
UNIQUEBRAND = 'uniquebrand';
var url = window.location.href;
var host = window.location.host;
var code = '';
var firstarea;
if (url.indexOf('search') !== -1) {
code = window.bannerMap['search' + window.cookieMap._Channel];
}
if (url.indexOf('list') !== -1) {
code = window.bannerMap['list' + window.cookieMap._Channel];
}
if (url.indexOf('brands') !== -1) {
code = window.bannerMap['brands' + window.cookieMap._Channel];
}
if (url.indexOf('new') !== -1) {
code = window.bannerMap['new' + window.cookieMap._Channel];
}
if (url.indexOf('sale') !== -1) {
code = window.bannerMap['sale' + window.cookieMap._Channel];
}
if (url.indexOf('home') !== -1) {
code = window.bannerMap['home' + window.cookieMap._Channel];
}
if (url.indexOf('kids') !== -1) {
code = window.bannerMap[INDEXKIDS];
}
if (url.indexOf('woman') !== -1) {
code = window.bannerMap[INDEXWOMAN];
}
if (url.indexOf('lifestyle') !== -1) {
code = window.bannerMap[INDEXLIFESTYLE];
}
if (url.indexOf('www.yohobuy.com') !== -1 && window.location.pathname === '/') {
code = window.bannerMap[INDEXBOYS];
}
firstarea = host.split('.')[0];
if (firstarea !== 'list' && firstarea !== 'search' && firstarea !== 'www' &&
firstarea !== 'new' && firstarea !== 'item' && firstarea !== 'guang') {
code = window.bannerMap[UNIQUEBRAND + window.cookieMap._Channel];
}
getBannerData(code); //获得banner信息
getNoticeData(code); //获得公告信息
}
function brandSwitch(index) {
$('.hot-brands').find('ul').stop().animate({
opacity: 0,
'z-index': 1
}, 200).eq(index).animate({
opacity: 1,
'z-index': 2
}, 200);
}
/**
* 品牌左右切换
* @return {[type]} [description]
*/
function actionBrandChange() {
var activeIndex = 0,
swiperLen;
if ($('.hot-brands').size() > 0) {
swiperLen = $('.hot-brands').find('ul').size();
$('.hot-brands').find('ul').eq(0).css({
opacity: 1,
'z-index': 2
});
$('.brands-control').on('click', '.next', function() {
if (activeIndex === swiperLen - 1) {
activeIndex = 0;
} else {
activeIndex++;
}
brandSwitch(activeIndex);
});
$('.brands-control').on('click', '.prev', function() {
if (activeIndex === 0) {
activeIndex = swiperLen - 1;
} else {
activeIndex--;
}
brandSwitch(activeIndex);
});
}
}
/**
* 初始化函数
* @return {[type]} [description]
*/
exports.init = function() {
actionExeCookieMap();
actionYoHoGroup();
actionTopTagToggle();
actionTopLogoAnimate();
actionGetBannerAndNotice();
actionBrandChange();
actionAddKeyWords();
};