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
|
||||
// backwards viewer API compatibility.
|
||||
function attachDOMEventsToEventBus(eventBus) {
|
||||
eventBus.on('documentload', function () {
|
||||
var event = document.createEvent('CustomEvent');
|
||||
eventBus.on('documentload', function() {
|
||||
let event = document.createEvent('CustomEvent');
|
||||
event.initCustomEvent('documentload', true, true, {});
|
||||
window.dispatchEvent(event);
|
||||
});
|
||||
eventBus.on('pagerendered', function (e) {
|
||||
var event = document.createEvent('CustomEvent');
|
||||
eventBus.on('pagerendered', function(evt) {
|
||||
let event = document.createEvent('CustomEvent');
|
||||
event.initCustomEvent('pagerendered', true, true, {
|
||||
pageNumber: e.pageNumber,
|
||||
cssTransform: e.cssTransform,
|
||||
pageNumber: evt.pageNumber,
|
||||
cssTransform: evt.cssTransform,
|
||||
});
|
||||
e.source.div.dispatchEvent(event);
|
||||
evt.source.div.dispatchEvent(event);
|
||||
});
|
||||
eventBus.on('textlayerrendered', function (e) {
|
||||
var event = document.createEvent('CustomEvent');
|
||||
eventBus.on('textlayerrendered', function(evt) {
|
||||
let event = document.createEvent('CustomEvent');
|
||||
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) {
|
||||
var event = document.createEvent('UIEvents');
|
||||
eventBus.on('pagechange', function(evt) {
|
||||
let event = document.createEvent('UIEvents');
|
||||
event.initUIEvent('pagechange', true, true, window, 0);
|
||||
event.pageNumber = e.pageNumber;
|
||||
e.source.container.dispatchEvent(event);
|
||||
event.pageNumber = evt.pageNumber;
|
||||
evt.source.container.dispatchEvent(event);
|
||||
});
|
||||
eventBus.on('pagesinit', function (e) {
|
||||
var event = document.createEvent('CustomEvent');
|
||||
eventBus.on('pagesinit', function(evt) {
|
||||
let event = document.createEvent('CustomEvent');
|
||||
event.initCustomEvent('pagesinit', true, true, null);
|
||||
e.source.container.dispatchEvent(event);
|
||||
evt.source.container.dispatchEvent(event);
|
||||
});
|
||||
eventBus.on('pagesloaded', function (e) {
|
||||
var event = document.createEvent('CustomEvent');
|
||||
eventBus.on('pagesloaded', function(evt) {
|
||||
let event = document.createEvent('CustomEvent');
|
||||
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) {
|
||||
var event = document.createEvent('UIEvents');
|
||||
eventBus.on('scalechange', function(evt) {
|
||||
let event = document.createEvent('UIEvents');
|
||||
event.initUIEvent('scalechange', true, true, window, 0);
|
||||
event.scale = e.scale;
|
||||
event.presetValue = e.presetValue;
|
||||
e.source.container.dispatchEvent(event);
|
||||
event.scale = evt.scale;
|
||||
event.presetValue = evt.presetValue;
|
||||
evt.source.container.dispatchEvent(event);
|
||||
});
|
||||
eventBus.on('updateviewarea', function (e) {
|
||||
var event = document.createEvent('UIEvents');
|
||||
eventBus.on('updateviewarea', function(evt) {
|
||||
let event = document.createEvent('UIEvents');
|
||||
event.initUIEvent('updateviewarea', true, true, window, 0);
|
||||
event.location = e.location;
|
||||
e.source.container.dispatchEvent(event);
|
||||
event.location = evt.location;
|
||||
evt.source.container.dispatchEvent(event);
|
||||
});
|
||||
eventBus.on('find', function (e) {
|
||||
if (e.source === window) {
|
||||
eventBus.on('find', function(evt) {
|
||||
if (evt.source === window) {
|
||||
return; // event comes from FirefoxCom, no need to replicate
|
||||
}
|
||||
var event = document.createEvent('CustomEvent');
|
||||
event.initCustomEvent('find' + e.type, true, true, {
|
||||
query: e.query,
|
||||
phraseSearch: e.phraseSearch,
|
||||
caseSensitive: e.caseSensitive,
|
||||
highlightAll: e.highlightAll,
|
||||
findPrevious: e.findPrevious,
|
||||
let event = document.createEvent('CustomEvent');
|
||||
event.initCustomEvent('find' + evt.type, true, true, {
|
||||
query: evt.query,
|
||||
phraseSearch: evt.phraseSearch,
|
||||
caseSensitive: evt.caseSensitive,
|
||||
highlightAll: evt.highlightAll,
|
||||
findPrevious: evt.findPrevious,
|
||||
});
|
||||
window.dispatchEvent(event);
|
||||
});
|
||||
eventBus.on('attachmentsloaded', function (e) {
|
||||
var event = document.createEvent('CustomEvent');
|
||||
eventBus.on('attachmentsloaded', function(evt) {
|
||||
let event = document.createEvent('CustomEvent');
|
||||
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) {
|
||||
var event = document.createEvent('CustomEvent');
|
||||
eventBus.on('sidebarviewchanged', function(evt) {
|
||||
let event = document.createEvent('CustomEvent');
|
||||
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) {
|
||||
var event = document.createEvent('CustomEvent');
|
||||
eventBus.on('pagemode', function(evt) {
|
||||
let event = document.createEvent('CustomEvent');
|
||||
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) {
|
||||
var event = document.createEvent('CustomEvent');
|
||||
eventBus.on('namedaction', function(evt) {
|
||||
let event = document.createEvent('CustomEvent');
|
||||
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) {
|
||||
var event = document.createEvent('CustomEvent');
|
||||
eventBus.on('presentationmodechanged', function(evt) {
|
||||
let event = document.createEvent('CustomEvent');
|
||||
event.initCustomEvent('presentationmodechanged', true, true, {
|
||||
active: e.active,
|
||||
switchInProgress: e.switchInProgress,
|
||||
active: evt.active,
|
||||
switchInProgress: evt.switchInProgress,
|
||||
});
|
||||
window.dispatchEvent(event);
|
||||
});
|
||||
eventBus.on('outlineloaded', function (e) {
|
||||
var event = document.createEvent('CustomEvent');
|
||||
eventBus.on('outlineloaded', function(evt) {
|
||||
let event = document.createEvent('CustomEvent');
|
||||
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() {
|
||||
if (globalEventBus) {
|
||||
return globalEventBus;
|
||||
|
Loading…
Reference in New Issue
Block a user