From 02db7e2d317db67d5a3eeb2018d94d3f9aa55be9 Mon Sep 17 00:00:00 2001
From: Mark Boas <markb@happyworm.com>
Date: Tue, 5 Jul 2022 15:02:25 +0200
Subject: [PATCH] upgrade to Hyperaudio Lite 2.0.14

---
 wp-hyperaudio/hyperaudio.php             |  3 ++-
 wp-hyperaudio/js/hyperaudio-lite.js      |  8 ++++++--
 wp-hyperaudio/js/share-this-clipboard.js | 17 +++++++++++++++++
 3 files changed, 25 insertions(+), 3 deletions(-)
 create mode 100644 wp-hyperaudio/js/share-this-clipboard.js

diff --git a/wp-hyperaudio/hyperaudio.php b/wp-hyperaudio/hyperaudio.php
index 76b93ab..e2c9bc8 100644
--- a/wp-hyperaudio/hyperaudio.php
+++ b/wp-hyperaudio/hyperaudio.php
@@ -183,7 +183,7 @@ function hyperaudio_shortcode_handler($atts, $transcript, $tag)
 
   $o .= '<script>
   ShareThis({
-      sharers: [ ShareThisViaTwitter ],
+      sharers: [ ShareThisViaTwitter, ShareThisViaClipboard ],
       selector: "article"
   }).init();
 
@@ -212,6 +212,7 @@ function hyperaudio_init()
     wp_enqueue_script('caption', plugins_url('/js/caption.js', __FILE__), false, '1.0.0', false);
     wp_enqueue_script('share-this', plugins_url('/js/share-this.js', __FILE__), false, '1.0.0', false);
     wp_enqueue_script('share-this-twitter', plugins_url('/js/share-this-twitter.js', __FILE__), false, '1.0.0', false);
+    wp_enqueue_script('share-this-clipboard', plugins_url('/js/share-this-clipboard.js', __FILE__), false, '1.0.0', false);
     wp_enqueue_script('twitter-widget', plugins_url('https://platform.twitter.com/widgets.js', __FILE__), false, '1.0.0', false);
   }
 }
diff --git a/wp-hyperaudio/js/hyperaudio-lite.js b/wp-hyperaudio/js/hyperaudio-lite.js
index 5bf9733..237e109 100644
--- a/wp-hyperaudio/js/hyperaudio-lite.js
+++ b/wp-hyperaudio/js/hyperaudio-lite.js
@@ -1,5 +1,5 @@
 /*! (C) The Hyperaudio Project. MIT @license: en.wikipedia.org/wiki/MIT_License. */
-/*! Version 2.0.13 */
+/*! Version 2.0.14 */
 
 'use strict';
 
@@ -459,7 +459,11 @@ class HyperaudioLite {
     if (paymentPointer !== null) {
       return paymentPointer;
     } else {
-      let parent = element.parentElement;
+      let parent = null;
+
+      if (typeof element !== 'undefined') {
+        parent = element.parentElement;
+      }
 
       if (parent === null) {
         return null;
diff --git a/wp-hyperaudio/js/share-this-clipboard.js b/wp-hyperaudio/js/share-this-clipboard.js
new file mode 100644
index 0000000..f11c3aa
--- /dev/null
+++ b/wp-hyperaudio/js/share-this-clipboard.js
@@ -0,0 +1,17 @@
+!function(e,r){
+  "object"==typeof exports&&"undefined"!=typeof module?r(exports):"function"==typeof define&&define.amd?define(["exports"],r):r((e=e||self).ShareThisViaClipboard={})
+}
+(this,(
+function(e){
+  "use strict";
+  e.getShareUrl = function(text,refUrl){
+    const saneText = text.replaceAll("'", "`");
+    const cbText = "&quot;" + saneText + "&quot; " + refUrl;
+    return `onclick="navigator.clipboard.writeText('${cbText}');alert('copied the following text to the clipboard – ${cbText}')"`;
+  },
+  e.name="clipboard",
+  e.render = function(text, rawText, refUrl){
+    return"<a "+this.getShareUrl(text,refUrl)+' rel="noopener nofollow noreferrer"><svg xmlns="http://www.w3.org/2000/svg" viewBox="-9 -9 600 600"><path d="m161,152.9h190c0.1,0 0.1,0 0.2,0 10.8,0 19.6-7.1 19.6-16 0-1.5-14.1-82.7-14.1-82.7-1.3-7.9-9.6-13.8-19.4-13.8l-61.7,.1v-13.5c0-8.8-8.8-16-19.6-16-10.8,0-19.6,7.1-19.6,16v13.6l-61.8,.1c-9.8,0-18,5.9-19.4,13.8l-13.7,80.3c-1.2,14.3 13.5,18.1 19.5,18.1z" fill="currentcolor"/><path d="m427.5,78.9h-26.8c0,0 9.3,53.5 9.3,58 0,30.4-26.4,55.2-58.8,55.2h-190.2c-19.6,0.4-63.3-14.7-58.1-63.9l8.4-49.2h-26.8c-10.8,0-19.6,8.8-19.6,19.6v382.9c0,10.8 8.8,19.6 19.6,19.6h343c10.8,0 19.6-8.8 19.6-19.6v-383c0-10.8-8.8-19.6-19.6-19.6zm-76.5,320.1h-190c-10.8,0-19.6-8.8-19.6-19.6 0-10.8 8.8-19.6 19.6-19.6h190c10.8,0 19.6,8.8 19.6,19.6 0,10.8-8.7,19.6-19.6,19.6zm0-110.3h-190c-10.8,0-19.6-8.8-19.6-19.6 0-10.8 8.8-19.6 19.6-19.6h190c10.8,0 19.6,8.8 19.6,19.6 0,10.8-8.7,19.6-19.6,19.6z" fill="currentcolor"/></svg></a>'
+  },
+  Object.defineProperty(e,"__esModule",{value:!0})
+}));