Skip to content

Commit 2d5f202

Browse files
committed
Fix JavaScript loading issues and remove extra spaces in script references
1 parent 5ae6b32 commit 2d5f202

File tree

5 files changed

+89
-62
lines changed

5 files changed

+89
-62
lines changed

_includes/footer.html

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</footer>
1919

2020
<!-- Critical JavaScript - Load Immediately -->
21-
<script src="{{ "/js/jquery.min.js " | prepend: site.baseurl }}"></script>
21+
<script src="{{ "/js/jquery.min.js" | prepend: site.baseurl }}"></script>
2222

2323
<!-- Non-Critical JavaScript - Load Asynchronously -->
2424
<script>
@@ -33,9 +33,12 @@
3333

3434
// Load scripts after page load
3535
window.addEventListener('load', function() {
36-
loadScript('{{ "/js/bootstrap.min.js " | prepend: site.baseurl }}');
37-
loadScript('{{ "/js/jason-blog.min.js " | prepend: site.baseurl }}');
38-
loadScript('{{ "/js/simple-jekyll-search.min.js" | prepend: site.baseurl }}');
36+
loadScript('{{ "/js/bootstrap.min.js" | prepend: site.baseurl }}');
37+
loadScript('{{ "/js/jason-blog.min.js" | prepend: site.baseurl }}');
38+
loadScript('{{ "/js/simple-jekyll-search.min.js" | prepend: site.baseurl }}', function() {
39+
// Initialize SimpleJekyllSearch after script loads
40+
initSimpleJekyllSearch();
41+
});
3942

4043
// Initialize all features when page loads
4144
initLazyLoading();
@@ -258,7 +261,7 @@
258261
$('#tag_cloud a').tagcloud();
259262
})
260263
</script>
261-
<script src='{{ "/js/archive.js " | prepend: site.baseurl }}'></script>
264+
<script src='{{ "/js/archive.js" | prepend: site.baseurl }}'></script>
262265
{% endif %}
263266

264267
<!--fastClick.js -->
@@ -432,26 +435,30 @@
432435
return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
433436
}
434437

