diff --git a/src/lib/viewers/doc/DocBaseViewer.js b/src/lib/viewers/doc/DocBaseViewer.js index b4a0d80b6..2a3f88048 100644 --- a/src/lib/viewers/doc/DocBaseViewer.js +++ b/src/lib/viewers/doc/DocBaseViewer.js @@ -667,7 +667,8 @@ class DocBaseViewer extends BaseViewer { (file.watermark_info && file.watermark_info.is_watermarked); // Disable text layer if user doesn't have download permissions - PDFJS.disableTextLayer = !checkPermission(file, PERMISSION_DOWNLOAD); + PDFJS.disableTextLayer = !checkPermission(file, PERMISSION_DOWNLOAD) || + !!this.getViewerOption('disableTextLayer'); // Decrease mobile canvas size to ~3MP (1920x1536) PDFJS.maxCanvasPixels = Browser.isMobile() ? MOBILE_MAX_CANVAS_SIZE : PDFJS.maxCanvasPixels; diff --git a/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js b/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js index 21c06b039..83a2e97c3 100644 --- a/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js +++ b/src/lib/viewers/doc/__tests__/DocBaseViewer-test.js @@ -1036,6 +1036,7 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => { stubs.urlCreator = sandbox.stub(util, 'createAssetUrlCreator').returns(() => { return 'asset'; }); stubs.browser = sandbox.stub(Browser, 'getName').returns('Safari'); stubs.checkPermission = sandbox.stub(file, 'checkPermission'); + stubs.getViewerOption = sandbox.stub(docBase, 'getViewerOption'); docBase.options = { location: { staticBaseURI: 'test/' @@ -1095,6 +1096,15 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => { expect(PDFJS.disableTextLayer).to.be.true; }); + it('should disable the text layer if disableTextLayer viewer option is set', () => { + stubs.checkPermission.withArgs(docBase.options.file, PERMISSION_DOWNLOAD).returns(true); + stubs.getViewerOption.withArgs('disableTextLayer').returns(true); + + docBase.setupPdfjs(); + + expect(PDFJS.disableTextLayer).to.be.true; + }); + it('should decrease max canvas size to 3MP if on mobile', () => { sandbox.stub(Browser, 'isMobile').returns(true); docBase.setupPdfjs(); diff --git a/src/lib/viewers/text/TextBaseViewer.js b/src/lib/viewers/text/TextBaseViewer.js index ad481ed39..dff9a5af3 100644 --- a/src/lib/viewers/text/TextBaseViewer.js +++ b/src/lib/viewers/text/TextBaseViewer.js @@ -85,8 +85,9 @@ class TextBaseViewer extends BaseViewer { * @return {void} */ load() { - // Enable text selection if user has download permissions - if (checkPermission(this.options.file, PERMISSION_DOWNLOAD)) { + // Enable text selection if user has download permissions and 'disableTextLayer' option is not true + if (checkPermission(this.options.file, PERMISSION_DOWNLOAD) && + !this.getViewerOption('disableTextLayer')) { this.containerEl.classList.add(CLASS_IS_SELECTABLE); } diff --git a/src/lib/viewers/text/__tests__/TextBase-test.html b/src/lib/viewers/text/__tests__/TextBaseViewer-test.html similarity index 100% rename from src/lib/viewers/text/__tests__/TextBase-test.html rename to src/lib/viewers/text/__tests__/TextBaseViewer-test.html diff --git a/src/lib/viewers/text/__tests__/TextBaseViewer-test.js b/src/lib/viewers/text/__tests__/TextBaseViewer-test.js index 8812991e9..c33615a0f 100644 --- a/src/lib/viewers/text/__tests__/TextBaseViewer-test.js +++ b/src/lib/viewers/text/__tests__/TextBaseViewer-test.js @@ -14,7 +14,7 @@ describe('lib/viewers/text/TextBaseViewer', () => { }); beforeEach(() => { - fixture.load('viewers/text/__tests__/TextBase-test.html'); + fixture.load('viewers/text/__tests__/TextBaseViewer-test.html'); containerEl = document.querySelector('.container'); textBase = new TextBaseViewer({ file: { @@ -91,7 +91,16 @@ describe('lib/viewers/text/TextBaseViewer', () => { it('should add selectable class if user has download permissions', () => { sandbox.stub(file, 'checkPermission').withArgs(textBase.options.file, PERMISSION_DOWNLOAD).returns(true); textBase.load(); - expect(textBase.containerEl.classList.contains('bp-is-selectable')).to.be.true; + expect(textBase.containerEl).to.have.class('bp-is-selectable'); + }); + + it('should not add selectable class if disableTextViewer option is true', () => { + sandbox.stub(file, 'checkPermission').withArgs(textBase.options.file, PERMISSION_DOWNLOAD).returns(true); + sandbox.stub(textBase, 'getViewerOption').withArgs('disableTextLayer').returns(true); + + textBase.load(); + + expect(textBase.containerEl).to.not.have.class('bp-is-selectable'); }); });