Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update: Add disableTextLayer option for doc and text viewers #71

Merged
merged 4 commits into from
Apr 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions src/lib/viewers/text/TextBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
13 changes: 11 additions & 2 deletions src/lib/viewers/text/__tests__/TextBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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');
});
});

Expand Down