From d345d1bd1dce33097293b3f7db01b905f07d9d8e Mon Sep 17 00:00:00 2001 From: filesite Date: Mon, 18 Sep 2023 21:46:24 +0800 Subject: [PATCH] add form to call api/addfav --- themes/tajian/views/layout/main.php | 5 ++- themes/tajian/views/site/form_addfav.php | 16 +++++++++ themes/tajian/views/site/index.php | 2 ++ www/css/videoblog.css | 4 +++ www/js/tajian.js | 42 ++++++++++++++++++++++++ 5 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 themes/tajian/views/site/form_addfav.php create mode 100644 www/js/tajian.js diff --git a/themes/tajian/views/layout/main.php b/themes/tajian/views/layout/main.php index 8cb1c3f..4c341bc 100644 --- a/themes/tajian/views/layout/main.php +++ b/themes/tajian/views/layout/main.php @@ -109,9 +109,8 @@ eof; - + - - + diff --git a/themes/tajian/views/site/form_addfav.php b/themes/tajian/views/site/form_addfav.php new file mode 100644 index 0000000..fe0171d --- /dev/null +++ b/themes/tajian/views/site/form_addfav.php @@ -0,0 +1,16 @@ +
+ + + +
\ No newline at end of file diff --git a/themes/tajian/views/site/index.php b/themes/tajian/views/site/index.php index 642e2b0..1b8cf1c 100644 --- a/themes/tajian/views/site/index.php +++ b/themes/tajian/views/site/index.php @@ -43,6 +43,8 @@ eof; eof; } + +include_once __DIR__ . '/form_addfav.php'; ?>
diff --git a/www/css/videoblog.css b/www/css/videoblog.css index 5ed6a32..7a1e36f 100644 --- a/www/css/videoblog.css +++ b/www/css/videoblog.css @@ -30,6 +30,10 @@ a{color: #aaadb2;text-decoration: none} .catedesc{padding: 0 10px} .cateinfo{margin-bottom: 1em;padding: 5px 10px 10px 10px} +.form-controll{padding:5px} +.txt-input{min-width:60%} +.btn{padding:3px 4px} +.px-2{padding-left:10px;padding-right:10px} /* for mobile */ diff --git a/www/js/tajian.js b/www/js/tajian.js new file mode 100644 index 0000000..19dd252 --- /dev/null +++ b/www/js/tajian.js @@ -0,0 +1,42 @@ +/* for theme TaJian */ +(function() { + + $('#btn_addfav').click(function(e) { + var share_content = $('input[name=share_content]').val(), + select_tag = $('select[name=tag]').val(); + if (!share_content) { + alert('请填写分享内容或网址!'); + return false; + }else if (/https:\/\/[\w\.]+\/[\w]+/ig.test(share_content) == false) { + alert('目前只支持抖音、快手、西瓜视频和Bilibili的分享网址哦!'); + return false; + } + + var btn = this; + $(btn).prop('disabled', true); + + var postData = {content: share_content}; + if (select_tag) { + postData.tag = select_tag; + } + + $.ajax({ + url: '/api/addfav', + method: 'POST', + dataType: 'JSON', + data: postData + }).done(function(data, textStatus, jqXHR) { + $(btn).prop('disabled', false); + + if (data.code == 1) { + alert(data.msg || data.err); + }else { + alert('保存失败,请稍后重试!'); + } + }).fail(function(jqXHR, textStatus, errorThrown) { + $(btn).props('disabled', false); + alert('服务器异常了:' + errorThrown); + }); + }); + +})(); \ No newline at end of file