MainContentLayout.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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">
  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. navopened: { type: Boolean }
  35. },
  36. watch: {
  37. reftoscrollto: function (newref, oldref) {
  38. console.log('MainLayout reftoscrollto watcher', oldref, newref)
  39. this.scrollToRef()
  40. }
  41. },
  42. mounted () {
  43. console.log('mounted')
  44. this.scrollToRef()
  45. },
  46. methods: {
  47. onScrollCenter (e) {
  48. console.log('mainLayout onScrollCenter: e', e)
  49. this.$emit('onCenterScrolled', e)
  50. // attribute scrollToRef is created then removed by this.$scrollTo()
  51. // we want to close the history panle only when user scroll the center
  52. // not when we click on toc item
  53. if (!e.currentTarget.hasAttribute('scrollToRef')) {
  54. this.$store.commit('History/setOpened', false)
  55. }
  56. },
  57. scrollToRef () {
  58. console.log('scrollToRef', this.reftoscrollto, this.$refs)
  59. this.$scrollTo(this.reftoscrollto, 500, {
  60. container: this.$refs.scrollablecenter,
  61. onStart: function (e) {
  62. console.log('$scrollTo start', e, this)
  63. this.setAttribute('scrollToRef', true)
  64. }.bind(this.$refs.scrollablecenter),
  65. onDone: function (e) {
  66. setTimeout(function () {
  67. console.log('$scrollTo done', e, this)
  68. this.removeAttribute('scrollToRef')
  69. }.bind(this), 100)
  70. }.bind(this.$refs.scrollablecenter)
  71. })
  72. }
  73. }
  74. }
  75. </script>
  76. <style lang="scss" scoped>
  77. </style>