public320.js
4.18 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
/*
* @description: h5 js
* @author: chenglong.wang@yoho.cn
* @date: 2015/1/13
*/
var $ = require('jquery');
var swiper = require('yoho.swiper');
var Hammer = require('hammerjs');
var tools = require('yoho-tools');
var mulLine = require('./plugin/mlellipsis');
var box = require('./plugin/box');
var tips = require("./plugin/tips");
require('lazyload');
require("./plugin/login");
//public banner
var publicSwiper = new swiper('.public-banner',{
mode:'horizontal',
loop: true,
pagination: '.pagination',
grabCursor: true,
paginationClickable: true,
autoplay: 5000,
slideElement: 'li',
onSlideChangeEnd: function () {
publicSwiper.startAutoplay();
$(".relazy").lazyload({threshold: 100});
}
});
//侧边栏展开、折叠
var isExpand = true;
var oNav = $('.nav-bar');
var wrap = $('#mobile');
var side = $('#side-bar');
var wW = $(window).width();
var nav = new Hammer(document.getElementById('mobile-wrap'),{time:50});
nav.on('tap',function (event) {
if ($(event.target).is(oNav)) {
side.css('visibility','visible');
wrap.addClass('menuOpen').css({
'height':'100%',
'min-height':'580px',
'overflow-y':'hidden',
'overflow-x':'hidden'
});
$('.header-download').css('left',0);
isExpand = false;
event.preventDefault();
}else {
if (!isExpand) {
wrap.removeClass('menuOpen').css({
'height':'auto',
'overflow-y':'auto',
'overflow-x':'hidden'
});
setTimeout(function () {
side.css('visibility','hidden');
$('.header-download').css({
'left':(wW-320)/2
});
},500);
}
}
});
var oLogin = $(".side-bar-header");
oLogin.login();
oLogin.click(function () {
$(this).login("loginBoxAnimate");
});
//关闭顶部浮层
$('.tip-c').click(function () {
$('.header-download-wrap').remove();
});
//滚动到顶部
var top = new Hammer(document.getElementById('back-top'));
top.on('tap',function () {
$('#mobile').animate({scrollTop: 0});
});
//懒加载
$(".lazy").lazyload({threshold: 100});
//rss
var oRss = $(".rss input");
if (oRss.length>0) {
$(".rss-btn").click(function(){
if(oRss.val()==='') {
box.alert(tips.getTips("emailEmpty"));
return;
}
if(!tools.IYOHO_isEmail(oRss.val())) {
box.alert(tips.getTips("emailError"));
return;
}
window.open( '/passport/subscribe/index?email='+oRss.val());
});
oRss.keydown(function(event){
if(event.keyCode===13) {
$(".rss-btn").trigger("click");
}
});
}
//截字
(function () {
var items=$(".home-content li");
if(items.length > 0) {
var detailStr = "";
items.each(function(index,obj){
detailStr = $(obj).find(".a-detail").text().substring(0, 58) + " ...";
$(obj).find(".a-detail").text( detailStr.replace(/[a-zA-Z]+?\s{1}\.\.\.\B/, " ...") );
});
items = null;
}
})();
//获取设备类型
(function (){
var sUserAgent = navigator.userAgent.toLowerCase();
var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
var bIsAndroid = sUserAgent.match(/android/i) == "android";
var bIsweixin = sUserAgent.match(/MicroMessenger/i) == 'micromessenger';
var app = $('.yohoboy-download-app');
var downBtn = $('.home-download').find('.down-btn');
if(bIsIphoneOs){
app.attr('href',app.attr('ios-href'));
app.attr('onclick','openApp("'+app.attr('data-ios')+'")');
downBtn.each(function (index) {
$(this).attr('href',$(this).attr('data-ios'));
});
}
if (bIsAndroid) {
downBtn.each(function (index) {
$(this).attr('href',$(this).attr('data-android'));
});
}
if (bIsweixin) {
$('.header-download-wrap').remove();
}
})();
function openApp(link) {
var clickedAt = +new Date();
setTimeout(function(){
if (+new Date() - clickedAt < 2000) {
window.location.href = link;
}
}, 500);
}