From 8760f7d817537625b0cbb3a3581ecf2d56f74a14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Mon, 30 Mar 2015 10:57:26 +0200 Subject: [PATCH] FEATURE: don't show the 'download' link to anon when they can't even download the original image --- .../javascripts/discourse/lib/lightbox.js.es6 | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/lightbox.js.es6 b/app/assets/javascripts/discourse/lib/lightbox.js.es6 index e45c1f56aa1..96630d05059 100644 --- a/app/assets/javascripts/discourse/lib/lightbox.js.es6 +++ b/app/assets/javascripts/discourse/lib/lightbox.js.es6 @@ -3,7 +3,7 @@ import loadScript from 'discourse/lib/load-script'; export default function($elem) { $("a.lightbox", $elem).each(function(i, e) { loadScript("/javascripts/jquery.magnific-popup-min.js").then(function() { - var $e = $(e); + const $e = $(e); // do not lightbox spoiled images if ($e.parents(".spoiler").length > 0 || $e.parents(".spoiled").length > 0) { return; } @@ -14,30 +14,30 @@ export default function($elem) { mainClass: "mfp-zoom-in", callbacks: { - open: function() { - var wrap = this.wrap, - img = this.currItem.img, - maxHeight = img.css("max-height"); + open() { + const wrap = this.wrap, + img = this.currItem.img, + maxHeight = img.css("max-height"); wrap.on("click.pinhandler", "img", function() { wrap.toggleClass("mfp-force-scrollbars"); img.css("max-height", wrap.hasClass("mfp-force-scrollbars") ? "none" : maxHeight); }); }, - beforeClose: function() { + beforeClose() { this.wrap.off("click.pinhandler"); this.wrap.removeClass("mfp-force-scrollbars"); } }, image: { - titleSrc: function(item) { - var href = item.el.data("download-href") || item.src; - return [ - item.el.attr("title"), - $("span.informations", item.el).text().replace('x', '×'), - '' + I18n.t("lightbox.download") + '' - ].join(' · '); + titleSrc(item) { + const href = item.el.data("download-href") || item.src; + let src = [item.el.attr("title"), $("span.informations", item.el).text().replace('x', '×')]; + if (!Discourse.SiteSettings.prevent_anons_from_downloading_files || Discourse.User.current()) { + src.push('' + I18n.t("lightbox.download") + ''); + } + return src.join(' · '); } }