Compare commits

..

2 Commits

Author SHA1 Message Date
b8070e48d7 membershipworks: Simplify WordPress post generator clipboard JS
All checks were successful
Ruff / ruff (push) Successful in 28s
Test / test (push) Successful in 5m32s
Firefox supports the newer Clipboard API now, and WordPress actually
seems to behave better with just `text/plain`. `text/html` was causing
annoying behaviour by wrapping the raw html with `html` and `body`
tags, which confused WordPress.
2024-07-19 00:11:28 -04:00
8689d14fc1 membershipworks: Fix up post generator formatting for WordPress 6.6 2024-07-19 00:11:22 -04:00

View File

@ -8,11 +8,11 @@
<div id="preview"> <div id="preview">
<!-- wp:image {"align":"center","id":2319} --> <!-- wp:image {"align":"center","id":2319} -->
<figure class="wp-block-image aligncenter"> <figure class="wp-block-image aligncenter">
{# djlint:off H006 #}
<img src="https://claremontmakerspace.org/wp-content/uploads/2019/03/CMS-Logo-b-y-g-300x168.png" <img src="https://claremontmakerspace.org/wp-content/uploads/2019/03/CMS-Logo-b-y-g-300x168.png"
width="300"
height="168"
alt="CMS Logo" alt="CMS Logo"
class="wp-image-2319" /> class="wp-image-2319" />
{# djlint:on #}
</figure> </figure>
<!-- /wp:image --> <!-- /wp:image -->
@ -65,21 +65,28 @@
{% with url="https://claremontmakerspace.org/events/#!event/register/"|add:event.url %} {% with url="https://claremontmakerspace.org/events/#!event/register/"|add:event.url %}
<!-- wp:group {"tagName":"section","layout":{"type":"constrained"}} --> <!-- wp:group {"tagName":"section","layout":{"type":"constrained"}} -->
<section class="wp-block-group"> <section class="wp-block-group">
{% if "lgo" in event %}
<!-- wp:image {"width":"400px","height":"auto","sizeSlug":"large","linkDestination":"media","align":"{% cycle 'left' 'right' %}"} -->
<figure class="wp-block-image {% cycle 'alignleft' 'alignright' %} size-large is-resized">
<a href="{{ url }}">
{# djlint:off H006 #}
<img src="{{ event.lgo.l }}"
alt="Image for {{ event.ttl|nh3:"" }}"
style="width:400px;
height:auto" />
{# djlint:on #}
</a>
</figure>
<!-- /wp:image -->
{% endif %}
<!-- wp:heading {"align":"center"} --> <!-- wp:heading {"align":"center"} -->
<h2 class="wp-block-heading"> <h2 class="wp-block-heading">
<a href="{{ url }}"> <a href="{{ url }}">{{ event.ttl|nh3 }}</a>
{% if "lgo" in event %}
{# djlint:off H006 #}
<img class="{% cycle 'alignleft' 'alignright' %}"
width="400"
alt="Image for {{ event.ttl|nh3:"" }}"
src="{{ event.lgo.l }}">
{# djlint:on #}
{% endif %}
<span>{{ event.ttl|nh3 }}</span>
</a>
</h2> </h2>
<!-- /wp:heading --> <!-- /wp:heading -->
<!-- wp:paragraph --> <!-- wp:paragraph -->
<p> <p>
{# wordpress is very annoying with spacing here #} {# wordpress is very annoying with spacing here #}
@ -110,7 +117,7 @@
{% endfor %} {% endfor %}
<!-- wp:paragraph --> <!-- wp:paragraph -->
<p style="clear: both;">Happy Makin!</p> <p>Happy Makin!</p>
<!-- /wp:paragraph --> <!-- /wp:paragraph -->
<!-- wp:paragraph --> <!-- wp:paragraph -->
<p> <p>
@ -132,34 +139,14 @@
{% block script %} {% block script %}
<script> <script>
async function copyToClipboard(event) { async function copyToClipboard(event) {
const rich = document.getElementById("preview").innerHTML; // https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API
const plain = document.getElementById("preview").innerHTML;
// from https://stackoverflow.com/a/77305170
if (typeof ClipboardItem !== "undefined") {
// Shiny new Clipboard API, not fully supported in Firefox.
// https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API#browser_compatibility
const html = new Blob([rich], {
type: "text/html"
});
const text = new Blob([plain], {
type: "text/plain"
});
const data = new ClipboardItem({ const data = new ClipboardItem({
"text/html": html, "text/plain": new Blob(
"text/plain": text [document.getElementById("preview").innerHTML], {
type: "text/plain"
})
}); });
await navigator.clipboard.write([data]); await navigator.clipboard.write([data]);
} else {
const cb = e => {
e.clipboardData.setData("text/html", rich);
e.clipboardData.setData("text/plain", plain);
e.preventDefault();
};
document.addEventListener("copy", cb);
document.execCommand("copy");
document.removeEventListener("copy", cb);
}
bootstrap.Popover.getInstance(event.target).show(); bootstrap.Popover.getInstance(event.target).show();
setTimeout(() => bootstrap.Popover.getInstance(event.target).hide(), 1000); setTimeout(() => bootstrap.Popover.getInstance(event.target).hide(), 1000);