diff options
author | Douwe Maan <douwe@selenight.nl> | 2017-04-21 13:33:48 -0500 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2017-04-27 12:23:26 -0500 |
commit | a7fd95cd22062f18474ee038d72fa9e1139a1a84 (patch) | |
tree | 030507d4479a93eaf0fa737d31b778d9872dadc9 /app/assets/javascripts/blob/viewer/index.js | |
parent | c69a0779fb499fb3c8352eede0b5c6d7bb1117d1 (diff) | |
download | gitlab-ce-a7fd95cd22062f18474ee038d72fa9e1139a1a84.tar.gz |
Render viewer error synchronously so that 'view the source' link will work
Diffstat (limited to 'app/assets/javascripts/blob/viewer/index.js')
-rw-r--r-- | app/assets/javascripts/blob/viewer/index.js | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/app/assets/javascripts/blob/viewer/index.js b/app/assets/javascripts/blob/viewer/index.js index a322351219c..8a5fb187a71 100644 --- a/app/assets/javascripts/blob/viewer/index.js +++ b/app/assets/javascripts/blob/viewer/index.js @@ -2,7 +2,8 @@ /* global Flash */ export default class BlobViewer { constructor() { - this.switcherBtns = document.querySelectorAll('.js-blob-viewer-switcher'); + this.switcher = document.querySelector('.js-blob-viewer-switcher'); + this.switcherBtns = document.querySelectorAll('.js-blob-viewer-switch-btn'); this.copySourceBtn = document.querySelector('.js-copy-blob-source-btn'); this.simpleViewer = document.querySelector('.blob-viewer[data-type="simple"]'); this.richViewer = document.querySelector('.blob-viewer[data-type="rich"]'); @@ -10,22 +11,22 @@ export default class BlobViewer { let initialViewerName = document.querySelector('.blob-viewer:not(.hidden)').getAttribute('data-type'); - if (this.switcherBtns.length) { - this.initBindings(); + this.initBindings(); - if (location.hash.indexOf('#L') === 0) { - initialViewerName = 'simple'; - } + if (this.switcher && location.hash.indexOf('#L') === 0) { + initialViewerName = 'simple'; } this.switchToViewer(initialViewerName); } initBindings() { - Array.from(this.switcherBtns) - .forEach((el) => { - el.addEventListener('click', this.switchViewHandler.bind(this)); - }); + if (this.switcherBtns.length) { + Array.from(this.switcherBtns) + .forEach((el) => { + el.addEventListener('click', this.switchViewHandler.bind(this)); + }); + } if (this.copySourceBtn) { this.copySourceBtn.addEventListener('click', () => { @@ -91,8 +92,8 @@ export default class BlobViewer { const newViewer = document.querySelector(`.blob-viewer[data-type='${name}']`); if (this.activeViewer === newViewer) return; - const oldButton = document.querySelector('.js-blob-viewer-switcher.active'); - const newButton = document.querySelector(`.js-blob-viewer-switcher[data-viewer='${name}']`); + const oldButton = document.querySelector('.js-blob-viewer-switch-btn.active'); + const newButton = document.querySelector(`.js-blob-viewer-switch-btn[data-viewer='${name}']`); const oldViewer = document.querySelector(`.blob-viewer:not([data-type='${name}'])`); if (oldButton) { |