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: 0a5e5022502b24e0bbbe02289f1463518b396cef89ef035d1883f0b6e4b3cd7f
4
- data.tar.gz: eb99ec063ec71398a13d6564ddd31cec74f536a7cc2606dff6aaf45fcd1086f7
3
+ metadata.gz: 85d29c515c9f74ebe29e62778560b8c6705fd32555c11ce9333aac73e7f770db
4
+ data.tar.gz: 07f845311fd9ec5647a853658c605b76e34f7d5707cbc8cb87d6bf28ef0ce45d
5
5
  SHA512:
6
- metadata.gz: 19ff97f4c7f5a5f75e1d4d59b90e4317369debf9d37380890663c807c224e6a289eb2bcad9f3a87d7b96d2436bff08494a2e6f898b7c3dccc4e27b212adab28d
7
- data.tar.gz: f2fcc111e1b7e6d9130786211199a4a01505dc7a26174b03021c1c8fddc12911a12fbbba95a6d7dffb25f1a39b5ae32f47932e76436a62988e816fa75653d22a
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 = 640, height = 480) {
3
- const left = (screen.width / 2) - (width / 2);
4
- const top = (screen.height * 0.3) - (height / 2);
5
- const options = `width=${width},height=${height},left=${left},top=${top},menubar=no,status=no,location=no`;
6
- window.open(url, 'popup', options);
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
- const result = {};
12
- keys.forEach(key => {
13
- result[key] = encodeURIComponent(el.getAttribute(`data-${site}-${key}`) || parent.getAttribute(`data-${key}`) || '');
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
- const site = el.getAttribute("data-site");
29
- const parent = el.parentNode;
30
- const { title, url, desc } = this.getEncodedAttributes(el, site, parent, ['title', 'url', 'desc']);
31
- const img = encodeURIComponent(parent.getAttribute("data-img") || '');
32
- const via = encodeURIComponent(parent.getAttribute("data-via") || '');
33
-
34
- this.trackEvent(site);
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
- const actions = {
37
- email: () => location.href = `mailto:?subject=${title}&body=${url}`,
38
- twitter: () => {
39
- const hashtags = encodeURIComponent(el.getAttribute(`data-${site}-hashtags`) || parent.getAttribute('data-hashtags') || '');
40
- const viaStr = via ? `&via=${via}` : '';
41
- this.openUrl(`https://twitter.com/intent/tweet?url=${url}&text=${title}&hashtags=${hashtags}${viaStr}`, 650, 300);
42
- },
43
- facebook: () => this.openUrl(`http://www.facebook.com/sharer/sharer.php?u=${url}`, 555, 400),
44
- google_bookmark: () => this.openUrl(`https://www.google.com/bookmarks/mark?op=edit&output=popup&bkmk=${url}&title=${title}`),
45
- pinterest: () => this.openUrl(`http://www.pinterest.com/pin/create/button/?url=${url}&media=${img}&description=${title}`),
46
- linkedin: () => this.openUrl(`https://www.linkedin.com/shareArticle?mini=true&url=${url}&title=${title}&summary=${desc}`),
47
- vkontakte: () => this.openUrl(`http://vk.com/share.php?url=${url}&title=${title}&image=${img}`),
48
- reddit: () => this.openUrl(`http://www.reddit.com/submit?url=${url}&title=${title}&newwindow=1`, 555, 400),
49
- telegram: () => this.openUrl(`https://telegram.me/share/url?text=${title}&url=${url}`),
50
- whatsapp_app: () => window.open(`whatsapp://send?text=${title}%0A${url}`, '_top'),
51
- whatsapp_web: () => this.openUrl(`https://web.whatsapp.com/send?text=${title}%0A${url}`)
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]) 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)}' data-img='#{opts[:image]}'"
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|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SocialShareRails
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
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.0
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-07 00:00:00.000000000 Z
11
+ date: 2025-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n