Skip to content

Commit

Permalink
enable sidebar on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
flashlab committed Jun 15, 2017
1 parent 4b9fedd commit 3a3b864
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 14 deletions.
2 changes: 2 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ sidebar:
# Scroll percent label in b2t button
scrollpercent: false

onmobile: false


# Blog rolls
#links_title: Links
Expand Down
1 change: 1 addition & 0 deletions layout/_macro/sidebar.swig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
</div>

<aside id="sidebar" class="sidebar">
<div id="sidebar-dimmer"></div>
<div class="sidebar-inner">

{% set display_toc = is_post and theme.toc.enable or is_page and theme.toc.enable %}
Expand Down
10 changes: 6 additions & 4 deletions source/css/_common/components/back-to-top-sidebar.styl
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
the-transition();
&:hover { opacity: 0.8; }

+mobile() {
display: none;
}
+tablet() {
display: none;
fixbutton() if hexo-config('sidebar.onmobile');
hide() if not hexo-config('sidebar.onmobile');
}
+mobile() {
fixbutton() if hexo-config('sidebar.onmobile');
hide() if not hexo-config('sidebar.onmobile');
}

&.back-to-top-on {
Expand Down
10 changes: 6 additions & 4 deletions source/css/_common/components/back-to-top.styl
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
transition-property: bottom;
the-transition();

+mobile() {
display: none;
}
+tablet() {
display: none;
fixbutton() if hexo-config('sidebar.onmobile');
hide() if not hexo-config('sidebar.onmobile');
}
+mobile() {
fixbutton() if hexo-config('sidebar.onmobile');
hide() if not hexo-config('sidebar.onmobile');
}

&.back-to-top-on {
Expand Down
21 changes: 21 additions & 0 deletions source/css/_common/components/sidebar/sidebar-dimmer.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.sidebar-active #sidebar-dimmer {
opacity: .7;
-webkit-transform: translateX(-150%);
transform: translateX(-150%);
transition: opacity .2s;
}

#sidebar-dimmer {
display: none;
position: absolute;
top: 0;
left: 100%;
width: 200%;
height: 100%;
background: #000;
opacity: 0;
transition: opacity .2s,transform 0s .2s;
+mobile() {
display: block;
}
}
6 changes: 4 additions & 2 deletions source/css/_common/components/sidebar/sidebar-toggle.styl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
-webkit-transform: translateZ(0);

+tablet() {
display: none;
fixbutton() if hexo-config('sidebar.onmobile');
hide() if not hexo-config('sidebar.onmobile');
}
+mobile() {
display: none;
fixbutton() if hexo-config('sidebar.onmobile');
hide() if not hexo-config('sidebar.onmobile');
}
}

Expand Down
9 changes: 5 additions & 4 deletions source/css/_common/components/sidebar/sidebar.styl
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
}

+tablet() {
display: none !important;
hide() if not hexo-config('sidebar.onmobile');
}
+mobile() {
display: none !important;
hide() if not hexo-config('sidebar.onmobile');
}

}

.sidebar-inner {
Expand All @@ -36,7 +37,7 @@
@import "site-state";
@import "sidebar-feed-link";
@import "sidebar-author-links";
@import "sidebar-blogroll.styl";
@import "sidebar-blogroll";
@import "sidebar-nav";
@import "sidebar-toc";

@import "sidebar-dimmer";
8 changes: 8 additions & 0 deletions source/css/_mixins/base.styl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ transform() {
transform: arguments
}

hide() {
display: none !important;
}

fixbutton() {
right: 20px;
opacity: 0.8;
}

random-color($min, $max) {
return floor(math(0, 'random') * ($max - $min + 1) + $min);
Expand Down
2 changes: 2 additions & 0 deletions source/js/src/motion.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,12 @@ $(document).ready(function () {

var sidebarToggleMotion = {
toggleEl: $('.sidebar-toggle'),
dimmerEl: $('#sidebar-dimmer'),
sidebarEl: $('.sidebar'),
isSidebarVisible: false,
init: function () {
this.toggleEl.on('click', this.clickHandler.bind(this));
this.dimmerEl.on('click', this.clickHandler.bind(this));
this.toggleEl.on('mouseenter', this.mouseEnterHandler.bind(this));
this.toggleEl.on('mouseleave', this.mouseLeaveHandler.bind(this));

Expand Down

0 comments on commit 3a3b864

Please sign in to comment.