1
0
mirror of https://github.com/flarum/core.git synced 2025-08-07 17:07:19 +02:00

add: forum/components/UserPageSidebar

- extracted from UserPage, replaces affixSidebar util
This commit is contained in:
Alexander Skvortsov
2020-08-10 00:34:03 -04:00
committed by Franz Liedke
parent 916cf4b546
commit 742f89f660

View File

@@ -0,0 +1,42 @@
import Component from "../../common/Component";
export default class UserPageSidebar extends Component {
view(vnode) {
return (
<nav className="sideNav UserPage-nav">
<ul>{vnode.children}</ul>
</nav>)
}
onresize(vnode) {
const $sidebar = $(vnode.dom);
const $header = $('#header');
const $footer = $('#footer');
const $affixElement = $sidebar.find('> ul');
$(window).off('.affix');
$affixElement.removeClass('affix affix-top affix-bottom').removeData('bs.affix');
// Don't affix the sidebar if it is taller than the viewport (otherwise
// there would be no way to scroll through its content).
if ($sidebar.outerHeight(true) > $(window).height() - $header.outerHeight(true)) return;
$affixElement.affix({
offset: {
top: () => $sidebar.offset().top - $header.outerHeight(true) - parseInt($sidebar.css('margin-top'), 10),
bottom: () => (this.bottom = $footer.outerHeight(true)),
},
});
};
oncreate(vnode) {
super.oncreate(vnode);
// Register the affix plugin to execute on every window resize (and trigger)
$(window).on('resize', this.onresize.bind(this, vnode)).resize();
}
onremove(vnode) {
$(window).off('resize', this.onresize.bind(this, vnode));
}
}