Merge pull request #1093 from ZogStriP/soften-the-lightbox-overlay

soften the lightbox overlay
This commit is contained in:
Sam 2013-06-25 18:49:12 -07:00
commit 7a16472041
3 changed files with 74 additions and 44 deletions

View file

@ -2,24 +2,31 @@
@import "foundation/mixins"; @import "foundation/mixins";
.lightbox { .lightbox {
display: inline-block;
position: relative; position: relative;
background: black; display: inline-block;
img { &:hover .meta {
background: rgba(0, 0, 0, .5);
opacity: 1; opacity: 1;
@include transition(opacity .2s); @include transition(opacity .5s);
}
} }
span { .meta {
color: white;
position: absolute; position: absolute;
display: none; bottom: 0;
font-size: 18px; width: 100%;
color: white;
background: black;
opacity: 0;
@include transition(opacity .2s);
&.filename { span {
top: 0; float: left;
left: 0; }
.filename {
margin: 5px;
&:before { &:before {
font-family: "FontAwesome"; font-family: "FontAwesome";
content: "\F03E"; content: "\F03E";
@ -27,16 +34,17 @@
} }
} }
&.informations { .informations {
margin: 6px;
padding-right: 20px;
color: $dark_gray; color: $dark_gray;
top: 20px;
left: 0;
font-size: 14px; font-size: 14px;
} }
&.expand { .expand {
top: 0; position: absolute;
right: 0; bottom: 4px;
right: 7px;
&:before { &:before {
font-family: "FontAwesome"; font-family: "FontAwesome";
content: "\F065"; content: "\F065";
@ -44,14 +52,7 @@
} }
} }
@include hover { // this should be removed once all the posts have been rebaked with the new lightboxes overlays
img { .lightbox > span {
opacity: .2; display: none;
}
span {
display: inline;
margin: 10px;
}
}
} }

View file

@ -126,21 +126,28 @@ class CookedPostProcessor
# not a hyperlink so we can apply # not a hyperlink so we can apply
img['src'] = upload.thumbnail_url if (upload && upload.thumbnail_url.present?) img['src'] = upload.thumbnail_url if (upload && upload.thumbnail_url.present?)
# first, create a div to hold our lightbox
lightbox = Nokogiri::XML::Node.new "div", @doc
img.add_next_sibling lightbox
lightbox.add_child img
# 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)
a["href"] = src a["href"] = src
a["class"] = "lightbox" a["class"] = "lightbox"
a.add_child(img) a.add_child(img)
# then, some overlay informations
meta = Nokogiri::XML::Node.new "div", @doc
meta["class"] = "meta"
img.add_next_sibling meta
# some overlay informations
filename = upload ? upload.original_filename : File.basename(src) filename = upload ? upload.original_filename : File.basename(src)
informations = "#{original_width}x#{original_height}" informations = "#{original_width}x#{original_height}"
informations << " | #{number_to_human_size(upload.filesize)}" if upload informations << " | #{number_to_human_size(upload.filesize)}" if upload
a.add_child create_span_node("filename", filename) meta.add_child create_span_node("filename", filename)
a.add_child create_span_node("informations", informations) meta.add_child create_span_node("informations", informations)
a.add_child create_span_node("expand") meta.add_child create_span_node("expand")
# TODO: download # TODO: download
# TODO: views-count # TODO: views-count

View file

@ -126,6 +126,28 @@ describe CookedPostProcessor do
end end
end end
context "with a large image" do
let(:user) { Fabricate(:user) }
let(:topic) { Fabricate(:topic, user: user) }
let(:post) { Fabricate.build(:post_with_uploads, topic: topic, user: user) }
let(:processor) { CookedPostProcessor.new(post) }
before do
FastImage.stubs(:size).returns([1000, 1000])
processor.post_process_images
end
it "generates overlay information" do
processor.html.should =~ /class="lightbox"/
processor.html.should =~ /class="meta"/
processor.html.should =~ /class="filename"/
processor.html.should =~ /class="informations"/
processor.html.should =~ /class="expand"/
end
end
end end
context 'link convertor' do context 'link convertor' do