better email/share functionality

This commit is contained in:
Leon van Kammen 2026-09-02 17:27:15 +02:00
parent 733ddd7cfc
commit 032eaba7de
2 changed files with 19 additions and 19 deletions

View file

@ -15,6 +15,9 @@ ${header}
]])
end
print([[
<a onclick="window.share(this)" href="mailto:friend@your.org?subject=${util.getURL()}&body=check%20this%20on%20your%20XR%20headset">
<img src="img/share.svg" class="icon share"/>
</a>
</center>
</div>
<hr style="margin-top:0"/>

View file

@ -18,6 +18,19 @@
print('<meta http-equiv="refresh" content="0;url=${opts.plugin_diskscan_dirname}">')
end}
</noscript>
<script>
window.share = (btn,e) => {
if( window.navigator.share ){
btn.setAttribute('href', '') // override mailto:
const title = "]] .. (item and item.title or opts.plugin_global_title) .. [["
window.navigator.share({title, url: document.location.href})
e.stopPropagation()
e.preventDefault()
return false
}
// perform the mailto:
}
</script>
</head>
<body background="#000000" class="${page}">
${opts.plugin_global_body_html}
@ -44,7 +57,7 @@
{if true then
print( app.opts.plugin_global_topmenu_html:gsub("\n","&nbsp;") )
end}
{if template == "page/dir.html" then
{if template == "page/dir.html" and not defined(item) then
local url = urlpath
if not urlpath:match(app.opts.plugin_diskscan_dirname) then
-- janusweb workaround (it does not support '/' url somehow)
@ -56,27 +69,11 @@
print([[<div class="btn XR"><a class="border secondary" href="${urlpath}?view=3D">3D</a></div>&nbsp;]])
end
end}
{if template == "page/index.html" then
local sharedata = {
title = (item and item.title or opts.plugin_global_title)
}
{if template == "page/index.html" or defined(item) then
print([[
<a id="share" href="mailto:friend@your.org?subject=${util.getURL()}&body=check%20this%20on%20your%20XR%20headset">
<a onclick="window.share(this)" href="mailto:friend@your.org?subject=${util.getURL()}&body=check%20this%20on%20your%20XR%20headset">
<img src="img/share.svg" class="icon share"/>
</a>
<script>
if( navigator.share ){
const sharebtn = document.querySelector('#share')
const title = "]] .. (item and item.title or opts.plugin_global_title) .. [["
sharebtn.setAttribute('href', '') // override mailto:
sharebtn.addEventListener('click', (e) => {
navigator.share({title, url: document.location.href})
e.stopPropagation()
e.preventDefault()
return false
})
}
</script>
]])
end}
</td>