Merge pull request #345 from zwagoth/blacklist-rework

Fix blacklist not applying on videos
This commit is contained in:
Zwagoth 2021-12-03 14:43:14 -05:00 committed by GitHub
commit 163bf18e84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 36 additions and 112 deletions

View File

@ -1,5 +1,6 @@
import Utility from './utility'
import LS from './local_storage'
import Post from './posts';
let Blacklist = {};
@ -103,85 +104,9 @@ Blacklist.domEntryToggle = function (e) {
Blacklist.apply();
};
Blacklist.postSaveReplaceSrcPicture = function (post, picture) {
const sources = picture.children('source');
const img = picture.children('img');
if (!img || !sources || sources.length !== 2)
return;
if (!img.attr('data-crop-url'))
img.attr('data-crop-url', $(sources[0]).attr('srcset'));
if (!img.attr('data-orig-url'))
img.attr('data-orig-url', $(sources[1]).attr('srcset'));
if (post.hasClass('post-thumbnail-blacklisted')) {
post.removeClass('blacklisted-active');
img.attr('src', '/images/blacklisted-preview.png');
$(sources[0]).attr('srcset', '/images/blacklisted-preview.png');
$(sources[1]).attr('srcset', '/images/blacklisted-preview.png');
}
};
Blacklist.postRestoreSrcPicture = function (post, picture) {
const sources = picture.children('source');
const img = picture.children('img');
if (!img || !sources || sources.length !== 2)
return;
const cropUrl = img.attr('data-crop-url');
const origUrl = img.attr('data-orig-url');
if (!cropUrl || !origUrl) {
return;
}
$(sources[0]).attr('srcset', img.attr('data-crop-url'));
$(sources[1]).attr('srcset', img.attr('data-orig-url'));
img.attr('src', img.attr('data-orig-url'));
};
Blacklist.postSaveReplaceSrc = function (post) {
const picture = post.find("picture");
if (picture.length) {
Blacklist.postSaveReplaceSrcPicture(post, picture);
return;
}
const img = post.children("img")[0];
if (!img)
return;
const $img = $(img);
if (!$img.attr('data-orig-url'))
$img.attr("data-orig-url", $img.attr('src'));
if (post.attr('id') === 'image-container' || post.hasClass('post-thumbnail') || post.hasClass('post-thumbnail-blacklisted')) {
$img.attr('src', '/images/blacklisted-preview.png');
post.removeClass('blacklisted-active').addClass('blacklisted-active-visible');
}
};
Blacklist.postRestoreSrc = function (post) {
const picture = post.find("picture");
if (picture.length) {
Blacklist.postRestoreSrcPicture(post, picture);
return;
}
const img = post.children("img")[0];
if (!img)
return;
const $img = $(img);
if (!$img.attr('data-orig-url'))
return;
$img.attr('src', $img.attr('data-orig-url'));
$img.attr('data-orig-url', null);
};
Blacklist.postHide = function (post) {
const $post = $(post);
$post.addClass("blacklisted").addClass("blacklisted-active");
Blacklist.postSaveReplaceSrc($post);
$post.addClass("blacklisted");
const $video = $post.find("video").get(0);
if ($video) {
@ -192,8 +117,8 @@ Blacklist.postHide = function (post) {
Blacklist.postShow = function (post) {
const $post = $(post);
Blacklist.postRestoreSrc(post);
$post.addClass("blacklisted").removeClass("blacklisted-active").removeClass("blacklisted-active-visible");
$post.removeClass("blacklisted");
Post.resize_notes();
};
Blacklist.sidebarUpdate = function () {
@ -221,7 +146,7 @@ Blacklist.sidebarUpdate = function () {
link.text(entry.tags);
link.addClass("blacklist-toggle-link");
if (entry.disabled) {
link.addClass("blacklisted-active");
link.addClass("entry-disabled");
}
link.attr("href", `/posts?tags=${encodeURIComponent(entry.tags)}`);
link.attr("title", entry.tags);

View File

@ -188,21 +188,16 @@ let Note = {
},
scale_all: function() {
var container = document.getElementById('note-container');
if (container === null) {
var $container = $("#note-container");
if ($container.length === 0) {
return;
}
// Hide notes while rescaling, to prevent unnecessary reflowing
var was_visible = container.style.display !== 'none';
if (was_visible) {
container.style.display = 'none';
}
$container.data("resizing", true);
$(".note-box").each(function(i, v) {
Note.Box.scale($(v));
});
if (was_visible) {
container.style.display = 'block';
}
$container.data("resizing", false);
},
toggle_all: function() {

View File

@ -582,9 +582,6 @@ Post.resize_image = function (post, target_size) {
Post.resize_to = function(target_size) {
target_size = update_size_selector(target_size);
if ($("#image-container").hasClass("blacklisted-active-visible"))
return;
const post = Post.currentPost();
if (is_video(post)) {
Post.resize_video(post, target_size);
@ -669,9 +666,6 @@ Post.resize_cycle_mode = function(e) {
if(e && e.target)
e.preventDefault();
if ($("#image-container").hasClass("blacklisted-active-visible"))
return;
Post.resize_to("next");
}

View File

@ -35,19 +35,17 @@ Thumbnails.initialize = function () {
});
const newTag = $('<div>');
const blacklisted = DAB ? false : blacklist_hit_count > 0;
if (blacklist_hit_count > 0) {
Blacklist.post_count++;
}
for (const key in postData) {
newTag.attr("data-" + key.replace(/_/g, '-'), postData[key]);
}
newTag.attr('class', blacklisted ? "post-thumbnail blacklisted blacklisted-active" : "post-thumbnail");
newTag.attr('class', blacklisted ? "post-thumbnail blacklisted" : "post-thumbnail");
if (p.hasClass('thumb-placeholder-link'))
newTag.addClass('dtext');
const img = $('<img>');
newTag.attr('data-orig-url', postData.preview_url || '/images/deleted-preview.png');
if (blacklisted) {
img.attr('src', '/images/blacklisted-preview.png');
} else {
img.attr('src', postData.preview_url || '/images/deleted-preview.png');
}
img.attr('src', postData.preview_url || '/images/deleted-preview.png');
img.attr({
height: postData.preview_url ? postData.preview_height : 150,
width: postData.preview_url ? postData.preview_width : 150,
@ -61,6 +59,7 @@ Thumbnails.initialize = function () {
newTag.append(link);
p.replaceWith(newTag);
});
Blacklist.sidebarUpdate();
};
$(document).ready(function () {

View File

@ -13,7 +13,7 @@
background: $lighten-background-5;
.avatar {
.post-thumbnail {
.post-thumbnail:not(.blacklisted) {
img {
height: auto;
width: auto;

View File

@ -32,7 +32,7 @@
vertical-align: bottom;
}
a.blacklisted-active {
a.entry-disabled {
text-decoration: line-through;
}
}
@ -64,14 +64,20 @@
}
}
.post-preview.blacklisted-active, #c-comments .post.blacklisted-active {
display: none !important;
// Hide blacklist box on post index page only
#c-posts #a-index .post-preview.blacklisted {
display: none;
}
#image-container.blacklisted-active, .post-thumbnail.blacklisted-active {
img {
height: 150px;
width: 150px;
#image-container.blacklisted, .post-thumbnail.blacklisted, .post-preview.blacklisted {
img, video {
height: 0px;
width: 0px;
padding: 150px 150px 0px 0px;
background: url("images/blacklisted-preview.png");
}
#note-container {
display: none;
}
}

View File

@ -4,6 +4,10 @@ div#note-container {
position: absolute;
z-index: 50;
&[data-resizing=true] {
display: none;
}
div.note-body {
position: absolute;
border: 1px solid $note-border;

View File

@ -10,7 +10,8 @@ default: &default
# Additional paths webpack should look up modules
# ['app/assets', 'engine/foo/app/assets']
additional_paths: []
additional_paths:
- public
# Reload manifest.json on all requests so we reload latest compiled packs
cache_manifest: false