diff --git a/app/javascript/src/javascripts/news_updates.js b/app/javascript/src/javascripts/news_updates.js index b7eafa88d..9cc303c77 100644 --- a/app/javascript/src/javascripts/news_updates.js +++ b/app/javascript/src/javascripts/news_updates.js @@ -2,28 +2,25 @@ import LS from './local_storage' let NewsUpdate = {}; -NewsUpdate.initialize = function() { - if (!$("#news-updates").length) { +NewsUpdate.initialize = function () { + if (!$("#news").length) { return; } + const key = parseInt($("#news").data("id"), 10); - var key = $("#news-updates").data("id").toString(); - - if (LS.get("news-ticker") === key) { - $("#news-updates").hide(); - } else { - $("#news-updates").show(); - - $("#close-news-ticker-link").on("click.danbooru", function(e) { - $("#news-updates").hide(); - LS.put("news-ticker", key); - - return false; - }); + $('#news').on('click', function () { + $('#news').toggleClass('open'); + }); + $('#news-closebutton').on('click', function () { + $('#news').hide(); + LS.put('hide_news_notice', key.toString()); + }); + if (parseInt(LS.get("hide_news_notice") || 0, 10) !== key) { + $("#news").show(); } -} +}; -$(function() { +$(function () { NewsUpdate.initialize(); }); diff --git a/app/javascript/src/styles/common/news.scss b/app/javascript/src/styles/common/news.scss index 2abaa7b5a..7dcc59f09 100644 --- a/app/javascript/src/styles/common/news.scss +++ b/app/javascript/src/styles/common/news.scss @@ -1,5 +1,34 @@ @import "../base/005_vars.scss"; +div#news { + max-height: 1rem; + overflow-y: hidden; + user-select: none; + + &:hover { + cursor: pointer; + } + + &.open { + max-height: none; + } + + .newsbody { + margin-top: 5px; + } + + .closebutton { + float: right; + cursor: pointer; + margin-right: 10px; + font-size: 14pt; + font-weight: bold; + color: white; + vertical-align: center; + margin-top: -3px; + } +} + div#news-updates { padding: 5px; background: $news-background; diff --git a/app/models/news_update.rb b/app/models/news_update.rb index b2263485c..6912b7eba 100644 --- a/app/models/news_update.rb +++ b/app/models/news_update.rb @@ -7,7 +7,7 @@ class NewsUpdate < ApplicationRecord def self.recent @recent_news ||= Cache.get('recent_news', 1.day) do - self.order('created_at desc').first(5) + self.order('id desc').first(1) end end diff --git a/app/views/layouts/default.html.erb b/app/views/layouts/default.html.erb index 775ebc303..f49fcc10a 100644 --- a/app/views/layouts/default.html.erb +++ b/app/views/layouts/default.html.erb @@ -108,7 +108,16 @@ <%= tag.body **body_attributes(CurrentUser.user) do %> - <%= render "news_updates/listing" %> + <% if Danbooru.config.beta_notice %> +