-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New: Add in SinglePageViewer for pdfs (#606)
- Loading branch information
Showing
5 changed files
with
124 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import DocumentViewer from './DocumentViewer'; | ||
|
||
class SinglePageViewer extends DocumentViewer { | ||
//-------------------------------------------------------------------------- | ||
// Protected | ||
//-------------------------------------------------------------------------- | ||
|
||
/** | ||
* Initialize pdf.js viewer. | ||
* | ||
* @protected | ||
* @override | ||
* @return {PDFJS.PDFViewer} PDF viewer type | ||
*/ | ||
initPdfViewer() { | ||
return new PDFJS.PDFSinglePageViewer({ | ||
container: this.docEl, | ||
linkService: new PDFJS.PDFLinkService(), | ||
// Enhanced text selection uses more memory, so disable on mobile | ||
enhanceTextSelection: !this.isMobile | ||
}); | ||
} | ||
} | ||
|
||
export default SinglePageViewer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div class="container"><div class="bp-container"><div class="bp"></div></div></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* eslint-disable no-unused-expressions */ | ||
import SinglePageViewer from '../SinglePageViewer'; | ||
import BaseViewer from '../../BaseViewer'; | ||
|
||
const sandbox = sinon.sandbox.create(); | ||
let containerEl; | ||
let doc; | ||
let stubs = {}; | ||
|
||
describe('lib/viewers/doc/SinglePageViewer', () => { | ||
const setupFunc = BaseViewer.prototype.setup; | ||
|
||
before(() => { | ||
fixture.setBase('src/lib'); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture.load('viewers/doc/__tests__/SinglePageViewer-test.html'); | ||
|
||
containerEl = document.querySelector('.container'); | ||
doc = new SinglePageViewer({ | ||
container: containerEl, | ||
file: { | ||
id: '0' | ||
} | ||
}); | ||
|
||
Object.defineProperty(BaseViewer.prototype, 'setup', { value: sandbox.mock() }); | ||
doc.containerEl = containerEl; | ||
doc.setup(); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.verifyAndRestore(); | ||
fixture.cleanup(); | ||
|
||
Object.defineProperty(BaseViewer.prototype, 'setup', { value: setupFunc }); | ||
|
||
if (doc && typeof doc.destroy === 'function') { | ||
doc.destroy(); | ||
} | ||
|
||
doc = null; | ||
stubs = {}; | ||
}); | ||
|
||
describe('initPdfViewer()', () => { | ||
const pdfViewer = { | ||
linkService: new PDFJS.PDFLinkService(), | ||
setDocument: sandbox.stub(), | ||
enhanceTextSelection: true | ||
}; | ||
|
||
beforeEach(() => { | ||
stubs.pdfViewerStub = sandbox.stub(PDFJS, 'PDFSinglePageViewer').returns(pdfViewer); | ||
}); | ||
|
||
it('should return the default pdfViewer', () => { | ||
const result = doc.initPdfViewer(); | ||
expect(stubs.pdfViewerStub).to.be.calledWith({ | ||
container: sinon.match.any, | ||
linkService: sinon.match.any, | ||
enhanceTextSelection: true | ||
}); | ||
expect(result).to.equal(pdfViewer); | ||
}); | ||
}); | ||
}); |