Skip to content

Commit

Permalink
popover check
Browse files Browse the repository at this point in the history
  • Loading branch information
maboa committed Aug 5, 2024
1 parent ad1cd53 commit 79170f5
Showing 1 changed file with 42 additions and 39 deletions.
81 changes: 42 additions & 39 deletions js/hyperaudio-lite.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*! (C) The Hyperaudio Project. MIT @license: en.wikipedia.org/wiki/MIT_License. */
/*! Version 2.3.0 */
/*! Version 2.3.1 */

'use strict';

Expand Down Expand Up @@ -324,46 +324,48 @@ class HyperaudioLite {

// Setup the popover for text selection
setupPopover() {
this.transcript.addEventListener('mouseup', () => {
const selection = window.getSelection();
const popover = document.getElementById('popover');
let selectionText;

if (selection.toString().length > 0) {
selectionText = selection.toString().replaceAll("'", "`");
const range = selection.getRangeAt(0);
const rect = range.getBoundingClientRect();

popover.style.left = `${rect.left + window.scrollX}px`;
popover.style.top = `${rect.bottom + window.scrollY}px`;
popover.style.display = 'block';

const mediaFragment = this.getSelectionMediaFragment();

if (mediaFragment) {
document.location.hash = mediaFragment;
if (typeof popover !== 'undefined') {
this.transcript.addEventListener('mouseup', () => {
const selection = window.getSelection();
const popover = document.getElementById('popover');
let selectionText;

if (selection.toString().length > 0) {
selectionText = selection.toString().replaceAll("'", "`");
const range = selection.getRangeAt(0);
const rect = range.getBoundingClientRect();

popover.style.left = `${rect.left + window.scrollX}px`;
popover.style.top = `${rect.bottom + window.scrollY}px`;
popover.style.display = 'block';

const mediaFragment = this.getSelectionMediaFragment();

if (mediaFragment) {
document.location.hash = mediaFragment;
}
} else {
popover.style.display = 'none';
}
} else {
popover.style.display = 'none';
}

const popoverBtn = document.getElementById('popover-btn');
popoverBtn.addEventListener('click', (e) => {
popover.style.display = 'none';
let cbText = `${selectionText} ${document.location}`;
navigator.clipboard.writeText(cbText);

const dialog = document.getElementById("clipboard-dialog");
document.getElementById("clipboard-text").innerHTML = cbText;
dialog.showModal();

const confirmButton = document.getElementById("clipboard-confirm");
confirmButton.addEventListener("click", () => dialog.close());

e.preventDefault();
return false;

const popoverBtn = document.getElementById('popover-btn');
popoverBtn.addEventListener('click', (e) => {
popover.style.display = 'none';
let cbText = `${selectionText} ${document.location}`;
navigator.clipboard.writeText(cbText);

const dialog = document.getElementById("clipboard-dialog");
document.getElementById("clipboard-text").innerHTML = cbText;
dialog.showModal();

const confirmButton = document.getElementById("clipboard-confirm");
confirmButton.addEventListener("click", () => dialog.close());

e.preventDefault();
return false;
});
});
});
}
}

// Setup the media player
Expand Down Expand Up @@ -519,6 +521,7 @@ class HyperaudioLite {
if (range === null) {
return null;
}
console.log(range);
return (this.transcript.id + '=' +range);
}

Expand Down

0 comments on commit 79170f5

Please sign in to comment.