Add italic toggle button

This commit is contained in:
Josh birnholz
2023-02-18 19:18:45 -05:00
parent 8d9b549a8d
commit b7ac4cd351
4 changed files with 42 additions and 1 deletions

View File

@@ -206,6 +206,7 @@
<div class='readable-background padding margin-bottom'>
<h5 class='margin-bottom padding input-description'>Enter card text</h5>
<textarea id='text-editor' class='input margin-bottom' oninput='textEdited();'></textarea>
<button class='input' onclick="toggleTextTag('i');">Italic</button>
<h5 class='margin-bottom padding input-description'>Edit the placement and size of the selected textbox</h5>
<button class='input' onclick='textboxEditor();'>Edit Bounds</button>
<h5 class='margin-bottom padding input-description'>Adjust font size</h5>

View File

@@ -19,6 +19,7 @@
<script defer src='js/main-1.js'></script>
</head>
<body>
<input hx
<div class='background'></div>
<header class='readable-background'>
<h1 class='title center'>CARD CONJURER</h1>
@@ -38,7 +39,7 @@
<div class='main-menu'>
<h2>Navigation</h2>
<h3><a href="#" hx-get="index.html" hx-target="#content" hx-trigger="click" onclick='toggleMenu()'>Home</a></h3>
<h3><a href="#" hx-get="creator/index.html" hx-target="#content" hx-trigger="click" onclick='toggleMenu()'>Card Creator</a></h3>
<h3><a href="#" hx-get="creator/index.html" hx-target="#content" hx-trigger="click, doCreate from:body" onclick='toggleMenu()'>Card Creator</a></h3>
<h3><a href="#" hx-get="print/index.html" hx-target="#content" hx-trigger="click" onclick='toggleMenu()'>Printing Tool</a></h3>
<h3><a href="#" hx-get="askurza/index.html" hx-target="#content" hx-trigger="click" onclick='toggleMenu()'>Ask Urza 2.0</a></h3>
<h3><a href="#" hx-get="phyrexian/index.html" hx-target="#content" hx-trigger="click" onclick='toggleMenu()'>Phyrexian Generator</a></h3>

View File

@@ -3907,6 +3907,36 @@ function fetchScryfallData(cardName, callback = console.log, searchUniqueArt = '
console.log('Scryfall API search failed.')
}
}
function toggleTextTag(tag) {
var element = document.getElementById('text-editor');
var text = element.value;
var start = element.selectionStart;
var end = element.selectionEnd;
var selection = text.substring(start, end);
var openTag = '{' + tag + '}';
var closeTag = '{/' + tag + '}';
var prefix = text.substring(0, start);
var suffix = text.substring(end);
if (prefix.endsWith(openTag) && suffix.startsWith(closeTag)) {
prefix = prefix.substring(0, prefix.length-openTag.length);
suffix = suffix.substring(closeTag.length);
} else if (selection.startsWith(openTag) && selection.endsWith(closeTag)) {
selection = selection.substring(openTag.length, selection.length-closeTag.length);
} else {
selection = openTag + selection + closeTag;
}
element.value = prefix + selection + suffix;
textEdited();
}
// INITIALIZATION
// auto load frame version (user defaults)

View File

@@ -123,3 +123,12 @@ document.addEventListener('DOMContentLoaded', function() {
document.body.dispatchEvent(new Event('doCreate'));
})
document.onkeyup = function(e) {
if (document.activeElement === document.getElementById('text-editor')) {
if (e.ctrlKey && e.which == 73) {
toggleTextTag('i');
e.preventDefault();
}
}
}