-
-
Notifications
You must be signed in to change notification settings - Fork 559
/
argontheme.js
2616 lines (2537 loc) · 85.1 KB
/
argontheme.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
if (typeof(argonConfig) == "undefined"){
var argonConfig = {};
}
if (typeof(argonConfig.wp_path) == "undefined"){
argonConfig.wp_path = "/";
}
/*Cookies 操作*/
function setCookie(cname, cvalue, exdays) {
let d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
let expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
/*多语言支持*/
var translation = {};
translation['en_US'] = {
"确定": "OK",
"清除": "Clear",
"恢复博客默认": "Set To Default",
"评论内容不能为空": "Comment content cannot be empty",
"昵称不能为空": "Name cannot be empty",
"邮箱或 QQ 号格式错误": "Incorrect email or QQ format",
"邮箱格式错误": "Incorrect email format",
"网站格式错误 (不是 http(s):// 开头)": "Website URL format error",
"验证码未输入": "CAPTCHA cannot be empty",
"验证码格式错误": "Incorrect CAPTCHA format",
"评论格式错误": "Comment format error",
"发送中": "Sending",
"正在发送": "Sending",
"评论正在发送中...": "Comment is sending...",
"发送": "Send",
"评论发送失败": "Comment failed",
"发送成功": "Success",
"您的评论已发送": "Your comment has been sent",
"评论": "Comments",
"未知原因": "Unknown Error",
"编辑中": "Editing",
"正在编辑": "Editing",
"评论正在编辑中...": "Comment is being edited...",
"编辑": "Edit",
"评论编辑失败": "Comment editing failed",
"已编辑": "Edited",
"编辑成功": "Success",
"您的评论已编辑": "Your comment has been edited",
"评论 #": "Comment #",
"的编辑记录": "- Edit History",
"加载失败": "Failed to load",
"展开": "Show",
"没有更多了": "No more comments",
"找不到该 Repo": "Can't find the repository",
"获取 Repo 信息失败": "Failed to get repository information",
"点赞失败": "Vote failed",
"Hitokoto 获取失败": "Failed to get Hitokoto",
"复制成功": "Copied",
"代码已复制到剪贴板": "Code has been copied to the clipboard",
"复制失败": "Failed",
"请手动复制代码": "Please copy the code manually",
"刚刚": "Now",
"分钟前": "minutes ago",
"小时前": "hours ago",
"昨天": "Yesterday",
"前天": "The day before yesterday",
"天前": "days ago",
"隐藏行号": "Hide Line Numbers",
"显示行号": "Show Line Numbers",
"开启折行": "Enable Break Line",
"关闭折行": "Disable Break Line",
"复制": "Copy",
"全屏": "Fullscreen",
"退出全屏": "Exit Fullscreen",
"置顶评论": "Pin Comment",
"取消置顶评论": "Unpin Comment",
"是否要取消置顶评论 #": "Do you want to unpin the comment #",
"是否要置顶评论 #": "Do you want to pin the comment #",
"确认": "Confirm",
"取消": "取消",
"置顶": "Pin",
"取消置顶": "Unpin",
"置顶成功": "Pinned",
"取消置顶成功": "Unpinned",
"该评论已置顶": "The comment has been pinned",
"该评论已取消置顶": "The comment has been unpinned",
"置顶失败": "Failed to pin",
"取消置顶失败": "Failed to unpin",
};
translation['ru_RU'] = {
"确定": "ОК",
"清除": "Очистить",
"恢复博客默认": "Восстановить по умолчанию",
"评论内容不能为空": "Содержимое комментария не может быть пустым",
"昵称不能为空": "Имя не может быть пустым",
"邮箱或 QQ 号格式错误": "Неверный формат электронной почты или QQ",
"邮箱格式错误": "Неправильный формат электронной почты",
"网站格式错误 (不是 http(s):// 开头)": "Сайт ошибка формата URL-адреса ",
"验证码未输入": "Вы не решили капчу",
"验证码格式错误": "Ошибка проверки капчи",
"评论格式错误": "Неправильный формат комментария",
"发送中": "Отправка",
"正在发送": "Отправка",
"评论正在发送中...": "Комментарий отправляется...",
"发送": "Отправить",
"评论发送失败": "Не удалось отправить комментарий",
"发送成功": "Комментарий отправлен",
"您的评论已发送": "Ваш комментарий был отправлен",
"评论": "Комментарии",
"未知原因": "Неизвестная ошибка",
"编辑中": "Редактируется",
"正在编辑": "Редактируется",
"评论正在编辑中...": "Комментарий редактируется",
"编辑": "Редактировать",
"评论编辑失败": "Не удалось отредактировать комментарий",
"已编辑": "Изменено",
"编辑成功": "Успешно",
"您的评论已编辑": "Ваш комментарий был изменен",
"评论 #": "Комментарий #",
"的编辑记录": "- История изменений",
"加载失败": "Ошибка загрузки",
"展开": "Показать",
"没有更多了": "Комментариев больше нет",
"找不到该 Repo": "Невозможно найти репозиторий",
"获取 Repo 信息失败": "Неудалось получить информацию репозитория",
"点赞失败": "Ошибка голосования",
"Hitokoto 获取失败": "Проблемы с вызовом Hitokoto",
"复制成功": "Скопировано",
"代码已复制到剪贴板": "Код скопирован в буфер обмена",
"复制失败": "Неудалось",
"请手动复制代码": "Скопируйте код вручную",
"刚刚": "Сейчас",
"分钟前": "минут назад",
"小时前": "часов назад",
"昨天": "Вчера",
"前天": "Позавчера",
"天前": "дней назад",
"隐藏行号": "Скрыть номера строк",
"显示行号": "Показать номера строк",
"开启折行": "Включить перенос строк",
"关闭折行": "Выключить перенос строк",
"复制": "Скопировать",
"全屏": "Полноэкранный режим",
"退出全屏": "Выход из полноэкранного режима",
};
translation['zh_TW'] = {
"确定": "確定",
"清除": "清除",
"恢复博客默认": "恢復博客默認",
"评论内容不能为空": "評論內容不能為空",
"昵称不能为空": "昵稱不能為空",
"邮箱或 QQ 号格式错误": "郵箱或 QQ 號格式錯誤",
"邮箱格式错误": "郵箱格式錯誤",
"网站格式错误 (不是 http(s):// 开头)": "網站格式錯誤 (不是 http(s):// 開頭)",
"验证码未输入": "驗證碼未輸入",
"验证码格式错误": "驗證碼格式錯誤",
"评论格式错误": "評論格式錯誤",
"发送中": "發送中",
"正在发送": "正在發送",
"评论正在发送中...": "評論正在發送中...",
"发送": "發送",
"评论发送失败": "評論發送失敗",
"发送成功": "發送成功",
"您的评论已发送": "您的評論已發送",
"评论": "評論",
"未知原因": "未知原因",
"编辑中": "編輯中",
"正在编辑": "正在編輯",
"评论正在编辑中...": "評論正在編輯中...",
"编辑": "編輯",
"评论编辑失败": "評論編輯失敗",
"已编辑": "已編輯",
"编辑成功": "編輯成功",
"您的评论已编辑": "您的評論已編輯",
"评论 #": "評論 #",
"的编辑记录": "的編輯記錄",
"加载失败": "加載失敗",
"展开": "展開",
"没有更多了": "沒有更多了",
"找不到该 Repo": "找不到該 Repo",
"获取 Repo 信息失败": "獲取 Repo 信息失敗",
"点赞失败": "點贊失敗",
"Hitokoto 获取失败": "Hitokoto 獲取失敗",
"复制成功": "復制成功",
"代码已复制到剪贴板": "代碼已復制到剪貼板",
"复制失败": "復制失敗",
"请手动复制代码": "請手動復制代碼",
"刚刚": "剛剛",
"分钟前": "分鐘前",
"小时前": "小時前",
"昨天": "昨天",
"前天": "前天",
"天前": "天前",
"隐藏行号": "隱藏行號",
"显示行号": "顯示行號",
"开启折行": "開啟折行",
"关闭折行": "關閉折行",
"复制": "復制",
"全屏": "全屏",
"退出全屏": "退出全屏"
};
function __(text){
let lang = argonConfig.language;
if (typeof(translation[lang]) == "undefined"){
return text;
}
if (typeof(translation[lang][text]) == "undefined"){
return text;
}
return translation[lang][text];
}
/*根据滚动高度改变顶栏透明度*/
!function(){
let toolbar = document.getElementById("navbar-main");
let $bannerContainer = $("#banner_container");
let $content = $("#content");
let startTransitionHeight;
let endTransitionHeight;
let maxOpacity = 0.85;
startTransitionHeight = $bannerContainer.offset().top - 75;
endTransitionHeight = $content.offset().top - 75;
$(window).resize(function(){
startTransitionHeight = $bannerContainer.offset().top - 75;
endTransitionHeight = $content.offset().top - 75;
});
function changeToolbarTransparency(){
let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
if (scrollTop < startTransitionHeight){
toolbar.style.setProperty('background-color', 'rgba(var(--toolbar-color), 0)', 'important');
toolbar.style.setProperty('box-shadow', 'none');
if (argonConfig.toolbar_blur){
toolbar.style.setProperty('backdrop-filter', 'blur(0px)');
}
toolbar.classList.add("navbar-ontop");
return;
}
if (scrollTop > endTransitionHeight){
toolbar.style.setProperty('background-color', 'rgba(var(--toolbar-color), ' + maxOpacity + ')', 'important');
toolbar.style.setProperty('box-shadow', '');
if (argonConfig.toolbar_blur){
toolbar.style.setProperty('backdrop-filter', 'blur(16px)');
}
toolbar.classList.remove("navbar-ontop");
return;
}
let transparency = (scrollTop - startTransitionHeight) / (endTransitionHeight - startTransitionHeight) * maxOpacity;
toolbar.style.setProperty('background-color', 'rgba(var(--toolbar-color), ' + transparency, 'important');
toolbar.style.setProperty('box-shadow', '');
if (argonConfig.toolbar_blur){
if ((scrollTop - startTransitionHeight) / (endTransitionHeight - startTransitionHeight) > 0.3){
toolbar.style.setProperty('backdrop-filter', 'blur(16px)');
}else{
toolbar.style.setProperty('backdrop-filter', 'blur(0px)');
}
}
toolbar.classList.remove("navbar-ontop");
}
function changeToolbarOnTopClass(){
let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
if (scrollTop < 30){
toolbar.classList.add("navbar-no-blur");
}else{
toolbar.classList.remove("navbar-no-blur");
}
}
if ($("html").hasClass("no-banner")) {
changeToolbarOnTopClass();
document.addEventListener("scroll", changeToolbarOnTopClass, {passive: true});
return;
}
if (argonConfig.headroom == "absolute") {
toolbar.classList.add("navbar-ontop");
return;
}
if ($("html").hasClass("toolbar-blur")) {
argonConfig.toolbar_blur = true;
maxOpacity = 0.65;
}else{
argonConfig.toolbar_blur = false;
}
changeToolbarTransparency();
document.addEventListener("scroll", changeToolbarTransparency, {passive: true});
}();
/*搜索*/
function searchPosts(word){
if ($(".search-result").length > 0){
let url = new URL(window.location.href);
url.searchParams.set("s", word);
$.pjax({
url: url.href
});
}else{
$.pjax({
url: argonConfig.wp_path + "?s=" + encodeURIComponent(word)
});
}
}
/*顶栏搜索*/
$(document).on("click" , "#navbar_search_input_container" , function(){
$(this).addClass("open");
$("#navbar_search_input").focus();
});
$(document).on("blur" , "#navbar_search_input_container" , function(){
$(this).removeClass("open");
});
$(document).on("keydown" , "#navbar_search_input_container #navbar_search_input" , function(e){
if (e.keyCode != 13){
return;
}
let word = $(this).val();
if (word == ""){
$("#navbar_search_input_container").blur();
return;
}
let scrolltop = $(document).scrollTop();
searchPosts(word);
});
/*顶栏搜索 (Mobile)*/
$(document).on("keydown" , "#navbar_search_input_mobile" , function(e){
if (e.keyCode != 13){
return;
}
let word = $(this).val();
$("#navbar_global .collapse-close button").click();
if (word == ""){
return;
}
let scrolltop = $(document).scrollTop();
searchPosts(word);
});
/*侧栏搜索*/
$(document).on("click" , "#leftbar_search_container" , function(){
$(".leftbar-search-button").addClass("open");
$("#leftbar_search_input").removeAttr("readonly").focus();
$("#leftbar_search_input").focus();
$("#leftbar_search_input").select();
return false;
});
$(document).on("blur" , "#leftbar_search_container" , function(){
$(".leftbar-search-button").removeClass("open");
$("#leftbar_search_input").attr("readonly", "readonly");
});
$(document).on("keydown" , "#leftbar_search_input" , function(e){
if (e.keyCode != 13){
return;
}
let word = $(this).val();
if (word == ""){
$("#leftbar_search_container").blur();
return;
}
$("html").removeClass("leftbar-opened");
searchPosts(word);
});
/*搜索过滤器*/
$(document).on("change" , ".search-filter" , function(e){
if (pjaxLoading){
$(this).prop("checked", !$(this).prop("checked"));
e.preventDefault();
return;
}
pjaxLoading = true;
let postTypes = [];
$(".search-filter:checked").each(function(){
postTypes.push($(this).attr("name"));
});
if (postTypes.length == 0){
postTypes = ["none"];
}
let url = new URL(document.location.href);
url.searchParams.set("post_type", postTypes.join(","));
url.pathname = url.pathname.replace(/\/page\/\d+$/, '');
$.pjax({
url: url.href
});
});
/*左侧栏随页面滚动浮动*/
!function(){
if ($("#leftbar").length == 0){
let contentOffsetTop = $('#content').offset().top;
function changeLeftbarStickyStatusWithoutSidebar(){
let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
if( contentOffsetTop - 10 - scrollTop <= 20 ){
document.body.classList.add('leftbar-can-headroom');
}else{
document.body.classList.remove('leftbar-can-headroom');
}
}
changeLeftbarStickyStatusWithoutSidebar();
document.addEventListener("scroll", changeLeftbarStickyStatusWithoutSidebar, {passive: true});
$(window).resize(function(){
contentOffsetTop = $('#content').offset().top;
changeLeftbarStickyStatusWithoutSidebar();
});
return;
}
let $leftbarPart1 = $('#leftbar_part1');
let $leftbarPart2 = $('#leftbar_part2');
let leftbarPart1 = document.getElementById('leftbar_part1');
let leftbarPart2 = document.getElementById('leftbar_part2');
let part1OffsetTop = $('#leftbar_part1').offset().top;
let part1OuterHeight = $('#leftbar_part1').outerHeight();
function changeLeftbarStickyStatus(){
let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
if( part1OffsetTop + part1OuterHeight + 10 - scrollTop <= (argonConfig.headroom != "absolute" ? 90 : 18) ){
//滚动条在页面中间浮动状态
leftbarPart2.classList.add('sticky');
}else{
//滚动条在顶部 不浮动状态
leftbarPart2.classList.remove('sticky');
}
if( part1OffsetTop + part1OuterHeight + 10 - scrollTop <= 20 ){//侧栏下部分是否可以随 Headroom 一起向上移动
document.body.classList.add('leftbar-can-headroom');
}else{
document.body.classList.remove('leftbar-can-headroom');
}
}
changeLeftbarStickyStatus();
document.addEventListener("scroll", changeLeftbarStickyStatus, {passive: true});
$(window).resize(function(){
part1OffsetTop = $leftbarPart1.offset().top;
part1OuterHeight = $leftbarPart1.outerHeight();
changeLeftbarStickyStatus();
});
new MutationObserver(function(){
part1OffsetTop = $leftbarPart1.offset().top;
part1OuterHeight = $leftbarPart1.outerHeight();
changeLeftbarStickyStatus();
}).observe(leftbarPart1, {attributes: true, childList: true, subtree: true});
}();
/*Headroom*/
if (argonConfig.headroom == "true"){
var headroom = new Headroom(document.querySelector("body"),{
"tolerance" : {
up : 0,
down : 0
},
"offset": 0,
"classes": {
"initial": "with-headroom",
"pinned": "headroom---pinned",
"unpinned": "headroom---unpinned",
"top": "headroom---top",
"notTop": "headroom---not-top",
"bottom": "headroom---bottom",
"notBottom": "headroom---not-bottom",
"frozen": "headroom---frozen"
}
}).init();
}
/*瀑布流布局*/
function waterflowInit() {
if (argonConfig.waterflow_columns == "1") {
return;
}
$("#main.article-list img").each(function(index, ele){
ele.onload = function(){
waterflowInit();
}
});
let columns;
if (argonConfig.waterflow_columns == "2and3") {
if ($("#main").outerWidth() > 1000) {
columns = 3;
} else {
columns = 2;
}
}else{
columns = parseInt(argonConfig.waterflow_columns);
}
if ($("#main").outerWidth() < 650 && columns == 2) {
columns = 1;
}else if ($("#main").outerWidth() < 800 && columns == 3) {
columns = 1;
}
let heights = [0, 0, 0];
function getMinHeightPosition(){
let res = 0, minn = 2147483647;
for (var i = 0; i < columns; i++) {
if (heights[i] < minn) {
minn = heights[i];
res = i;
}
}
return res;
}
function getMaxHeight(){
let res = 0;
for (let i in heights) {
res = Math.max(res, heights[i]);
}
return res;
}
$("#primary").css("transition", "none")
.addClass("waterflow");
let $container = $("#main.article-list");
if (!$container.length){
return;
}
let $items = $container.find("article.post:not(.no-results), .shuoshuo-preview-container");
columns = Math.max(Math.min(columns, $items.length), 1);
if (columns == 1) {
$container.removeClass("waterflow");
$items.css("transition", "").css("position", "").css("width", "").css("top", "").css("left", "").css("margin", "");
$(".waterflow-placeholder").remove();
}else{
$container.addClass("waterflow");
$items.each(function(index, item) {
let $item = $(item);
$item.css("transition", "none")
.css("position", "absolute")
.css("width", "calc(" + (100 / columns) + "% - " + (10 * (columns - 1) / columns) + "px)").css("margin", 0);
let itemHeight = $item.outerHeight() + 10;
let pos = getMinHeightPosition();
$item.css("top", heights[getMinHeightPosition()] + "px")
.css("left", (pos * $item.outerWidth() + 10 * pos) + "px");
heights[pos] += itemHeight;
});
}
if ($(".waterflow-placeholder").length) {
$(".waterflow-placeholder").css("height", getMaxHeight() + "px");
}else{
$container.prepend("<div class='waterflow-placeholder' style='height: " + getMaxHeight() +"px;'></div>");
}
}
waterflowInit();
if (argonConfig.waterflow_columns != "1") {
$(window).resize(function(){
waterflowInit();
});
new MutationObserver(function(mutations, observer){
waterflowInit();
}).observe(document.querySelector("#primary"), {
'childList': true
});
}
/*浮动按钮栏相关 (回顶等)*/
!function(){
let $fabtns = $('#float_action_buttons');
let $backToTopBtn = $('#fabtn_back_to_top');
let $toggleSidesBtn = $('#fabtn_toggle_sides');
let $toggleDarkmode = $('#fabtn_toggle_darkmode');
let $toggleAmoledMode = $('#blog_setting_toggle_darkmode_and_amoledarkmode');
let $toggleBlogSettings = $('#fabtn_toggle_blog_settings_popup');
let $goToComment = $('#fabtn_go_to_comment');
let $readingProgressBtn = $('#fabtn_reading_progress');
let $readingProgressBar = $('#fabtn_reading_progress_bar');
let $readingProgressDetails = $('#fabtn_reading_progress_details');
$backToTopBtn.on("click" , function(){
$("body,html").stop().animate({
scrollTop: 0
}, 800, 'easeOutExpo');
});
$toggleDarkmode.on("click" , function(){
toggleDarkmode();
});
$toggleAmoledMode.on("click" , function(){
toggleAmoledDarkMode();
})
if ($("#post_comment").length > 0){
$("#fabtn_go_to_comment").removeClass("d-none");
}else{
$("#fabtn_go_to_comment").addClass("d-none");
}
$goToComment.on("click" , function(){
gotoHash("#post_comment" , 600);
$("#post_comment_content").focus();
});
if (localStorage['Argon_fabs_Floating_Status'] == "left"){
$fabtns.addClass("fabtns-float-left");
}
$toggleSidesBtn.on("click" , function(){
$fabtns.addClass("fabtns-unloaded");
setTimeout(function(){
$fabtns.toggleClass("fabtns-float-left");
if ($fabtns.hasClass("fabtns-float-left")){
localStorage['Argon_fabs_Floating_Status'] = "left";
}else{
localStorage['Argon_fabs_Floating_Status'] = "right";
}
$fabtns.removeClass("fabtns-unloaded");
} , 300);
});
//博客设置
$toggleBlogSettings.on("click" , function(){
$("#float_action_buttons").toggleClass("blog_settings_opened");
});
$("#close_blog_settings").on("click" , function(){
$("#float_action_buttons").removeClass("blog_settings_opened");
});
$("#blog_setting_darkmode_switch .custom-toggle-slider").on("click" , function(){
toggleDarkmode();
});
//字体
$("#blog_setting_font_sans_serif").on("click" , function(){
$("html").removeClass("use-serif");
localStorage['Argon_Use_Serif'] = "false";
});
$("#blog_setting_font_serif").on("click" , function(){
$("html").addClass("use-serif");
localStorage['Argon_Use_Serif'] = "true";
});
if (localStorage['Argon_Use_Serif'] == "true"){
$("html").addClass("use-serif");
}else if (localStorage['Argon_Use_Serif'] == "false"){
$("html").removeClass("use-serif");
}
//阴影
$("#blog_setting_shadow_small").on("click" , function(){
$("html").removeClass("use-big-shadow");
localStorage['Argon_Use_Big_Shadow'] = "false";
});
$("#blog_setting_shadow_big").on("click" , function(){
$("html").addClass("use-big-shadow");
localStorage['Argon_Use_Big_Shadow'] = "true";
});
if (localStorage['Argon_Use_Big_Shadow'] == "true"){
$("html").addClass("use-big-shadow");
}else if (localStorage['Argon_Use_Big_Shadow'] == "false"){
$("html").removeClass("use-big-shadow");
}
//滤镜
function setBlogFilter(name){
if (name == undefined || name == ""){
name = "off";
}
if (!$("html").hasClass("filter-" + name)){
$("html").removeClass("filter-sunset filter-darkness filter-grayscale");
if (name != "off"){
$("html").addClass("filter-" + name);
}
}
$("#blog_setting_filters .blog-setting-filter-btn").removeClass("active");
$("#blog_setting_filters .blog-setting-filter-btn[filter-name='" + name + "']").addClass("active");
localStorage['Argon_Filter'] = name;
}
setBlogFilter(localStorage['Argon_Filter']);
$(".blog-setting-filter-btn").on("click" , function(){
setBlogFilter(this.getAttribute("filter-name"));
});
let $window = $(window);
function changefabtnDisplayStatus(){
//阅读进度
function hideReadingProgress(){
$readingProgressBtn.addClass("fabtn-hidden");
}
function setReadingProgress(percent){
$readingProgressBtn.removeClass("fabtn-hidden");
$readingProgressDetails.html((percent * 100).toFixed(0) + "%");
$readingProgressBar.css("width" , (percent * 100).toFixed(0) + "%");
}
if ($("article.post.post-full").length == 0){
hideReadingProgress();
}else{
let a = $window.scrollTop() - ($("article.post.post-full").offset().top - 80);
let b = $("article.post.post-full").outerHeight() + 50 - $window.height();
if (b <= 0){
hideReadingProgress();
}else{
readingProgress = a / b;
if (isNaN(readingProgress) || readingProgress < 0 || readingProgress > 1){
hideReadingProgress();
}else{
setReadingProgress(readingProgress);
}
}
}
//是否显示回顶
if ($(window).scrollTop() >= 400){
$backToTopBtn.removeClass("fabtn-hidden");
}else{
$backToTopBtn.addClass("fabtn-hidden");
}
}
changefabtnDisplayStatus();
$(window).scroll(function(){
changefabtnDisplayStatus();
});
$(window).resize(function(){
changefabtnDisplayStatus();
});
$fabtns.removeClass("fabtns-unloaded");
}();
/*卡片圆角大小调整*/
!function(){
function setCardRadius(radius, setcookie){
document.documentElement.style.setProperty('--card-radius', radius + "px");
if (setcookie){
setCookie("argon_card_radius", radius, 365);
}
}
let slider = document.getElementById('blog_setting_card_radius');
noUiSlider.create(slider, {
start: [$("meta[name='theme-card-radius']").attr("content")],
step: 0.5,
connect: [true, false],
range: {
'min': [0],
'max': [30]
}
});
slider.noUiSlider.on('update', function (values){
let value = values[0];
setCardRadius(value, false);
});
slider.noUiSlider.on('set', function (values){
let value = values[0];
setCardRadius(value, true);
});
$(document).on("click" , "#blog_setting_card_radius_to_default" , function(){
slider.noUiSlider.set($("meta[name='theme-card-radius-origin']").attr("content"));
setCardRadius($("meta[name='theme-card-radius-origin']").attr("content"), false);
setCookie("argon_card_radius", $("meta[name='theme-card-radius-origin']").attr("content"), 0);
});
}();
/*评论区 & 发送评论*/
!function(){
//回复评论
let replying = false , replyID = 0;
function reply(commentID){
cancelEdit(false);
replying = true;
replyID = commentID;
$("#post_comment_reply_name").html($("#comment-" + commentID + " .comment-item-title > .comment-name")[0].innerHTML);
let preview = $("#comment-" + commentID + " .comment-item-text")[0].innerHTML;
if ($("#comment-" + commentID + " .comment-item-source")[0].innerHTML != ''){
preview = $("#comment-" + commentID + " .comment-item-source")[0].innerHTML.replace(/\n/g, "</br>");
}
$("#post_comment_reply_preview").html(preview);
if ($("#comment-" + commentID + " .comment-item-title .badge-private-comment").length > 0){
$("#post_comment").addClass("post-comment-force-privatemode-on");
}else{
$("#post_comment").addClass("post-comment-force-privatemode-off");
}
$("body,html").animate({
scrollTop: $('#post_comment').offset().top - 100
}, 500, 'easeOutCirc');
$('#post_comment_reply_info').slideDown(500, 'easeOutCirc');
setTimeout(function(){
$("#post_comment_content").focus();
}, 500);
}
function cancelReply(){
replying = false;
replyID = 0;
$('#post_comment_reply_info').slideUp(300, 'easeOutCirc');
$("#post_comment").removeClass("post-comment-force-privatemode-on post-comment-force-privatemode-off");
}
$(document).on("click" , ".comment-reply" , function(){
reply(this.getAttribute("data-id"));
});
$(document).on("click pjax:click" , "#post_comment_reply_cancel" , function(){
cancelReply();
});
$(document).on("pjax:click" , function(){
replying = false;
replyID = 0;
$('#post_comment_reply_info').css("display", "none");
$("#post_comment").removeClass("post-comment-force-privatemode-on post-comment-force-privatemode-off");
});
//编辑评论
let editing = false , editID = 0;
function edit(commentID){
cancelReply();
editing = true;
editID = commentID;
$('#post_comment').addClass("editing");
$("#post_comment_content").val($("#comment-" + editID + " .comment-item-source").text());
$("#post_comment_content").trigger("change");
if ($("#comment-" + editID).data("use-markdown") == true && document.getElementById("comment_post_use_markdown") != null){
document.getElementById("comment_post_use_markdown").checked = true;
}else{
document.getElementById("comment_post_use_markdown").checked = false;
}
if ($("#comment-" + commentID + " .comment-item-title .badge-private-comment").length > 0){
$("#post_comment").addClass("post-comment-force-privatemode-on");
}else{
$("#post_comment").addClass("post-comment-force-privatemode-off");
}
$("body,html").animate({
scrollTop: $('#post_comment').offset().top - 100
}, 500, 'easeOutCirc');
$("#post_comment_content").focus();
}
function cancelEdit(clear){
editing = false;
editID = 0;
$("#post_comment").removeClass("post-comment-force-privatemode-on post-comment-force-privatemode-off");
if (clear == true) $("#post_comment_content").val("");
$("#post_comment_content").trigger("change");
$('#post_comment').removeClass("editing");
}
$(document).on("click", ".comment-edit", function(){
edit(this.getAttribute("data-id"));
});
$(document).on("click", "#post_comment_edit_cancel", function(){
$("body,html").animate({
scrollTop: $("#comment-" + editID).offset().top - 100
}, 400, 'easeOutCirc');
cancelEdit(true);
});
$(document).on("pjax:click", function(){
cancelEdit(true);
});
$(document).on("click", ".comment-pin, .comment-unpin", function(){
toogleCommentPin(this.getAttribute("data-id"), !this.classList.contains("comment-pin"));
});
$(document).on("mouseenter", ".comment-parent-info", function(){
$("#comment-" + this.getAttribute("data-parent-id")).addClass("highlight");
});
$(document).on("mouseleave", ".comment-parent-info", function(){
$("#comment-" + this.getAttribute("data-parent-id")).removeClass("highlight");
});
//切换评论置顶状态
function toogleCommentPin(commentID, pinned){
$("#comment_pin_comfirm_dialog .modal-title").html(pinned ? __("取消置顶评论") : __("置顶评论"));
$("#comment_pin_comfirm_dialog .modal-body").html(pinned ? __("是否要取消置顶评论 #") + commentID + "?" : __("是否要置顶评论 #") + commentID + "?");
$("#comment_pin_comfirm_dialog .btn-comfirm").html(__("确认")).attr("disabled", false);
$("#comment_pin_comfirm_dialog .btn-dismiss").html(__("取消")).attr("disabled", false);
$("#comment_pin_comfirm_dialog .btn-comfirm").off("click").on("click", function(){
$("#comment_pin_comfirm_dialog .btn-dismiss").attr("disabled", true)
$("#comment_pin_comfirm_dialog .btn-comfirm").attr("disabled", true).prepend(__(`<span class="btn-inner--icon" style="margin-right: 10px;"><i class="fa fa-spinner fa-spin"></i></span>`));
$.ajax({
type: 'POST',
url: argonConfig.wp_path + "wp-admin/admin-ajax.php",
dataType : "json",
data: {
action: "pin_comment",
id: commentID,
pinned: pinned ? "false" : "true"
},
success: function(result){
$("#comment_pin_comfirm_dialog").modal('hide');
if (result.status == "success"){
if (pinned){
$("#comment-" + commentID + " .comment-name .badge-pinned").remove();
$("#comment-" + commentID + " .comment-unpin").removeClass("comment-unpin").addClass("comment-pin").html(__("置顶"));
}else{
$("#comment-" + commentID + " .comment-name").append(`<span class="badge badge-danger badge-pinned">${__("置顶")}</span>`);
$("#comment-" + commentID + " .comment-pin").removeClass("comment-pin").addClass("comment-unpin").html(__("取消置顶"));
}
iziToast.show({
title: pinned ? __("取消置顶成功") : __("置顶成功"),
message: pinned ? __("该评论已取消置顶") : __("该评论已置顶"),
class: 'shadow-sm',
position: 'topRight',
backgroundColor: '#2dce89',
titleColor: '#ffffff',
messageColor: '#ffffff',
iconColor: '#ffffff',
progressBarColor: '#ffffff',
icon: 'fa fa-check',
timeout: 5000
});
} else {
iziToast.show({
title: pinned ? __("取消置顶失败") : __("置顶失败"),
message: result.msg,
class: 'shadow-sm',
position: 'topRight',
backgroundColor: '#f5365c',
titleColor: '#ffffff',
messageColor: '#ffffff',
iconColor: '#ffffff',
progressBarColor: '#ffffff',
icon: 'fa fa-close',
timeout: 5000
});
}
},
error: function(result){
$("#comment_pin_comfirm_dialog").modal('hide');
iziToast.show({
title: pinned ? __("取消置顶失败") : __("置顶失败"),
message: __("未知错误"),
class: 'shadow-sm',
position: 'topRight',
backgroundColor: '#f5365c',
titleColor: '#ffffff',
messageColor: '#ffffff',
iconColor: '#ffffff',
progressBarColor: '#ffffff',
icon: 'fa fa-close',
timeout: 5000
});
}
});
});
$("#comment_pin_comfirm_dialog").modal(null);
}
//显示/隐藏额外输入框 (评论者网站)
$(document).on("click" , "#post_comment_toggle_extra_input" , function(){
$("#post_comment").toggleClass("show-extra-input");
if ($("#post_comment").hasClass("show-extra-input")){
$("#post_comment_extra_input").slideDown(300, 'easeOutCirc');
}else{
$("#post_comment_extra_input").slideUp(300, 'easeOutCirc');
}
});
//输入框细节
$(document).on("change input keydown keyup propertychange" , "#post_comment_content" , function(){
$("#post_comment_content_hidden")[0].innerText = $("#post_comment_content").val() + "\n";
$("#post_comment_content").css("height" , $("#post_comment_content_hidden").outerHeight());
});
$(document).on("focus" , "#post_comment_link" , function(){
$(".post-comment-link-container").addClass("active");
});
$(document).on("blur" , "#post_comment_link" , function(){
$(".post-comment-link-container").removeClass("active");
});
$(document).on("focus" , "#post_comment_captcha" , function(){
$(".post-comment-captcha-container").addClass("active");
});
$(document).on("blur" , "#post_comment_captcha" , function(){
$(".post-comment-captcha-container").removeClass("active");
});
//发送评论
function postComment(){
let commentContent = $("#post_comment_content").val();
let commentName = $("#post_comment_name").val();
let commentEmail = $("#post_comment_email").val();
let commentLink = $("#post_comment_link").val();
let commentCaptcha = $("#post_comment_captcha").val();
let useMarkdown = false;
let privateMode = false;
let mailNotice = false;
if ($("#comment_post_use_markdown").length > 0){
useMarkdown = $("#comment_post_use_markdown")[0].checked;
}
if ($("#comment_post_privatemode").length > 0){
privateMode = $("#comment_post_privatemode")[0].checked;
}
if ($("#comment_post_mailnotice").length > 0){
mailNotice = $("#comment_post_mailnotice")[0].checked;
}
let postID = $("#post_comment_post_id").val();
let commentCaptchaSeed = $("#post_comment_captcha_seed").val();
let isError = false;
let errorMsg = "";
//检查表单合法性
if (commentContent.match(/^\s*$/)){
isError = true;
errorMsg += __("评论内容不能为空") + "</br>";
}
if (!$("#post_comment").hasClass("no-need-name-email")){
if (commentName.match(/^\s*$/)){
isError = true;
errorMsg += __("昵称不能为空") + "</br>";
}
if ($("#post_comment").hasClass("enable-qq-avatar")){
if (!(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(commentEmail) && !(/^[1-9][0-9]{4,10}$/).test(commentEmail)){
isError = true;
errorMsg += __("邮箱或 QQ 号格式错误") + "</br>";
}
}else{
if (!(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(commentEmail)){
isError = true;
errorMsg += __("邮箱格式错误") + "</br>";