Skip to content

Commit

Permalink
Closes #1 - page number is linked to the ember component
Browse files Browse the repository at this point in the history
it requires some work on the pdfViewerContainer element though (see README explanation)
  • Loading branch information
leojpod committed Nov 29, 2016
1 parent 9677591 commit b95d6f9
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 9 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@
## Addon's "API"

TODO!!


## A word about the current page update

There are some limitation ATM on how the current page is updated. The "scroll" need to be placed on the `.pdfViewerContainer`. For an example on how to do it, check the dummy app's [style sheet](https://github.com/smith-carson/ember-pdf-js/blob/master/tests/dummy/app/styles/app.css)
6 changes: 5 additions & 1 deletion addon/components/pdf-js-toolbar.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import Ember from 'ember'
import layout from '../templates/components/pdf-js-toolbar'

const { Component } = Ember
const {
Component
} = Ember

export default Component.extend({
layout,
Expand All @@ -11,6 +13,8 @@ export default Component.extend({
caseSensitive: false,
highlightAll: true,
phraseSearch: false,
page: undefined,
pageTotal: undefined,

actions: {
search () {
Expand Down
22 changes: 19 additions & 3 deletions addon/components/pdf-js.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ const {
Component,
computed: { reads },
inject: { service: injectService },
observer
observer,
run
} = Ember

export default Component.extend({
Expand All @@ -33,17 +34,19 @@ export default Component.extend({
pdfHistory: undefined,
pdfViewer: undefined,
pdfFindController: undefined,
pdfPage: 0,
pdfPage: undefined,
pdfTotalPages: undefined,

// components
toolbarComponent: 'pdf-js-toolbar',

// initialization
didInsertElement () {
let [container] = this.element.getElementsByClassName('pdfViewerContainer')
let pdfLinkService = new PDFLinkService()
this.set('pdfLinkService', pdfLinkService)
let pdfViewer = new PDFViewer({
container: this.element.getElementsByClassName('pdfViewerContainer')[0],
container,
linkService: pdfLinkService
})
this.set('pdfViewer', pdfViewer)
Expand All @@ -52,11 +55,22 @@ export default Component.extend({
linkService: pdfLinkService
})
this.set('pdfHistory', pdfHistory)
pdfLinkService.setHistory(pdfHistory)
let pdfFindController = new PDFFindController({
pdfViewer
})
this.set('pdfFindController', pdfFindController)
pdfViewer.setFindController(pdfFindController)
pdfViewer.currentScaleValue = 'page-fit'

// setup the event listening to synchronise with pdf.js' modifications
let self = this
pdfViewer.eventBus.on('pagechange', function (evt) {
let page = evt.pageNumber
run(function () {
self.set('pdfPage', page)
})
})

if (this.get('pdf')) {
this.send('load')
Expand Down Expand Up @@ -86,6 +100,8 @@ export default Component.extend({
linkService.setDocument(pdfDocument)
let history = this.get('pdfHistory')
history.initialize(pdfDocument.fingerprint)
this.set('pdfTotalPages', linkService.pagesCount)
this.set('pdfPage', linkService.page)
})

this.set('loadingTask', loadingTask)
Expand Down
5 changes: 3 additions & 2 deletions addon/templates/components/pdf-js-toolbar.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<button type="button" {{action (action this.attrs.changePage) 'next'}}>
<button type="button" {{action (action this.attrs.changePage) 'next'}} disabled={{gte page pageTotal}}>
Next page !
</button>
<button type="button" {{action (action this.attrs.changePage) 'prev'}}>
<button type="button" {{action (action this.attrs.changePage) 'prev'}} disabled={{lte page 1}}>
Prev page !
</button>
{{one-way-input searchTerms update=(action 'updateSearchTerm')}}
Expand All @@ -18,3 +18,4 @@
{{one-way-checkbox highlightAll update=(action 'updateHighlightAll')}}
highlightAll
</label>
<label>page {{page}} of {{pageTotal}}</label>
2 changes: 2 additions & 0 deletions addon/templates/components/pdf-js.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@

{{component toolbarComponent
changePage=(action 'changePage')
search=(action 'search')
zoom=(action 'zoom')
page=pdfPage
pageTotal=pdfTotalPages
class="ember-pdf-js toolbar"
}}
<div class="pdfViewerContainer">
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"author": "leojpod",
"license": "MIT",
"devDependencies": {
"broccoli-asset-rev": "^2.4.5",
"broccoli-funnel": "^1.0.9",
"broccoli-merge-trees": "^1.1.5",
"broccoli-asset-rev": "^2.4.5",
"ember-ajax": "^2.4.1",
"ember-browserify": "1.1.13",
"ember-cli": "2.9.1",
Expand Down Expand Up @@ -54,7 +54,8 @@
"dependencies": {
"ember-cli-babel": "^5.1.7",
"ember-cli-htmlbars": "1.1.0",
"ember-one-way-controls": "1.1.2"
"ember-one-way-controls": "1.1.2",
"ember-truth-helpers": "1.2.0"
},
"ember-addon": {
"configPath": "tests/dummy/config"
Expand Down
12 changes: 12 additions & 0 deletions tests/dummy/app/styles/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,16 @@
position: fixed;
top: 0;
z-index: 100;
background: solid white;
}
.ember-pdf-js.viewer .pdfViewerContainer{
position: absolute;
top:0;
bottom: 0;
overflow-y: auto;
left: 0;
right: 0;
}
body, html {
overflow: hidden;
}
2 changes: 1 addition & 1 deletion tests/dummy/app/templates/application.hbs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
{{#pdf-js pdf="/compressed.tracemonkey-pldi-09.pdf"}}
{{#pdf-js pdf="/compressed.tracemonkey-pldi-09.pdf" class='ember-pdf-js viewer'}}
{{/pdf-js}}

0 comments on commit b95d6f9

Please sign in to comment.