| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 | <template>  <div v-if="options.length">    <!-- <select class="" name="page-nav" v-model="page_selected" placeholder="Pages">      <option value="" disabled selected>Pages</option>      <option v-for="(page, index) in pages" :key="index" :value="page">{{ page }}</option>    </select> -->    <v-select      id="page-nav-select"      type="select"      placeholder="Aller à la page ..."      append-to-body      :calculate-position="dropDownMenuPos"      :options="options"      :clearable="false"      :value="page_selected"      :selectable="option => ! option.disabled"      @input="onClickPaginationItem"    >      <template v-slot:option="option">        <span v-for="l in option.level" :key="l" class="op-tab"> </span>        <span v-html="option.label" />      </template>    </v-select>  </div></template><script>import { createPopper } from '@popperjs/core'export default {  name: 'EdPagination',  props: {    pagination: Array  },  data: () => ({    options: [],    page_selected: ''  }),  created () {    this.parsePagesToOptions(this.pagination)  },  // watch: {  //   loadedtextsuuids (n, o) {  //     console.log('EdToc watch loadedtxtsuuids', o, n)  //   }  // },  methods: {    parsePagesToOptions (p, vol = null, i = 0, l = 0) {      console.log('EdPagination parsePagesToOptions', p)      for (var j = 0; j < p.length; j++) {        // if it is just a section without page like a volume        // not used anymore        if (p[j].text) {          this.options.push({            key: i,            code: p[j].text,            label: p[j].text,            disabled: true,            level: l          })        }        // if its a volume        if (p[j].vol) {          this.options.push({            code: p[j].vol.label,            label: `<b>${p[j].vol.label}</b>`,            disabled: true,            level: l          })        }        // if it's a real page break        if (p[j].pageBreak) {          let label          if (vol) {            label = `${vol.unit}${vol.n} page ${p[j].pageNum}`          } else {            label = p[j].pageNum          }          this.options.push({            key: i,            code: p[j].pageBreak,            label: label,            uuid: p[j].uuid,            level: l          })        }        if (p[j].pages && p[j].pages.length) {          this.parsePagesToOptions(p[j].pages, p[j].vol, i++, l + 1)        } else {          i++        }      }    },    dropDownMenuPos (dropdownList, component, { width }) {      /**       * We need to explicitly define the dropdown width since       * it is usually inherited from the parent with CSS.       */      dropdownList.style.width = width      /**       * Here we position the dropdownList relative to the $refs.toggle Element.       *       * The 'offset' modifier aligns the dropdown so that the $refs.toggle and       * the dropdownList overlap by 1 pixel.       *       * The 'toggleClass' modifier adds a 'drop-up' class to the Vue Select       * wrapper so that we can set some styles for when the dropdown is placed       * above.       */      const popper = createPopper(component.$refs.toggle, dropdownList, {        placement: 'top',        modifiers: [          {            name: 'offset',            options: {              offset: [0, -1]            }          },          {            name: 'toggleClass',            enabled: true,            phase: 'write',            fn ({ state }) {              component.$el.classList.toggle('drop-up', state.placement === 'top')            }          }]      })      /**       * To prevent memory leaks Popper needs to be destroyed.       * If you return function, it will be called just before dropdown is removed from DOM.       */      return () => popper.destroy()    },    onClickPaginationItem (o) {      this.page_selected = o      this.$emit('onClickPaginationItem', o)    }  }}</script><style lang="scss" scoped></style>
 |