public.js
10.7 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
$(function() {
var host = 'http://' + window.location.host + '/themes/simpleboot3_mobile/public/assets';
// 点击左上角
$('.nav_downN9,.nav_drop-down ul a').click(function() {
$('.nav_down').hide();
$('.navImg1 img').attr('src', host + "/images/cicon_02@2x.png")
});
//导航
$('.navImg1 img').click(function(e) {
if ($(this).attr('src') == host + "/images/cicon_02@2x.png") {
e.stopPropagation();
$(this).attr('src', host + '/images/xx.png');
$('.nav_down').slideDown();
} else {
$(this).attr('src', host + '/images/cicon_02@2x.png');
$('.nav_down').slideUp();
}
});
// 关闭导航
$(document).click(function(e) {
if (!$(e.target).closest(".nav_down").length) {
$(".nav_down").slideUp(200);
$('.navImg1 img').attr('src', host + "/images/cicon_02@2x.png")
// $(this).children('.bottom_liCir p').css('color', '#999999');
}
});
//二级导航
$('.nav_downN').each(function() {
$(this).click(function() {
if ($(this).children('.nav_downImg2').attr('src') == host + '/images/down.png') {
$(this).children('.nav_downImg2').attr('src', host + '/images/top.png');
$(this).next('.nav_drop-down').slideDown();
} else {
$(this).children('.nav_downImg2').attr('src', host + '/images/down.png');
$(this).next('.nav_drop-down').slideUp();
}
});
});
// 收藏
$('.collections').click(function() {
if ($(this).children('img').attr('src') == host + '/images/bicon_02.png') {
var login = operation('/portal/star/collection');
if (login == 0) {
return false;
}
$(this).children('img').attr('src', host + '/images/bicon_15.png');
} else {
var login = operation('/portal/star/cancelCollection');
if (login == 0) {
return false;
}
$(this).children('img').attr('src', host + '/images/bicon_02.png');
}
});
//点赞
$('.likes').click(function() {
if ($(this).children('img').attr('src') == host + '/images/bicon_03.png') {
var login = operation('/portal/star/like');
if (login == 0) {
return false;
}
$(this).children('img').attr('src', host + '/images/bicon_16.png');
} else {
var login = operation('/portal/star/cancelLike');
if (login == 0) {
return false;
}
$(this).children('img').attr('src', host + '/images/bicon_03.png');
}
});
// 收藏更多视频
$('#collections').click(function() {
if ($(this).attr('src') == host + '/images/bicon_02.png') {
var login = operation('/portal/star/collection', 1);
if (login == 0) {
return false;
}
$(this).attr('src', host + '/images/bicon_15.png');
} else {
var login = operation('/portal/star/cancelCollection', 1);
if (login == 0) {
return false;
}
$(this).attr('src', host + '/images/bicon_02.png');
}
});
//点赞
$('#likes').click(function() {
if ($(this).attr('src') == host + '/images/bicon_031.png') {
var login = operation('/portal/star/like', 1);
if (login == 0) {
return false;
}
$(this).attr('src', host + '/images/bicon_161.png');
} else {
var login = operation('/portal/star/cancelLike', 1);
if (login == 0) {
return false;
}
$(this).attr('src', host + '/images/bicon_031.png');
}
});
// 评论判断长度显示与隐藏
if ($('.show_2_pinL').length < 3) {
$('.show_main_more').hide();
$('.show_main2_show ul').removeClass('show_main2_show_H');
$('.show_main_more').removeClass('comments2_more');
} else {
$('.show_main_more').show();
}
var maxwidth = 4;//设置最多显示的字数
var user_nickname = $('#user_nickname').text();
if(user_nickname.length > maxwidth){
var user = user_nickname.substring(0,maxwidth);
$('#user_nickname').text(user+'...');
}
//改变分页图标
$('.page-item').eq(0).children().text('<');
$('.page-item:last').children().text('>');
//点击评论收起与展开
$('.comments2_more').click(function() {
if ($.trim($(this).text()) == '查看更多评论') {
$('.comments2').removeClass('comments2N');
$(this).text('收起');
} else {
$('.comments2').addClass('comments2N');
$(this).text('查看更多评论');
}
});
// 点击出现搜索栏
$('.navImg3').click(function() {
$('.navImg2').hide();
$(this).addClass('searchs');
setInterval(function() {
$('.nav_search').show();
}, 200);
//搜索
$(".searchs").click(function() {
$("#searchForm").submit(); //处理事件
});
});
//登录
$("#login").click(function() {
window.location.href = "/portal/login/login";
});
//注册
$("#register").click(function() {
window.location.href = "/portal/login/register";
});
//个人中心
$('.login_person').click(function() {
window.location.href = '/portal/login/info';
});
//修改资料页面
$('#editInfo').click(function() {
window.location.href = '/portal/login/editInfo';
});
//我的收藏页面
$('#myCollection').click(function() {
window.location.href = '/portal/login/myCollection';
});
//跳转链接
$('.nav_drop-down a').click(function() {
$('.nav_down').css('display', 'none');
});
//评论
$('#comment').click(function() {
var content = $('#comment_content').val();
var article_id = getUrlParam('id');
var url = window.location.pathname + window.location.search;
$.ajax({
type: 'POST',
url: "/portal/star/comment",
data: {
'content': content,
'article_id': article_id,
'url': url
},
dataType: 'json',
success: function(data) {
console.log(data);
if (data.code == 1) {
mask(data.msg);
$('#comment_content').val('');
} else {
mask(data.msg);
}
}
});
});
//退出登录
$('#logout').click(function() {
$.ajax({
type: 'POST',
url: "/portal/login/logout",
data: {
},
dataType: 'json',
success: function(data) {
console.log(data);
if (data.code == 1) {
mask(data.msg);
window.location.href = '/';
} else {
mask(data.msg);
}
}
});
});
//关于我们
$('#about_us,#about_us1').click(function() {
window.location.href = '/portal/index/aboutUs';
});
//搜索
$("#keywords").keypress(function(e) {
if (e.which == 13) {
$("#searchForm").submit(); //处理事件
}
});
var share_url = encodeURIComponent(location.href);
var share_title = encodeURIComponent(document.title);
//分享到微博
$('.weibo').click(function() {
var param = {
url: share_url,
title: share_title,
rnd: new Date().valueOf()
};
var temp = [];
for (var p in param) {
temp.push(p + '=' + encodeURIComponent(param[p] || ''))
}
window.open('http://v.t.sina.com.cn/share/share.php?' + temp.join('&'));
});
//微博分享
$('.wb_share').click(function() {
thirdShare('/portal/login/wb_share');
});
//星球影院微博分享
$('.wb_share_video').click(function() {
thirdShare('/portal/login/wb_share');
});
//微博登录
$('#wb_login').click(function(){
$('#wb_form').submit();
});
//微信登录(暂时无用)
$('#wx_login').click(function(){
window.location.href = '/portal/login/wx_login_mobile';
});
//微信分享
$('#wx_share,#wx_share_video').click(function(){
mask('打开微信,点击右上角即可分享网页');
});
});
//第三方分享
function thirdShare(url){
var title = $(document).attr("title");
var share_url = window.location.href;
var article_id = getUrlParam('id');
$.ajax({
type: 'POST',
url: url,
data: {
'id': article_id,
'title': title,
'share_url': share_url
},
dataType: 'json',
async: false,
success: function(data) {
if (data.code == 1) {
mask(data.msg);
window.location.reload();
} else {
mask(data.msg);
}
}
});
}
//弹框
function mask(msg) {
$('.mask').text(msg);
$('.mask').show();
setTimeout(function() {
$('.mask').hide();
$('.mask').text('');
}, 6000);
}
//弹框
function video_mask(msg) {
$('.mask').text(msg);
$('.mask').show();
setTimeout(function() {
$('.mask').hide();
$('.mask').text('');
}, 6000);
}
//点赞收藏
function operation(url,id) {
if (id == '' || id == undefined) {
var article_id = getUrlParam('id');
} else {
var article_id = $('#li_id').val();
}
var is_login = 1;
var post_url = window.location.pathname + window.location.search;
$.ajax({
type: 'POST',
url: url,
data: {
'article_id': article_id,
'post_url': post_url
},
dataType: 'json',
async: false,
success: function(data) {
if (data.code == 1) {
mask(data.msg);
} else {
mask(data.msg);
is_login = data.code;
}
}
});
return is_login;
}
//获取url的参数
function getUrlParam(paraName) {
var url = document.location.toString();
var arrObj = url.split("?");
if (arrObj.length > 1) {
var arrPara = arrObj[1].split("&");
var arr;
for (var i = 0; i < arrPara.length; i++) {
arr = arrPara[i].split("=");
if (arr != null && arr[0] == paraName) {
return arr[1];
}
}
return "";
} else {
return "";
}
}