Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable sidebar on mobile移动设备上开启侧栏 #1717

Merged
merged 2 commits into from
Jul 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ sidebar:

# Scroll percent label in b2t button
scrollpercent: false
# Enable sidebar on narrow view
onmobile: false


# Blog rolls
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>
Copy link
Collaborator

@ivan-nginx ivan-nginx Jul 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add conditional import there:

{% if theme.onmobile %}
<div id="sidebar-dimmer"></div>
{% endif %}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need for one line I think.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<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";
Copy link
Collaborator

@ivan-nginx ivan-nginx Jul 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add conditional import there:
@import "sidebar-dimmer" if hexo-config('onmobile');

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not necessary consist with the context

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add conditional import there:

      if (CONFIG.sidebar.onmobile) {
        ...
      }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no harmful I think

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, right.

sidebarEl: $('.sidebar'),
isSidebarVisible: false,
init: function () {
this.toggleEl.on('click', this.clickHandler.bind(this));
this.dimmerEl.on('click', this.clickHandler.bind(this));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add conditional import there:

      if (CONFIG.sidebar.onmobile) {
        ...
      }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DITTO

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.

this.toggleEl.on('mouseenter', this.mouseEnterHandler.bind(this));
this.toggleEl.on('mouseleave', this.mouseLeaveHandler.bind(this));

Expand Down