From 7e132b3e2c53b25ae408daa2f04f3811185412e5 Mon Sep 17 00:00:00 2001 From: Skylar Ittner Date: Sat, 15 Mar 2025 11:59:36 -0600 Subject: [PATCH] Add event bus info --- README.md | 2 +- docs/Events.md | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 docs/Events.md diff --git a/README.md b/README.md index afcbb85..b6cef70 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ The PostalPoint plugin API is a globally-available object. * `getPluginFolder(pluginName)`: Get the filesystem path to a plugin's folder. If used without arguments, gets the root plugin storage folder. * `f7`: The Framework7 app instance for PostalPoint's entire UI, created by `new Framework7()`. See https://framework7.io/docs/app for details. Be very careful. - +* `eventbus`: A [Framework7 event bus](https://framework7.io/docs/events#events-bus) that parts of PostalPoint broadcast on. See docs/Events.md for details. #### Barcode diff --git a/docs/Events.md b/docs/Events.md new file mode 100644 index 0000000..7f2d5b1 --- /dev/null +++ b/docs/Events.md @@ -0,0 +1,25 @@ +# Event Bus + +Plugins can use `global.apis.eventbus` to receive events when certain actions happen in PostalPoint. + +## Event List + +* `barcodeScanned`: Contents of a barcode that was just scanned. +* `browserCloseRequest`: The embedded web browser listens for this event, and closes itself when received. +* `browserNavigate`: Contains the URL the embedded web browser just navigated to. +* `transactionFinished`: Contains a receipt object of a transaction that was just finalized. + +## Example Code + +```javascript + +// Handle a barcode scan. +// Remember that PostalPoint will probably also be doing something in response to the barcode. +global.apis.eventbus.on("barcodeScanned", function (barcodedata) { + // do something with the barcode +}); + +// Close the embedded web browser, returning the user to whatever was onscreen before it opened +global.apis.eventbus.emit("browserCloseRequest"); + +``` \ No newline at end of file