Re-factor the PresentationMode handling in BaseViewer.#ensurePageViewVisible
				
					
				
			Given that we're (ab)using spread-modes in order to ensure that pages are centered *vertically* in PresentationMode, this re-factoring simplifies the code slightly. Furthermore, in the event that we *possibly* want to try and support spread-modes in PresentationMode[1] this re-factoring will also prevent future duplication. --- [1] Note that I'm not particularly keen on doing that, since documents with varying page sizes will be annoying to handle.
This commit is contained in:
		
							parent
							
								
									da4f7dfcd0
								
							
						
					
					
						commit
						aad4c6538f
					
				@ -885,23 +885,10 @@ class BaseViewer {
 | 
				
			|||||||
    // ... and clear out the active ones.
 | 
					    // ... and clear out the active ones.
 | 
				
			||||||
    state.pages.length = 0;
 | 
					    state.pages.length = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (this._spreadMode === SpreadMode.NONE) {
 | 
					    if (this._spreadMode === SpreadMode.NONE && !this.isInPresentationMode) {
 | 
				
			||||||
      // Finally, append the new page to the viewer.
 | 
					      // Finally, append the new page to the viewer.
 | 
				
			||||||
      const pageView = this._pages[pageNumber - 1];
 | 
					      const pageView = this._pages[pageNumber - 1];
 | 
				
			||||||
 | 
					 | 
				
			||||||
      if (this.isInPresentationMode) {
 | 
					 | 
				
			||||||
        const spread = document.createElement("div");
 | 
					 | 
				
			||||||
        spread.className = "spread";
 | 
					 | 
				
			||||||
        const dummyPage = document.createElement("div");
 | 
					 | 
				
			||||||
        dummyPage.className = "dummyPage";
 | 
					 | 
				
			||||||
        dummyPage.style.height = `${this.container.clientHeight}px`;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        spread.appendChild(dummyPage);
 | 
					 | 
				
			||||||
        spread.appendChild(pageView.div);
 | 
					 | 
				
			||||||
        viewer.appendChild(spread);
 | 
					 | 
				
			||||||
      } else {
 | 
					 | 
				
			||||||
      viewer.appendChild(pageView.div);
 | 
					      viewer.appendChild(pageView.div);
 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
      state.pages.push(pageView);
 | 
					      state.pages.push(pageView);
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
@ -909,7 +896,10 @@ class BaseViewer {
 | 
				
			|||||||
        parity = this._spreadMode - 1;
 | 
					        parity = this._spreadMode - 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // Determine the pageIndices in the new spread.
 | 
					      // Determine the pageIndices in the new spread.
 | 
				
			||||||
      if (pageNumber % 2 !== parity) {
 | 
					      if (parity === -1) {
 | 
				
			||||||
 | 
					        // PresentationMode is active, with `SpreadMode.NONE` set.
 | 
				
			||||||
 | 
					        pageIndexSet.add(pageNumber - 1);
 | 
				
			||||||
 | 
					      } else if (pageNumber % 2 !== parity) {
 | 
				
			||||||
        // Left-hand side page.
 | 
					        // Left-hand side page.
 | 
				
			||||||
        pageIndexSet.add(pageNumber - 1);
 | 
					        pageIndexSet.add(pageNumber - 1);
 | 
				
			||||||
        pageIndexSet.add(pageNumber);
 | 
					        pageIndexSet.add(pageNumber);
 | 
				
			||||||
@ -923,6 +913,13 @@ class BaseViewer {
 | 
				
			|||||||
      const spread = document.createElement("div");
 | 
					      const spread = document.createElement("div");
 | 
				
			||||||
      spread.className = "spread";
 | 
					      spread.className = "spread";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      if (this.isInPresentationMode) {
 | 
				
			||||||
 | 
					        const dummyPage = document.createElement("div");
 | 
				
			||||||
 | 
					        dummyPage.className = "dummyPage";
 | 
				
			||||||
 | 
					        dummyPage.style.height = `${this.container.clientHeight}px`;
 | 
				
			||||||
 | 
					        spread.appendChild(dummyPage);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      for (const i of pageIndexSet) {
 | 
					      for (const i of pageIndexSet) {
 | 
				
			||||||
        const pageView = this._pages[i];
 | 
					        const pageView = this._pages[i];
 | 
				
			||||||
        if (!pageView) {
 | 
					        if (!pageView) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user