public.js
8.6 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
$(function() {
var host = 'http://' + window.location.host;
// 收藏
$('.collections').click(function() {
if ($(this).children('img').attr('src') == host + '/themes/simpleboot3/public/assets/starImg/bicon_02.png') {
var login = operation('/portal/star/collection');
if (login == 0) {
return false;
}
$(this).children('img').attr('src', host + '/themes/simpleboot3/public/assets/starImg/bicon_15.png');
} else {
var login = operation('/portal/star/cancelCollection');
if (login == 0) {
return false;
}
$(this).children('img').attr('src', host + '/themes/simpleboot3/public/assets/starImg/bicon_02.png');
}
});
//点赞
$('.likes').click(function() {
if ($(this).children('img').attr('src') == host + '/themes/simpleboot3/public/assets/starImg/bicon_03.png') {
var login = operation('/portal/star/like');
if (login == 0) {
return false;
}
$(this).children('img').attr('src', host + '/themes/simpleboot3/public/assets/starImg/bicon_16.png');
} else {
var login = operation('/portal/star/cancelLike');
if (login == 0) {
return false;
}
$(this).children('img').attr('src', host + '/themes/simpleboot3/public/assets/starImg/bicon_03.png');
}
});
// 收藏更多视频
$('#collections').click(function() {
if ($(this).attr('src') == host + '/themes/simpleboot3/public/assets/starImg/bicon_02.png') {
var login = operation('/portal/star/collection', 1);
if (login == 0) {
return false;
}
$(this).attr('src', host + '/themes/simpleboot3/public/assets/starImg/bicon_15.png');
} else {
var login = operation('/portal/star/cancelCollection', 1);
if (login == 0) {
return false;
}
$(this).attr('src', host + '/themes/simpleboot3/public/assets/starImg/bicon_02.png');
}
});
//点赞
$('#likes').click(function() {
if ($(this).attr('src') == host + '/themes/simpleboot3/public/assets/starImg/bicon_031.png') {
var login = operation('/portal/star/like', 1);
if (login == 0) {
return false;
}
$(this).attr('src', host + '/themes/simpleboot3/public/assets/starImg/bicon_161.png');
} else {
var login = operation('/portal/star/cancelLike', 1);
if (login == 0) {
return false;
}
$(this).attr('src', host + '/themes/simpleboot3/public/assets/starImg/bicon_031.png');
}
});
// 评论判断长度显示与隐藏
if ($('.show_2_pinL').length < 3) {
$('.show_main_more').hide();
$('.show_main2_show ul').removeClass('show_main2_show_H');
} else {
$('.show_main_more').show();
}
// 点击查看更多,与提示
$('.show_main_more').click(function() {
if ($(this).text() == "查看更多评论") {
$('.show_main2_show ul').removeClass('show_main2_show_H');
$(this).text('收起');
} else {
$('.show_main2_show ul').addClass('show_main2_show_H');
$(this).text('查看更多评论');
}
});
//头部导航栏切换颜色
var str_url = window.location.pathname;
$('.home_nav_act,.slide_vo').children('a').removeClass('home_nav_act');
var star = 'star'; //星球奇境
var region = 'region'; //星域秀场
var enjoy = 'enjoy'; //星享体验
var scout = 'scout'; //星探推荐
var active = 'active'; //星际活动
if (str_url.indexOf(star) != -1) {
$('.slide_vo').eq(0).children('a').addClass('home_nav_act');
} else if (str_url.indexOf(region) != -1) {
$('.slide_vo').eq(1).children('a').addClass('home_nav_act');
} else if (str_url.indexOf(enjoy) != -1) {
$('.slide_vo').eq(2).children('a').addClass('home_nav_act');
} else if (str_url.indexOf(scout) != -1) {
$('.slide_vo').eq(3).children('a').addClass('home_nav_act');
} else if (str_url.indexOf(active) != -1) {
$('.slide_vo').eq(4).children('a').addClass('home_nav_act');
} else {
$('.home_nav_act').children('a').addClass('home_nav_act');
}
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('>');
//注册页面
$('#register').click(function() {
window.location.href = '/portal/login/register';
});
//登录页面
$('#login').click(function() {
window.location.href = '/portal/login/login';
});
//个人中心
$('.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';
});
//评论
$('#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);
}
}
});
});
//关于我们
$('#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('&'));
});
$('.weibo_share').click(function() {
$('#wb_share').submit();
});
//微博登录
$('#wb_login').click(function(){
$('#wb_form').submit();
});
});
//点赞收藏
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;
}
//弹框
function mask(msg) {
$('.mask').text(msg);
$('.mask').show();
setTimeout(function() {
$('.mask').hide();
$('.mask').text('');
}, 4000);
}
//弹框
function video_mask(msg) {
$('.mask').text(msg);
$('.mask').show();
setTimeout(function() {
$('.mask').hide();
$('.mask').text('');
}, 6000);
}
//获取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 "";
}
}