435-
SimpleJekyllSearch({
436-
searchInput: document.getElementById('search-input'),
437-
resultsContainer: document.getElementById('search-results'),
438-
json: '/search.json',
439-
searchResultTemplate: '<div class="post-preview item"><a href="{url}"><h2 class="post-title">{title}</h2><h3 class="post-subtitle">{subtitle}</h3><hr></a></div>',
440-
noResultsText: 'No results',
441-
limit: 50,
442-
fuzzy: false,
443-
// a hack to get escaped subtitle unescaped. for some reason,
444-
// post.subtitle w/o escape filter nuke entire search.
445-
templateMiddleware: function (prop, value, template) {
446-
if (prop === 'subtitle' || prop === 'title') {
447-
if (value.indexOf("code")) {
448-
return htmlDecode(value);
449-
} else {
450-
return value;
438+
function initSimpleJekyllSearch() {
439+
if (typeof SimpleJekyllSearch !== 'undefined') {
440+
SimpleJekyllSearch({
441+
searchInput: document.getElementById('search-input'),
442+
resultsContainer: document.getElementById('search-results'),
443+
json: '/search.json',
444+
searchResultTemplate: '<div class="post-preview item"><a href="{url}"><h2 class="post-title">{title}</h2><h3 class="post-subtitle">{subtitle}</h3><hr></a></div>',
445+
noResultsText: 'No results',
446+
limit: 50,
447+
fuzzy: false,
448+
// a hack to get escaped subtitle unescaped. for some reason,
449+
// post.subtitle w/o escape filter nuke entire search.
450+
templateMiddleware: function (prop, value, template) {
451+
if (prop === 'subtitle' || prop === 'title') {
452+
if (value.indexOf("code")) {
453+
return htmlDecode(value);
454+
} else {
455+
return value;
456+
}
457+
}
451458
}
452-
}
459+
});
453460
}
454-
});
461+
}
455462

456463
$(document).ready(function () {
457464
var $searchPage = $('.search-page');

_layouts/default.html

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,7 @@
3636
</div>
3737
</div>
3838

39-
<!-- Background Switcher -->
40-
<div class="bg-switcher" id="bg-switcher">
41-
<div class="bg-switcher-toggle" onclick="toggleBackgroundSwitcher()">
42-
<i class="fa fa-palette"></i>
43-
<span>背景</span>
44-
</div>
45-
<div class="bg-switcher-panel" id="bg-switcher-panel">
46-
<div class="bg-switcher-title">选择背景主题</div>
47-
<div class="bg-switcher-themes" id="bg-switcher-themes">
48-
<!-- 主题选项将通过JavaScript动态生成 -->
49-
</div>
50-
</div>
51-
</div>
39+
<!-- Background Switcher will be created dynamically by JavaScript -->
5240

5341
<!-- Image to hack wechat -->
5442
<img src="/img/icon_wechat.png" width="0" height="0" />

css/jason-blog.css

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3158,44 +3158,52 @@ body.dark-mode table.table > tbody tr:nth-child(even) {
31583158
}
31593159

31603160
body.dark-mode .sidebar-container {
3161-
background: #2a2a2a;
3162-
color: #60a5fa;
3161+
background: rgba(15, 23, 42, 0.98);
3162+
color: #f1f5f9;
3163+
border: 1px solid rgba(96, 165, 250, 0.3);
3164+
backdrop-filter: blur(10px);
31633165
}
31643166

31653167
body.dark-mode .sidebar-container h5,
31663168
body.dark-mode .sidebar-container h5 a {
3167-
color: #60a5fa !important;
3169+
color: #f1f5f9 !important;
3170+
font-weight: 600;
31683171
}
31693172

31703173
body.dark-mode .sidebar-container h5 a:hover {
31713174
color: #93c5fd !important;
31723175
}
31733176

31743177
body.dark-mode .sidebar-container a {
3175-
color: #60a5fa !important;
3178+
color: #f1f5f9 !important;
31763179
}
31773180

31783181
body.dark-mode .sidebar-container a:hover,
31793182
body.dark-mode .sidebar-container a:active {
3180-
color: #93c5fd !important;
3183+
color: #60a5fa !important;
31813184
}
31823185

31833186
body.dark-mode .sidebar-container .short-about p {
3184-
color: #60a5fa !important;
3187+
color: #e2e8f0 !important;
31853188
}
31863189

31873190
body.dark-mode .sidebar-container .friends a {
3188-
color: #60a5fa !important;
3191+
color: #f1f5f9 !important;
3192+
background: rgba(30, 64, 175, 0.1);
3193+
border-radius: 6px;
3194+
padding: 6px 12px;
3195+
margin: 2px 0;
31893196
}
31903197

31913198
body.dark-mode .sidebar-container .friends a:hover {
3192-
color: #93c5fd !important;
3199+
color: #60a5fa !important;
3200+
background: rgba(30, 64, 175, 0.2);
31933201
}
31943202

31953203
body.dark-mode .sidebar-container .tags a {
3196-
color: #60a5fa !important;
3197-
background: #374151;
3198-
border-color: #4b5563;
3204+
color: #f1f5f9 !important;
3205+
background: rgba(30, 64, 175, 0.15);
3206+
border-color: rgba(96, 165, 250, 0.3);
31993207
}
32003208

32013209
body.dark-mode .sidebar-container .tags a:hover,
@@ -3390,9 +3398,8 @@ body.dark-mode .intro-header {
33903398
/* 背景切换器样式 */
33913399
.bg-switcher {
33923400
position: fixed;
3393-
top: 50%;
3401+
top: 10px;
33943402
right: 20px;
3395-
transform: translateY(-50%);
33963403
z-index: 9999;
33973404
font-family: 'Helvetica Neue', Arial, sans-serif;
33983405
}
@@ -3460,18 +3467,23 @@ body.dark-mode .intro-header {
34603467
display: grid;
34613468
grid-template-columns: repeat(2, 1fr);
34623469
gap: 12px;
3470+
max-height: 300px;
3471+
overflow-y: auto;
34633472
}
34643473

34653474
.bg-theme-option {
34663475
display: flex;
34673476
flex-direction: column;
34683477
align-items: center;
3469-
padding: 12px;
3478+
justify-content: center;
3479+
padding: 12px 8px;
34703480
border-radius: 12px;
34713481
cursor: pointer;
34723482
transition: all 0.3s ease;
34733483
border: 2px solid transparent;
34743484
background: rgba(248, 250, 252, 0.8);
3485+
min-height: 80px;
3486+
text-align: center;
34753487
}
34763488

34773489
.bg-theme-option:hover {
@@ -3487,12 +3499,13 @@ body.dark-mode .intro-header {
34873499
}
34883500

34893501
.bg-theme-preview {
3490-
width: 40px;
3491-
height: 40px;
3502+
width: 32px;
3503+
height: 32px;
34923504
border-radius: 50%;
3493-
margin-bottom: 8px;
3505+
margin-bottom: 6px;
34943506
border: 2px solid rgba(255, 255, 255, 0.8);
34953507
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
3508+
flex-shrink: 0;
34963509
}
34973510

34983511
.bg-theme-icon {
@@ -3501,15 +3514,18 @@ body.dark-mode .intro-header {
35013514
}
35023515

35033516
.bg-theme-name {
3504-
font-size: 12px;
3517+
font-size: 11px;
35053518
font-weight: 500;
35063519
color: #374151;
35073520
text-align: center;
3521+
line-height: 1.2;
3522+
word-break: keep-all;
35083523
}
35093524

35103525
/* 响应式设计 */
35113526
@media (max-width: 768px) {
35123527
.bg-switcher {
3528+
top: 10px;
35133529
right: 15px;
35143530
}
35153531

@@ -3523,30 +3539,35 @@ body.dark-mode .intro-header {
35233539
}
35243540

35253541
.bg-switcher-panel {
3526-
min-width: 240px;
3542+
min-width: 260px;
35273543
padding: 16px;
3544+
right: -10px;
35283545
}
35293546

35303547
.bg-switcher-themes {
3531-
grid-template-columns: repeat(3, 1fr);
3532-
gap: 8px;
3548+
grid-template-columns: repeat(2, 1fr);
3549+
gap: 10px;
35333550
}
35343551

35353552
.bg-theme-option {
3536-
padding: 8px;
3553+
padding: 10px 6px;
3554+
min-height: 70px;
35373555
}
35383556

35393557
.bg-theme-preview {
3540-
width: 30px;
3541-
height: 30px;
3558+
width: 28px;
3559+
height: 28px;
3560+
margin-bottom: 4px;
35423561
}
35433562

35443563
.bg-theme-icon {
3545-
font-size: 14px;
3564+
font-size: 12px;
3565+
margin-bottom: 2px;
35463566
}
35473567

35483568
.bg-theme-name {
35493569
font-size: 10px;
3570+
line-height: 1.1;
35503571
}
35513572
}
35523573

js/background-switcher.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ class BackgroundSwitcher {
4848
}
4949

5050
createSwitcher() {
51+
// 检查是否已经存在背景切换器,避免重复创建
52+
if (document.querySelector('.bg-switcher')) {
53+
return;
54+
}
55+
5156
// 创建背景切换器容器
5257
const switcher = document.createElement('div');
5358
switcher.className = 'bg-switcher';
@@ -78,6 +83,12 @@ class BackgroundSwitcher {
7883
const panel = document.querySelector('.bg-switcher-panel');
7984
const options = document.querySelectorAll('.bg-theme-option');
8085

86+
// 确保元素存在后再绑定事件
87+
if (!toggle || !panel || options.length === 0) {
88+
console.warn('Background switcher elements not found');
89+
return;
90+
}
91+
8192
// 切换面板显示/隐藏
8293
toggle.addEventListener('click', () => {
8394
panel.classList.toggle('active');

js/jason-blog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ jQuery(document).ready(function($) {
305305

306306

307307
//adjust the appearance of side-catalog
308-
$catalog.show()
308+
$catalog.show();
309309
if (currentTop > (bannerHeight + 41)) {
310310
$catalog.addClass('fixed')
311311
} else {

0 commit comments

Comments
 (0)