[Pkg-javascript-commits] [pdf.js] 77/119: Refactor the options passed to |PresentationMode.initialize| and clean-up some code in viewer.js and presentation_mode.js
David Prévot
taffit at moszumanska.debian.org
Wed May 13 21:27:43 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository pdf.js.
commit e7fd5b4d4d2bcdfdbffed588fdfa344239020d44
Author: Jonas Jenwald <jonas.jenwald at gmail.com>
Date: Sun Feb 1 11:31:18 2015 +0100
Refactor the options passed to |PresentationMode.initialize| and clean-up some code in viewer.js and presentation_mode.js
This patch:
- Passes in a reference to the current PDFThumbnailViewer, which is used to ensure that the current thumbnail becomes visible when exiting PresentationMode.
- Changes the way that the event listeners for the contextmenu items are defined, to avoid passing in a reference to the SecondaryToolbar.
- Ensures that |supportsFullscreen| always returns a boolean.
Currently `supportsFullscreen` will, when the browser supports the fullscreen API, return e.g. `function mozRequestFullScreen()` instead of `true`.
- Simplifies the |click| handler code when PresentationMode is active.
This code has been obsolete ever since PR 2919 landed.
- Removes hack used to workaround a bug in WebKit browsers, which caused |mousemove| events to be fired when the cursor changed.
This was fixed close to a year ago, see http://code.google.com/p/chromium/issues/detail?id=103041.
---
web/presentation_mode.js | 60 ++++++++++++++----------------------------------
web/viewer.js | 35 ++++++++++++++--------------
2 files changed, 35 insertions(+), 60 deletions(-)
diff --git a/web/presentation_mode.js b/web/presentation_mode.js
index 6fc223b..4ef1a0e 100644
--- a/web/presentation_mode.js
+++ b/web/presentation_mode.js
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-/* globals scrollIntoView, PDFViewerApplication */
+/* globals PDFViewerApplication */
'use strict';
@@ -27,41 +27,26 @@ var PresentationMode = {
active: false,
args: null,
contextMenuOpen: false,
-//#if (GENERIC || CHROME)
- prevCoords: { x: null, y: null },
-//#endif
mouseScrollTimeStamp: 0,
mouseScrollDelta: 0,
initialize: function presentationModeInitialize(options) {
this.initialized = true;
this.container = options.container;
- this.secondaryToolbar = options.secondaryToolbar;
+ this.pdfThumbnailViewer = options.pdfThumbnailViewer || null;
+ var contextMenuItems = options.contextMenuItems || null;
this.viewer = this.container.firstElementChild;
- this.firstPage = options.firstPage;
- this.lastPage = options.lastPage;
- this.pageRotateCw = options.pageRotateCw;
- this.pageRotateCcw = options.pageRotateCcw;
-
- this.firstPage.addEventListener('click', function() {
- this.contextMenuOpen = false;
- this.secondaryToolbar.firstPageClick();
- }.bind(this));
- this.lastPage.addEventListener('click', function() {
- this.contextMenuOpen = false;
- this.secondaryToolbar.lastPageClick();
- }.bind(this));
-
- this.pageRotateCw.addEventListener('click', function() {
- this.contextMenuOpen = false;
- this.secondaryToolbar.pageRotateCwClick();
- }.bind(this));
- this.pageRotateCcw.addEventListener('click', function() {
- this.contextMenuOpen = false;
- this.secondaryToolbar.pageRotateCcwClick();
- }.bind(this));
+ if (contextMenuItems) {
+ for (var i = 0, ii = contextMenuItems.length; i < ii; i++) {
+ var item = contextMenuItems[i];
+ item.element.addEventListener('click', function (handler) {
+ this.contextMenuOpen = false;
+ handler();
+ }.bind(this, item.handler));
+ }
+ }
},
get isFullscreen() {
@@ -186,9 +171,11 @@ var PresentationMode = {
this.container.removeAttribute('contextmenu');
this.contextMenuOpen = false;
- // Ensure that the thumbnail of the current page is visible
- // when exiting presentation mode.
- scrollIntoView(document.getElementById('thumbnailContainer' + page));
+ if (this.pdfThumbnailViewer) {
+ // Ensure that the thumbnail of the current page is visible
+ // when exiting presentation mode.
+ this.pdfThumbnailViewer.ensureThumbnailVisible(page);
+ }
},
showControls: function presentationModeShowControls() {
@@ -213,19 +200,6 @@ var PresentationMode = {
},
mouseMove: function presentationModeMouseMove(evt) {
-//#if (GENERIC || CHROME)
- // Workaround for a bug in WebKit browsers that causes the 'mousemove' event
- // to be fired when the cursor is changed. For details, see:
- // http://code.google.com/p/chromium/issues/detail?id=103041.
-
- var currCoords = { x: evt.clientX, y: evt.clientY };
- var prevCoords = PresentationMode.prevCoords;
- PresentationMode.prevCoords = currCoords;
-
- if (currCoords.x === prevCoords.x && currCoords.y === prevCoords.y) {
- return;
- }
-//#endif
PresentationMode.showControls();
},
diff --git a/web/viewer.js b/web/viewer.js
index 994835d..819be1a 100644
--- a/web/viewer.js
+++ b/web/viewer.js
@@ -15,7 +15,7 @@
* limitations under the License.
*/
/* globals PDFJS, PDFBug, FirefoxCom, Stats, Cache, ProgressBar,
- DownloadManager, getFileName, scrollIntoView, getPDFFileNameFromURL,
+ DownloadManager, getFileName, getPDFFileNameFromURL,
PDFHistory, Preferences, SidebarView, ViewHistory, Stats,
PDFThumbnailViewer, URL, noContextMenuHandler, SecondaryToolbar,
PasswordPrompt, PresentationMode, HandTool, Promise,
@@ -188,13 +188,20 @@ var PDFViewerApplication = {
});
if (this.supportsFullscreen) {
+ var toolbar = SecondaryToolbar;
PresentationMode.initialize({
container: container,
- secondaryToolbar: SecondaryToolbar,
- firstPage: document.getElementById('contextFirstPage'),
- lastPage: document.getElementById('contextLastPage'),
- pageRotateCw: document.getElementById('contextPageRotateCw'),
- pageRotateCcw: document.getElementById('contextPageRotateCcw')
+ pdfThumbnailViewer: this.pdfThumbnailViewer,
+ contextMenuItems: [
+ { element: document.getElementById('contextFirstPage'),
+ handler: toolbar.firstPageClick.bind(toolbar) },
+ { element: document.getElementById('contextLastPage'),
+ handler: toolbar.lastPageClick.bind(toolbar) },
+ { element: document.getElementById('contextPageRotateCw'),
+ handler: toolbar.pageRotateCwClick.bind(toolbar) },
+ { element: document.getElementById('contextPageRotateCcw'),
+ handler: toolbar.pageRotateCcwClick.bind(toolbar) }
+ ]
});
}
@@ -317,8 +324,8 @@ var PDFViewerApplication = {
get supportsFullscreen() {
var doc = document.documentElement;
- var support = doc.requestFullscreen || doc.mozRequestFullScreen ||
- doc.webkitRequestFullScreen || doc.msRequestFullscreen;
+ var support = !!(doc.requestFullscreen || doc.mozRequestFullScreen ||
+ doc.webkitRequestFullScreen || doc.msRequestFullscreen);
if (document.fullscreenEnabled === false ||
document.mozFullScreenEnabled === false ||
@@ -1936,15 +1943,9 @@ window.addEventListener('DOMMouseScroll', handleMouseWheel);
window.addEventListener('mousewheel', handleMouseWheel);
window.addEventListener('click', function click(evt) {
- if (!PDFViewerApplication.pdfViewer.isInPresentationMode) {
- if (SecondaryToolbar.opened &&
- PDFViewerApplication.pdfViewer.containsElement(evt.target)) {
- SecondaryToolbar.close();
- }
- } else if (evt.button === 0) {
- // Necessary since preventDefault() in 'mousedown' won't stop
- // the event propagation in all circumstances in presentation mode.
- evt.preventDefault();
+ if (SecondaryToolbar.opened &&
+ PDFViewerApplication.pdfViewer.containsElement(evt.target)) {
+ SecondaryToolbar.close();
}
}, false);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/pdf.js.git
More information about the Pkg-javascript-commits
mailing list