diff options
-rw-r--r-- | _layouts/postlist.html | 29 | ||||
-rw-r--r-- | assets/js/newsbanner.js | 28 |
2 files changed, 29 insertions, 28 deletions
diff --git a/_layouts/postlist.html b/_layouts/postlist.html index b6b29ef..24909d1 100644 --- a/_layouts/postlist.html +++ b/_layouts/postlist.html @@ -57,31 +57,4 @@ layout: default </div> -<script> - document.addEventListener("DOMContentLoaded", function() { - {%- assign news_ids = site.data.news | map: 'id' | jsonify %} - - const ids = {{ news_ids }}; - for (currId of ids) { - const currentBanner = document.getElementById(currId); - if (!currentBanner) { - continue; - } - const closeLink = currentBanner.firstElementChild; - const currentNewsClosed = localStorage.getItem(currId+"closed"); - if (currentNewsClosed === "true") { - currentBanner.style.display = "none"; - } - - function closeBanner(evt) { - currentBanner.style.display = "none"; - const storId = evt.currentTarget.closeArg + "closed"; - localStorage.setItem(storId, "true"); - } - - closeLink.closeArg=currId; - closeLink.addEventListener("click", closeBanner); - } - - }); -</script> +<script src="/assets/js/newsbanner.js"></script> diff --git a/assets/js/newsbanner.js b/assets/js/newsbanner.js new file mode 100644 index 0000000..1a06f2b --- /dev/null +++ b/assets/js/newsbanner.js @@ -0,0 +1,28 @@ +--- +--- + document.addEventListener("DOMContentLoaded", function() { + {% assign news_ids = site.data.news | map: 'id' | jsonify %} + + const ids = {{ news_ids }}; + for (currId of ids) { + const currentBanner = document.getElementById(currId); + if (!currentBanner) { + continue; + } + const closeLink = currentBanner.firstElementChild; + const currentNewsClosed = localStorage.getItem(currId+"closed"); + if (currentNewsClosed === "true") { + currentBanner.style.display = "none"; + } + + function closeBanner(evt) { + currentBanner.style.display = "none"; + const storId = evt.currentTarget.closeArg + "closed"; + localStorage.setItem(storId, "true"); + } + + closeLink.closeArg=currId; + closeLink.addEventListener("click", closeBanner); + } + + }); |