-
Notifications
You must be signed in to change notification settings - Fork 0
/
argontheme.js
1397 lines (1338 loc) · 45.4 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) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var 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",
"评论内容不能为空": "Comment content cannot be empty",
"编辑中": "Editing",
"正在编辑": "Editing",
"评论正在编辑中...": "Comment is editing",
"编辑": "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",
};
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;
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');
toolbar.classList.add("navbar-ontop");
return;
}
if (scrollTop > endTransitionHeight){
toolbar.style.setProperty('background-color', 'rgba(var(--toolbar-color), 0.85)', 'important');
toolbar.style.setProperty('box-shadow', '');
toolbar.classList.remove("navbar-ontop");
return;
}
let transparency = (scrollTop - startTransitionHeight) / (endTransitionHeight - startTransitionHeight) * 0.85;
toolbar.style.setProperty('background-color', 'rgba(var(--toolbar-color), ' + transparency, 'important');
toolbar.style.setProperty('box-shadow', '');
toolbar.classList.remove("navbar-ontop");
}
changeToolbarTransparency();
document.addEventListener("scroll", changeToolbarTransparency, {passive: true});
}();
/*顶栏搜索*/
$(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();
$.pjax({
url: argonConfig.wp_path + "?s=" + encodeURI(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");
$.pjax({
url: argonConfig.wp_path + "?s=" + encodeURI(word)
});
});
/*左侧栏随页面滚动浮动*/
!function(){
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 <= 90 ){
//滚动条在页面中间浮动状态
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 = $('#leftbar_part1').offset().top;
part1OuterHeight = $('#leftbar_part1').outerHeight();
changeLeftbarStickyStatus();
});
new MutationObserver(function(){
part1OffsetTop = $('#leftbar_part1').offset().top;
part1OuterHeight = $('#leftbar_part1').outerHeight();
changeLeftbarStickyStatus();
}).observe(leftbarPart1, {attributes: true, childList: true, subtree: true});
}();
/*Headroom*/
if (argonConfig.headroom){
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(){
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 $readingProgressBar = $('#fabtn_reading_progress_bar');
let $readingProgressDetails = $('#fabtn_reading_progress_details');
let isScrolling = false;
$backToTopBtn.on("click" , function(){
if (!isScrolling){
isScrolling = true;
setTimeout(function(){
isScrolling = false;
} , 600);
$("body,html").animate({
scrollTop: 0
}, 600);
}
});
$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"));
});
function changefabtnDisplayStatus(){
//阅读进度
let readingProgress = $(window).scrollTop() / Math.max($(document).height() - $(window).height(), 0.01);
$readingProgressDetails.html((readingProgress * 100).toFixed(0) + "%");
$readingProgressBar.css("width" , (readingProgress * 100).toFixed(0) + "%");
//是否显示回顶
if ($(window).scrollTop() >= 400 || readingProgress >= 0.5){
$backToTopBtn.removeClass("fabtn-hidden");
}else{
$backToTopBtn.addClass("fabtn-hidden");
}
}
changefabtnDisplayStatus();
$(window).scroll(function(){
changefabtnDisplayStatus();
});
$fabtns.removeClass("fabtns-unloaded");
}();
/*卡片圆角大小调整*/
!function(){
function setCardRadius(radius, save){
document.documentElement.style.setProperty('--card-radius', radius + "px");
if (save){
localStorage["argon_card_radius"] = radius;
}
}
let slider = document.getElementById('blog_setting_card_radius');
noUiSlider.create(slider, {
start: [localStorage["argon_card_radius"] == undefined ? $("meta[name='theme-card-radius']").attr("content") : localStorage["argon_card_radius"]],
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']").attr("content"));
setCardRadius($("meta[name='theme-card-radius']").attr("content"), false);
localStorage.removeItem("argon_card_radius");
});
if (localStorage["argon_card_radius"] != undefined){
setCardRadius(localStorage["argon_card_radius"], false);
}
}();
/*需要密码的文章加载*/
$(document).on("submit" , ".post-password-form" , function(){
$("input[type='submit']", this).attr("disabled", "disabled");
let url = $(this).attr("action");
$.pjax.form(this, {
push: false,
replace: false
});
return false;
});
/*URL 中 # 根据 ID 定位*/
function gotoHash(hash , durtion){
if (hash.length == 0){
return;
}
if ($(hash).length == 0){
return;
}
if (durtion == null){
durtion = 200;
}
$("body,html").animate({
scrollTop: $(hash).offset().top - 80
}, durtion);
}
function getHash(url){
return url.substring(url.indexOf('#'));
}
!function(){
$(window).on("hashchange" , function(){
hash = window.location.hash;
gotoHash(hash);
});
$(window).trigger("hashchange");
}();
/*显示文章过时信息 Toast*/
function showPostOutdateToast(){
if ($("#primary #post_outdate_toast").length > 0){
iziToast.show({
title: '',
message: $("#primary #post_outdate_toast").data("text"),
class: 'shadow-sm',
position: 'topRight',
backgroundColor: 'var(--themecolor)',
titleColor: '#ffffff',
messageColor: '#ffffff',
iconColor: '#ffffff',
progressBarColor: '#ffffff',
icon: 'fa fa-info',
close: false,
timeout: 8000
});
$("#primary #post_outdate_toast").remove();
}
}
showPostOutdateToast();
/*Zoomify*/
function zoomifyInit(){
if (argonConfig.zoomify == false){
return;
}
$("article img").zoomify(argonConfig.zoomify);
}
zoomifyInit();
/*Lazyload*/
function lazyloadInit(){
if (argonConfig.lazyload == false){
return;
}
if (argonConfig.lazyload.effect == "none"){
delete argonConfig.lazyload.effect;
}
$("article img.lazyload:not(.lazyload-loaded) , .post-thumbnail.lazyload:not(.lazyload-loaded) , .related-post-thumbnail.lazyload:not(.lazyload-loaded)").lazyload(Object.assign(argonConfig.lazyload, {load: function(){$(this).addClass("lazyload-loaded")}}));
$(".comment-item-text .comment-sticker.lazyload").lazyload(Object.assign(argonConfig.lazyload, {load: function(){$(this).removeClass("lazyload")}}));
}
lazyloadInit();
/*Pangu.js*/
function panguInit(){
if (argonConfig.pangu == true){
pangu.spacingElementById('post_content');
}
}
panguInit();
/*Clamp.js*/
function clampInit(){
$(".clamp").each(function(index, dom) {
$clamp(dom, {clamp: dom.getAttribute("clamp-line")});
});
}
clampInit();
/*Pjax*/
$.pjax.defaults.timeout = 10000;
$.pjax.defaults.container = ['#primary', '#leftbar_part1_menu', '#leftbar_part2_inner', '.page-information-card-container', '#wpadminbar'];
$.pjax.defaults.fragment = ['#primary', '#leftbar_part1_menu', '#leftbar_part2_inner', '.page-information-card-container', '#wpadminbar'];
$(document).pjax("a[href]:not([no-pjax]):not(.no-pjax):not([target='_blank']):not([download])")
.on('pjax:click', function(e, f, g){
if (argonConfig.disable_pjax == true){
e.preventDefault();
return;
}
NProgress.remove();
NProgress.start();
}).on('pjax:afterGetContainers', function(e, f, g) {
if (g.is("#main article.post-preview a.post-title")){
let $card = $(g.parents("article.post-preview")[0]);
$card.append("<div class='loading-css-animation'><div class='loading-dot loading-dot-1' ></div><div class='loading-dot loading-dot-2' ></div><div class='loading-dot loading-dot-3' ></div><div class='loading-dot loading-dot-4' ></div><div class='loading-dot loading-dot-5' ></div><div class='loading-dot loading-dot-6' ></div><div class='loading-dot loading-dot-7' ></div><div class='loading-dot loading-dot-8' ></div></div></div>");
$card.addClass("post-pjax-loading");
$("#main").addClass("post-list-pjax-loading");
let offsetTop = $($card).offset().top - $("#main").offset().top;
$card.css("transform" , "translateY(-" + offsetTop + "px)");
$("body,html").animate({
scrollTop: 0
}, 450);
}
}).on('pjax:send', function() {
NProgress.set(0.618);
}).on('pjax:beforeReplace', function(e, dom) {
if ($("#post_comment", dom[0]).length > 0){
$("#fabtn_go_to_comment").removeClass("d-none");
}else{
$("#fabtn_go_to_comment").addClass("d-none");
}
}).on('pjax:complete', function() {
NProgress.inc();
try{
if (MathJax != undefined){
MathJax.typeset();
}
}catch (err){}
try{
if ($("script#mathjax_v2_script" , $vdom).length > 0){
MathJax.Hub.Typeset();
}
}catch (err){}
try{
if (renderMathInElement != undefined){
renderMathInElement(document.body,{
delimiters: [
{left: "$$", right: "$$", display: true},
{left: "$", right: "$", display: false},
{left: "\\(", right: "\\)", display: false}
]
});
}
}catch (err){}
lazyloadInit();
zoomifyInit();
highlightJsRender();
panguInit();
clampInit();
getGithubInfoCardContent();
showPostOutdateToast();
calcHumanTimesOnPage();
if (typeof(window.pjaxLoaded) == "function"){
try{
window.pjaxLoaded();
}catch (err){
console.error(err);
}
}
NProgress.done();
}).on('pjax:end', function() {
lazyloadInit();
});
/*Tags Dialog pjax 加载后自动关闭*/
$(document).on("click" , "#blog_tags .tag" , function(){
$("#blog_tags button.close").trigger("click");
});
$(document).on("click" , "#blog_categories .tag" , function(){
$("#blog_categories button.close").trigger("click");
});
/*侧栏 & 顶栏菜单手机适配*/
!function(){
$(document).on("click" , "#fabtn_open_sidebar" , function(){
$("html").addClass("leftbar-opened");
});
$(document).on("click" , "#sidebar_mask" , function(){
$("html").removeClass("leftbar-opened");
});
$(document).on("click" , "#leftbar a[href]:not([no-pjax]):not([href^='#'])" , function(){
$("html").removeClass("leftbar-opened");
});
$(document).on("click" , "#navbar_global.show .navbar-nav a[href]:not([no-pjax]):not([href^='#'])" , function(){
$("#navbar_global .navbar-toggler").click();
});
$(document).on("click" , "#navbar_global.show #navbar_search_btn_mobile" , function(){
$("#navbar_global .navbar-toggler").click();
});
}();
/*折叠区块小工具*/
$(document).on("click" , ".collapse-block .collapse-block-title" , function(){
let id = this.getAttribute("collapse-id");
let selecter = ".collapse-block[collapse-id='" + id +"']";
$(selecter).toggleClass("collapsed");
if ($(selecter).hasClass("collapsed")){
$(selecter + " .collapse-block-body").stop(true , false).slideUp(200);
}else{
$(selecter + " .collapse-block-body").stop(true , false).slideDown(200);
}
$("html").trigger("scroll");
});
/*获得 Github Repo Shortcode 信息卡内容*/
function getGithubInfoCardContent(){
$(".github-info-card").each(function(){
(function($this){
if ($this.attr("data-getdata") == "backend"){
$(".github-info-card-description" , $this).html($this.attr("data-description"));
$(".github-info-card-stars" , $this).html($this.attr("data-stars"));
$(".github-info-card-forks" , $this).html($this.attr("data-forks"));
return;
}
$(".github-info-card-description" , $this).html("Loading...");
$(".github-info-card-stars" , $this).html("-");
$(".github-info-card-forks" , $this).html("-");
author = $this.attr("data-author");
project = $this.attr("data-project");
$.ajax({
url : "https://api.github.com/repos/" + author + "/" + project,
type : "GET",
dataType : "json",
success : function(result){
description = result.description;
if (result.homepage != ""){
description += " <a href='" + result.homepage + "' target='_blank' no-pjax>" + result.homepage + "</a>"
}
$(".github-info-card-description" , $this).html(description);
$(".github-info-card-stars" , $this).html(result.stargazers_count);
$(".github-info-card-forks" , $this).html(result.forks_count);
//console.log(result);
},
error : function(xhr){
if (xhr.status == 404){
$(".github-info-card-description" , $this).html(__("找不到该 Repo"));
}else{
$(".github-info-card-description" , $this).html(__("获取 Repo 信息失败"));
}
}
});
})($(this));
});
}
getGithubInfoCardContent();
//颜色计算
function rgb2hsl(R,G,B){
let r = R / 255;
let g = G / 255;
let b = B / 255;
let var_Min = Math.min(r, g, b);
let var_Max = Math.max(r, g, b);
let del_Max = var_Max - var_Min;
let H, S, L = (var_Max + var_Min) / 2;
if (del_Max == 0){
H = 0;
S = 0;
}else{
if (L < 0.5){
S = del_Max / (var_Max + var_Min);
}else{
S = del_Max / (2 - var_Max - var_Min);
}
del_R = (((var_Max - r) / 6) + (del_Max / 2)) / del_Max;
del_G = (((var_Max - g) / 6) + (del_Max / 2)) / del_Max;
del_B = (((var_Max - b) / 6) + (del_Max / 2)) / del_Max;
if (r == var_Max){
H = del_B - del_G;
}
else if (g == var_Max){
H = (1 / 3) + del_R - del_B;
}
else if (b == var_Max){
H = (2 / 3) + del_G - del_R;
}
if (H < 0) H += 1;
if (H > 1) H -= 1;
}
return {
'h': H,//0~1
's': S,
'l': L
};
}
function Hue_2_RGB(v1,v2,vH){
if (vH < 0) vH += 1;
if (vH > 1) vH -= 1;
if ((6 * vH) < 1) return (v1 + (v2 - v1) * 6 * vH);
if ((2 * vH) < 1) return v2;
if ((3 * vH) < 2) return (v1 + (v2 - v1) * ((2 / 3) - vH) * 6);
return v1;
}
function hsl2rgb(h,s,l){
let r, g, b, var_1, var_2;
if (s == 0){
r = l;
g = l;
b = l;
}
else{
if (l < 0.5){
var_2 = l * (1 + s);
}
else{
var_2 = (l + s) - (s * l);
}
var_1 = 2 * l - var_2;
r = Hue_2_RGB(var_1, var_2, h + (1 / 3));
g = Hue_2_RGB(var_1, var_2, h);
b = Hue_2_RGB(var_1, var_2, h - (1 / 3));
}
return {
'R': Math.round(r * 255),//0~255
'G': Math.round(g * 255),
'B': Math.round(b * 255),
'r': r,//0~1
'g': g,
'b': b
};
}
function rgb2hex(r,g,b){
let hex = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
let rh, gh, bh;
rh = "", gh ="", bh="";
while (rh.length < 2){
rh = hex[r%16] + rh;
r = Math.floor(r / 16);
}
while (gh.length < 2){
gh = hex[g%16] + gh;
g = Math.floor(g / 16);
}
while (bh.length < 2){
bh = hex[b%16] + bh;
b = Math.floor(b / 16);
}
return "#" + rh + gh + bh;
}
function hex2rgb(hex){
//hex: #XXXXXX
let dec = {
'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, 'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15
};
return {
'R': (dec[hex.substr(1,1)] * 16 + dec[hex.substr(2,1)]),//0~255
'G': (dec[hex.substr(3,1)] * 16 + dec[hex.substr(4,1)]),
'B': (dec[hex.substr(5,1)] * 16 + dec[hex.substr(6,1)]),
'r': (dec[hex.substr(1,1)] * 16 + dec[hex.substr(2,1)]) / 255,//0~1
'g': (dec[hex.substr(3,1)] * 16 + dec[hex.substr(4,1)]) / 255,
'b': (dec[hex.substr(5,1)] * 16 + dec[hex.substr(6,1)]) / 255
};
}
function rgb2gray(R,G,B){
return Math.round(R * 0.299 + G * 0.587 + B * 0.114);
}
function hex2gray(hex){
let rgb_array = hex2rgb(hex);
return hex2gray(rgb_array['R'], rgb_array['G'], rgb_array['B']);
}
function rgb2str(rgb){
return rgb['R'] + "," + rgb['G'] + "," + rgb['B'];
}
function hex2str(hex){
return rgb2str(hex2rgb(hex));
}
//颜色选择器 & 切换主题色
if ($("meta[name='argon-enable-custom-theme-color']").attr("content") == 'true'){
let themeColorPicker = new Pickr({
el: '#theme-color-picker',
container: 'body',
theme: 'monolith',
closeOnScroll: false,
appClass: 'theme-color-picker-box',
useAsButton: false,
padding: 8,
inline: false,
autoReposition: true,
sliders: 'h',
disabled: false,
lockOpacity: true,
outputPrecision: 0,
comparison: false,
default: localStorage["argon_custom_theme_color"] == undefined ? ($("meta[name='theme-color']").attr("content")) : localStorage["argon_custom_theme_color"],
swatches: ['#5e72e4', '#fa7298', '#009688', '#607d8b', '#2196f3', '#3f51b5', '#ff9700', '#109d58', '#dc4437', '#673bb7', '#212121', '#795547'],
defaultRepresentation: 'HEX',
showAlways: false,
closeWithKey: 'Escape',
position: 'top-start',
adjustableNumbers: false,
components: {
palette: true,
preview: true,
opacity: false,
hue: true,
interaction: {
hex: true,
rgba: true,
hsla: false,
hsva: false,
cmyk: false,
input: true,
clear: false,
cancel: true,
save: true
}
},
strings: {
save: __('确定'),
clear: __('清除'),
cancel: __('恢复博客默认')
}
});
themeColorPicker.on('change', instance => {
updateThemeColor(pickrObjectToHEX(instance), true);
})
themeColorPicker.on('save', (color, instance) => {
updateThemeColor(pickrObjectToHEX(instance._color), true);
themeColorPicker.hide();
})
themeColorPicker.on('cancel', instance => {
themeColorPicker.hide();
themeColorPicker.setColor($("meta[name='theme-color-origin']").attr("content").toUpperCase());
updateThemeColor($("meta[name='theme-color-origin']").attr("content").toUpperCase(), false);
localStorage.removeItem("argon_custom_theme_color");
});
}
function pickrObjectToHEX(color){
let HEXA = color.toHEXA();
return ("#" + HEXA[0] + HEXA[1] + HEXA[2]).toUpperCase();
}
function updateThemeColor(color, save){
let themecolor = color;
let themecolor_rgbstr = hex2str(themecolor);
let RGB = hex2rgb(themecolor);
let HSL = rgb2hsl(RGB['R'], RGB['G'], RGB['B']);
let RGB_dark0 = hsl2rgb(HSL['h'], HSL['s'], Math.max(HSL['l'] - 0.025, 0));
let themecolor_dark0 = rgb2hex(RGB_dark0['R'],RGB_dark0['G'],RGB_dark0['B']);
let RGB_dark = hsl2rgb(HSL['h'], HSL['s'], Math.max(HSL['l'] - 0.05, 0));
let themecolor_dark = rgb2hex(RGB_dark['R'], RGB_dark['G'], RGB_dark['B']);
let RGB_dark2 = hsl2rgb(HSL['h'], HSL['s'], Math.max(HSL['l'] - 0.1, 0));
let themecolor_dark2 = rgb2hex(RGB_dark2['R'],RGB_dark2['G'],RGB_dark2['B']);
let RGB_dark3 = hsl2rgb(HSL['h'], HSL['s'], Math.max(HSL['l'] - 0.15, 0));
let themecolor_dark3 = rgb2hex(RGB_dark3['R'],RGB_dark3['G'],RGB_dark3['B']);
let RGB_light = hsl2rgb(HSL['h'], HSL['s'], Math.min(HSL['l'] + 0.1, 1));
let themecolor_light = rgb2hex(RGB_light['R'],RGB_light['G'],RGB_light['B']);