EdPagination.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <template>
  2. <div v-if="options.length">
  3. <!-- <select class="" name="page-nav" v-model="page_selected" placeholder="Pages">
  4. <option value="" disabled selected>Pages</option>
  5. <option v-for="(page, index) in pages" :key="index" :value="page">{{ page }}</option>
  6. </select> -->
  7. <v-select
  8. id="page-nav-select"
  9. type="select"
  10. placeholder="Aller à la page ..."
  11. append-to-body
  12. :calculate-position="dropDownMenuPos"
  13. :options="options"
  14. :clearable="false"
  15. :value="page_selected"
  16. :selectable="option => ! option.disabled"
  17. @input="onClickPaginationItem"
  18. >
  19. <template v-slot:option="option">
  20. <span v-for="l in option.level" :key="l" class="op-tab" />
  21. {{ option.label }}
  22. </template>
  23. </v-select>
  24. </div>
  25. </template>
  26. <script>
  27. import { createPopper } from '@popperjs/core'
  28. export default {
  29. name: 'EdPagination',
  30. props: {
  31. pagination: Array
  32. },
  33. data: () => ({
  34. options: [],
  35. page_selected: ''
  36. }),
  37. created () {
  38. this.parsePagesToOptions(this.pagination)
  39. },
  40. // watch: {
  41. // loadedtextsuuids (n, o) {
  42. // console.log('EdToc watch loadedtxtsuuids', o, n)
  43. // }
  44. // },
  45. methods: {
  46. parsePagesToOptions (p, i = 0, l = 0) {
  47. // console.log('EdPagination parsePagesToOptions', p)
  48. for (var j = 0; j < p.length; j++) {
  49. // if it is just a section without page like a volume
  50. if (p[j].text) {
  51. this.options.push({
  52. key: i,
  53. code: p[j].text,
  54. label: p[j].text,
  55. disabled: true,
  56. level: l
  57. })
  58. }
  59. // if it's a real page break
  60. if (p[j].pageBreak) {
  61. this.options.push({
  62. key: i,
  63. code: p[j].pageBreak,
  64. label: p[j].pageNum,
  65. uuid: p[j].uuid,
  66. level: l
  67. })
  68. }
  69. if (p[j].pages && p[j].pages.length) {
  70. this.parsePagesToOptions(p[j].pages, i++, l + 1)
  71. } else {
  72. i++
  73. }
  74. }
  75. },
  76. dropDownMenuPos (dropdownList, component, { width }) {
  77. /**
  78. * We need to explicitly define the dropdown width since
  79. * it is usually inherited from the parent with CSS.
  80. */
  81. dropdownList.style.width = width
  82. /**
  83. * Here we position the dropdownList relative to the $refs.toggle Element.
  84. *
  85. * The 'offset' modifier aligns the dropdown so that the $refs.toggle and
  86. * the dropdownList overlap by 1 pixel.
  87. *
  88. * The 'toggleClass' modifier adds a 'drop-up' class to the Vue Select
  89. * wrapper so that we can set some styles for when the dropdown is placed
  90. * above.
  91. */
  92. const popper = createPopper(component.$refs.toggle, dropdownList, {
  93. placement: 'top',
  94. modifiers: [
  95. {
  96. name: 'offset',
  97. options: {
  98. offset: [0, -1]
  99. }
  100. },
  101. {
  102. name: 'toggleClass',
  103. enabled: true,
  104. phase: 'write',
  105. fn ({ state }) {
  106. component.$el.classList.toggle('drop-up', state.placement === 'top')
  107. }
  108. }]
  109. })
  110. /**
  111. * To prevent memory leaks Popper needs to be destroyed.
  112. * If you return function, it will be called just before dropdown is removed from DOM.
  113. */
  114. return () => popper.destroy()
  115. },
  116. onClickPaginationItem (o) {
  117. this.page_selected = o
  118. this.$emit('onClickPaginationItem', o)
  119. }
  120. }
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. </style>