Merge pull request #8752 from Snuffleupagus/es6-dom_events
ES6-ify the code in `web/dom_events.js`
This commit is contained in:
commit
f83bd721fc
@ -18,117 +18,117 @@ import { EventBus } from './ui_utils';
|
|||||||
// Attaching to the application event bus to dispatch events to the DOM for
|
// Attaching to the application event bus to dispatch events to the DOM for
|
||||||
// backwards viewer API compatibility.
|
// backwards viewer API compatibility.
|
||||||
function attachDOMEventsToEventBus(eventBus) {
|
function attachDOMEventsToEventBus(eventBus) {
|
||||||
eventBus.on('documentload', function () {
|
eventBus.on('documentload', function() {
|
||||||
var event = document.createEvent('CustomEvent');
|
let event = document.createEvent('CustomEvent');
|
||||||
event.initCustomEvent('documentload', true, true, {});
|
event.initCustomEvent('documentload', true, true, {});
|
||||||
window.dispatchEvent(event);
|
window.dispatchEvent(event);
|
||||||
});
|
});
|
||||||
eventBus.on('pagerendered', function (e) {
|
eventBus.on('pagerendered', function(evt) {
|
||||||
var event = document.createEvent('CustomEvent');
|
let event = document.createEvent('CustomEvent');
|
||||||
event.initCustomEvent('pagerendered', true, true, {
|
event.initCustomEvent('pagerendered', true, true, {
|
||||||
pageNumber: e.pageNumber,
|
pageNumber: evt.pageNumber,
|
||||||
cssTransform: e.cssTransform,
|
cssTransform: evt.cssTransform,
|
||||||
});
|
});
|
||||||
e.source.div.dispatchEvent(event);
|
evt.source.div.dispatchEvent(event);
|
||||||
});
|
});
|
||||||
eventBus.on('textlayerrendered', function (e) {
|
eventBus.on('textlayerrendered', function(evt) {
|
||||||
var event = document.createEvent('CustomEvent');
|
let event = document.createEvent('CustomEvent');
|
||||||
event.initCustomEvent('textlayerrendered', true, true, {
|
event.initCustomEvent('textlayerrendered', true, true, {
|
||||||
pageNumber: e.pageNumber,
|
pageNumber: evt.pageNumber,
|
||||||
});
|
});
|
||||||
e.source.textLayerDiv.dispatchEvent(event);
|
evt.source.textLayerDiv.dispatchEvent(event);
|
||||||
});
|
});
|
||||||
eventBus.on('pagechange', function (e) {
|
eventBus.on('pagechange', function(evt) {
|
||||||
var event = document.createEvent('UIEvents');
|
let event = document.createEvent('UIEvents');
|
||||||
event.initUIEvent('pagechange', true, true, window, 0);
|
event.initUIEvent('pagechange', true, true, window, 0);
|
||||||
event.pageNumber = e.pageNumber;
|
event.pageNumber = evt.pageNumber;
|
||||||
e.source.container.dispatchEvent(event);
|
evt.source.container.dispatchEvent(event);
|
||||||
});
|
});
|
||||||
eventBus.on('pagesinit', function (e) {
|
eventBus.on('pagesinit', function(evt) {
|
||||||
var event = document.createEvent('CustomEvent');
|
let event = document.createEvent('CustomEvent');
|
||||||
event.initCustomEvent('pagesinit', true, true, null);
|
event.initCustomEvent('pagesinit', true, true, null);
|
||||||
e.source.container.dispatchEvent(event);
|
evt.source.container.dispatchEvent(event);
|
||||||
});
|
});
|
||||||
eventBus.on('pagesloaded', function (e) {
|
eventBus.on('pagesloaded', function(evt) {
|
||||||
var event = document.createEvent('CustomEvent');
|
let event = document.createEvent('CustomEvent');
|
||||||
event.initCustomEvent('pagesloaded', true, true, {
|
event.initCustomEvent('pagesloaded', true, true, {
|
||||||
pagesCount: e.pagesCount,
|
pagesCount: evt.pagesCount,
|
||||||
});
|
});
|
||||||
e.source.container.dispatchEvent(event);
|
evt.source.container.dispatchEvent(event);
|
||||||
});
|
});
|
||||||
eventBus.on('scalechange', function (e) {
|
eventBus.on('scalechange', function(evt) {
|
||||||
var event = document.createEvent('UIEvents');
|
let event = document.createEvent('UIEvents');
|
||||||
event.initUIEvent('scalechange', true, true, window, 0);
|
event.initUIEvent('scalechange', true, true, window, 0);
|
||||||
event.scale = e.scale;
|
event.scale = evt.scale;
|
||||||
event.presetValue = e.presetValue;
|
event.presetValue = evt.presetValue;
|
||||||
e.source.container.dispatchEvent(event);
|
evt.source.container.dispatchEvent(event);
|
||||||
});
|
});
|
||||||
eventBus.on('updateviewarea', function (e) {
|
eventBus.on('updateviewarea', function(evt) {
|
||||||
var event = document.createEvent('UIEvents');
|
let event = document.createEvent('UIEvents');
|
||||||
event.initUIEvent('updateviewarea', true, true, window, 0);
|
event.initUIEvent('updateviewarea', true, true, window, 0);
|
||||||
event.location = e.location;
|
event.location = evt.location;
|
||||||
e.source.container.dispatchEvent(event);
|
evt.source.container.dispatchEvent(event);
|
||||||
});
|
});
|
||||||
eventBus.on('find', function (e) {
|
eventBus.on('find', function(evt) {
|
||||||
if (e.source === window) {
|
if (evt.source === window) {
|
||||||
return; // event comes from FirefoxCom, no need to replicate
|
return; // event comes from FirefoxCom, no need to replicate
|
||||||
}
|
}
|
||||||
var event = document.createEvent('CustomEvent');
|
let event = document.createEvent('CustomEvent');
|
||||||
event.initCustomEvent('find' + e.type, true, true, {
|
event.initCustomEvent('find' + evt.type, true, true, {
|
||||||
query: e.query,
|
query: evt.query,
|
||||||
phraseSearch: e.phraseSearch,
|
phraseSearch: evt.phraseSearch,
|
||||||
caseSensitive: e.caseSensitive,
|
caseSensitive: evt.caseSensitive,
|
||||||
highlightAll: e.highlightAll,
|
highlightAll: evt.highlightAll,
|
||||||
findPrevious: e.findPrevious,
|
findPrevious: evt.findPrevious,
|
||||||
});
|
});
|
||||||
window.dispatchEvent(event);
|
window.dispatchEvent(event);
|
||||||
});
|
});
|
||||||
eventBus.on('attachmentsloaded', function (e) {
|
eventBus.on('attachmentsloaded', function(evt) {
|
||||||
var event = document.createEvent('CustomEvent');
|
let event = document.createEvent('CustomEvent');
|
||||||
event.initCustomEvent('attachmentsloaded', true, true, {
|
event.initCustomEvent('attachmentsloaded', true, true, {
|
||||||
attachmentsCount: e.attachmentsCount,
|
attachmentsCount: evt.attachmentsCount,
|
||||||
});
|
});
|
||||||
e.source.container.dispatchEvent(event);
|
evt.source.container.dispatchEvent(event);
|
||||||
});
|
});
|
||||||
eventBus.on('sidebarviewchanged', function (e) {
|
eventBus.on('sidebarviewchanged', function(evt) {
|
||||||
var event = document.createEvent('CustomEvent');
|
let event = document.createEvent('CustomEvent');
|
||||||
event.initCustomEvent('sidebarviewchanged', true, true, {
|
event.initCustomEvent('sidebarviewchanged', true, true, {
|
||||||
view: e.view,
|
view: evt.view,
|
||||||
});
|
});
|
||||||
e.source.outerContainer.dispatchEvent(event);
|
evt.source.outerContainer.dispatchEvent(event);
|
||||||
});
|
});
|
||||||
eventBus.on('pagemode', function (e) {
|
eventBus.on('pagemode', function(evt) {
|
||||||
var event = document.createEvent('CustomEvent');
|
let event = document.createEvent('CustomEvent');
|
||||||
event.initCustomEvent('pagemode', true, true, {
|
event.initCustomEvent('pagemode', true, true, {
|
||||||
mode: e.mode,
|
mode: evt.mode,
|
||||||
});
|
});
|
||||||
e.source.pdfViewer.container.dispatchEvent(event);
|
evt.source.pdfViewer.container.dispatchEvent(event);
|
||||||
});
|
});
|
||||||
eventBus.on('namedaction', function (e) {
|
eventBus.on('namedaction', function(evt) {
|
||||||
var event = document.createEvent('CustomEvent');
|
let event = document.createEvent('CustomEvent');
|
||||||
event.initCustomEvent('namedaction', true, true, {
|
event.initCustomEvent('namedaction', true, true, {
|
||||||
action: e.action,
|
action: evt.action,
|
||||||
});
|
});
|
||||||
e.source.pdfViewer.container.dispatchEvent(event);
|
evt.source.pdfViewer.container.dispatchEvent(event);
|
||||||
});
|
});
|
||||||
eventBus.on('presentationmodechanged', function (e) {
|
eventBus.on('presentationmodechanged', function(evt) {
|
||||||
var event = document.createEvent('CustomEvent');
|
let event = document.createEvent('CustomEvent');
|
||||||
event.initCustomEvent('presentationmodechanged', true, true, {
|
event.initCustomEvent('presentationmodechanged', true, true, {
|
||||||
active: e.active,
|
active: evt.active,
|
||||||
switchInProgress: e.switchInProgress,
|
switchInProgress: evt.switchInProgress,
|
||||||
});
|
});
|
||||||
window.dispatchEvent(event);
|
window.dispatchEvent(event);
|
||||||
});
|
});
|
||||||
eventBus.on('outlineloaded', function (e) {
|
eventBus.on('outlineloaded', function(evt) {
|
||||||
var event = document.createEvent('CustomEvent');
|
let event = document.createEvent('CustomEvent');
|
||||||
event.initCustomEvent('outlineloaded', true, true, {
|
event.initCustomEvent('outlineloaded', true, true, {
|
||||||
outlineCount: e.outlineCount,
|
outlineCount: evt.outlineCount,
|
||||||
});
|
});
|
||||||
e.source.container.dispatchEvent(event);
|
evt.source.container.dispatchEvent(event);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
var globalEventBus = null;
|
let globalEventBus = null;
|
||||||
function getGlobalEventBus() {
|
function getGlobalEventBus() {
|
||||||
if (globalEventBus) {
|
if (globalEventBus) {
|
||||||
return globalEventBus;
|
return globalEventBus;
|
||||||
|
Loading…
Reference in New Issue
Block a user