channel.js
23.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
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
define('channel', function(require, exports) {
var swipe = require("plugins/swipe"),
swiper = require("plugins/idangerous.swiper"),
$ = require("jquery"),
freetile = require("lib/ui/jquery.freetile"),
share = require('plugins/share');
require("plugins/pagination");
require("plugins/imgZoom");
require("plugins/slider");
require("lib/jquery.validate");
function setLayout() {
$('.fluid-list-inner').freetile({
animate: false,
elementDelay: 0
});
};
function getTopProduct(gender) {
$.ajax({
type: "post",
url: '/default/getTopProduct',
data: {
gender: gender
},
dataType: "json",
success: function(data) {
if (data.code == 200) {
var html = '';
var pos = 1;
var number_class = '';
var number = '';
$.each(data.data, function(key, val) {
if (pos == 1) {
number_class = 'number_1';
number = '';
} else {
number = pos;
number_class = 'number_2';
}
html += '<li><div class="goods-image">' +
'<img src="' + val.product_img + '" alt=""/>' +
'<span class="' + number_class + '">' + number + '</span></div>' +
'<h3><a target="_blank" href="' + val.product_url + '">' + val.product_name + '</a></h3><p>人气: ' + val.sale_sum + '</p></li>';
pos++;
});
$(".show-goods-list").html('<ul>' + html + '</ul>');
}
}
});
};
exports.common = function() {
var goodsSwiper,
limitedPrev,
limitedNext,
swiperLen,
shareUrl,
shareCover,
detailTitle,
detailSubtitle;
// 弹窗关闭
$(document).click(function() {
$('.dialog-w').hide();
});
$('.dia-content').click(function(e) {
e.stopPropagation();
});
//导航动画效果
$('.nav').on('click', 'li', function() {
$(this).addClass('current');
});
if (navigator.userAgent.indexOf('iPad') === -1) {
$('.nav').on('mouseenter', 'li', function() {
$(this).addClass('animate');
}).on('mouseleave', 'li', function() {
$('.nav').find('li').removeClass('animate');
});
}
/**
* 首页顶部 banner 滑动条
*/
({
bannerSwiper: new swiper('.slide-box', {
autoplay: 4000,
loop: true,
wrapperClass: 'slide-wrap',
slideClass: 'box',
slidesPerView: 'auto',
loopedSlides: $(".slide-box").find(".box").size(),
onSlideChangeEnd: function(swiper) {
var activeIndex = swiper.activeIndex,
len = $('.dib a').size(),
pos = (activeIndex - 1) % len;
$('.dib a').removeClass('on').eq(pos).addClass('on');
}
}),
init: function() {
var swiper = this.bannerSwiper;
$('.slide-box-warp .slide-prev').on('click', function(e) {
e.preventDefault();
swiper.swipePrev();
});
$('.slide-box-warp .slide-next').on('click', function(e) {
e.preventDefault();
swiper.swipeNext();
});
}
}).init();
//限量商品滑动
// limitedPrev = $('.limited-slide-prev');
// limitedNext = $('.limited-slide-next');
// swiperLen = $('.limited-slide-box').find('.box').size();
// goodsSwiper = swipe.init({
// slideBox: '.limited-slide-box',
// prev: '.limited-slide-prev',
// next: '.limited-slide-next',
// auto: false,
// callback: function(index, element) {
// limitedPrev.removeClass('disable');
// limitedNext.removeClass('disable');
// console.log(index);
// console.log(swiperLen);
// if (index === swiperLen - 1) {
// limitedNext.addClass('disable');
// };
// if (index === 0) {
// limitedPrev.addClass('disable');
// };
// }
// });
//tab
$('.content-tab').on('click', 'li', function() {
var nowIndex = $(this).index();
$(this).addClass('current').siblings().removeClass('current');
$('.content-main').hide().eq(nowIndex).show();
});
//回到顶部
$(window).scroll(function() {
if ($(window).scrollTop() > 100) {
$(".return-top").fadeIn(500);
} else {
$(".return-top").fadeOut(500);
}
});
$(".return-top").click(function() {
$('body, html').animate({
scrollTop: 0
}, 500);
return false;
});
//使用瀑布流布局
setLayout();
if ($('.share').size() > 0) {
//微信分享鼠标事件
$('.yohoo-share-button-wx').on('mouseover', function() {
$('.wx-qrcode-dialog').show();
}).on('mouseout', function() {
$('.wx-qrcode-dialog').hide();
});
shareUrl = $(".share").attr("data-link");
shareCover = $(".share").attr("cover-url");
detailTitle = $('.detail-title').find('h2');
detailSubtitle = $('.detail-title').find('h3');
//分享
share.init({
shareUrl: shareUrl,
img: shareCover,
sinaText: '【YO’HOOD 2016】' + detailTitle.text() + '\r\n' + detailSubtitle.text() + '@YOHO!潮流志' + shareUrl,
fbTextFunction: function() {
return {
des: '【YO’HOOD 2016】' + detailTitle.text() + '\r\n' + detailSubtitle.text() + '#YO’HOOD 2016',
name: '【YO’HOOD 2016】' + detailTitle.text() + '\r\n' + detailSubtitle.text() + '#YO’HOOD 2016',
caption: '【YO’HOOD 2016】' + detailTitle.text() + '\r\n' + detailSubtitle.text() + '#YO’HOOD 2016',
url: location.href
}
},
tweetText: '【YO’HOOD 2016】' + detailTitle.text() + '\r\n' + detailSubtitle.text(),
qqText: '【YO’HOOD 2016】' + detailTitle.text() + ' ' + detailSubtitle.text() + shareUrl,
});
}
// 表单验证
if ($('#index-form').length > 0) {
$('#index-form').validate({
focusInvalid: false,
onkeyup: false,
rules: {
indexName: {
required: true
}
},
messages: {
indexName: {
required: '必填'
}
},
submitHandler: function(form) {
form.submit();
}
});
}
};
//yohood展会页面
exports.exhibition = function() {
swipe.init({
slideBox: '.slide-box-exhibition',
prev: '.slide-prev-exhibition',
next: '.slide-next-exhibition',
pagination: '.dib a',
activeClass: 'on',
auto: 3000,
continuous: true
});
};
//首页
exports.index = function() {
if ($('.slide-box').find('.box').size() <= 1) {
$('.slide-navigator').hide();
$('.slide-control').hide();
}
var sortPos = 0;
var productGenders = [];
var currentGenderPos = 0;
var productListNames = [];
var cooperateSwiper,
cooperatePrev,
cooperateNext,
swiperLen,
changeCooperationClass;
/**
* 将 资讯页面的 固定 banner 位插入资讯右侧
*/
({
init: function() {
var rightBanner = $("#right_banner_warp .right-banner")[0],
$banners = $(rightBanner).find(".image-box"),
len = $banners.length,
$pageContent = $("#content"),
$layoutItems = $pageContent.find(".layout-item"),
placeholderItems = "";
if (len <= 0) {
return;
}
if ($layoutItems.length < 2) {
placeholderItems = "<div class='fluid-item layout-item tiled'></div>";
placeholderItems += placeholderItems;
$pageContent.prepend($(placeholderItems));
$layoutItems = $pageContent.find(".layout-item");
}
$(rightBanner).insertAfter($layoutItems[1]);
//插入新元素、重新瀑布流布局
setLayout();
}
}).init();
/**
* 页面所有标题为两行的资讯、调整内容margin 使得所有资讯内容对齐
*/
({
/**
* 获取元素计算后CSS样式
* @param {HTMLElement} element 要获取计算后CSS样式的元素
* @return {CSSStyleDeclaration} 计算后的CSS样式
*/
getComputedStyle: function(element) {
if (typeof window.getComputedStyle === "function") {
return window.getComputedStyle(element, null);
} else {
return element.currentStyle;
}
},
init: function() {
var content = $("#content"),
volupia = content.find(".volupia"),
style = null;
i = 0,
len = 0;
for (i = 0, len = volupia.length; i < len; i++) {
style = this.getComputedStyle(volupia[i]);
if (parseInt(style.height) > 30) {
$(volupia[i]).next(".text-content").css("margin", "20px 0 0 0");
}
}
}
}).init();
if ($(".show-goods").size() > 0) {
productGenders = $(".show-goods").attr("product_genders").split(',');
currentGenderPos = $(".show-goods").attr("current_gender_pos");
productListNames = $(".show-goods").attr("product_list_names").split(',');
getTopProduct(productGenders[currentGenderPos]);
}
/**
* 首页底部合作商滑动条
*/
({
cooperateSwiper: new swiper('.cooperation-slide-box', {
wrapperClass: 'slide-wrap',
loop: true,
slideClass: 'box',
slidesPerView: 'auto',
loopedSlides: 4
}),
clearOtherSlideStyle: function(swiper) {
var slides = swiper.slides,
i = 0,
len = 0;
for (i = 0, len = slides.length; i < len; i++) {
slides[i].style = null;
}
},
nextChagneSileSize: function(swiper) {
var activeIndex = swiper.activeIndex,
slides = swiper.slides,
activeSlide = slides[activeIndex],
nextSlide = slides[activeIndex + 1],
nextNextSlide = slides[activeIndex + 2];
if (/big\-size/.test(nextNextSlide.className)) {
nextSlide.style.width = "1180px";
}
},
prevChangeSlideSize: function(swiper) {
var activeIndex = swiper.activeIndex,
slides = swiper.slides,
activeSlide = slides[activeIndex],
prevSlide = slides[activeIndex - 1];
if (/big-size/.test(activeSlide.className)) {
prevSlide.style.width = "1180px";
}
},
init: function() {
if ($(".cooperation").size() <= 0) {
return;
}
var swiper = this.cooperateSwiper,
prevChangeSlideSize = this.prevChangeSlideSize,
nextChagneSileSize = this.nextChagneSileSize,
clearOtherSlideStyle = this.clearOtherSlideStyle,
firstSlide = swiper.slides[swiper.activeIndex],
secondSlide = swiper.slides[swiper.activeIndex + 1];
$('.cooperation-slide-prev').on('click', function(e) {
e.preventDefault();
clearOtherSlideStyle(swiper);
prevChangeSlideSize(swiper);
swiper.swipePrev();
});
$('.cooperation-slide-next').on('click', function(e) {
e.preventDefault();
clearOtherSlideStyle(swiper);
nextChagneSileSize(swiper);
swiper.swipeNext();
});
if (firstSlide == null || secondSlide == null) {
return;
}
if (/big-size/.test(secondSlide.className)) {
firstSlide.style.width = "1180px";
}
}
}).init();
};
//品牌
exports.brand = function() {
/**
* 关于品牌点击弹窗事件
*/
({
init: function() {
// 点击品牌图标、弹窗显示品牌信息
$('.brand-list').on('click', 'li', function() {
if ($(this).find('.brand-introduction').size() > 0) {
$(this).find('.brand-introduction').show();
$('.overlay').show();
}
});
// 点击遮罩层、关闭modal窗
$('.overlay').on('click', function() {
$(this).hide();
$('.brand-introduction').hide();
});
// 点击关闭按钮、关闭modal窗
$('.brand-introduction .close-tag').on('click', function(event) {
event.preventDefault();
event.stopPropagation();
$('.overlay').hide();
$('.brand-introduction').hide();
});
}
}).init();
/**
* 鼠标移入显示彩色logo 移出显示灰色logo
*/
({
init: function() {
$(".brand-list").on("mouseenter", "li > a", function(event) {
var $img = $(this).find("img");
$img.removeClass("grey-brand-logo");
}).on("mouseleave", "li > a", function() {
var $img = $(this).find("img");
$img.addClass("grey-brand-logo");
})
}
}).init();
};
//资讯
exports.news = function() {
setLayout();
};
//detail页面
exports.detail = function() {
var timer,
nowIndex,
detailSwiper;
var relatedTop,
relatedPost,
relatedH,
maxH;
//详情页图片滚动
if ($('.detail-slide').size() > 0) {
//slide大图上的左右箭头显示
$('.slide-shadow').on('mouseover', 'a', function() {
if ($(this).hasClass('slide-shadow-prev')) {
$('.slide-big-ctrl-prev').show();
} else {
$('.slide-big-ctrl-next').show();
}
}).on('mouseout', 'a', function() {
$('.slide-big-ctrl-prev, .slide-big-ctrl-next').hide();
});
$('.detail-slide-body').on('mouseout', function() {
$('.slide-big-ctrl-prev, .slide-big-ctrl-next').hide();
});
$('.detail-slide-big-ctrl').on('mouseenter', 'a', function() {
$(this).show();
});
detailSwiper = new swiper('.detail-slide-body', {
wrapperClass: 'detail-slide-piclist',
slideClass: 'box',
loop: true,
slidesPerView: 'auto',
slideElement: 'li'
});
$('.slide-big-ctrl-prev').bind('click', function(e) {
e.preventDefault();
detailSwiper.swipePrev();
});
$('.slide-big-ctrl-next').bind('click', function(e) {
e.preventDefault();
detailSwiper.swipeNext();
});
$('.detail-slide-ctrl-tabs').slider();
$('.detail-slide-big-ctrl').on('click', 'a', function() {
$('.detail-slide-ctrl-tabs').slider('slideTo', detailSwiper.activeLoopIndex);
});
$('.detail-slide-ctrl-tabs').on('click', 'li', function() {
detailSwiper.swipeTo($(this).index());
});
({
detialImgZoom: $('.detail-slide-body').find('.box').each(function() {
$(this).imgZoom({
imgTag: 'pic-tip',
});
}),
init: function() {
$(".img-zoom-ctrl-prev").on("click", function(event) {
event.preventDefault();
$('.slide-big-ctrl-prev').click();
$(".detail-slide-body .swiper-slide-active").find("img").click();
});
$(".img-zoom-ctrl-next").on("click", function(event) {
event.preventDefault();
$('.slide-big-ctrl-next').click();
$(".detail-slide-body .swiper-slide-active").find("img").click();
});
}
}).init();
};
/**
* 详情页面侧边栏 最新信息 切换
*/
({
/**
* setIimeout编号 以便清除
* @type {Number}
*/
setTimeoutNum: 0,
/**
* 自动切换时间
* @type {Number}
*/
autoSwitchTime: 5000,
/**
* 自动切换标签
* @return {Undefined}
*/
autoSwitch: function() {
$('.side-related-tab').find('a').each(function(i) {
if ($(this).hasClass('current')) {
$(this).removeClass('current');
} else {
$(this).addClass('current');
$('.side-related-list').hide().eq(i).show();
}
});
this.setTimeoutNum = setTimeout(this.autoSwitch, this.autoSwitchTime);
},
init: function() {
var that = this;
// 鼠标移入 停止自动切换 移出 开始自动切换
$('.side-related-post').on('mouseenter', function() {
clearTimeout(that.setTimeoutNum);
}).on('mouseleave', function() {
that.autoSwitch();
});
// 点击标签 切换信息
$('.side-related-tab').on('click', 'a', function() {
nowIndex = $(this).index(".side-related-tab a");
if ($(this).hasClass('current')) {
return;
}
$(this).addClass('current').siblings().removeClass('current');
$('.side-related-list').hide().eq(nowIndex).show();
});
// 开始自动切换
this.autoSwitch();
}
}).init();
};
exports.siteActivity = function() {
$('.site-activity-content').find('.layout-item').each(function() {
$(this).imgZoom({
imgTag: 'pic-tip'
});
});
//活动日期定位
var tabTop = $('.site-activity-tab').offset().top - 10,
oTab = $('.site-activity-tab'),
mainBodyOffsetTop,
mainBodyHeight,
tabOffsetHeightTop,
distance,
eleTop,
tabPositionTop;
$(window).on('scroll', function() {
if (tabTop <= $(this).scrollTop()) {
$('.site-activity-tab').css({
"position": "fixed",
"top": "0",
"left": "50%",
"width": "134px",
"marginLeft": "356px",
"marginTop": "10px"
})
mainBodyOffsetTop = $('.bd').offset().top;
mainBodyHeight = $('.bd').outerHeight();
tabOffsetHeightTop = oTab.offset().top + oTab.outerHeight();
distance = mainBodyHeight + mainBodyOffsetTop;
eleTop = distance - oTab.outerHeight();
tabPositionTop = 10;
if (tabOffsetHeightTop >= distance) {
oTab.css({
'position': 'absolute',
'top': eleTop - tabPositionTop - 10
});
}
if (oTab.offset().top - $(window).scrollTop() > tabPositionTop) {
oTab.css({
'position': 'fixed',
'top': tabPositionTop
});
}
} else {
$('.site-activity-tab').removeAttr('style');
};
});
};
//show页面
exports.show = function() {
$(".look_big_image").bind("click", function(event) {
var divName = '#mask';
var sourceImage = $(this).attr("source");
var imageWidth = parseInt($(divName).children().attr("width"));
var imageHeight = parseInt($(divName).children().attr("height"));
$(divName).html('<img src="' + sourceImage + '" width="' + imageWidth + '" height="' + imageHeight + '" />').attr("current_class", $(this).parent().attr("class"));
var top = ($(window).height() - imageHeight) / 2;
var left = ($(window).width() - imageWidth) / 2;
var scrollTop = 0; //$(document).scrollTop();
var scrollLeft = 0; //$(document).scrollLeft();
$(divName).css({
position: 'absolute',
'top': top + scrollTop,
left: left + scrollLeft
});
$(".model").show();
if (left - 75 > 10) {
$(".image-prev").css("left", left - 75);
$(".image-next").css("right", left - 75);
}
$.each($(this).parents("span").children("span"), function(index, dom) {
var style_top = parseInt($(dom).attr("x")) / 10000 * imageHeight;
var style_left = parseInt($(dom).attr("y")) / 10000 * imageWidth;
$(divName).append('<a class="pic-tip" style="left:' + style_left + 'px;top:' + style_top + 'px;">' + $(dom).attr("label") + '</a>')
});
event.stopPropagation();
});
$(".ui-dialog-close").bind("click", function(event) {
$(".model").hide();
event.stopPropagation();
});
$('.show-wrap').find('.layout-item').each(function() {
$(this).imgZoom({
imgTag: 'pic-tip'
});
});
}
});