rob-revisited/skeleton-app/ui/app.js

16 lines
699 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// window.jumphp is there before this script: invoke (page -> PHP, a Promise), send, on (PHP -> page).
const $ = (id) => document.getElementById(id);
$('greet').addEventListener('submit', async (e) => {
e.preventDefault();
const r = await jumphp.invoke('greet', {name: $('name').value});
$('answer').textContent = `${r.message} (×${r.clicks})`;
});
jumphp.on('clock', (p) => { $('clock').textContent = p.time; });
// a native feature without PHP code of its own (JumPHP\Tauri\NativeCommands)
$('open').addEventListener('click', async () => {
const file = await jumphp.invoke('native.open', {title: 'Open a file'});
$('file').textContent = file ? `You chose ${file}` : 'Cancelled';
});