code cleanup

This commit is contained in:
Jacob Haddon
2024-03-12 21:16:51 -04:00
parent e52846a08f
commit faaeb2633b
2 changed files with 58 additions and 102 deletions

View File

@ -4,6 +4,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Daily Blackout Poetry Challenge</title>
<!--
@ -30,7 +31,6 @@ this file uses:
-->
<link rel="stylesheet" href="style.css">
<script src="jquery-3.7.1.min.js"></script>
@ -44,77 +44,65 @@ this file uses:
// console.log(book.pages[14][6]);
$(document).ready(function(){
// let text = $("#spina").html().split(" ");
// console.log(text);
// Make the header with the book info
$("#poem_header").html("<h2>" + book.title + "</h2>\n\n<h3>" + book.author + "</h3>\n");
// Add in the page, change the underscores to italics
$("#spina").html(book.pages[14][6].replace(/(_([a-z0-9]+)_)/ig, "<i>$2</i>"));
// format the text with span tags
$("#spina p").each(function( index ) {
let text = $( this ).html().split(" ");
let newText = [];
$.each( text , function(index, value ){
newText[index] = "<span>" + value + "</span>";
// console.log("index:" + index + " <span>" + value + "</span>")
}); // each text
$( this ).html(newText.join(" "));
// console.log(newText.join(" "));
}); // each p
$("#spina p span").each(function( index ) {
}); // each p
// lock the page to prevent edits
$("#lock").click(function(){
$("#spina").toggleClass("unlock");
}); // lock button click
$("#screen").click(function(){
html2canvas(document.getElementById('poem'), {
scale: 3
// make a screenshot
$("#screen").click(function() {
html2canvas(document.getElementById('poem'), {
scale: 3
}).then(function(canvas) {
// Export the canvas to its data URI representation
// var base64image = canvas.toDataURL("image/png");
//
// // Open the image in a new window
// window.open(base64image , "_blank");
// Export canvas as a blob
canvas.toBlob(function(blob) {
// Generate file download
window.saveAs(blob, "yourwebsite_screenshot.png");
});
canvas.toBlob(function(blob) {
window.saveAs(blob, "yourwebsite_screenshot.png");
});
});
}); // screen button click
// change for composition view
$("#compose").click(function(){
$("#blackout").click(function() {
$("#spina").toggleClass("unlock");
$("#spina").toggleClass("done");
$( "#spina p span.click" ).toggleClass("clickDone");
$("#spina p span.click").toggleClass("clickDone");
// get today and format
const today = Date(Date.now());
todayFormatted = today.toString();
$("#byline").html("<p>blackout poem inspired by " + book.title + " by " + book.author + "</p><p>composed on: " + todayFormatted) + "</p>";
$(this).text(function(i, text){
return text === "Blackout!" ? "Un-Blackout!" : "Blackout!";
})
}); // compose
// add the byline
$("#byline").html("<p>blackout poem inspired by " + book.title + " by " + book.author + "</p><p>composed on: " + todayFormatted) + "</p>";
// toggle the text on the button
$(this).text(function(i, text) {
return text === "Blackout!" ? "Un-Blackout!": "Blackout!";
});
}); // blackout button click
// reset everything back
$("#clear").click(function(){
$("#spina").removeClass("done");
$( "#spina p span.click" ).removeClass("click");
$("#spina p span.click").removeClass("click");
$("#byline").html("");
$("#poem_list").html("");
$("#spina").addClass("unlock");
}); // clear
// $("help").hide();
}); // clear button click
// show help section
$(".helpbtn").click(function(){
@ -127,25 +115,31 @@ $(document).ready(function(){
}); // copy text
$("#copy_text_meta").click(function(){
// get today and format it
const today = Date(Date.now());
todayFormatted = today.toString();
// add the meta to the copyed text
var poem_meta = "#dailyBlackoutPoetryChallenge\n\n" + $("#poem_list").text() + "\n\n" + book.title + " - " + todayFormatted;
navigator.clipboard.writeText(poem_meta);
}); // copy text
}); // copy text w/meta
// change the color of a clicked word; add/remove clicked word to list
$(document).on('click', "#spina.unlock p span", function(e){
// $("#spina.unlock p span").click(function(){
// add the class to the clicked word
$( this ).toggleClass("click");
// make the list of words
let list = "";
$("#spina p span.click").each(function(index) {
list += " " + $(this).text();
}); //poem
// Add to the list, but strip out punctuation
// console.log(list.replace(/[^a-z0-9 ]+/ig, ""));
$("#poem_list").html(list.replace(/[^a-z0-9 ]+/ig, ""));
}); //spina click
}); // document ready
</script>
@ -161,41 +155,15 @@ $(document).ready(function(){
<p>Click on a word to select it, click on it again to unselect. When youve found your poem hit Blackout! Get a screen shot and copy the words below!</p>
</header>
<div id="poem_header">
<h2>Invaders from the Dark</h2>
<h3>Greye La Spina</h3>
</div>
<div id="poem_header"></div>
<nav>
<button class="helpbtn btn btn-mn">Help</button> - <button id="clear" class="btn btn-mn">Start Over</button> - <button id="compose" class="btn btn-mn">Blackout!</button> - <button id="screen" class="btn btn-mn">Save as image</button>
<button class="helpbtn btn btn-mn">Help</button> - <button id="clear" class="btn btn-mn">Start Over</button> - <button id="blackout" class="btn btn-mn">Blackout!</button> - <button id="screen" class="btn btn-mn">Save as image</button>
</nav>
<main id="poem">
<div id="spina" class="unlock">
<p>I ascertained that Miss Delorme was a responsible person, quite able and willing to defray the costs of printing her book, in case it proved to be out of the line of the regular publishing houses. I arranged to visit her home on June 18th, an easy matter, as I found I could get there by subway. On June 18th, therefor, I walked across the fields to the great wall which she had described in her letters, and rang the bell of the bronze gate. From that moment, I began to realize what Miss Delorme meant when she wrote that she feared for the safety of her manuscript. </p>
<p>Even as I stood there waiting, things started to happen in a most bewildering fashion. I heard somebody throw up a window on a side of the house (to my right), and then there came a woman&#8217;s scream, which sounded to me more angry than fearful. The scream was followed by a heavy, metallic clang upon the pavement just around the corner from where I stood. I left the gate and ran in the direction of the noise. </p>
<p>On the sidewalk lay a black tin box as is often used to preserve papers of importance. It was dented badly where it had struck the pavement. I picked it up and then turned my eyes toward the windows above me. </p>
<p>And elderly woman stood at the open window nearest the corner of the house, holding with both hands to the window-frame at either side of her. Although she appeared to be alone, I received a strong impression that she was being pulled from behind, for she was struggling as if with all her power to maintain her position there. As I looked up, the tin box in my hand, she called to me anxiously. </p>
<p>&#8220;Who are you?&#8221;</p>
<p>I told her. </p>
<p>&#8220;Thank God you came in time!&#8221; She cried excitedly. &#8220;Take the box and get away from her as quickly as you can. Don&#8217;t let it out of your sight until it has been printed and the books distributed. You&#8217;ll understand why, when you&#8217;ve read it. Never mind about me! My work is done!&#8221;</p>
<p>As the last words were flung down at me, she disappeared backward into the room, as if pulled there by invisible hands. </p>
</div>
<div id="spina" class="unlock"></div>
<div id="byline"></div>
</main>
<section>
@ -209,21 +177,18 @@ $(document).ready(function(){
<div id="poem_list"></div>
</section>
<footer>
<p>This site made with <a href="https://jquery.com/">jQuery</a>, PHP and <a href="https://www.barebones.com/products/bbedit/">BBEdit</a> with help from <a href="https://espressoapp.com/">Espresso</a>.</p>
<p><a href="https://code.jacobhaddon.com/jake/smhn">Code</a> by Jacob Haddon - license <a href="https://www.gnu.org/licenses/gpl-3.0.en.html">GPLv3.0</a> - <a href="https://Apokrupha.com/BlackOut">Apokrupha.com/Blackout</a></p>
</footer>
<!--Help Section-->
<div id="help" class="help">
<div class="help btn-hlp-bx">
<button class="btn btn-hlp helpbtn">Close</button>
</div>
<div class="help btn-hlp-bx">
<button class="btn btn-hlp helpbtn">Close</button>
</div>
<div class="helpwords">