From a6499b5169f95819bb12178360e43a74fab0d4a3 Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 28 Apr 2018 23:18:49 -0500 Subject: [PATCH] post tooltips: add disable option (#3689). * Add "disable post tooltips" account setting. * Add back title attribute for when fancy tooltips are disabled. --- app/assets/javascripts/post_tooltips.js.erb | 10 +++++++++- app/controllers/users_controller.rb | 2 +- app/logical/anonymous_user.rb | 4 ++++ app/models/user.rb | 1 + app/presenters/post_presenter.rb | 3 ++- app/views/layouts/default.html.erb | 1 + app/views/users/edit.html.erb | 2 ++ 7 files changed, 20 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/post_tooltips.js.erb b/app/assets/javascripts/post_tooltips.js.erb index 1b45bb047..a85247032 100644 --- a/app/assets/javascripts/post_tooltips.js.erb +++ b/app/assets/javascripts/post_tooltips.js.erb @@ -56,7 +56,11 @@ Danbooru.PostTooltip.QTIP_OPTIONS = { Danbooru.PostTooltip.initialize = function () { $(document).on("mouseenter", Danbooru.PostTooltip.POST_SELECTOR, function (event) { - $(this).qtip(Danbooru.PostTooltip.QTIP_OPTIONS, event); + if (Danbooru.PostTooltip.disabled()) { + $(this).qtip("disable"); + } else { + $(this).qtip(Danbooru.PostTooltip.QTIP_OPTIONS, event); + } }); // Hide tooltips when clicking thumbnails. @@ -67,4 +71,8 @@ Danbooru.PostTooltip.hide = function (event) { $(".post-tooltip:visible").qtip("hide"); }; +Danbooru.PostTooltip.disabled = function (event) { + return Danbooru.meta("disable-post-tooltips") === "true"; +}; + $(document).ready(Danbooru.PostTooltip.initialize); diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index ddb900cdd..2eaf9d230 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -91,7 +91,7 @@ class UsersController < ApplicationController enable_auto_complete show_deleted_children disable_categorized_saved_searches disable_tagged_filenames enable_recent_searches disable_cropped_thumbnails disable_mobile_gestures - enable_safe_mode disable_responsive_mode + enable_safe_mode disable_responsive_mode disable_post_tooltips ] permitted_params += [dmail_filter_attributes: %i[id words]] diff --git a/app/logical/anonymous_user.rb b/app/logical/anonymous_user.rb index ff31e8db3..24adbeb4c 100644 --- a/app/logical/anonymous_user.rb +++ b/app/logical/anonymous_user.rb @@ -277,6 +277,10 @@ class AnonymousUser false end + def disable_post_tooltips? + false + end + User::Roles.reject {|r| r == :anonymous}.each do |name| define_method("is_#{name}?") do false diff --git a/app/models/user.rb b/app/models/user.rb index d7b9933a4..aa9dba5c6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -58,6 +58,7 @@ class User < ApplicationRecord disable_mobile_gestures enable_safe_mode disable_responsive_mode + disable_post_tooltips ) include Danbooru::HasBitFlags diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index ad0fd599d..7a532cea8 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -40,7 +40,8 @@ class PostPresenter < Presenter src = post.preview_file_url end - html << %{#{h(post.tag_string)}} + tooltip = "#{post.tag_string} rating:#{post.rating} score:#{post.score}" + html << %{#{h(post.tag_string)}} html << %{} if options[:pool] diff --git a/app/views/layouts/default.html.erb b/app/views/layouts/default.html.erb index 9483d219c..8b3b4b74f 100644 --- a/app/views/layouts/default.html.erb +++ b/app/views/layouts/default.html.erb @@ -25,6 +25,7 @@ + <%= content_tag(:meta, nil, name: "disable-mobile-gestures", content: CurrentUser.disable_mobile_gestures?) %> <%= auto_discovery_link_tag :atom, posts_path(:format => "atom", :tags => params[:tags]) %> diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 01ea347bf..164efec11 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -78,6 +78,8 @@ <%= f.input :disable_mobile_gestures, :as => :select, :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false %> + <%= f.input :disable_post_tooltips, :as => :select, :hint => "Disable advanced tooltips when hovering over thumbnails", :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false %> + <%#= f.input :disable_cropped_thumbnails, :as => :select, :collection => [["No", "false"], ["Yes", "true"]], :include_blank => false %>