|
@@ -53,8 +53,15 @@ class ListenerMap {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+class InterpreterConfig {
|
|
|
+ constructor(intercept_link_redirects) {
|
|
|
+ this.intercept_link_redirects = intercept_link_redirects;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
class Interpreter {
|
|
|
- constructor(root) {
|
|
|
+ constructor(root, config) {
|
|
|
+ this.config = config;
|
|
|
this.root = root;
|
|
|
this.listeners = new ListenerMap(root);
|
|
|
this.nodes = [root];
|
|
@@ -397,7 +404,7 @@ class Interpreter {
|
|
|
);
|
|
|
} else {
|
|
|
this.NewEventListener(edit.name, edit.id, bubbles, (event) => {
|
|
|
- handler(event, edit.name, bubbles);
|
|
|
+ handler(event, edit.name, bubbles, this.config);
|
|
|
});
|
|
|
}
|
|
|
break;
|
|
@@ -407,32 +414,34 @@ class Interpreter {
|
|
|
|
|
|
// this handler is only provided on the desktop and liveview implementations since this
|
|
|
// method is not used by the web implementation
|
|
|
-function handler(event, name, bubbles) {
|
|
|
+function handler(event, name, bubbles, config) {
|
|
|
let target = event.target;
|
|
|
if (target != null) {
|
|
|
let preventDefaultRequests = target.getAttribute(`dioxus-prevent-default`);
|
|
|
|
|
|
if (event.type === "click") {
|
|
|
// todo call prevent default if it's the right type of event
|
|
|
- let a_element = target.closest("a");
|
|
|
- if (a_element != null) {
|
|
|
- event.preventDefault();
|
|
|
-
|
|
|
- let elementShouldPreventDefault =
|
|
|
- preventDefaultRequests && preventDefaultRequests.includes(`onclick`);
|
|
|
- let aElementShouldPreventDefault = a_element.getAttribute(
|
|
|
- `dioxus-prevent-default`
|
|
|
- );
|
|
|
- let linkShouldPreventDefault =
|
|
|
- aElementShouldPreventDefault &&
|
|
|
- aElementShouldPreventDefault.includes(`onclick`);
|
|
|
-
|
|
|
- if (!elementShouldPreventDefault && !linkShouldPreventDefault) {
|
|
|
- const href = a_element.getAttribute("href");
|
|
|
- if (href !== "" && href !== null && href !== undefined) {
|
|
|
- window.ipc.postMessage(
|
|
|
- serializeIpcMessage("browser_open", { href })
|
|
|
- );
|
|
|
+ if (config.intercept_link_redirects) {
|
|
|
+ let a_element = target.closest("a");
|
|
|
+ if (a_element != null) {
|
|
|
+ event.preventDefault();
|
|
|
+
|
|
|
+ let elementShouldPreventDefault =
|
|
|
+ preventDefaultRequests && preventDefaultRequests.includes(`onclick`);
|
|
|
+ let aElementShouldPreventDefault = a_element.getAttribute(
|
|
|
+ `dioxus-prevent-default`
|
|
|
+ );
|
|
|
+ let linkShouldPreventDefault =
|
|
|
+ aElementShouldPreventDefault &&
|
|
|
+ aElementShouldPreventDefault.includes(`onclick`);
|
|
|
+
|
|
|
+ if (!elementShouldPreventDefault && !linkShouldPreventDefault) {
|
|
|
+ const href = a_element.getAttribute("href");
|
|
|
+ if (href !== "" && href !== null && href !== undefined) {
|
|
|
+ window.ipc.postMessage(
|
|
|
+ serializeIpcMessage("browser_open", { href })
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|