Use new news style

This commit is contained in:
Kira 2020-01-25 02:13:55 -08:00
parent ece93bced5
commit 512b00d321
8 changed files with 71 additions and 33 deletions

View File

@ -2,28 +2,25 @@ import LS from './local_storage'
let NewsUpdate = {}; let NewsUpdate = {};
NewsUpdate.initialize = function() { NewsUpdate.initialize = function () {
if (!$("#news-updates").length) { if (!$("#news").length) {
return; return;
} }
const key = parseInt($("#news").data("id"), 10);
var key = $("#news-updates").data("id").toString(); $('#news').on('click', function () {
$('#news').toggleClass('open');
if (LS.get("news-ticker") === key) { });
$("#news-updates").hide(); $('#news-closebutton').on('click', function () {
} else { $('#news').hide();
$("#news-updates").show(); LS.put('hide_news_notice', key.toString());
});
$("#close-news-ticker-link").on("click.danbooru", function(e) { if (parseInt(LS.get("hide_news_notice") || 0, 10) !== key) {
$("#news-updates").hide(); $("#news").show();
LS.put("news-ticker", key);
return false;
});
} }
} };
$(function() { $(function () {
NewsUpdate.initialize(); NewsUpdate.initialize();
}); });

View File

@ -1,5 +1,34 @@
@import "../base/005_vars.scss"; @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 { div#news-updates {
padding: 5px; padding: 5px;
background: $news-background; background: $news-background;

View File

@ -7,7 +7,7 @@ class NewsUpdate < ApplicationRecord
def self.recent def self.recent
@recent_news ||= Cache.get('recent_news', 1.day) do @recent_news ||= Cache.get('recent_news', 1.day) do
self.order('created_at desc').first(5) self.order('id desc').first(1)
end end
end end

View File

@ -108,7 +108,16 @@
</noscript> </noscript>
</head> </head>
<%= tag.body **body_attributes(CurrentUser.user) do %> <%= tag.body **body_attributes(CurrentUser.user) do %>
<%= render "news_updates/listing" %> <% if Danbooru.config.beta_notice %>
<div id="news-updates">
<ul>
<li>
<h1>Please make sure to check out the <a href="/wiki_pages/e621:beta_rules">beta rules</a> before proceeding
to use this site.</h1>
</li>
</ul>
</div>
<% end %>
<header id="top"> <header id="top">
<h1><%= link_to Danbooru.config.app_name, "/" %></h1> <h1><%= link_to Danbooru.config.app_name, "/" %></h1>
@ -125,6 +134,8 @@
</header> </header>
<div id="page"> <div id="page">
<%= render "news_updates/listing" %>
<% if CurrentUser.user.is_banned? %> <% if CurrentUser.user.is_banned? %>
<%= render "users/ban_notice" %> <%= render "users/ban_notice" %>
<% end %> <% end %>

View File

@ -1,13 +1,10 @@
<% cache("news-updates", :expires_in => 1.hour) do %> <% if NewsUpdate.recent.present? %>
<% if NewsUpdate.recent.any? %> <div class="ui-state-highlight site-notice" style="display: none;" id="news" data-id="<%= NewsUpdate.recent[0].id %>">
<div id="news-updates" data-id="<%= NewsUpdate.recent.first.try(:id) %>" style="display: none;"> <div id="news-closebutton" class="closebutton">Dismiss</div>
<ul> <h6><%= link_to("News", news_updates_path) %> - <%= NewsUpdate.recent[0].created_at.strftime("%b %d, %Y") %>
<% NewsUpdate.recent.each do |news_update| %> (<%= time_ago_in_words NewsUpdate.recent[0].created_at %> ago)
<li><%= news_update.created_at.strftime("%b %d") %>: <%= news_update.message.html_safe %></li> <span id="news-showtext" class="showtext">Click to show.</span>
<% end %> </h6>
</ul> <div class="newsbody"><%= format_text(NewsUpdate.recent[0].message) %></div>
</div>
<a href="#" id="close-news-ticker-link">close</a>
</div>
<% end %>
<% end %> <% end %>

View File

@ -3,7 +3,7 @@
<h1>Edit Update</h1> <h1>Edit Update</h1>
<%= simple_form_for(@news_update) do |f| %> <%= simple_form_for(@news_update) do |f| %>
<%= f.input :message, :hint => "Use HTML for formatting", :input_html => {:size => "30x5"} %> <%= f.input :message, :hint => "Use DText for formatting", :input_html => {:size => "30x5"} %>
<%= f.button :submit, "Submit" %> <%= f.button :submit, "Submit" %>
<% end %> <% end %>
</div> </div>

View File

@ -3,7 +3,7 @@
<h1>New Update</h1> <h1>New Update</h1>
<%= simple_form_for(@news_update) do |f| %> <%= simple_form_for(@news_update) do |f| %>
<%= f.input :message, :hint => "Use HTML for formatting", :input_html => {:size => "30x5"} %> <%= f.input :message, :hint => "Use DText for formatting", :input_html => {:size => "30x5"} %>
<%= f.button :submit, "Submit" %> <%= f.button :submit, "Submit" %>
<% end %> <% end %>
</div> </div>

View File

@ -289,6 +289,10 @@ fart'
1_000 1_000
end end
def beta_notice
false
end
# Maximum size of an upload. If you change this, you must also change # Maximum size of an upload. If you change this, you must also change
# `client_max_body_size` in your nginx.conf. # `client_max_body_size` in your nginx.conf.
def max_file_size def max_file_size