Comments (5)
I too am seeing this issue. I dug in further to the trace that @cadecairos started.
This error occurs when the checkTimer calls drawPages while the viewer is hidden. When that happens, the value of _sortedIndex(c, i) is zero, which causes the call to this.helpers.sortPages to have an argument of -1, which returns undefined as none of the if clauses offer a return for a negative value. This then causes the drawPageAt function to error when it tries to use the value from the result of this.helpers.sortPages(-1), and then various images in the viewer fail to appear at all.
Important to note here is that it isn't the act of hiding and showing that is causing the issue, but having the element hidden during the time at which the drawPages method is called. If you hide and then show the viewer very quickly, you won't notice this error, as the timeout for the checkTimer is 100ms, so it is likely you can hide and show before it runs the code that causes the error.
As a side note, is there an un-minified version of viewer.js available somewhere?
from document-viewer.
viewer.js is just a concatenation of the other JS files; see config/assets.yml.
from document-viewer.
@croby, did you ever come up with a good workaround? I tried adding logic in the drawPages function to not try rendering the pages if the viewer is hidden. It still raises javascript exceptions, but keeps the viewer from breaking. It's messy but simple. A better but trickier solution might be to change the code and add a "Hidden" state for the viewer that plays nice with all the state & event observers.
My change to docViewer/DV/events/events.js, at line 16:
...
// Draw (or redraw) the visible pages on the screen.
drawPages: function() {
if (this.viewer.state != 'ViewDocument') return;
if (!$(this.viewer.options.container).is(':visible')) return; // Hack by MattJones
var doc = this.models.document;
...
from document-viewer.
The viewer is a bit hack-ful. I'd be happy to incorporate that in.
I'm currently in the midst of a viewer refactor that will make screwing with the viewer a lot simpler (you can check it on the refactor branch).
from document-viewer.
Good to know you're still supporting docViewer. I've had more luck with checking for errors deeper in the function, to avoid errors when the viewer is loading. It still has a bad code-smell, but it works a little better as a quick fix than what I posted above. I haven't tried this out with any other views (thumbnails, annotation, etc).
...
// Draw (or redraw) the visible pages on the screen.
drawPages: function() {
if (this.viewer.state != 'ViewDocument') return;
var doc = this.models.document;
var win = this.elements.window[0];
var offsets = doc.baseHeightsPortionOffsets;
var scrollPos = this.viewer.scrollPosition = win.scrollTop;
var midpoint = scrollPos + (this.viewer.$(win).height() / 3);
var currentPage = _.sortedIndex(offsets, scrollPos);
var middlePage = _.sortedIndex(offsets, midpoint);
if( middlePage <= 0) return; // Don't draw pages if the viewer is hidden // Hack by MattJones
if (offsets[currentPage] == scrollPos) currentPage++ && middlePage++;
var pageIds = this.helpers.sortPages(middlePage - 1);
var total = doc.totalPages;
if (doc.currentPage() != currentPage) doc.setPageIndex(currentPage - 1);
this.drawPageAt(pageIds, middlePage - 1);
},
...
from document-viewer.
Related Issues (20)
- Responsive option HOT 3
- Suggestion: Remove annotation padding HOT 2
- Translation support HOT 2
- Add download option on embed view
- Padding is screwed up. HOT 3
- viewer.api.redraw(true) isn't redrawing page widths HOT 1
- Viewer CSS and JavaScript aren't served gzip-compressed HOT 1
- Adding an annotation or redaction resets the zoom level
- enable annotations
- Page number text input does not switch to proper page when changed HOT 3
- Add two-up view for simultaneously viewing image and text
- Maintain in-page scroll position when moving between viewer tabs
- on getPageText, DocumentViewer returns undefined if text has not yet been presented in the viewer
- Support translations in viewer interface
- pushState for the viewer
- Expose document metadata in viewer API
- Add padding to note view
- don't use document.write to insert script HOT 2
- Highlight Previous Match doesn't work when transitioning back to First Page HOT 1
- I imported total code into my local desktop . now I want to set few buttons into annotations bar?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from document-viewer.