|
125 | 125 | }
|
126 | 126 | this.initialized = true;
|
127 | 127 | },
|
128 |
| - measurePage: function(page) { |
129 |
| - var ph = this.calcPageHeight(page); |
130 |
| - var pn = page.pageNum; |
131 |
| - if (!this.rowHeight) { |
132 |
| - // rowHeight is not set, use the page's height to setup initial values |
133 |
| - this.initialize(ph, pn); |
134 |
| - } |
135 |
| - var ph0 = this.getPageHeight(pn); |
136 |
| - if (ph && ph0 != ph) { |
137 |
| - this.pageHeights[pn] = ph; |
138 |
| - // since page height has changed, invalidate all the pageTops after |
139 |
| - // this page |
140 |
| - this.pageTops.splice(pn+1, this.pageTops.length); |
141 |
| - // also adjust the viewport's height |
142 |
| - this.viewportHeight += ph - ph0; |
143 |
| - } |
144 |
| - }, |
145 | 128 | get viewportHeight() {
|
146 | 129 | return this._viewportHeight;
|
147 | 130 | },
|
|
191 | 174 | var ph = this.getPageHeight(pn);
|
192 | 175 | return pn + (pos-pt+ph)/ph;
|
193 | 176 | },
|
| 177 | + /* returns delta between actual and expected */ |
| 178 | + measurePage: function(page) { |
| 179 | + var ph = this.calcPageHeight(page); |
| 180 | + var pn = page.pageNum; |
| 181 | + if (!this.rowHeight) { |
| 182 | + // rowHeight is not set, use the page's height to setup initial values |
| 183 | + this.initialize(ph, pn); |
| 184 | + } |
| 185 | + var ph0 = this.getPageHeight(pn); |
| 186 | + if (ph && ph0 != ph) { |
| 187 | + this.pageHeights[pn] = ph; |
| 188 | + // since page height has changed, invalidate all the pageTops after |
| 189 | + // this page |
| 190 | + this.pageTops.splice(pn+1, this.pageTops.length); |
| 191 | + // also adjust the viewport's height |
| 192 | + return ph - ph0; |
| 193 | + } |
| 194 | + return 0; |
| 195 | + }, |
194 | 196 | // positions the given page and returns the adjustment delta.
|
195 | 197 | positionPage: function(page) {
|
196 | 198 | var pn = page.pageNum, t;
|
|
257 | 259 | invalidate: function(info) {
|
258 | 260 | info = info || this.getViewportPageInfo();
|
259 | 261 | var k = info.start, n = info.start+this.numPages,
|
260 |
| - c = info.center; |
| 262 | + c = info.center, v=0, s=0, d; |
261 | 263 | this.previousPages = this.pages;
|
262 | 264 | this.pages = [];
|
263 | 265 | for (; k<n; k++) {
|
|
266 | 268 | if (this.retainPages) {
|
267 | 269 | p.style.display = null;
|
268 | 270 | }
|
269 |
| - this.measurePage(p); |
270 |
| - var d = this.positionPage(p); |
| 271 | + v += this.measurePage(p); |
| 272 | + d = this.positionPage(p); |
271 | 273 | // adjust scrollOffset if center page's top has changed
|
272 |
| - if (!this.fixedHeight && (d && k === c)) { |
273 |
| - this.scrollOffset -= d; |
| 274 | + if (d && k === c) { |
| 275 | + s = d; |
274 | 276 | }
|
275 | 277 | this.pages.push(p);
|
276 | 278 | }
|
277 | 279 | }
|
| 280 | + // adjust viewport and scroll position iff needed |
| 281 | + if (!this.fixedHeight) { |
| 282 | + if (v) { |
| 283 | + this.viewportHeight += v; |
| 284 | + } |
| 285 | + if (s) { |
| 286 | + this.scrollOffset -= s; |
| 287 | + } |
| 288 | + } |
278 | 289 | // remove out-of-bounds pages
|
279 | 290 | this.cleanupPages();
|
280 | 291 | },
|
|
0 commit comments