BigW Consortium Gitlab

index.js 1.38 KB
Newer Older
1 2
/* eslint-disable no-new */
import Vue from 'vue';
Sam Rose committed
3
import pdfLab from '../../pdf/index.vue';
4 5 6 7

export default () => {
  const el = document.getElementById('js-pdf-viewer');

8
  return new Vue({
9 10 11 12 13 14 15 16 17
    el,
    data() {
      return {
        error: false,
        loadError: false,
        loading: true,
        pdf: el.dataset.endpoint,
      };
    },
Sam Rose committed
18 19 20
    components: {
      pdfLab,
    },
21 22 23 24 25 26 27 28 29 30 31
    methods: {
      onLoad() {
        this.loading = false;
      },
      onError(error) {
        this.loading = false;
        this.loadError = true;
        this.error = error;
      },
    },
    template: `
Douwe Maan committed
32
      <div class="js-pdf-viewer container-fluid md prepend-top-default append-bottom-default">
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
        <div
          class="text-center loading"
          v-if="loading && !error">
          <i
            class="fa fa-spinner fa-spin"
            aria-hidden="true"
            aria-label="PDF loading">
          </i>
        </div>
        <pdf-lab
          v-if="!loadError"
          :pdf="pdf"
          @pdflabload="onLoad"
          @pdflaberror="onError" />
        <p
          class="text-center"
          v-if="error">
          <span v-if="loadError">
51
            An error occurred whilst loading the file. Please try again later.
52 53
          </span>
          <span v-else>
54
            An error occurred whilst decoding the file.
55 56 57 58 59 60
          </span>
        </p>
      </div>
    `,
  });
};