1 | 'use strict';
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | const blockHardwareBackButton = () => {
|
14 | document.addEventListener('backbutton', () => { });
|
15 | };
|
16 | const startHardwareBackButton = () => {
|
17 | const doc = document;
|
18 | let busy = false;
|
19 | doc.addEventListener('backbutton', () => {
|
20 | if (busy) {
|
21 | return;
|
22 | }
|
23 | let index = 0;
|
24 | let handlers = [];
|
25 | const ev = new CustomEvent('ionBackButton', {
|
26 | bubbles: false,
|
27 | detail: {
|
28 | register(priority, handler) {
|
29 | handlers.push({ priority, handler, id: index++ });
|
30 | }
|
31 | }
|
32 | });
|
33 | doc.dispatchEvent(ev);
|
34 | const executeAction = async (handlerRegister) => {
|
35 | try {
|
36 | if (handlerRegister && handlerRegister.handler) {
|
37 | const result = handlerRegister.handler(processHandlers);
|
38 | if (result != null) {
|
39 | await result;
|
40 | }
|
41 | }
|
42 | }
|
43 | catch (e) {
|
44 | console.error(e);
|
45 | }
|
46 | };
|
47 | const processHandlers = () => {
|
48 | if (handlers.length > 0) {
|
49 | let selectedHandler = {
|
50 | priority: Number.MIN_SAFE_INTEGER,
|
51 | handler: () => undefined,
|
52 | id: -1
|
53 | };
|
54 | handlers.forEach(handler => {
|
55 | if (handler.priority >= selectedHandler.priority) {
|
56 | selectedHandler = handler;
|
57 | }
|
58 | });
|
59 | busy = true;
|
60 | handlers = handlers.filter(handler => handler.id !== selectedHandler.id);
|
61 | executeAction(selectedHandler).then(() => busy = false);
|
62 | }
|
63 | };
|
64 | processHandlers();
|
65 | });
|
66 | };
|
67 | const OVERLAY_BACK_BUTTON_PRIORITY = 100;
|
68 | const MENU_BACK_BUTTON_PRIORITY = 99;
|
69 |
|
70 | exports.MENU_BACK_BUTTON_PRIORITY = MENU_BACK_BUTTON_PRIORITY;
|
71 | exports.OVERLAY_BACK_BUTTON_PRIORITY = OVERLAY_BACK_BUTTON_PRIORITY;
|
72 | exports.blockHardwareBackButton = blockHardwareBackButton;
|
73 | exports.startHardwareBackButton = startHardwareBackButton;
|