Skip to content

Commit

Permalink
feat: add sticky sidebar (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
seatonjiang committed May 18, 2021
1 parent 2e66276 commit 8af851f
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 10 deletions.
9 changes: 9 additions & 0 deletions assets/js/kratos.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@
});
};

var siderbarConfig = function () {
$(".sticky-sidebar").theiaStickySidebar({
additionalMarginTop: 25,
});
};

var consoleConfig = function () {
console.log(
"\n Kratos v" +
Expand All @@ -187,6 +193,9 @@
postlikeConfig();
donateConfig();
consoleConfig();
if (kratos.sticky) {
siderbarConfig();
}
});
})();

Expand Down
2 changes: 1 addition & 1 deletion assets/js/kratos.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions assets/js/theia-sticky-sidebar.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions inc/theme-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 核心函数
* @author Seaton Jiang <[email protected]>
* @license MIT License
* @version 2021.03.11
* @version 2021.05.18
*/

if (kratos_option('g_cdn', false)) {
Expand Down Expand Up @@ -73,6 +73,7 @@ function theme_autoload()
wp_enqueue_script('jquery', ASSET_PATH . '/assets/js/jquery.min.js', array(), '3.4.1', false);
wp_enqueue_script('bootstrap-bundle', ASSET_PATH . '/assets/js/bootstrap.bundle.min.js', array(), '4.5.0', true);
wp_enqueue_script('layer', ASSET_PATH . '/assets/js/layer.min.js', array(), '3.1.1', true);
wp_enqueue_script('sticky', ASSET_PATH . '/assets/js/theia-sticky-sidebar.min.js', array(), '1.5.0', true);
wp_enqueue_script('kratos', ASSET_PATH . '/assets/js/kratos.min.js', array(), THEME_VERSION, true);
wp_enqueue_script('custom', get_template_directory_uri() . '/custom/custom.js', array(), THEME_VERSION, true);

Expand All @@ -84,7 +85,8 @@ function theme_autoload()
'repeat' => __('您已经赞过了', 'kratos'),
'thanks' => __('感谢您的支持', 'kratos'),
'donate' => __('打赏作者', 'kratos'),
'scan' => __('扫码支付', 'kratos'),
'scan' => __('扫码支付', 'kratos'),
'sticky' => kratos_option('g_sticky', false),
);
wp_localize_script('kratos', 'kratos', $data);
}
Expand Down
10 changes: 9 additions & 1 deletion inc/theme-options.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 主题选项
* @author Seaton Jiang <[email protected]>
* @license MIT License
* @version 2021.04.15
* @version 2021.05.18
*/

function getrobots()
Expand Down Expand Up @@ -111,6 +111,14 @@ function kratos_options()
'type' => 'checkbox',
);

$options[] = array(
'name' => __('侧边栏随动', 'kratos'),
'desc' => __('开启小工具侧边栏随动功能', 'kratos'),
'std' => '0',
'id' => 'g_sticky',
'type' => 'checkbox',
);

$options[] = array(
'name' => __('搜索增强', 'kratos'),
'desc' => __('仅查找文章标题,而不全文搜索(适用于文章数量较多的站点)', 'kratos'),
Expand Down
4 changes: 2 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 首页模板
* @author Seaton Jiang <[email protected]>
* @license MIT License
* @version 2020.04.12
* @version 2021.05.18
*/

get_header(); ?>
Expand Down Expand Up @@ -40,7 +40,7 @@
pagelist();
wp_reset_query(); ?>
</div>
<div class="col-lg-4 sidebar d-none d-lg-block">
<div class="col-lg-4 sidebar sticky-sidebar d-none d-lg-block">
<?php dynamic_sidebar('sidebar_tool'); ?>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions page.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 页面模板
* @author Seaton Jiang <[email protected]>
* @license MIT License
* @version 2020.03.14
* @version 2021.05.18
*/

get_header(); ?>
Expand Down Expand Up @@ -51,7 +51,7 @@
<?php endif; ?>
<?php comments_template(); ?>
</div>
<div class="col-lg-4 sidebar d-none d-lg-block">
<div class="col-lg-4 sidebar sticky-sidebar d-none d-lg-block">
<?php dynamic_sidebar('sidebar_tool'); ?>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions single.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 文章内容
* @author Seaton Jiang <[email protected]>
* @license MIT License
* @version 2021.03.20
* @version 2021.05.18
*/

get_header();
Expand Down Expand Up @@ -145,7 +145,7 @@
<?php comments_template(); ?>
</div>
<?php if (kratos_option('g_article_widgets', 'two_side') == 'two_side'){ ?>
<div class="col-lg-4 sidebar d-none d-lg-block">
<div class="col-lg-4 sidebar sticky-sidebar d-none d-lg-block">
<?php dynamic_sidebar('sidebar_tool'); ?>
</div>
<?php } ?>
Expand Down

0 comments on commit 8af851f

Please sign in to comment.