soften the lightbox overlay

This commit is contained in:
Régis Hanol 2013-06-26 02:44:20 +02:00
parent 92562c2090
commit d3eae56e71
3 changed files with 74 additions and 44 deletions

View File

@ -2,56 +2,57 @@
@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);
} }
}
.meta {
position: absolute;
bottom: 0;
width: 100%;
color: white;
background: black;
opacity: 0;
@include transition(opacity .2s);
span { span {
color: white; float: left;
position: absolute; }
display: none;
font-size: 18px;
&.filename { .filename {
top: 0; margin: 5px;
left: 0; &:before {
&:before { font-family: "FontAwesome";
font-family: "FontAwesome"; content: "\F03E";
content: "\F03E"; margin-right: 5px;
margin-right: 5px;
}
}
&.informations {
color: $dark_gray;
top: 20px;
left: 0;
font-size: 14px;
}
&.expand {
top: 0;
right: 0;
&:before {
font-family: "FontAwesome";
content: "\F065";
}
} }
} }
@include hover { .informations {
img { margin: 6px;
opacity: .2; padding-right: 20px;
} color: $dark_gray;
font-size: 14px;
}
span { .expand {
display: inline; position: absolute;
margin: 10px; bottom: 4px;
right: 7px;
&:before {
font-family: "FontAwesome";
content: "\F065";
} }
} }
} }
// this should be removed once all the posts have been rebaked with the new lightboxes overlays
.lightbox > span {
display: none;
}

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