diff --git a/tasks/guestBook/components/newComment.php b/tasks/guestBook/components/newComment.php index 6ff36eb..b5da39d 100644 --- a/tasks/guestBook/components/newComment.php +++ b/tasks/guestBook/components/newComment.php @@ -1,3 +1,30 @@ +

Leave a Comment!

@@ -15,8 +42,11 @@
- - + +
+ Please enter text. +
+ 0/250
diff --git a/tasks/guestBook/textarea.js b/tasks/guestBook/textarea.js index ecc98c8..ee6a606 100644 --- a/tasks/guestBook/textarea.js +++ b/tasks/guestBook/textarea.js @@ -1,10 +1,10 @@ "use strict"; document.addEventListener("DOMContentLoaded", () => { - const handler = (event) => { - console.log(event.target); - const length = event.target.value.length; - const maxLength = event.target.maxLength; + const handlerCounter = (event) => { + const comment = event.target; + const length = comment.value.length; + const maxLength = comment.maxLength; const counter = document.getElementById("comment-count"); counter.innerText = `${length}/${maxLength}`; @@ -18,10 +18,26 @@ document.addEventListener("DOMContentLoaded", () => { } }; - const addValidation = () => { - const textarea = document.getElementById("comment"); + const handlerSize = () => { + const scroll = window.scrollY; + const comment = document.getElementById("comment"); + const counter = document.getElementById("comment-count"); + const commentHeight = comment.clientHeight; + const counterHeight = counter.clientHeight; - textarea.addEventListener("keyup", handler); + if (commentHeight + 0.5 * counterHeight < comment.scrollHeight) { + comment.style.height = `${comment.scrollHeight + counterHeight}px`; + } + }; + + const addValidation = () => { + const comment = document.getElementById("comment"); + const counter = document.getElementById("comment-count"); + comment.style.height = `${comment.scrollHeight + counter.style.height}px`; + + comment.addEventListener("input", handlerCounter); + comment.addEventListener("input", handlerSize); + window.addEventListener("resize", handlerSize); }; addValidation(); diff --git a/tasks/random/arrays.php b/tasks/random/arrays.php new file mode 100644 index 0000000..5b89187 --- /dev/null +++ b/tasks/random/arrays.php @@ -0,0 +1,34 @@ + $name) { + if ($name === $toFind) { + echo "$name at $key"; + break; + } +} +?> +
+ $value) { + if ($value > $max) { + $max = $value; + $maxKey = $key; + } +} + +echo "$max at $maxKey"; + + +for ($i = 0; $i < 10; $i++) { + echo "$i
"; +} +echo "AFTER: $i
";