posts/show: fix flickering fav/unfav buttons.
This commit is contained in:
@@ -3,30 +3,6 @@ import Utility from './utility'
|
|||||||
|
|
||||||
let Favorite = {}
|
let Favorite = {}
|
||||||
|
|
||||||
Favorite.initialize_all = function() {
|
|
||||||
if ($("#c-posts").length) {
|
|
||||||
this.hide_or_show_add_to_favorites_link();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Favorite.hide_or_show_add_to_favorites_link = function() {
|
|
||||||
var current_user_id = Utility.meta("current-user-id");
|
|
||||||
if (current_user_id === "") {
|
|
||||||
$("#add-to-favorites").hide();
|
|
||||||
$("#remove-from-favorites").hide();
|
|
||||||
$("#add-fav-button").hide();
|
|
||||||
$("#remove-fav-button").hide();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if ($("#image-container").length && $("#image-container").data("is-favorited") === true) {
|
|
||||||
$("#add-to-favorites").hide();
|
|
||||||
$("#add-fav-button").hide();
|
|
||||||
} else {
|
|
||||||
$("#remove-from-favorites").hide();
|
|
||||||
$("#remove-fav-button").hide();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Favorite.create = function(post_id) {
|
Favorite.create = function(post_id) {
|
||||||
Post.notice_update("inc");
|
Post.notice_update("inc");
|
||||||
|
|
||||||
@@ -57,9 +33,5 @@ Favorite.destroy = function(post_id) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).ready(function() {
|
|
||||||
Favorite.initialize_all();
|
|
||||||
});
|
|
||||||
|
|
||||||
export default Favorite
|
export default Favorite
|
||||||
|
|
||||||
|
|||||||
@@ -2,8 +2,8 @@
|
|||||||
<li><%= link_to "Resize to window", "#", :id => "image-resize-to-window-link" %></li>
|
<li><%= link_to "Resize to window", "#", :id => "image-resize-to-window-link" %></li>
|
||||||
|
|
||||||
<% if CurrentUser.is_member? %>
|
<% if CurrentUser.is_member? %>
|
||||||
<li><%= link_to "Favorite", favorites_path(:post_id => post.id), :remote => true, :method => :post, :id => "add-to-favorites", :"data-shortcut" => "f" %></li>
|
<li><%= link_to "Favorite", favorites_path(:post_id => post.id), :remote => true, :method => :post, :id => "add-to-favorites", :"data-shortcut" => "f", style: ("display: none;" if @post.is_favorited?) %></li>
|
||||||
<li><%= link_to "Unfavorite", favorite_path(post), :remote => true, :method => :delete, :id => "remove-from-favorites", :"data-shortcut" => "shift+f" %></li>
|
<li><%= link_to "Unfavorite", favorite_path(post), :remote => true, :method => :delete, :id => "remove-from-favorites", :"data-shortcut" => "shift+f", style: ("display: none;" if !@post.is_favorited?) %></li>
|
||||||
<li><%= link_to_if post.visible?, "Download", post.tagged_file_url + "?download=1", download: post.presenter.filename_for_download %></li>
|
<li><%= link_to_if post.visible?, "Download", post.tagged_file_url + "?download=1", download: post.presenter.filename_for_download %></li>
|
||||||
<li id="add-to-pool-list"><%= link_to "Add to pool", "#", :id => "pool" %></li>
|
<li id="add-to-pool-list"><%= link_to "Add to pool", "#", :id => "pool" %></li>
|
||||||
<% if post.is_note_locked? %>
|
<% if post.is_note_locked? %>
|
||||||
|
|||||||
@@ -48,10 +48,12 @@
|
|||||||
<%= @post.presenter.image_html(self) %>
|
<%= @post.presenter.image_html(self) %>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<div class="fav-buttons">
|
<% if CurrentUser.is_member? %>
|
||||||
<%= button_to "Favorite", favorites_path(post_id: @post.id), remote: true, method: :post, form: {id: "add-fav-button"}, class: "ui-button ui-widget ui-corner-all gradient", data: {disable_with: "Favoriting..."} %>
|
<div class="fav-buttons">
|
||||||
<%= button_to "Unfavorite", favorite_path(@post), remote: true, method: :delete, form: {id: "remove-fav-button"}, class: "ui-button ui-widget ui-corner-all gradient", data: {disable_with: "Unfavoriting..."} %>
|
<%= button_to "Favorite", favorites_path(post_id: @post.id), remote: true, method: :post, form: {id: "add-fav-button", style: ("display: none;" if @post.is_favorited?)}, class: "ui-button ui-widget ui-corner-all gradient", data: {disable_with: "Favoriting..."} %>
|
||||||
</div>
|
<%= button_to "Unfavorite", favorite_path(@post), remote: true, method: :delete, form: {id: "remove-fav-button", style: ("display: none;" if !@post.is_favorited?)}, class: "ui-button ui-widget ui-corner-all gradient", data: {disable_with: "Unfavoriting..."} %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<section id="mark-as-translated-section" style="display: none;">
|
<section id="mark-as-translated-section" style="display: none;">
|
||||||
<%= form_tag(mark_as_translated_post_path(@post), :class => "simple_form", :method => :put) do |f| %>
|
<%= form_tag(mark_as_translated_post_path(@post), :class => "simple_form", :method => :put) do |f| %>
|
||||||
|
|||||||
Reference in New Issue
Block a user