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

Make sidebar position optional for all schemes #952

Merged
merged 7 commits into from
Jul 9, 2019
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: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ toc:
max_depth: 6

sidebar:
# Sidebar Position, available values: left | right (only for Pisces | Gemini).
# Sidebar Position.
position: left
#position: right

Expand Down
3 changes: 2 additions & 1 deletion source/css/_schemes/Mist/index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
@import "_menu";
@import "_search.styl";
@import "_posts-expanded";
@import "sidebar/sidebar-blogroll";
@import "../Muse/sidebar/_sidebar";
@import "../Muse/sidebar/sidebar-blogroll";

// Components
// --------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion source/css/_schemes/Mist/sidebar/sidebar-blogroll.styl

This file was deleted.

1 change: 1 addition & 0 deletions source/css/_schemes/Muse/index.styl
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
@import "_logo.styl";
@import "_menu.styl";
@import "_search.styl";
@import "sidebar/_sidebar";
@import "sidebar/sidebar-blogroll";
14 changes: 14 additions & 0 deletions source/css/_schemes/Muse/sidebar/_sidebar.styl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
if (hexo-config('sidebar.position') == 'left') {
.sidebar {
right: auto;
left: 0;
}
.sidebar-toggle, .back-to-top {
right: auto;
left: $b2t-position-right;

+tablet-mobile() {
left: $b2t-position-right-mobile;
}
}
}
187 changes: 0 additions & 187 deletions source/js/motion.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,193 +3,6 @@
$(document).ready(function() {
NexT.motion = {};

var sidebarToggleLines = {
lines: [],
push : function(line) {
this.lines.push(line);
},
init: function() {
this.lines.forEach(function(line) {
line.init();
});
},
arrow: function() {
this.lines.forEach(function(line) {
line.arrow();
});
},
close: function() {
this.lines.forEach(function(line) {
line.close();
});
}
};

function SidebarToggleLine(settings) {
this.el = $(settings.el);
this.status = $.extend({}, {
init: {
width : '100%',
opacity: 1,
left : 0,
rotateZ: 0,
top : 0
}
}, settings.status);
}

SidebarToggleLine.prototype.init = function() {
this.transform('init');
};
SidebarToggleLine.prototype.arrow = function() {
this.transform('arrow');
};
SidebarToggleLine.prototype.close = function() {
this.transform('close');
};
SidebarToggleLine.prototype.transform = function(status) {
this.el.velocity('stop').velocity(this.status[status]);
};

var sidebarToggleLine1st = new SidebarToggleLine({
el : '.sidebar-toggle-line-first',
status: {
arrow: {width: '50%', rotateZ: '-45deg', top: '2px'},
close: {width: '100%', rotateZ: '-45deg', top: '5px'}
}
});
var sidebarToggleLine2nd = new SidebarToggleLine({
el : '.sidebar-toggle-line-middle',
status: {
arrow: {width: '90%'},
close: {opacity: 0}
}
});
var sidebarToggleLine3rd = new SidebarToggleLine({
el : '.sidebar-toggle-line-last',
status: {
arrow: {width: '50%', rotateZ: '45deg', top: '-2px'},
close: {width: '100%', rotateZ: '45deg', top: '-5px'}
}
});

sidebarToggleLines.push(sidebarToggleLine1st);
sidebarToggleLines.push(sidebarToggleLine2nd);
sidebarToggleLines.push(sidebarToggleLine3rd);

var SIDEBAR_WIDTH = CONFIG.sidebar.width ? CONFIG.sidebar.width : '320px';
var SIDEBAR_DISPLAY_DURATION = 200;
var xPos, yPos;

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));
this.sidebarEl.on('touchstart', this.touchstartHandler.bind(this));
this.sidebarEl.on('touchend', this.touchendHandler.bind(this));
this.sidebarEl.on('touchmove', function(e) { e.preventDefault(); });

$(document)
.on('sidebar.isShowing', function() {
NexT.utils.isDesktop() && $('body').velocity('stop').velocity(
{paddingRight: SIDEBAR_WIDTH},
SIDEBAR_DISPLAY_DURATION
);
})
.on('sidebar.isHiding', function() {
});
},
clickHandler: function() {
this.isSidebarVisible ? this.hideSidebar() : this.showSidebar();
this.isSidebarVisible = !this.isSidebarVisible;
},
mouseEnterHandler: function() {
if (this.isSidebarVisible) {
return;
}
sidebarToggleLines.arrow();
},
mouseLeaveHandler: function() {
if (this.isSidebarVisible) {
return;
}
sidebarToggleLines.init();
},
touchstartHandler: function(e) {
xPos = e.originalEvent.touches[0].clientX;
yPos = e.originalEvent.touches[0].clientY;
},
touchendHandler: function(e) {
var _xPos = e.originalEvent.changedTouches[0].clientX;
var _yPos = e.originalEvent.changedTouches[0].clientY;
if (_xPos - xPos > 30 && Math.abs(_yPos - yPos) < 20) {
this.clickHandler();
}
},
showSidebar: function() {
var self = this;

sidebarToggleLines.close();

this.sidebarEl.velocity('stop').velocity({
width: SIDEBAR_WIDTH
}, {
display : 'block',
duration: SIDEBAR_DISPLAY_DURATION,
begin : function() {
$('.sidebar .motion-element').not('.site-state').velocity(
'transition.slideRightIn', {
stagger : 50,
drag : true,
complete: function() {
self.sidebarEl.trigger('sidebar.motion.complete');
}
}
);
$('.site-state').velocity(
'transition.slideRightIn', {
stagger : 50,
drag : true,
display : 'flex'
}
);
},
complete: function() {
self.sidebarEl.addClass('sidebar-active');
self.sidebarEl.trigger('sidebar.didShow');
}
});

this.sidebarEl.trigger('sidebar.isShowing');
},
hideSidebar: function() {
NexT.utils.isDesktop() && $('body').velocity('stop').velocity({paddingRight: 0});
this.sidebarEl.find('.motion-element').velocity('stop').css('display', 'none');
this.sidebarEl.velocity('stop').velocity({width: 0}, {display: 'none'});

sidebarToggleLines.init();

this.sidebarEl.removeClass('sidebar-active');
this.sidebarEl.trigger('sidebar.isHiding');

// Prevent adding TOC to Overview if Overview was selected when close & open sidebar.
if ($('.post-toc-wrap')) {
if ($('.site-overview-wrap').css('display') === 'block') {
$('.post-toc-wrap').removeClass('motion-element');
} else {
$('.post-toc-wrap').addClass('motion-element');
}
}
}
};
sidebarToggleMotion.init();

NexT.motion.integrator = {
queue : [],
cursor: -1,
Expand Down
Loading