Skip to content

Commit

Permalink
Testing expanding output box on italics
Browse files Browse the repository at this point in the history
  • Loading branch information
pauld0051 committed Dec 27, 2023
1 parent 5eba971 commit 3bd7ff4
Showing 1 changed file with 35 additions and 32 deletions.
67 changes: 35 additions & 32 deletions scripts/italics.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,40 @@ const italicMap = {
'ú': '𝘶́', 'û': '𝘶̂', 'ü': '𝘶̈', 'ý': '𝘺́', 'þ': '𝘵̵', 'ÿ': '𝘺̈'
};

document.addEventListener('DOMContentLoaded', function () {
document.getElementById('alternatingTextForm').addEventListener('submit', function (e) {
e.preventDefault();

let inputText = document.getElementById('textInput').value;
let italicText = '';

// Convert each character to its italic equivalent
for (let char of inputText) {
italicText += italicMap[char] || char; // Fallback to the original character if no italic equivalent
document.addEventListener('DOMContentLoaded', function () {
document.getElementById('alternatingTextForm').addEventListener('submit', function (e) {
e.preventDefault();

let inputText = document.getElementById('textInput').value;
let italicText = '';

// Convert each character to its italic equivalent
for (let char of inputText) {
italicText += italicMap[char] || char; // Fallback to the original character if no italic equivalent
}

// Set the italic text as the value of the output element
const outputElement = document.getElementById('alternatingTextOutput');
outputElement.textContent = italicText; // Use textContent to set text
outputElement.style.height = ""; // Reset the height
outputElement.style.height = outputElement.scrollHeight + "px"; // Adjust the height to fit content
});

// Function to copy text to clipboard
function copyToClipboard(text) {
const dummy = document.createElement('textarea');
document.body.appendChild(dummy);
dummy.value = text;
dummy.select();
document.execCommand('copy');
document.body.removeChild(dummy);
}

// Set the italic text as the value of the output element
const outputElement = document.getElementById('alternatingTextOutput');
outputElement.textContent = italicText; // Use textContent to set text

// Event listener for the copy button
document.getElementById('copyButton').addEventListener('click', function () {
// Copy the value, which will retain italic formatting when pasted
const textToCopy = document.getElementById('alternatingTextOutput').textContent;
copyToClipboard(textToCopy);
});
});

// Function to copy text to clipboard
function copyToClipboard(text) {
const dummy = document.createElement('textarea');
document.body.appendChild(dummy);
dummy.value = text;
dummy.select();
document.execCommand('copy');
document.body.removeChild(dummy);
}

// Event listener for the copy button
document.getElementById('copyButton').addEventListener('click', function () {
// Copy the value, which will retain italic formatting when pasted
const textToCopy = document.getElementById('alternatingTextOutput').textContent;
copyToClipboard(textToCopy);
});
});

0 comments on commit 3bd7ff4

Please sign in to comment.