From 4ecb4439b940ff021c69cd0552e695ea1147571d Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 22 Jul 2020 11:54:22 -0400 Subject: [PATCH] REFACTOR: Remove `Discourse.SiteSettings` from lightbox.js --- .../javascripts/discourse/app/components/image-uploader.js | 2 +- .../discourse/app/initializers/post-decorations.js | 7 +++++++ app/assets/javascripts/discourse/app/lib/lightbox.js | 4 ++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/image-uploader.js b/app/assets/javascripts/discourse/app/components/image-uploader.js index 5285d5bef51..5f5c0929874 100644 --- a/app/assets/javascripts/discourse/app/components/image-uploader.js +++ b/app/assets/javascripts/discourse/app/components/image-uploader.js @@ -86,7 +86,7 @@ export default Component.extend(UploadMixin, { }, _applyLightbox() { - if (this.imageUrl) next(() => lightbox(this.element)); + if (this.imageUrl) next(() => lightbox(this.element, this.siteSettings)); }, actions: { diff --git a/app/assets/javascripts/discourse/app/initializers/post-decorations.js b/app/assets/javascripts/discourse/app/initializers/post-decorations.js index 25c3b1c01aa..9fb4440222a 100644 --- a/app/assets/javascripts/discourse/app/initializers/post-decorations.js +++ b/app/assets/javascripts/discourse/app/initializers/post-decorations.js @@ -12,6 +12,13 @@ export default { api.decorateCooked(highlightSyntax, { id: "discourse-syntax-highlighting" }); + + api.decorateCookedElement( + elem => { + return lightbox(elem, siteSettings); + }, + { id: "discourse-lightbox" } + ); api.decorateCookedElement(lightbox, { id: "discourse-lightbox" }); if (siteSettings.support_mixed_text_direction) { api.decorateCooked(setTextDirections, { diff --git a/app/assets/javascripts/discourse/app/lib/lightbox.js b/app/assets/javascripts/discourse/app/lib/lightbox.js index a22b8fc429b..28b6fe69bf8 100644 --- a/app/assets/javascripts/discourse/app/lib/lightbox.js +++ b/app/assets/javascripts/discourse/app/lib/lightbox.js @@ -6,7 +6,7 @@ import { isAppWebview, postRNWebviewMessage } from "discourse/lib/utilities"; import { spinnerHTML } from "discourse/helpers/loading-spinner"; import User from "discourse/models/user"; -export default function(elem) { +export default function(elem, siteSettings) { if (!elem) { return; } @@ -76,7 +76,7 @@ export default function(elem) { $("span.informations", item.el).text() ]; if ( - !Discourse.SiteSettings.prevent_anons_from_downloading_files || + !siteSettings.prevent_anons_from_downloading_files || User.current() ) { src.push(