summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/blob/viewer
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-12 15:06:26 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-12 15:06:26 +0000
commit69944ffb68788d190e81ff7e33db5dcb6c903184 (patch)
tree4112a1285f186c140749e8410a8a2788b6812500 /app/assets/javascripts/blob/viewer
parent1b7381e998ff4b33ec8f633766030082e95f10c8 (diff)
downloadgitlab-ce-69944ffb68788d190e81ff7e33db5dcb6c903184.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/blob/viewer')
-rw-r--r--app/assets/javascripts/blob/viewer/index.js58
1 files changed, 21 insertions, 37 deletions
diff --git a/app/assets/javascripts/blob/viewer/index.js b/app/assets/javascripts/blob/viewer/index.js
index f032c2f216b..07e4dde41d9 100644
--- a/app/assets/javascripts/blob/viewer/index.js
+++ b/app/assets/javascripts/blob/viewer/index.js
@@ -4,10 +4,6 @@ import Flash from '../../flash';
import { handleLocationHash } from '../../lib/utils/common_utils';
import axios from '../../lib/utils/axios_utils';
import { __ } from '~/locale';
-import { blobLinkRegex } from '~/blob/blob_utils';
-
-const SIMPLE_VIEWER_NAME = 'simple';
-const RICH_VIEWER_NAME = 'rich';
export default class BlobViewer {
constructor() {
@@ -25,7 +21,7 @@ export default class BlobViewer {
}
static initRichViewer() {
- const viewer = document.querySelector(`.blob-viewer[data-type="${RICH_VIEWER_NAME}"]`);
+ const viewer = document.querySelector('.blob-viewer[data-type="rich"]');
if (!viewer || !viewer.dataset.richType) return;
const initViewer = promise =>
@@ -65,12 +61,8 @@ export default class BlobViewer {
this.switcherBtns = document.querySelectorAll('.js-blob-viewer-switch-btn');
this.copySourceBtn = document.querySelector('.js-copy-blob-source-btn');
- this.simpleViewer = this.$fileHolder[0].querySelector(
- `.blob-viewer[data-type="${SIMPLE_VIEWER_NAME}"]`,
- );
- this.richViewer = this.$fileHolder[0].querySelector(
- `.blob-viewer[data-type="${RICH_VIEWER_NAME}"]`,
- );
+ this.simpleViewer = this.$fileHolder[0].querySelector('.blob-viewer[data-type="simple"]');
+ this.richViewer = this.$fileHolder[0].querySelector('.blob-viewer[data-type="rich"]');
this.initBindings();
@@ -79,10 +71,10 @@ export default class BlobViewer {
switchToInitialViewer() {
const initialViewer = this.$fileHolder[0].querySelector('.blob-viewer:not(.hidden)');
- let initialViewerName = initialViewer.dataset.type;
+ let initialViewerName = initialViewer.getAttribute('data-type');
if (this.switcher && window.location.hash.indexOf('#L') === 0) {
- initialViewerName = SIMPLE_VIEWER_NAME;
+ initialViewerName = 'simple';
}
this.switchToViewer(initialViewerName);
@@ -99,41 +91,35 @@ export default class BlobViewer {
this.copySourceBtn.addEventListener('click', () => {
if (this.copySourceBtn.classList.contains('disabled')) return this.copySourceBtn.blur();
- return this.switchToViewer(SIMPLE_VIEWER_NAME);
+ return this.switchToViewer('simple');
});
}
}
- static linkifyURLs(viewer) {
- if (viewer.dataset.linkified) return;
-
- document.querySelectorAll('.js-blob-content .code .line').forEach(line => {
- // eslint-disable-next-line no-param-reassign
- line.innerHTML = line.innerHTML.replace(blobLinkRegex, '<a href="$&">$&</a>');
- });
-
- // eslint-disable-next-line no-param-reassign
- viewer.dataset.linkified = true;
- }
-
switchViewHandler(e) {
const target = e.currentTarget;
e.preventDefault();
- this.switchToViewer(target.dataset.viewer);
+ this.switchToViewer(target.getAttribute('data-viewer'));
}
toggleCopyButtonState() {
if (!this.copySourceBtn) return;
- if (this.simpleViewer.dataset.loaded) {
- this.copySourceBtn.dataset.title = __('Copy file contents');
+ if (this.simpleViewer.getAttribute('data-loaded')) {
+ this.copySourceBtn.setAttribute('title', __('Copy file contents'));
this.copySourceBtn.classList.remove('disabled');
} else if (this.activeViewer === this.simpleViewer) {
- this.copySourceBtn.dataset.title = __('Wait for the file to load to copy its contents');
+ this.copySourceBtn.setAttribute(
+ 'title',
+ __('Wait for the file to load to copy its contents'),
+ );
this.copySourceBtn.classList.add('disabled');
} else {
- this.copySourceBtn.dataset.title = __('Switch to the source to copy the file contents');
+ this.copySourceBtn.setAttribute(
+ 'title',
+ __('Switch to the source to copy the file contents'),
+ );
this.copySourceBtn.classList.add('disabled');
}
@@ -173,8 +159,6 @@ export default class BlobViewer {
this.$fileHolder.trigger('highlight:line');
handleLocationHash();
- if (name === SIMPLE_VIEWER_NAME) BlobViewer.linkifyURLs(viewer);
-
this.toggleCopyButtonState();
})
.catch(() => new Flash(__('Error loading viewer')));
@@ -182,17 +166,17 @@ export default class BlobViewer {
static loadViewer(viewerParam) {
const viewer = viewerParam;
- const { url, loaded, loading } = viewer.dataset;
+ const url = viewer.getAttribute('data-url');
- if (!url || loaded || loading) {
+ if (!url || viewer.getAttribute('data-loaded') || viewer.getAttribute('data-loading')) {
return Promise.resolve(viewer);
}
- viewer.dataset.loading = true;
+ viewer.setAttribute('data-loading', 'true');
return axios.get(url).then(({ data }) => {
viewer.innerHTML = data.html;
- viewer.dataset.loaded = true;
+ viewer.setAttribute('data-loaded', 'true');
return viewer;
});