mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-30 10:58:31 -05:00
FEATURE: use original filename when clicking the download link in the lightbox
This commit is contained in:
parent
4762b4ac24
commit
31e9cafe0e
6 changed files with 33 additions and 16 deletions
|
@ -36,10 +36,11 @@ Discourse.Lightbox = {
|
||||||
|
|
||||||
image: {
|
image: {
|
||||||
titleSrc: function(item) {
|
titleSrc: function(item) {
|
||||||
|
var href = item.el.data("download-href") || item.src;
|
||||||
return [
|
return [
|
||||||
item.el.attr("title"),
|
item.el.attr("title"),
|
||||||
$("span.informations", item.el).text().replace('x', '×'),
|
$("span.informations", item.el).text().replace('x', '×'),
|
||||||
'<a class="image-source-link" href="' + item.src + '" target="_blank">' + I18n.t("lightbox.download") + '</a>'
|
'<a class="image-source-link" href="' + href + '">' + I18n.t("lightbox.download") + '</a>'
|
||||||
].join(' · ');
|
].join(' · ');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -159,6 +159,11 @@ class CookedPostProcessor
|
||||||
# then, the link to our larger image
|
# then, the link to our larger image
|
||||||
a = Nokogiri::XML::Node.new("a", @doc)
|
a = Nokogiri::XML::Node.new("a", @doc)
|
||||||
img.add_next_sibling(a)
|
img.add_next_sibling(a)
|
||||||
|
|
||||||
|
if upload && Discourse.store.internal?
|
||||||
|
a["data-download-href"] = Discourse.store.download_url(upload)
|
||||||
|
end
|
||||||
|
|
||||||
a["href"] = img["src"]
|
a["href"] = img["src"]
|
||||||
a["class"] = "lightbox"
|
a["class"] = "lightbox"
|
||||||
a.add_child(img)
|
a.add_child(img)
|
||||||
|
@ -217,9 +222,11 @@ class CookedPostProcessor
|
||||||
end
|
end
|
||||||
|
|
||||||
def optimize_urls
|
def optimize_urls
|
||||||
@doc.css("a[href]").each do |a|
|
%w{href data-download-href}.each do |selector|
|
||||||
href = a["href"].to_s
|
@doc.css("a[#{selector}]").each do |a|
|
||||||
a["href"] = schemaless absolute(href) if is_local(href)
|
href = a["#{selector}"].to_s
|
||||||
|
a["#{selector}"] = schemaless absolute(href) if is_local(href)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc.css("img[src]").each do |img|
|
@doc.css("img[src]").each do |img|
|
||||||
|
@ -243,17 +250,17 @@ class CookedPostProcessor
|
||||||
end
|
end
|
||||||
|
|
||||||
def disable_if_low_on_disk_space
|
def disable_if_low_on_disk_space
|
||||||
if available_disk_space < SiteSetting.download_remote_images_threshold
|
return false if available_disk_space >= SiteSetting.download_remote_images_threshold
|
||||||
SiteSetting.download_remote_images_to_local = false
|
|
||||||
# log the site setting change
|
SiteSetting.download_remote_images_to_local = false
|
||||||
reason = I18n.t("disable_remote_images_download_reason")
|
# log the site setting change
|
||||||
staff_action_logger = StaffActionLogger.new(Discourse.system_user)
|
reason = I18n.t("disable_remote_images_download_reason")
|
||||||
staff_action_logger.log_site_setting_change("download_remote_images_to_local", true, false, { details: reason })
|
staff_action_logger = StaffActionLogger.new(Discourse.system_user)
|
||||||
# also send a private message to the site contact user
|
staff_action_logger.log_site_setting_change("download_remote_images_to_local", true, false, { details: reason })
|
||||||
SystemMessage.create_from_system_user(Discourse.site_contact_user, :download_remote_images_disabled)
|
# also send a private message to the site contact user
|
||||||
return true
|
SystemMessage.create_from_system_user(Discourse.site_contact_user, :download_remote_images_disabled)
|
||||||
end
|
|
||||||
false
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def available_disk_space
|
def available_disk_space
|
||||||
|
|
|
@ -23,6 +23,9 @@ module FileStore
|
||||||
def relative_base_url
|
def relative_base_url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def download_url(upload)
|
||||||
|
end
|
||||||
|
|
||||||
def external?
|
def external?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,11 @@ module FileStore
|
||||||
"/uploads/#{RailsMultisite::ConnectionManagement.current_db}"
|
"/uploads/#{RailsMultisite::ConnectionManagement.current_db}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def download_url(upload)
|
||||||
|
return unless upload
|
||||||
|
"#{relative_base_url}/#{upload.sha1}"
|
||||||
|
end
|
||||||
|
|
||||||
def external?
|
def external?
|
||||||
!internal?
|
!internal?
|
||||||
end
|
end
|
||||||
|
|
1
plugins/emoji/public/public
Symbolic link
1
plugins/emoji/public/public
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
/home/regis/Poetry/discourse/plugins/emoji/public
|
|
@ -90,7 +90,7 @@ describe CookedPostProcessor do
|
||||||
|
|
||||||
it "generates overlay information" do
|
it "generates overlay information" do
|
||||||
cpp.post_process_images
|
cpp.post_process_images
|
||||||
cpp.html.should match_html '<div class="lightbox-wrapper"><a href="/uploads/default/1/1234567890123456.jpg" class="lightbox" title="logo.png"><img src="/uploads/default/_optimized/da3/9a3/ee5e6b4b0d_690x1380.png" width="690" height="1380"><div class="meta">
|
cpp.html.should match_html '<div class="lightbox-wrapper"><a data-download-href="/uploads/default/e9d71f5ee7c92d6dc9e92ffdad17b8bd49418f98" href="/uploads/default/1/1234567890123456.jpg" class="lightbox" title="logo.png"><img src="/uploads/default/_optimized/da3/9a3/ee5e6b4b0d_690x1380.png" width="690" height="1380"><div class="meta">
|
||||||
<span class="filename">logo.png</span><span class="informations">1000x2000 1.21 KB</span><span class="expand"></span>
|
<span class="filename">logo.png</span><span class="informations">1000x2000 1.21 KB</span><span class="expand"></span>
|
||||||
</div></a></div>'
|
</div></a></div>'
|
||||||
cpp.should be_dirty
|
cpp.should be_dirty
|
||||||
|
|
Loading…
Reference in a new issue