diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-04 15:08:09 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-04 15:08:09 +0000 |
commit | d3fc3be040a4fed2328e23ef28696dd8bd8238b4 (patch) | |
tree | f1874ea5e6e3c50c6a3c2ca2900af4ae73a53119 /app/assets/javascripts/blob | |
parent | c6c7437861bff9572747674095c4dfbdfbea4988 (diff) | |
download | gitlab-ce-d3fc3be040a4fed2328e23ef28696dd8bd8238b4.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/blob')
-rw-r--r-- | app/assets/javascripts/blob/components/blob_content.vue | 8 | ||||
-rw-r--r-- | app/assets/javascripts/blob/viewer/index.js | 71 |
2 files changed, 41 insertions, 38 deletions
diff --git a/app/assets/javascripts/blob/components/blob_content.vue b/app/assets/javascripts/blob/components/blob_content.vue index 2639a099093..7d5d48cfc31 100644 --- a/app/assets/javascripts/blob/components/blob_content.vue +++ b/app/assets/javascripts/blob/components/blob_content.vue @@ -45,7 +45,13 @@ export default { <template v-else> <blob-content-error v-if="viewerError" :viewer-error="viewerError" /> - <component :is="viewer" v-else ref="contentViewer" :content="content" /> + <component + :is="viewer" + v-else + ref="contentViewer" + :content="content" + :type="activeViewer.fileType" + /> </template> </div> </template> diff --git a/app/assets/javascripts/blob/viewer/index.js b/app/assets/javascripts/blob/viewer/index.js index 742404da46c..3ac419557eb 100644 --- a/app/assets/javascripts/blob/viewer/index.js +++ b/app/assets/javascripts/blob/viewer/index.js @@ -5,10 +5,43 @@ import { handleLocationHash } from '../../lib/utils/common_utils'; import axios from '../../lib/utils/axios_utils'; import { __ } from '~/locale'; +const loadRichBlobViewer = type => { + switch (type) { + case 'balsamiq': + return import(/* webpackChunkName: 'balsamiq_viewer' */ '../balsamiq_viewer'); + case 'notebook': + return import(/* webpackChunkName: 'notebook_viewer' */ '../notebook_viewer'); + case 'openapi': + return import(/* webpackChunkName: 'openapi_viewer' */ '../openapi_viewer'); + case 'pdf': + return import(/* webpackChunkName: 'pdf_viewer' */ '../pdf_viewer'); + case 'sketch': + return import(/* webpackChunkName: 'sketch_viewer' */ '../sketch_viewer'); + case 'stl': + return import(/* webpackChunkName: 'stl_viewer' */ '../stl_viewer'); + default: + return Promise.resolve(); + } +}; + +export const handleBlobRichViewer = (viewer, type) => { + if (!viewer || !type) return; + + loadRichBlobViewer(type) + .then(module => module?.default(viewer)) + .catch(error => { + Flash(__('Error loading file viewer.')); + throw error; + }); +}; + export default class BlobViewer { constructor() { + const viewer = document.querySelector('.blob-viewer[data-type="rich"]'); + const type = viewer?.dataset?.richType; BlobViewer.initAuxiliaryViewer(); - BlobViewer.initRichViewer(); + + handleBlobRichViewer(viewer, type); this.initMainViewers(); } @@ -20,42 +53,6 @@ export default class BlobViewer { BlobViewer.loadViewer(auxiliaryViewer); } - static initRichViewer() { - const viewer = document.querySelector('.blob-viewer[data-type="rich"]'); - if (!viewer || !viewer.dataset.richType) return; - - const initViewer = promise => - promise - .then(module => module.default(viewer)) - .catch(error => { - Flash(__('Error loading file viewer.')); - throw error; - }); - - switch (viewer.dataset.richType) { - case 'balsamiq': - initViewer(import(/* webpackChunkName: 'balsamiq_viewer' */ '../balsamiq_viewer')); - break; - case 'notebook': - initViewer(import(/* webpackChunkName: 'notebook_viewer' */ '../notebook_viewer')); - break; - case 'openapi': - initViewer(import(/* webpackChunkName: 'openapi_viewer' */ '../openapi_viewer')); - break; - case 'pdf': - initViewer(import(/* webpackChunkName: 'pdf_viewer' */ '../pdf_viewer')); - break; - case 'sketch': - initViewer(import(/* webpackChunkName: 'sketch_viewer' */ '../sketch_viewer')); - break; - case 'stl': - initViewer(import(/* webpackChunkName: 'stl_viewer' */ '../stl_viewer')); - break; - default: - break; - } - } - initMainViewers() { this.$fileHolder = $('.file-holder'); if (!this.$fileHolder.length) return; |