mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-02 08:10:56 +08:00
Support data-wml-trigger
attribute
This commit is contained in:
parent
c9492ec258
commit
0881914244
@ -92,4 +92,19 @@ Example:
|
||||
<button data-wml-event="delete-all-items" data-wml-confirm="Are you sure?">Delete All Items</button>
|
||||
```
|
||||
|
||||
### `data-wml-window`
|
||||
### `data-wml-window`
|
||||
|
||||
Any `wails.window` method can be called by adding the `data-wml-window` attribute to an element. The value of the attribute should be the name of the method to call. The method name should be in the same case as the method.
|
||||
|
||||
```html
|
||||
<button data-wml-window="Close">Close Window</button>
|
||||
```
|
||||
|
||||
### `data-wml-trigger`
|
||||
|
||||
This attribute specifies which javascript event should trigger the action. The default is `click`.
|
||||
|
||||
```html
|
||||
<button data-wml-event="hover-box" data-wml-trigger="mouseover">Hover over me!</button>
|
||||
```
|
||||
|
||||
|
@ -1,18 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Wails ML Demo</title>
|
||||
</head>
|
||||
<body style="margin-top:50px">
|
||||
<h2>Wails ML Demo</h2>
|
||||
<p>This application contains no Javascript!</p>
|
||||
<button data-wml-event="button-pressed">Press me!</button>
|
||||
<button data-wml-event="delete-things" data-wml-confirm="Are you sure?">Delete all the things!</button>
|
||||
<button data-wml-window="Close" data-wml-confirm="Are you sure?">Close the Window?</button>
|
||||
<button data-wml-window="Center">Center</button>
|
||||
<button data-wml-window="Minimise">Minimise</button>
|
||||
<button data-wml-window="Maximise">Maximise</button>
|
||||
<button data-wml-window="Fullscreen">Fullscreen</button>
|
||||
</body>
|
||||
</html>
|
@ -1,47 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"embed"
|
||||
_ "embed"
|
||||
"log"
|
||||
|
||||
"github.com/wailsapp/wails/v3/pkg/application"
|
||||
)
|
||||
|
||||
//go:embed assets/*
|
||||
var assets embed.FS
|
||||
|
||||
func main() {
|
||||
|
||||
app := application.New(application.Options{
|
||||
Name: "Wails ML Demo",
|
||||
Description: "A demo of the Wails ML API",
|
||||
Mac: application.MacOptions{
|
||||
ApplicationShouldTerminateAfterLastWindowClosed: true,
|
||||
},
|
||||
})
|
||||
|
||||
app.NewWebviewWindowWithOptions(&application.WebviewWindowOptions{
|
||||
Title: "Wails ML Demo",
|
||||
Width: 800,
|
||||
Height: 600,
|
||||
Assets: application.AssetOptions{
|
||||
FS: assets,
|
||||
},
|
||||
Mac: application.MacWindow{
|
||||
Backdrop: application.MacBackdropTranslucent,
|
||||
TitleBar: application.MacTitleBarHiddenInsetUnified,
|
||||
InvisibleTitleBarHeight: 50,
|
||||
},
|
||||
})
|
||||
|
||||
app.Events.On("button-pressed", func(_ *application.CustomEvent) {
|
||||
println("Button Pressed!")
|
||||
})
|
||||
|
||||
err := app.Run()
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
}
|
@ -19,7 +19,7 @@ import {newWindow} from "./window";
|
||||
import {dispatchCustomEvent, Emit, Off, OffAll, On, Once, OnMultiple} from "./events";
|
||||
import {dialogCallback, dialogErrorCallback, Error, Info, OpenFile, Question, SaveFile, Warning,} from "./dialogs";
|
||||
import {enableContextMenus} from "./contextmenu";
|
||||
import {addEventListeners} from "./wml";
|
||||
import {refresh} from "./wml";
|
||||
|
||||
window.wails = {
|
||||
...newRuntime(-1),
|
||||
@ -43,6 +43,9 @@ export function newRuntime(id) {
|
||||
},
|
||||
Log,
|
||||
Screens,
|
||||
WML: {
|
||||
Refresh: refresh,
|
||||
},
|
||||
Dialog: {
|
||||
Info,
|
||||
Warning,
|
||||
@ -70,5 +73,5 @@ if (DEBUG) {
|
||||
enableContextMenus(true);
|
||||
|
||||
document.addEventListener("DOMContentLoaded", function(event) {
|
||||
addEventListeners();
|
||||
refresh();
|
||||
});
|
@ -12,6 +12,7 @@ function addWMLEventListeners() {
|
||||
const element = elements[i];
|
||||
const eventType = element.getAttribute('data-wml-event');
|
||||
const confirm = element.getAttribute('data-wml-confirm');
|
||||
const trigger = element.getAttribute('data-wml-trigger') || "click";
|
||||
|
||||
let callback = function () {
|
||||
if (confirm) {
|
||||
@ -25,10 +26,11 @@ function addWMLEventListeners() {
|
||||
sendEvent(eventType);
|
||||
}
|
||||
// Remove existing listeners
|
||||
element.removeEventListener("click", callback);
|
||||
|
||||
element.removeEventListener(trigger, callback);
|
||||
|
||||
// Add new listener
|
||||
element.addEventListener("click", callback);
|
||||
element.addEventListener(trigger, callback);
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,6 +47,7 @@ function addWMLWindowListeners() {
|
||||
const element = elements[i];
|
||||
const windowMethod = element.getAttribute('data-wml-window');
|
||||
const confirm = element.getAttribute('data-wml-confirm');
|
||||
const trigger = element.getAttribute('data-wml-trigger') || "click";
|
||||
|
||||
let callback = function () {
|
||||
if (confirm) {
|
||||
@ -57,15 +60,16 @@ function addWMLWindowListeners() {
|
||||
}
|
||||
callWindowMethod(windowMethod);
|
||||
}
|
||||
|
||||
// Remove existing listeners
|
||||
element.removeEventListener("click", callback);
|
||||
element.removeEventListener(trigger, callback);
|
||||
|
||||
// Add new listener
|
||||
element.addEventListener("click", callback);
|
||||
element.addEventListener(trigger, callback);
|
||||
}
|
||||
}
|
||||
|
||||
export function addEventListeners() {
|
||||
export function refresh() {
|
||||
addWMLEventListeners();
|
||||
addWMLWindowListeners();
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user