social_rails 2.1.5 → 3.0.0

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
  SHA1:
3
- metadata.gz: 382c98167b81ef2eb5540a2a3967b5d41432c78f
4
- data.tar.gz: 452ddc68d06784c9ea9ab8904648c9f5f4667275
3
+ metadata.gz: 60ef8763a3b5568a98a7a83c8d8be31effb2a7ee
4
+ data.tar.gz: 1a438a17ccb3c1e2148168a400da3f481639ddf4
5
5
  SHA512:
6
- metadata.gz: 2850c936194484c177bb30d4a5bd9f99e2f500c4b762fa3d8cb4060b210ed9b7fcbd6c1a920ec0a8dac1d307c73c7568570503e7ded69d32abd55fdf2407a75d
7
- data.tar.gz: 40ac15d079df913b816c0e6b5aaece731b2898ba0fcd6711d739c5a97189eb7a521502b31277e5c714005862f0de1868642f06a3e5e7dadcf2e2683161b6b0e9
6
+ metadata.gz: d0f6bd9b924ad5ec6811486874b1fbbb55d7e1ace14b3e19cd62813d627a18696ca7343399d61dff93fdd5c6a66614583921aee9594074ffef5e39bf6b0ff860
7
+ data.tar.gz: bef7740c827c635620dd9003b5ee551274d47e1cf77573f447d0511c7b0fd9b61f8ed540f4465de4e50a5c965408be7ee829353e2b3f097ac0f910ca276eb10b
@@ -6,27 +6,29 @@ window.SocialRails = () => {
6
6
  twitter: '/social/twitter'
7
7
  }
8
8
 
9
+ for (const placeholder of document.getElementsByClassName('js-social')) {
10
+ const namespace = placeholder.dataset.namespace
11
+ const node = document.getElementById(`social-${namespace}`)
12
+ const options = JSON.parse(node.dataset.options)
13
+ node.dataset.options = []
14
+ update_social_content(placeholder, { namespace, node, options })
15
+ }
9
16
 
10
- const placeholders = document.getElementsByClassName('js-social')
11
-
12
- for( let i = 0, len = placeholders.length; i < len; i++ ) {
13
-
14
- let namespace = placeholders[i].dataset.namespace
15
- let node = document.getElementById('social-' + namespace)
16
- let options = node.dataset.options
17
- let xhr = new XMLHttpRequest();
18
-
19
- // xhr.open('GET', `${routes[namespace]}?options=${options}`);
17
+ function update_social_content (placeholder, {namespace, node, options}) {
18
+ const xhr = new XMLHttpRequest()
20
19
  xhr.open('GET', routes[namespace])
21
20
 
22
21
  xhr.onload = () => {
23
- if (xhr.status === 200)
24
- node.outerHTML = xhr.responseText
25
- }
22
+ if (xhr.status === 200) {
23
+ node.innerHTML = xhr.responseText
24
+ }
26
25
 
26
+ if (options.refresh === true) {
27
+ setTimeout(() => update_social_content(placeholder, { namespace, node, options }), options.refresh_time)
28
+ }
29
+ }
27
30
  xhr.send()
28
31
  }
29
-
30
32
  }
31
33
 
32
34
  /* Auto init */
@@ -8,27 +8,55 @@ window.SocialRails = function () {
8
8
  twitter: '/social/twitter'
9
9
  };
10
10
 
11
- var placeholders = document.getElementsByClassName('js-social');
11
+ var _iteratorNormalCompletion = true;
12
+ var _didIteratorError = false;
13
+ var _iteratorError = undefined;
12
14
 
13
- var _loop = function _loop(i, len) {
15
+ try {
16
+ for (var _iterator = document.getElementsByClassName('js-social')[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
17
+ var placeholder = _step.value;
14
18
 
15
- var namespace = placeholders[i].dataset.namespace;
16
- var node = document.getElementById('social-' + namespace);
17
- var options = node.dataset.options;
18
- var xhr = new XMLHttpRequest();
19
+ var namespace = placeholder.dataset.namespace;
20
+ var node = document.getElementById('social-' + namespace);
21
+ var options = JSON.parse(node.dataset.options);
22
+ node.dataset.options = [];
23
+ update_social_content(placeholder, { namespace: namespace, node: node, options: options });
24
+ }
25
+ } catch (err) {
26
+ _didIteratorError = true;
27
+ _iteratorError = err;
28
+ } finally {
29
+ try {
30
+ if (!_iteratorNormalCompletion && _iterator.return) {
31
+ _iterator.return();
32
+ }
33
+ } finally {
34
+ if (_didIteratorError) {
35
+ throw _iteratorError;
36
+ }
37
+ }
38
+ }
19
39
 
20
- // xhr.open('GET', `${routes[namespace]}?options=${options}`);
40
+ function update_social_content(placeholder, _ref) {
41
+ var namespace = _ref.namespace,
42
+ node = _ref.node,
43
+ options = _ref.options;
44
+
45
+ var xhr = new XMLHttpRequest();
21
46
  xhr.open('GET', routes[namespace]);
22
47
 
23
48
  xhr.onload = function () {
24
- if (xhr.status === 200) node.outerHTML = xhr.responseText;
25
- };
49
+ if (xhr.status === 200) {
50
+ node.innerHTML = xhr.responseText;
51
+ }
26
52
 
53
+ if (options.refresh === true) {
54
+ setTimeout(function () {
55
+ return update_social_content(placeholder, { namespace: namespace, node: node, options: options });
56
+ }, options.refresh_time);
57
+ }
58
+ };
27
59
  xhr.send();
28
- };
29
-
30
- for (var i = 0, len = placeholders.length; i < len; i++) {
31
- _loop(i, len);
32
60
  }
33
61
  };
34
62
 
@@ -1,4 +1,4 @@
1
- <div class="js-social" id="social-<%= namespace %>" data-namespace="<%= namespace %>">
1
+ <div class="js-social" id="social-<%= namespace %>" data-namespace="<%= namespace %>" data-options="<%= options.to_json %>">
2
2
  <div class="spinner">
3
3
  <div class="double-bounce1"></div>
4
4
  <div class="double-bounce2"></div>
@@ -18,7 +18,7 @@ module SocialRails
18
18
  if valid_media(api)
19
19
  api = "SocialRails::API::#{api.to_s.capitalize}".constantize
20
20
  api.set_public_options(options)
21
- render partial: 'social_rails/shared/placeholder', locals: {namespace: api.uid}
21
+ render partial: 'social_rails/shared/placeholder', locals: {namespace: api.uid, options: api.config["public"]}
22
22
  end
23
23
  end
24
24
 
@@ -1,3 +1,3 @@
1
1
  module SocialRails
2
- VERSION = '2.1.5'
2
+ VERSION = '3.0.0'
3
3
  end
data/lib/social_rails.rb CHANGED
@@ -6,7 +6,9 @@ module SocialRails
6
6
  cooldown: 15.minutes,
7
7
  public: {
8
8
  max_characters: 0,
9
- post_count: 1
9
+ post_count: 1,
10
+ refresh: false,
11
+ refresh_time: 15.minutes.in_milliseconds
10
12
  }
11
13
  }
12
14
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.5
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francis G
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-30 00:00:00.000000000 Z
11
+ date: 2018-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  version: '0'
139
139
  requirements: []
140
140
  rubyforge_project:
141
- rubygems_version: 2.6.13
141
+ rubygems_version: 2.6.14
142
142
  signing_key:
143
143
  specification_version: 4
144
144
  summary: Ease the pain of integrating social media posts in a Rails app.