article.js 8.6 KB

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