Skip to content
This repository was archived by the owner on May 12, 2020. It is now read-only.

Commit a2a3398

Browse files
committed
Add social-share button to posts#show page
Allow user to share a post on Facebook, Twitter, and Google plus by clicking on the share button in posts#show page.
1 parent 5559732 commit a2a3398

File tree

4 files changed

+129
-0
lines changed

4 files changed

+129
-0
lines changed

app/assets/stylesheets/application.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
@import 'modules/add_tag_button';
6464
@import 'modules/inline_editor';
6565
@import 'modules/follow_suggestions';
66+
@import 'modules/social_share';
6667

6768
// Vendor
6869
@import 'vendor/medium-editor';
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
.social-share-wrapper {
2+
position: relative;
3+
margin-top: 20px;
4+
}
5+
6+
.social-share {
7+
position: absolute;
8+
right: 0;
9+
padding: 5.3px 12px;
10+
width: 143.3px;
11+
height: 40px;
12+
font-size: 16px;
13+
letter-spacing: 1px;
14+
overflow: hidden;
15+
background: $button-green;
16+
border-radius: 20px;
17+
text-shadow: 0 -0.5px 0 rgba(0, 0, 0, .1);
18+
transition: all .2s ease-in-out;
19+
cursor: default;
20+
user-select: none;
21+
color: $white;
22+
23+
.text {
24+
position: absolute;
25+
top: 9.3px;
26+
left: 28px;
27+
overflow: hidden;
28+
width: 60px;
29+
height: 18px;
30+
text-align: right;
31+
z-index: 1;
32+
33+
em {
34+
position: absolute;
35+
right: 0;
36+
top: 0;
37+
transition: right .2s ease-in-out .1s;
38+
}
39+
}
40+
41+
.ico-share {
42+
position: absolute;
43+
top: 9.3px;
44+
right: 28.5px;
45+
transition: right .2s ease-in-out;
46+
width: 13.3px;
47+
height: 13.3px;
48+
}
49+
50+
.fa {
51+
font-size: 16px !important;
52+
}
53+
54+
.ico {
55+
font-size: 16px;
56+
position: absolute;
57+
top: 9.3px;
58+
left: -23.3px;
59+
transition: all .2s ease-in-out;
60+
display: inline-block;
61+
z-index: 2;
62+
color: $white;
63+
}
64+
65+
&:hover {
66+
background-color: $white;
67+
border: 1px solid $button-green;
68+
em {
69+
right: -300%;
70+
transition-delay: 0;
71+
}
72+
73+
.fa {
74+
font-size: 16px !important;
75+
color: $button-green;
76+
&:hover:not(.fa-share-alt) {
77+
color: darken($button-green, 5%);
78+
}
79+
}
80+
81+
.fb, .tw, .gp {
82+
cursor: pointer;
83+
}
84+
85+
.fb {
86+
left: 21.3px;
87+
transition-delay: 0.3s;
88+
}
89+
90+
.tw {
91+
left: 46.5px;
92+
transition-delay: 0.2s;
93+
}
94+
95+
.gp {
96+
left: 79.3px;
97+
transition-delay: 0.1s;
98+
}
99+
100+
.ico-share {
101+
top: 9.3px;
102+
right: 20px;
103+
width: 10px;
104+
height: 10px;
105+
}
106+
}
107+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<div class="social-share-wrapper">
2+
<div class="social-share">
3+
<a onclick="javascript:window.open('http://www.facebook.com/sharer.php?u=<%= post_url(post) %>', '_blank', 'width=800, height=500, top=200, left=300');void(0)"
4+
class="ico fb">
5+
<i class="fa fa-facebook"></i>
6+
</a>
7+
<a onclick="javascript:window.open('http://twitter.com/share?text=<%= post.title %> by <%= post.username %> - &amp;url=<%= post_url(post) %>', '_blank', 'width=800, height=500, top=200, left=300');void(0)"
8+
class="ico tw">
9+
<i class="fa fa-twitter"></i>
10+
</a>
11+
<a onclick="javascript:window.open('http://plus.google.com/share?url=<%= post_url(post) %>', '_blank', 'width=800, height=500, top=200, left=300');void(0)"
12+
class="ico gp">
13+
<i class="fa fa-google-plus"></i>
14+
</a>
15+
<span class="text"><em>SHARE</em></span>
16+
<span class="ico-share"><i class="fa fa-share-alt"></i></span>
17+
</div>
18+
</div>

app/views/posts/show.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
<%= feature_post_button_for(@post) %>
55
<% end %>
66

7+
<div class="pull-right">
8+
<%= render partial: 'posts/social_share', locals: { post: @post } %>
9+
</div>
710
<%= render 'post_metadata', post: @post %>
811

912
<% if @post.picture? %>

0 commit comments

Comments
 (0)