Source code of filesite.io. https://filesite.io
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

356 lines
11 KiB

/* for theme TaJian */
(function() {
// 公用功能
var taJian = {
debug: false,
domain: 'https://tajian.tv',
apis: {
addVideos: '/frontapi/addfav', //添加视频
sendSmsCode: '/frontapi/sendsmscode', //发送短信验证码
register: '/frontapi/createuser', //注册
login: '/frontapi/loginuser' //登入
}
};
var publicAjax = function(apiUrl, method, datas, callback, fail) {
let self = this;
let Options = {
url: apiUrl,
method: method,
data: datas,
dataType: 'json'
};
if (self.debug) {
Options.crossDomain = true;
Options.xhrFields = {
withCredentials: true
};
}
$.ajax(Options).done(function(data) {
callback(data);
}).fail(function (jqXHR, textStatus, errorThrown) {
fail(jqXHR, textStatus, errorThrown);
});
};
//多用户支持
if (typeof(current_user_id) != 'undefined' && current_user_id) {
for (var apiKey in taJian.apis) {
taJian.apis[apiKey] = '/' + current_user_id + taJian.apis[apiKey];
}
}
//--v2.0--
// 图片异步加载
if ($("img.lazy").get(0)) {
$("img.lazy").lazyload({
effect: "fadeIn",
event: "scroll"
});
}
if ($('.connectmeJS').get(0)) {
// 点击打开右侧弹出框
$('.connectmeJS').click(function () {
$('.blank_coverJS, .right_sideboxJS').removeClass('elementNone');
window.setTimeout(function () {
$('.blank_coverJS').addClass('opacityshow');
$('.right_sideboxJS').addClass('sideboxShow');
}, 0);
});
// 点击关闭右侧弹出框
$('.rtcloseJS').click(function () {
$('.blank_coverJS').removeClass('opacityshow');
$('.right_sideboxJS').removeClass('sideboxShow');
window.setTimeout(function () {
$('.blank_coverJS, .right_sideboxJS').addClass('elementNone');
}, 500);
});
}
// 打开移动端搜索框
if ($('.search_mob_JS').get(0)) {
$('.search_mob_JS').click(function () {
$('.blank_coverJS, .mobile_search_JS').removeClass('elementNone');
window.setTimeout(function () {
$('.blank_coverJS').addClass('opacityshow');
$('.mobile_search_JS').addClass('sideboxShow');
}, 0);
$('#mobile_search .ms_input_js').focus();
});
$('.ms_close_JS').click(function () {
$('.blank_coverJS').removeClass('opacityshow');
$('.mobile_search_JS').removeClass('sideboxShow');
window.setTimeout(function () {
$('.blank_coverJS, .mobile_search_JS').addClass('elementNone');
}, 500);
});
}
// 搜索相关
$('#search_form .jsbtn').click(function (e) {
e.preventDefault();
if (!$('#search_form .input_sf_JS').val()) {
return;
}
$('#search_form').submit();
});
// 添加视频
if ($('#add_video_form').get(0)) {
// 添加视频表单处理
$('#add_video_form .jsbtn').click(function (e) {
e.preventDefault();
let inputList = $('#add_video_form textarea');
if (!inputList[0].value) {
alert('请填写分享内容或网址!');
return false;
} else if (/https:\/\/[\w\.]+\/[\w]+/ig.test(inputList[0].value) == false) {
alert('目前只支持抖音、快手、西瓜视频和Bilibili的分享网址哦!');
return false;
}
let bt = $(this), btLoading = bt.children('.bt_class_JS'), btText = bt.children('.bt_text_JS');
btLoading.removeClass('elementNone');
bt.prop('disabled', true);
btText.text('提交中...');
let datas = {
'content': inputList[0].value,
'tag': $('#add_video_form select').val()
}
let apiUrl = taJian.debug ? taJian.domain + taJian.apis.addVideos : taJian.apis.addVideos;
publicAjax(apiUrl, 'POST', datas, function (data) {
bt.prop('disabled', false);
btText.text('提交');
btLoading.addClass('elementNone');
if (data.code == 1) {
$(inputList[0]).val('');
alert(data.msg || data.err);
} else {
alert(data.err);
}
}, function (jqXHR, textStatus, errorThrown) {
bt.prop('disabled', false);
btText.text('提交');
btLoading.addClass('elementNone');
alert('网络请求失败,请重试。');
});
});
}
// form表单
if ($('.g_form_js').get(0)) {
$('.g_form_js .jsbtn').click(function (e) {
e.preventDefault();
let inputList = $('.g_form_js input');
for (let i = 0; i < inputList.length; i++) {
if (!inputList[i].value) {
alert($(inputList[i]).attr('Warning'));
return false;
}
}
let bt = $(this), btLoading = bt.children('.bt_class_JS'), btText = bt.children('.bt_text_JS');
btLoading.removeClass('elementNone');
bt.prop('disabled', true);
btText.text('请求中...');
});
}
// 注册/登录等页面展示客服微信二维码切换按钮
if ($('.bt_kf_JS').get(0)) {
var kf_hide_text = $('.bt_kf_JS').attr('data-hide'),
kf_text = $('.bt_kf_JS').text();
$('.bt_kf_JS').click(function(e) {
if ($('.kf_wx_JS').hasClass('hide')) {
$('.kf_wx_JS').removeClass('hide');
$('.bt_kf_JS').text(kf_hide_text);
}else {
$('.kf_wx_JS').addClass('hide');
$('.bt_kf_JS').text(kf_text);
}
});
var win_width = $(window).width();
if (win_width > 768 && $('.tajian_index').get(0)) {
$('.bt_kf_JS').click().addClass('hide');
}
}
var smsCodeBtnHandler = function(e) {
var cellphone = $('input[name=username]').val();
if (/^1[3-9][0-9]{9}$/.test(cellphone)) {
$('.bt_sms_JS').removeAttr('disabled');
}
};
//验证码发送
if ($('.bt_sms_JS').get(0)) {
var timer_restore_smsBtn = null, timer_num = 60;
var autoRestoreSmsBtn = function() {
if (timer_restore_smsBtn) {clearTimeout(timer_restore_smsBtn);}
if (timer_num <= 0) {
$('.bt_sms_JS').removeAttr('disabled').text('发送验证码');
timer_num = 60;
return false;
}
timer_num --;
$('.bt_sms_JS').prop('disabled', true).text('已发送(' + timer_num + ')');
timer_restore_smsBtn = setTimeout(autoRestoreSmsBtn, 1000);
};
$('.bt_sms_JS').click(function(e) {
autoRestoreSmsBtn();
//调用api发送验证码
var cellphone = $('input[name=username]').val();
var datas = {
'phoneNum': cellphone
};
publicAjax(taJian.apis.sendSmsCode, 'POST', datas, function (data) {
if (data.code == 0 && data.err) {
alert(data.err);
}
}, function (jqXHR, textStatus, errorThrown) {
alert('网络请求失败,请重试。');
});
});
}
// 注册
if ($('#register_form').get(0)) {
$('#register_form input[name=username]').blur(smsCodeBtnHandler);
$('#register_form .jsbtn').click(function(e) {
e.preventDefault();
var friends_code = $('input[name=friendscode]').val(),
cellphone = $('input[name=username]').val(),
smscode = $('input[name=smscode]').val();
if (!friends_code || !cellphone || !smscode) {
alert('请填写完整再注册!');
return false;
}else if (!friends_code) {
alert('请填写邀请码:朋友的手机尾号 6 位(或加客服微信索要)!');
return false;
}else if (!cellphone) {
alert('请填写手机号码!');
return false;
}else if (!smscode) {
alert('请填写你手机收到的短信验证码!');
return false;
}
var bt = $(this), btLoading = bt.children('.bt_class_JS'), btText = bt.children('.bt_text_JS');
btLoading.removeClass('elementNone');
bt.prop('disabled', true);
btText.text('提交中...');
var datas = {
'friendscode': friends_code,
'username': cellphone,
'smscode': smscode
};
publicAjax(taJian.apis.register, 'POST', datas, function (data) {
btLoading.addClass('elementNone');
if (data.code == 1 && data.shareUrl) {
btText.text('完成');
alert(data.msg);
setTimeout(function() {
location.href = data.shareUrl;
}, 100);
} else {
btText.text('注册');
bt.prop('disabled', false);
alert(data.err);
}
}, function (jqXHR, textStatus, errorThrown) {
bt.prop('disabled', false);
btText.text('注册');
btLoading.addClass('elementNone');
alert('网络请求失败,请重试。');
});
});
}
// 登录
if ($('#login_form').get(0)) {
$('#login_form .jsbtn').click(function(e) {
e.preventDefault();
var cellphone = $('input[name=username]').val(),
smscode = $('input[name=smscode]').val();
if (!cellphone || !smscode) {
alert('请填写完整再登录!');
return false;
}else if (!cellphone) {
alert('请填写手机号码!');
return false;
}else if (!smscode) {
alert('请填写你手机收到的短信验证码!');
return false;
}
var bt = $(this), btLoading = bt.children('.bt_class_JS'), btText = bt.children('.bt_text_JS');
btLoading.removeClass('elementNone');
bt.prop('disabled', true);
btText.text('提交中...');
var datas = {
'username': cellphone,
'smscode': smscode
};
publicAjax(taJian.apis.login, 'POST', datas, function (data) {
btLoading.addClass('elementNone');
if (data.code == 1 && data.shareUrl) {
btText.text('完成');
alert(data.msg);
setTimeout(function() {
location.href = data.shareUrl;
}, 100);
} else {
btText.text('登录');
bt.prop('disabled', false);
alert(data.err);
}
}, function (jqXHR, textStatus, errorThrown) {
bt.prop('disabled', false);
btText.text('登录');
btLoading.addClass('elementNone');
alert('网络请求失败,请重试。');
});
});
}
})();