MainContentLayout.vue 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <div
  3. :id="id"
  4. class="full-width med-row large-row main-content-layout"
  5. >
  6. <header class="med-col-3 large-col-3" :class="{ opened: headeropened }">
  7. <slot name="header" />
  8. </header>
  9. <section
  10. class="med-col-6 large-col-6"
  11. >
  12. <div
  13. ref="scrollablecenter"
  14. class="wrapper"
  15. @scroll.passive="onScrollCenter"
  16. >
  17. <slot />
  18. </div>
  19. </section>
  20. <nav class="med-col-3 large-col-3" :class="{ opened: navopened }">
  21. <slot name="nav" />
  22. </nav>
  23. </div>
  24. </template>
  25. <script>
  26. export default {
  27. name: 'MainContentLayout',
  28. props: {
  29. id: {
  30. type: String,
  31. required: true
  32. },
  33. reftoscrollto: { type: String },
  34. headeropened: { type: Boolean },
  35. navopened: { type: Boolean }
  36. },
  37. watch: {
  38. reftoscrollto: function (newref, oldref) {
  39. console.log('MainLayout reftoscrollto watcher', oldref, newref)
  40. this.scrollToRef()
  41. }
  42. },
  43. mounted () {
  44. console.log('mounted')
  45. this.scrollToRef()
  46. },
  47. methods: {
  48. onScrollCenter (e) {
  49. console.log('mainLayout onScrollCenter: e', e)
  50. this.$emit('onCenterScrolled', e)
  51. // attribute scrollToRef is created then removed by this.$scrollTo()
  52. // we want to close the history panle only when user scroll the center
  53. // not when we click on toc item
  54. if (!e.currentTarget.hasAttribute('scrollToRef')) {
  55. this.$store.commit('History/setOpened', false)
  56. }
  57. },
  58. scrollToRef () {
  59. console.log('scrollToRef', this.reftoscrollto, this.$refs)
  60. this.$scrollTo(this.reftoscrollto, 500, {
  61. container: this.$refs.scrollablecenter,
  62. onStart: function (e) {
  63. console.log('$scrollTo start', e, this)
  64. this.setAttribute('scrollToRef', true)
  65. }.bind(this.$refs.scrollablecenter),
  66. onDone: function (e) {
  67. setTimeout(function () {
  68. console.log('$scrollTo done', e, this)
  69. this.removeAttribute('scrollToRef')
  70. }.bind(this), 100)
  71. }.bind(this.$refs.scrollablecenter)
  72. })
  73. }
  74. }
  75. }
  76. </script>
  77. <style lang="scss" scoped>
  78. </style>