Browse Source

add form to call api/addfav

master
filesite 1 year ago
parent
commit
d345d1bd1d
  1. 5
      themes/tajian/views/layout/main.php
  2. 16
      themes/tajian/views/site/form_addfav.php
  3. 2
      themes/tajian/views/site/index.php
  4. 4
      www/css/videoblog.css
  5. 42
      www/js/tajian.js

5
themes/tajian/views/layout/main.php

@ -109,9 +109,8 @@ eof;
<script src="/js/jquery-3.6.0.min.js"></script> <script src="/js/jquery-3.6.0.min.js"></script>
<script src="/js/js.cookie.min.js"></script> <script src="/js/js.cookie.min.js"></script>
<script src="/js/main.js?v.1.0"></script> <script src="/js/main.js?v.1.0"></script>
<!--for theme videoblog--> <!--for theme tajian-->
<script src="/js/lazysizes.min.js"></script> <script src="/js/lazysizes.min.js"></script>
<script src="/js/video.min.js"></script> <script src="/js/tajian.js?v<?=Html::getStaticFileVersion('tajian.js', 'js')?>"></script>
<script src="/js/videoblog.js?v<?=Html::getStaticFileVersion('videoblog.js', 'js')?>"></script>
</body> </body>
</html> </html>

16
themes/tajian/views/site/form_addfav.php

@ -0,0 +1,16 @@
<form action="" method="post" class="px-2">
<input type="text" name="share_content" value="" placeholder="请粘贴分享网址/内容" class="form-controll txt-input">
<select name="tag" class="form-controll">
<option value="">选分类</option>
<?php
if (!empty($viewData['tags'])) { //显示tags分类
foreach($viewData['tags'] as $id => $item) {
echo <<<eof
<option value="{$item['name']}">{$item['name']}</option>
eof;
}
}
?>
</select>
<button class="btn" type="button" id="btn_addfav">保存</button>
</form>

2
themes/tajian/views/site/index.php

@ -43,6 +43,8 @@ eof;
</div> </div>
eof; eof;
} }
include_once __DIR__ . '/form_addfav.php';
?> ?>
<div class="content"> <div class="content">

4
www/css/videoblog.css

@ -30,6 +30,10 @@ a{color: #aaadb2;text-decoration: none}
.catedesc{padding: 0 10px} .catedesc{padding: 0 10px}
.cateinfo{margin-bottom: 1em;padding: 5px 10px 10px 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 */ /* for mobile */

42
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);
});
});
})();
Loading…
Cancel
Save