mirror of
https://github.com/flarum/core.git
synced 2025-08-05 16:07:34 +02:00
Add documentation, keep lifecycle methods on top
This commit is contained in:
@@ -1,10 +1,33 @@
|
||||
import Component from '../../common/Component';
|
||||
|
||||
/**
|
||||
* The `AffixedSidebar` component uses Bootstrap's "affix" plugin to keep a
|
||||
* sidebar navigation at the top of the viewport when scrolling.
|
||||
*
|
||||
* ### Children
|
||||
*
|
||||
* The component must wrap an element that itself wraps an <ul> element, which
|
||||
* will be "affixed".
|
||||
*
|
||||
* @see https://getbootstrap.com/docs/3.4/javascript/#affix
|
||||
*/
|
||||
export default class AffixedSidebar extends Component {
|
||||
view(vnode) {
|
||||
return vnode.children[0];
|
||||
}
|
||||
|
||||
oncreate(vnode) {
|
||||
super.oncreate(vnode);
|
||||
|
||||
// Register the affix plugin to execute on every window resize (and trigger)
|
||||
this.boundOnresize = this.onresize.bind(this);
|
||||
$(window).on('resize', this.boundOnresize).resize();
|
||||
}
|
||||
|
||||
onremove() {
|
||||
$(window).off('resize', this.boundOnresize);
|
||||
}
|
||||
|
||||
onresize() {
|
||||
const $sidebar = this.$();
|
||||
const $header = $('#header');
|
||||
@@ -25,16 +48,4 @@ export default class AffixedSidebar extends Component {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
oncreate(vnode) {
|
||||
super.oncreate(vnode);
|
||||
|
||||
// Register the affix plugin to execute on every window resize (and trigger)
|
||||
this.boundOnresize = this.onresize.bind(this);
|
||||
$(window).on('resize', this.boundOnresize).resize();
|
||||
}
|
||||
|
||||
onremove() {
|
||||
$(window).off('resize', this.boundOnresize);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user