social_share_rails 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 85d29c515c9f74ebe29e62778560b8c6705fd32555c11ce9333aac73e7f770db
|
|
4
|
+
data.tar.gz: 07f845311fd9ec5647a853658c605b76e34f7d5707cbc8cb87d6bf28ef0ce45d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7b3378355847cb8c632878c850bbb4e7f844dba39a6ceb72f6e3f07f7517e0dd6f8567690579e06fa18f4bd854676c3afb27d5391eeb61156908a514f956bd13
|
|
7
|
+
data.tar.gz: b25b407705578f9e8bd715c9f19b73ba3eb7487a2e090010c6aed7a4f91450f58f8e1e5445f77e1cac8bb51ef6e352f170a25b07268bf4254563a74822a4ab97
|
data/README.md
CHANGED
|
@@ -8,7 +8,6 @@ SocialShareRails is a Ruby on Rails gem that simplifies the process of adding so
|
|
|
8
8
|
- Supports popular social platforms: Twitter, Facebook, Pinterest, LinkedIn, Reddit, Telegram, WhatsApp, and more.
|
|
9
9
|
- Customizable styles with rounded icons.
|
|
10
10
|
- JavaScript-based popup for sharing links.
|
|
11
|
-
- Google Analytics integration for tracking share events (optional).
|
|
12
11
|
- Easy integration with Rails views and assets pipeline.
|
|
13
12
|
|
|
14
13
|
---
|
|
@@ -76,7 +75,6 @@ Add the `social_share` helper to your views:
|
|
|
76
75
|
|
|
77
76
|
- **title** (String): The title of the post to share.
|
|
78
77
|
- **url** (String): The URL to share.
|
|
79
|
-
- **image** (String): Optional image URL for platforms that support it.
|
|
80
78
|
- **desc** (String): Optional description of the content.
|
|
81
79
|
- **allow_sites** (Array): List of social platforms to include.
|
|
82
80
|
- **rounded** (Boolean): If `true`, uses rounded icon styles.
|
|
@@ -86,7 +84,6 @@ Example with more options:
|
|
|
86
84
|
```erb
|
|
87
85
|
<%= social_share("Check out this article", {
|
|
88
86
|
url: "https://example.com/article",
|
|
89
|
-
image: "https://example.com/image.jpg",
|
|
90
87
|
desc: "This is an amazing article!",
|
|
91
88
|
allow_sites: %w[twitter facebook pinterest],
|
|
92
89
|
rounded: false
|
|
@@ -1,57 +1,75 @@
|
|
|
1
1
|
window.SocialShare = {
|
|
2
|
-
openUrl: function(url, width
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
openUrl: function(url, width, height) {
|
|
3
|
+
width = width || 640; // Default width
|
|
4
|
+
height = height || 480; // Default height
|
|
5
|
+
var left = (screen.width / 2) - (width / 2);
|
|
6
|
+
var top = (screen.height * 0.3) - (height / 2);
|
|
7
|
+
var options = "width=" + width + ",height=" + height + ",left=" + left + ",top=" + top + ",menubar=no,status=no,location=no";
|
|
8
|
+
window.open(url, "popup", options);
|
|
7
9
|
return false;
|
|
8
10
|
},
|
|
9
11
|
|
|
10
12
|
getEncodedAttributes: function(el, site, parent, keys) {
|
|
11
|
-
|
|
12
|
-
keys.forEach(key
|
|
13
|
-
result[key] = encodeURIComponent(el.getAttribute(
|
|
13
|
+
var result = {};
|
|
14
|
+
keys.forEach(function(key) {
|
|
15
|
+
result[key] = encodeURIComponent(el.getAttribute("data-" + site + "-" + key) || parent.getAttribute("data-" + key) || "");
|
|
14
16
|
});
|
|
15
17
|
return result;
|
|
16
18
|
},
|
|
17
19
|
|
|
18
|
-
trackEvent: function(site) {
|
|
19
|
-
const ga = window[window['GoogleAnalyticsObject'] || 'ga'];
|
|
20
|
-
if (typeof ga === 'function') {
|
|
21
|
-
ga('send', 'event', 'Social Share Button', 'click', site);
|
|
22
|
-
}
|
|
23
|
-
},
|
|
24
|
-
|
|
25
20
|
share: function(el) {
|
|
26
21
|
if (!el.getAttribute) el = document.querySelector(el);
|
|
27
22
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
var site = el.getAttribute("data-site");
|
|
24
|
+
var parent = el.parentNode;
|
|
25
|
+
var attributes = this.getEncodedAttributes(el, site, parent, ["title", "url", "desc"]);
|
|
26
|
+
var title = attributes.title;
|
|
27
|
+
var url = attributes.url;
|
|
28
|
+
var desc = attributes.desc;
|
|
29
|
+
var img = encodeURIComponent(parent.getAttribute("data-img") || "");
|
|
30
|
+
var via = encodeURIComponent(parent.getAttribute("data-via") || "");
|
|
35
31
|
|
|
36
|
-
|
|
37
|
-
email: ()
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
32
|
+
var actions = {
|
|
33
|
+
email: function() {
|
|
34
|
+
location.href = "mailto:?subject=" + title + "&body=" + url;
|
|
35
|
+
},
|
|
36
|
+
twitter: function() {
|
|
37
|
+
var hashtags = encodeURIComponent(el.getAttribute("data-" + site + "-hashtags") || parent.getAttribute("data-hashtags") || "");
|
|
38
|
+
var viaStr = via ? "&via=" + via : "";
|
|
39
|
+
window.SocialShare.openUrl("https://twitter.com/intent/tweet?url=" + url + "&text=" + title + "&hashtags=" + hashtags + viaStr, 650, 300);
|
|
40
|
+
},
|
|
41
|
+
facebook: function() {
|
|
42
|
+
window.SocialShare.openUrl("http://www.facebook.com/sharer/sharer.php?u=" + url, 555, 400);
|
|
43
|
+
},
|
|
44
|
+
google_bookmark: function() {
|
|
45
|
+
window.SocialShare.openUrl("https://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=" + url + "&title=" + title);
|
|
46
|
+
},
|
|
47
|
+
pinterest: function() {
|
|
48
|
+
window.SocialShare.openUrl("http://www.pinterest.com/pin/create/button/?url=" + url + "&media=" + img + "&description=" + title);
|
|
49
|
+
},
|
|
50
|
+
linkedin: function() {
|
|
51
|
+
window.SocialShare.openUrl("https://www.linkedin.com/shareArticle?mini=true&url=" + url + "&title=" + title + "&summary=" + desc);
|
|
52
|
+
},
|
|
53
|
+
vkontakte: function() {
|
|
54
|
+
window.SocialShare.openUrl("http://vk.com/share.php?url=" + url + "&title=" + title + "&image=" + img);
|
|
55
|
+
},
|
|
56
|
+
reddit: function() {
|
|
57
|
+
window.SocialShare.openUrl("http://www.reddit.com/submit?url=" + url + "&title=" + title + "&newwindow=1", 555, 400);
|
|
58
|
+
},
|
|
59
|
+
telegram: function() {
|
|
60
|
+
window.SocialShare.openUrl("https://telegram.me/share/url?text=" + title + "&url=" + url);
|
|
61
|
+
},
|
|
62
|
+
whatsapp_app: function() {
|
|
63
|
+
window.open("whatsapp://send?text=" + title + "%0A" + url, "_top");
|
|
64
|
+
},
|
|
65
|
+
whatsapp_web: function() {
|
|
66
|
+
window.SocialShare.openUrl("https://web.whatsapp.com/send?text=" + title + "%0A" + url);
|
|
67
|
+
}
|
|
52
68
|
};
|
|
53
69
|
|
|
54
|
-
if (actions[site])
|
|
70
|
+
if (actions[site]) {
|
|
71
|
+
actions[site]();
|
|
72
|
+
}
|
|
55
73
|
return false;
|
|
56
74
|
}
|
|
57
75
|
};
|
|
@@ -5,7 +5,7 @@ module SocialShareRails
|
|
|
5
5
|
is_rounded = opts.delete(:rounded) || false
|
|
6
6
|
|
|
7
7
|
html = []
|
|
8
|
-
html << "<div class='social-share' data-title='#{ERB::Util.html_escape(title)}'
|
|
8
|
+
html << "<div class='social-share' data-title='#{ERB::Util.html_escape(title)}'"
|
|
9
9
|
html << "data-url='#{opts[:url]}' data-desc='#{opts[:desc]}'>"
|
|
10
10
|
|
|
11
11
|
opts[:allow_sites].each do |name|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: social_share_rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gleydson Tavares
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2025-01-
|
|
11
|
+
date: 2025-01-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: i18n
|