article.js 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. $(function () {
  2. $("#toc").show();
  3. var toc = $("#toc").tocify({
  4. selectors: ".ibox-content h3,.ibox-content h4,.ibox-content h5"
  5. }).data("toc-tocify");
  6. $(".tocify>.close").on("click", function(e) {
  7. $(this).parent().hide();
  8. });
  9. SyntaxHighlighter.all();
  10. SyntaxHighlighter.defaults['toolbar'] = false;
  11. layui.use('layedit', function () {
  12. layui.layedit.build('layedit', {
  13. tool: ["strong", "italic", 'link', "unlink", "face"],
  14. height: 100
  15. });
  16. });
  17. $("#code-token").on("submit", function(e) {
  18. e.preventDefault();
  19. $.post("/post/CheckViewToken", $(this).serialize(), function(data) {
  20. if (data.Success) {
  21. window.location.reload();
  22. } else {
  23. window.notie.alert({
  24. type: 3,
  25. text: data.Message,
  26. time: 4
  27. });
  28. }
  29. });
  30. });
  31. $(".getcode").on("click", function(e) {
  32. e.preventDefault();
  33. $.post("/post/getviewtoken",
  34. {
  35. __RequestVerificationToken:$("[name=__RequestVerificationToken]").val(),
  36. email:$("#email3").val()
  37. }, function(data) {
  38. if (data.Success) {
  39. window.notie.alert({
  40. type: 1,
  41. text: "验证码发送成功,请注意查收邮件,若未收到,请检查你的邮箱地址或邮件垃圾箱!",
  42. time: 4
  43. });
  44. window.localStorage.setItem("email",$("#email3").val());
  45. $(".getcode").attr('disabled',true);
  46. var count=0;
  47. var timer=setInterval(function() {
  48. count++;
  49. $(".getcode").text('重新发送('+(120-count)+')');
  50. if (count>120) {
  51. clearInterval(timer);
  52. }
  53. },1000);
  54. } else {
  55. window.notie.alert({
  56. type: 3,
  57. text: data.Message,
  58. time: 4
  59. });
  60. }
  61. });
  62. });
  63. var user = JSON.parse(localStorage.getItem("user"));
  64. var email = localStorage.getItem("email");
  65. if (email) {
  66. $("[name='Email']").val(email);
  67. $("#email-token").submit();
  68. }
  69. if (user) {
  70. $("[name='NickName']").val(user.NickName);
  71. $("[name='Email']").val(user.Email);
  72. $("[name='QQorWechat']").val(user.QQorWechat);
  73. }
  74. bindReplyBtn();//绑定回复按钮事件
  75. bindVote();//绑定文章投票按钮
  76. getcomments();//获取评论
  77. commentVoteBind(); //评论投票
  78. $("#OperatingSystem").val(platform.os.toString());
  79. $("#Browser").val(platform.name + " " + platform.version);
  80. //异步提交评论表单
  81. $("#comment").on("submit", function(e) {
  82. e.preventDefault();
  83. layui.layedit.sync(1);
  84. if ($("#name").val().trim().length <= 1 || $("#name").val().trim().length > 36) {
  85. window.notie.alert({
  86. type: 3,
  87. text: '再怎么你也应该留个合理的名字吧,非主流的我可不喜欢!',
  88. time: 4
  89. });
  90. return;
  91. }
  92. if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test($("#email").val().trim())) {
  93. window.notie.alert({
  94. type: 3,
  95. text: '请输入正确的邮箱格式!',
  96. time: 4
  97. });
  98. return;
  99. }
  100. if($("#email").val().indexOf("163")>1||$("#email").val().indexOf("126")>1) {
  101. var _this=this;
  102. swal({
  103. title: '邮箱确认',
  104. text: "检测到您输入的邮箱是网易邮箱,本站的邮件服务器可能会因为您的反垃圾设置而无法将邮件正常发送到您的邮箱,建议使用您的其他邮箱,或者检查反垃圾设置后,再点击确定按钮继续!",
  105. type: 'warning',
  106. showCancelButton: true,
  107. confirmButtonColor: '#3085d6',
  108. cancelButtonColor: '#d33',
  109. confirmButtonText: '确定',
  110. cancelButtonText: '换个邮箱',
  111. confirmButtonClass: 'btn btn-success btn-lg',
  112. cancelButtonClass: 'btn btn-danger btn-lg',
  113. buttonsStyling: false
  114. }).then(function(isConfirm) {
  115. if (isConfirm === true) {
  116. submitComment(_this);
  117. }
  118. });
  119. return;
  120. }
  121. submitComment(this);
  122. });
  123. //表单取消按钮
  124. $(".btn-cancel").click(function() {
  125. $(':input', '#reply-form').not(':button,:submit,:reset,:hidden').val('').removeAttr('checked')
  126. .removeAttr('checked'); //评论成功清空表单
  127. //Custombox.close();
  128. layer.closeAll();
  129. setTimeout(function() {
  130. $("#reply").css("display", "none");
  131. }, 500);
  132. });
  133. //回复表单的提交
  134. $("#reply-form").on("submit", function(e) {
  135. e.preventDefault();
  136. layui.layedit.sync(window.currentEditor);
  137. loading();
  138. if ($("#name2").val().trim().length <= 0 || $("#name").val().trim().length > 36) {
  139. window.notie.alert({
  140. type: 3,
  141. text: "亲,能留个正常点的名字不!",
  142. time: 4
  143. });
  144. loadingDone();
  145. return;
  146. }
  147. if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test($("#email2")
  148. .val().trim())) {
  149. window.notie.alert({
  150. type: 3,
  151. text: "请输入正确的邮箱格式!",
  152. time: 4
  153. });
  154. loadingDone();
  155. return;
  156. }
  157. localStorage.setItem("user", JSON.stringify($(this).serializeObject()));
  158. $.post("/comment/put", $(this).serialize(), (data) => {
  159. loadingDone();
  160. if (data.Success) {
  161. window.notie.alert({
  162. type: 1,
  163. text: data.Message,
  164. time: 4
  165. });
  166. layer.closeAll();
  167. setTimeout(function () {
  168. getcomments();
  169. $("[id^='LAY_layedit']").contents().find('body').html('');
  170. $("#reply").css("display", "none");
  171. }, 500);
  172. } else {
  173. window.notie.alert({
  174. type: 3,
  175. text: data.Message,
  176. time: 4
  177. });
  178. }
  179. });
  180. });
  181. $("#donate").on("click", function (e) {
  182. $.post("/system/getsetting", { name: "Donate" }, function (data) {
  183. swal({
  184. title: "支付宝扫一扫付款捐赠!",
  185. html:"<a href='/donate'>更多方式</a>",
  186. showCancelButton: true,
  187. confirmButtonColor: "#DD6B55",
  188. confirmButtonText: "确定",
  189. cancelButtonText: "取消",
  190. showLoaderOnConfirm: true,
  191. imageUrl: data.Data.Value,
  192. imageWidth: 400,
  193. animation: true,
  194. allowOutsideClick: false
  195. }).then(function() {
  196. }, function() {
  197. swal("您的捐赠将会支持本站做的更好!", null, "error");
  198. });
  199. });
  200. });
  201. });
  202. /**
  203. * 提交评论
  204. * @returns {}
  205. */
  206. function submitComment(_this) {
  207. loading();
  208. localStorage.setItem("user", JSON.stringify($(_this).serializeObject()));
  209. $.post("/comment/put", $(_this).serialize(), (data) => {
  210. loadingDone();
  211. if (data.Success) {
  212. window.notie.alert({
  213. type: 1,
  214. text: data.Message,
  215. time: 4
  216. });
  217. setTimeout(function() {
  218. getcomments();
  219. $("[id^='LAY_layedit']").contents().find('body').html('');
  220. },100);
  221. } else {
  222. window.notie.alert({
  223. type: 3,
  224. text: data.Message,
  225. time: 4
  226. });
  227. }
  228. });
  229. }
  230. //评论回复按钮事件
  231. function bindReplyBtn() {
  232. $(".msg-list article .panel-body a").on("click", function(e) {
  233. e.preventDefault();
  234. loadingDone();
  235. var user = JSON.parse(localStorage.getItem("user"));
  236. if (user) {
  237. $("[name='NickName']").val(user.NickName);
  238. $("[name='Email']").val(user.Email);
  239. $("[name='QQorWechat']").val(user.QQorWechat);
  240. }
  241. var href = $(this).attr("href");
  242. var uid = href.substring(href.indexOf("uid") + 4);
  243. $("#uid").val(uid);
  244. $("#OperatingSystem2").val(platform.os.toString());
  245. $("#Browser2").val(platform.name + " " + platform.version);
  246. //Custombox.open({
  247. // target: '#modal',
  248. // overlayOpacity: 0.1,
  249. // speed:10,
  250. // zIndex: 100
  251. //});
  252. layui.use("layer", function() {
  253. var layer = layui.layer;
  254. layer.open({
  255. type: 1,
  256. zIndex: 20,
  257. title: '回复评论',
  258. area: (window.screen.width > 540 ? 540 : window.screen.width) + 'px',// '340px'], //宽高
  259. content: $("#reply"),
  260. end: function() {
  261. $("#reply").css("display", "none");
  262. }
  263. });
  264. });
  265. $(".layui-layer").insertBefore($(".layui-layer-shade"));
  266. window.currentEditor = layui.layedit.build('layedit2', {
  267. tool: ["strong", "italic", 'link', "unlink", "face"],
  268. height: 100
  269. });
  270. });
  271. }
  272. //绑定评论投票
  273. function commentVoteBind() {
  274. $(".cmvote").on("click", function(e) {
  275. $.post("/comment/CommentVote", {
  276. id: $(this).data("id")
  277. }, (data) => {
  278. if (data) {
  279. if (data.Success) {
  280. console.log($(this).children("span.count"));
  281. $(this).children("span.count").text(parseInt($(this).children("span.count").text())+1);
  282. $(this).addClass("disabled");
  283. this.disabled = true;
  284. window.notie.alert({
  285. type: 1,
  286. text: data.Message,
  287. time: 4
  288. });
  289. } else {
  290. window.notie.alert({
  291. type: 3,
  292. text: data.Message,
  293. time: 4
  294. });
  295. }
  296. }
  297. });
  298. });
  299. }
  300. function bindVote() {
  301. $("#voteup").on("click", function(e) {
  302. $.post("/post/voteup", {
  303. id: $("#postId").val()
  304. }, (data) => {
  305. if (data) {
  306. if (data.Success) {
  307. $(this).children()[1].innerText = parseInt($(this).children()[1].innerText) + 1;
  308. $(this).addClass("disabled");
  309. this.disabled = true;
  310. window.notie.alert({
  311. type: 1,
  312. text: data.Message,
  313. time: 4
  314. });
  315. } else {
  316. window.notie.alert({
  317. type: 3,
  318. text: data.Message,
  319. time: 4
  320. });
  321. }
  322. }
  323. });
  324. });
  325. $("#votedown").on("click", function(e) {
  326. $.post("/post/votedown", {
  327. id: $("#postId").val()
  328. }, (data) => {
  329. if (data) {
  330. if (data.Success) {
  331. $(this).children()[1].innerText = parseInt($(this).children()[1].innerText) + 1;
  332. $(this).addClass("disabled");
  333. this.disabled = true;
  334. window.notie.alert({
  335. type: 1,
  336. text: data.Message,
  337. time: 4
  338. });
  339. } else {
  340. window.notie.alert({
  341. type: 3,
  342. text: data.Message,
  343. time: 4
  344. });
  345. }
  346. }
  347. });
  348. });
  349. }