sharing_tags 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -0
- data/Todo.md +2 -3
- data/app/assets/javascripts/sharing_tags.js.coffee +3 -1
- data/app/assets/javascripts/sharing_tags/init.js.coffee +2 -0
- data/app/assets/javascripts/sharing_tags/links.js.coffee +6 -1
- data/app/assets/javascripts/sharing_tags/{share.coffee → share.js.coffee} +12 -8
- data/app/assets/javascripts/sharing_tags/share/facebook.coffee +64 -9
- data/lib/sharing_tags/action_view/button_helper.rb +2 -1
- data/lib/sharing_tags/version.rb +1 -1
- data/spec/javascripts/fixtures/facebook.json +18 -0
- data/spec/javascripts/sharing_tags/share/facebook_share_spec.coffee +101 -30
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5fb477566fe6d310fe532406ac33317b51a35826
|
4
|
+
data.tar.gz: 4cbc0cce2a9f871533146f65f09a5a3a6e274543
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04d3e69d58ed8925d52913d4b5ad77e4e4e11a81322aba836ba1ccf66aa2a7a77204782bdc951004273fa261f9b29d025498bb81d29814bf4790686349761e28
|
7
|
+
data.tar.gz: 182188e1a0e6267f740d5ff6c3c307e58e3de46eab0af85576e7c9d4f633da607de51fd0c83f98885dd2f6bb48dd3542e4dbc06308e0f993a308c27a4b097c06
|
data/README.md
CHANGED
@@ -95,6 +95,20 @@ end
|
|
95
95
|
|
96
96
|
```
|
97
97
|
|
98
|
+
### Javascript
|
99
|
+
|
100
|
+
You can subscribe to javascript events
|
101
|
+
|
102
|
+
```coffeescript
|
103
|
+
# click on sharing link
|
104
|
+
jQuery("body").on "sharing_tags.click_action", ({network, context, target})->
|
105
|
+
# your code
|
106
|
+
|
107
|
+
# after successful sharing
|
108
|
+
jQuery("body").on "sharing_tags.shared", ({network, context, target})->
|
109
|
+
# your code
|
110
|
+
```
|
111
|
+
|
98
112
|
## Tools for testing
|
99
113
|
|
100
114
|
Facebook Debugger (https://developers.facebook.com/tools/debug)
|
data/Todo.md
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
# TODO
|
2
2
|
|
3
|
-
* Write specs
|
3
|
+
* Write specs views/js/requests
|
4
|
+
* Init context running helper class on init railie (should work in console)
|
4
5
|
* Run js and ruby specs by default rake task
|
5
|
-
* Add default values to image networks
|
6
6
|
* Correct merge values in default context and defined
|
7
7
|
* Define network list
|
8
|
-
* Render icons with links
|
9
8
|
* Add to install task sample of view and require assets
|
10
9
|
* Add recommendation about image size and length of text
|
11
10
|
* Add version to sharing tags: append ?version=1 to links and assets
|
@@ -2,12 +2,17 @@
|
|
2
2
|
$(document).on 'click', "@sharing_tags_share", (event) ->
|
3
3
|
event.preventDefault()
|
4
4
|
self = $(@)
|
5
|
+
network = self.data('network')
|
6
|
+
context = self.data('context')
|
7
|
+
jQuery?("body").trigger(type: "sharing_tags.click_action", network: network, context: context, target: self)
|
8
|
+
|
5
9
|
SharingTags.share(
|
6
|
-
|
10
|
+
network,
|
7
11
|
mobile: device?.mobile() # for mobile devices
|
8
12
|
page_url: self.attr("href")
|
9
13
|
url: self.data 'share-url'
|
10
14
|
title: self.data 'title'
|
11
15
|
message: self.data 'description'
|
12
16
|
image: self.data 'image'
|
17
|
+
app_id: self.data 'app-id'
|
13
18
|
)
|
@@ -4,14 +4,17 @@ class @SharingTags
|
|
4
4
|
share_object = if attributes?.mobile then SharingTags.MobileShare else SharingTags.Share
|
5
5
|
share_object[network]?(attributes, callback)
|
6
6
|
|
7
|
-
#=require sharing_tags/share/facebook
|
8
7
|
class @Error extends Error
|
9
8
|
constructor: -> super
|
10
9
|
|
11
10
|
class @Share
|
12
11
|
|
13
|
-
@facebook: ({url}, callback) ->
|
14
|
-
|
12
|
+
@facebook: ({url, app_id}, callback) ->
|
13
|
+
if app_id
|
14
|
+
social_share = new SharingTags.FacebookShare url: url, app_id: app_id
|
15
|
+
social_share.share()
|
16
|
+
else
|
17
|
+
@_share("http://www.facebook.com/sharer.php", u: url, callback)
|
15
18
|
|
16
19
|
@twitter: ({url, message}, callback) ->
|
17
20
|
@_share("http://twitter.com/intent/tweet", text: message, url: url, callback)
|
@@ -52,6 +55,7 @@ class @SharingTags
|
|
52
55
|
if @_checkSharing(share_url, share_window, iteration)
|
53
56
|
clearInterval @interval
|
54
57
|
callback() if callback
|
58
|
+
jQuery?("body").trigger("sharing_tags.shared")
|
55
59
|
), 500)
|
56
60
|
|
57
61
|
@_checkSharing: (share_url, share_window, iteration)=>
|
@@ -61,11 +65,11 @@ class @SharingTags
|
|
61
65
|
class @MobileShare extends @Share
|
62
66
|
|
63
67
|
@facebook: ({url, return_url, app_id}, callback) ->
|
64
|
-
if app_id
|
65
|
-
return_url = url if !return_url
|
66
|
-
@_share("http://www.facebook.com/dialog/share", href: url, redirect_uri: return_url, app_id: app_id, display: 'touch', callback)
|
67
|
-
else
|
68
|
-
|
68
|
+
# if app_id
|
69
|
+
# return_url = url if !return_url
|
70
|
+
# @_share("http://www.facebook.com/dialog/share", href: url, redirect_uri: return_url, app_id: app_id, display: 'touch', callback)
|
71
|
+
# else
|
72
|
+
super
|
69
73
|
|
70
74
|
@twitter: ({title, url, message}, callback) ->
|
71
75
|
# todo: fix adding hash tags
|
@@ -5,33 +5,88 @@ class @SharingTags.BaseShare
|
|
5
5
|
description: null
|
6
6
|
|
7
7
|
constructor: ({@url, @title, @description})->
|
8
|
-
|
9
|
-
throw new SharingTags.Error("Error could not initialize sharing class, with params:#{ " #{arg}: '#{val}'" for arg, val of arguments[0]}")
|
8
|
+
@_assert_vars 'url'
|
10
9
|
|
11
|
-
|
10
|
+
_open_popup: (api_url, params)->
|
11
|
+
share_url = if params then "#{api_url}?#{$.param(params)}" else api_url
|
12
|
+
share_window = window.open share_url, 'Sharing', 'width=740,height=440'
|
13
|
+
|
14
|
+
clearInterval(@interval)
|
15
|
+
iteration = 0
|
16
|
+
@interval = setInterval((=>
|
17
|
+
iteration++
|
18
|
+
if @_checkSharing(share_url, share_window, iteration)
|
19
|
+
clearInterval @interval
|
20
|
+
jQuery("body").trigger("sharing_tags.shared") if jQuery
|
21
|
+
), 500)
|
22
|
+
|
23
|
+
_checkSharing: (share_url, share_window, iteration)=>
|
24
|
+
# console.log("check desktop sharing", share_url, share_window, iteration)
|
25
|
+
share_window?.closed || iteration >= 15
|
26
|
+
|
27
|
+
_after_callback: =>
|
28
|
+
jQuery?("body").trigger("sharing_tags.shared")
|
29
|
+
|
30
|
+
_assert_vars: (vars...)->
|
31
|
+
for var_name in vars
|
32
|
+
if ! @[var_name]
|
33
|
+
arguments_list = ''
|
34
|
+
arguments_list += " #{var_name}: '#{@[var_name]}'" for arg, val in vars
|
35
|
+
throw new SharingTags.Error("Error could not initialize sharing class, with params: #{arguments_list}")
|
12
36
|
|
13
37
|
class @SharingTags.FacebookShare extends @SharingTags.BaseShare
|
14
38
|
|
15
39
|
# available providers: sharer, fb_ui, dialog
|
16
40
|
@default_provider: "fb_ui"
|
17
|
-
@provider: "fb_ui"
|
18
41
|
|
19
42
|
app_id: null
|
20
43
|
return_url: null
|
21
44
|
provider: null
|
22
45
|
|
23
46
|
constructor: ({@app_id, @return_url, @provider})->
|
47
|
+
@provider = @_detect_provider() if !@provider
|
48
|
+
|
49
|
+
# todo: throw error for invalid provider
|
50
|
+
@constructor.init() if @provider is 'fb_ui' and not FB?
|
51
|
+
|
24
52
|
super
|
25
53
|
|
54
|
+
@init: (locale="en_US")->
|
55
|
+
if not FB?
|
56
|
+
jQuery.ajax(
|
57
|
+
url: "//connect.facebook.net/#{locale}/all.js"
|
58
|
+
dataType: "script"
|
59
|
+
cache: true
|
60
|
+
)
|
61
|
+
|
26
62
|
share: ()->
|
63
|
+
@["_#{@provider}"]()
|
64
|
+
|
65
|
+
_sharer: ->
|
66
|
+
@_assert_vars "url"
|
67
|
+
@_open_popup("http://www.facebook.com/sharer.php", u: @url)
|
27
68
|
|
28
|
-
|
29
|
-
|
69
|
+
_fb_ui: =>
|
70
|
+
@_assert_vars "url", "app_id"
|
71
|
+
return @constructor.init().done(@_fb_ui) if not FB?
|
30
72
|
|
31
|
-
|
73
|
+
FB?.ui(method: 'share', href: @url, app_id: @app_id, (response)=>
|
74
|
+
@_after_callback(response)
|
75
|
+
# if response && !response.error_code
|
76
|
+
# @_after_callback(response)
|
77
|
+
# else
|
78
|
+
# # another callback
|
79
|
+
)
|
32
80
|
|
33
|
-
|
81
|
+
_dialog: (display = 'page')->
|
82
|
+
@_assert_vars 'url', 'return_url'
|
83
|
+
@_open_popup("http://www.facebook.com/dialog/share", href: @url, redirect_uri: @return_url, app_id: @app_id, display: display)
|
34
84
|
|
35
85
|
|
36
|
-
|
86
|
+
_detect_provider: ->
|
87
|
+
# todo: detect provider by params
|
88
|
+
# try fb_ui url, app_id
|
89
|
+
# try dialog url, return_url
|
90
|
+
# try sharer url
|
37
91
|
|
92
|
+
@constructor.default_provider
|
@@ -8,7 +8,7 @@ module SharingTags::ActionView::ButtonHelper
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def link_to_facebook_share(name_or_options = nil, &block)
|
11
|
-
share_link_to name_or_options, :facebook, [], &block
|
11
|
+
share_link_to name_or_options, :facebook, [:app_id], &block
|
12
12
|
end
|
13
13
|
|
14
14
|
def link_to_vkontakte_share(name_or_options = nil, &block)
|
@@ -32,6 +32,7 @@ module SharingTags::ActionView::ButtonHelper
|
|
32
32
|
def share_link_to(name_or_options = nil, network = nil, data_params = [], &block)
|
33
33
|
params = sharing_tags[network]
|
34
34
|
data_attrs = params.get(*(data_params +[:network, :share_url]))
|
35
|
+
data_attrs[:context] = SharingTags.config.current_context.name
|
35
36
|
|
36
37
|
if block_given?
|
37
38
|
name_or_options = {} if !name_or_options || name_or_options.is_a?(String)
|
data/lib/sharing_tags/version.rb
CHANGED
@@ -11,5 +11,23 @@
|
|
11
11
|
"url": "http://partial.url",
|
12
12
|
"title": "Partial title",
|
13
13
|
"description": "Description"
|
14
|
+
},
|
15
|
+
|
16
|
+
"fb_ui": {
|
17
|
+
"url": "http://fb_ui.url",
|
18
|
+
"app_id": "123",
|
19
|
+
"provider": "fb_ui"
|
20
|
+
},
|
21
|
+
|
22
|
+
"dialog": {
|
23
|
+
"url": "http://dialog/share.url",
|
24
|
+
"return_url": "http://dialog/return.url",
|
25
|
+
"provider": "dialog"
|
26
|
+
},
|
27
|
+
|
28
|
+
"sharer": {
|
29
|
+
"url": "http://fb_ui.url",
|
30
|
+
"provider": "sharer"
|
14
31
|
}
|
32
|
+
|
15
33
|
}
|
@@ -44,43 +44,114 @@ describe "SharingTags.FacebookShare", ->
|
|
44
44
|
delete @fb_partial.url
|
45
45
|
expect(=> new subject(@fb_partial)).toThrow(SharingTags.Error(), /Error could not initialize sharing class/)
|
46
46
|
|
47
|
-
|
48
|
-
delete @fb_partial.title
|
49
|
-
expect(=> new subject(@fb_partial)).toThrow(SharingTags.Error(), /Error could not initialize sharing class/)
|
47
|
+
describe "share", ->
|
50
48
|
|
51
|
-
it "expect
|
52
|
-
|
53
|
-
|
49
|
+
it "expect call fb_ui sharing", ->
|
50
|
+
@share = new subject(@fb_fixture.fb_ui)
|
51
|
+
spyOn(@share, "_fb_ui")
|
52
|
+
|
53
|
+
@share.share()
|
54
|
+
expect(@share._fb_ui).toHaveBeenCalled()
|
55
|
+
|
56
|
+
it "expect call sharer sharing", ->
|
57
|
+
@share = new subject(@fb_fixture.sharer)
|
58
|
+
spyOn(@share, "_sharer")
|
59
|
+
|
60
|
+
@share.share()
|
61
|
+
expect(@share._sharer).toHaveBeenCalled()
|
62
|
+
|
63
|
+
it "expect call _dialog sharing", ->
|
64
|
+
@share = new subject(@fb_fixture.dialog)
|
65
|
+
spyOn(@share, "_dialog")
|
66
|
+
|
67
|
+
@share.share()
|
68
|
+
expect(@share._dialog).toHaveBeenCalled()
|
54
69
|
|
55
70
|
describe "share provider", ->
|
56
|
-
it "expect use default provider"
|
57
|
-
it "expect change default provider"
|
58
|
-
it "expect change provider on initialize"
|
59
71
|
|
72
|
+
it "expect fb_ui as default provider", ->
|
73
|
+
@share = new subject(@fb_fixture.full)
|
74
|
+
expect(@share.provider).toBe "fb_ui"
|
60
75
|
|
61
|
-
|
62
|
-
|
63
|
-
|
76
|
+
it "expect change provider to sharer on initialize", ->
|
77
|
+
@share = new subject(@fb_fixture.sharer)
|
78
|
+
expect(@share.provider).toBe "sharer"
|
64
79
|
|
65
80
|
describe "events", ->
|
66
81
|
it "expect trigger event start sharing"
|
67
82
|
it "expect trigger event after sharing"
|
68
83
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
84
|
+
describe "#_sharer", ->
|
85
|
+
beforeEach ->
|
86
|
+
@fb = @fb_fixture.sharer
|
87
|
+
@share = new subject(@fb)
|
88
|
+
spyOn(@share, "_open_popup")
|
89
|
+
|
90
|
+
it "expect call open popup with params", ->
|
91
|
+
@share._sharer()
|
92
|
+
expect(@share._open_popup).toHaveBeenCalled()
|
93
|
+
expect(@share._open_popup).toHaveBeenCalledWith("http://www.facebook.com/sharer.php", u: @fb.url)
|
94
|
+
|
95
|
+
it "expect error if init without url", ->
|
96
|
+
delete @share.url
|
97
|
+
expect(=> @share._sharer()).toThrow(SharingTags.Error(), /Error could not initialize sharing class/)
|
98
|
+
|
99
|
+
describe "#_dialog", ->
|
100
|
+
beforeEach ->
|
101
|
+
@fb = @fb_fixture.dialog
|
102
|
+
@share = new subject(@fb)
|
103
|
+
spyOn(@share, "_open_popup")
|
104
|
+
|
105
|
+
it "expect call open popup with params", ->
|
106
|
+
@share._dialog()
|
107
|
+
expect(@share._open_popup).toHaveBeenCalled()
|
108
|
+
expect(@share._open_popup).toHaveBeenCalledWith(
|
109
|
+
"http://www.facebook.com/dialog/share",
|
110
|
+
jasmine.objectContaining(href: @fb.url, redirect_uri: @fb.return_url, app_id: @fb.app_id, display: 'page')
|
111
|
+
)
|
112
|
+
|
113
|
+
it "expect error if init without return_url", ->
|
114
|
+
delete @share.return_url
|
115
|
+
expect(=> @share._dialog()).toThrow(SharingTags.Error(), /Error could not initialize sharing class/)
|
116
|
+
|
117
|
+
it "expect error if init without url", ->
|
118
|
+
delete @share.url
|
119
|
+
expect(=> @share._dialog()).toThrow(SharingTags.Error(), /Error could not initialize sharing class/)
|
120
|
+
|
121
|
+
|
122
|
+
describe "#_fb_ui", ->
|
123
|
+
beforeEach ->
|
124
|
+
@fb = @fb_fixture.fb_ui
|
125
|
+
@share = new subject(@fb)
|
126
|
+
window.FB
|
127
|
+
|
128
|
+
afterEach ->
|
129
|
+
delete window.FB
|
130
|
+
|
131
|
+
describe "loaded FB js SDK", ->
|
132
|
+
beforeEach ->
|
133
|
+
window.FB = jasmine.createSpyObj "FB", ['ui', 'init']
|
134
|
+
|
135
|
+
it "expect call FB.ui method with params", ->
|
136
|
+
@share._fb_ui()
|
137
|
+
expect(FB.ui).toHaveBeenCalled()
|
138
|
+
expect(FB.ui).toHaveBeenCalledWith(
|
139
|
+
jasmine.objectContaining(app_id: @fb.app_id, href: @fb.url, method: 'share'),
|
140
|
+
jasmine.any(Function)
|
141
|
+
)
|
142
|
+
|
143
|
+
it "expect error if init without url", ->
|
144
|
+
delete @share.url
|
145
|
+
expect(=> @share._fb_ui()).toThrow(SharingTags.Error(), /Error could not initialize sharing class/)
|
146
|
+
|
147
|
+
describe "loading FB.ui", ->
|
148
|
+
beforeEach ->
|
149
|
+
spyOn(@share.constructor, "init").andCallThrough()
|
150
|
+
spyOn(@share, "_fb_ui").andCallThrough()
|
151
|
+
|
152
|
+
it "expect load FB.ui if FB undefined", ->
|
153
|
+
expect(typeof FB).toBe('undefined')
|
154
|
+
|
155
|
+
@share._fb_ui()
|
156
|
+
expect(@share.constructor.init).toHaveBeenCalled()
|
157
|
+
expect(@share._fb_ui).toHaveBeenCalled()
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sharing_tags
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anatoliy Kovalchuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -287,8 +287,9 @@ files:
|
|
287
287
|
- app/assets/images/sharing_tags/icons/twitter.svg
|
288
288
|
- app/assets/images/sharing_tags/icons/vkontakte.svg
|
289
289
|
- app/assets/javascripts/sharing_tags.js.coffee
|
290
|
+
- app/assets/javascripts/sharing_tags/init.js.coffee
|
290
291
|
- app/assets/javascripts/sharing_tags/links.js.coffee
|
291
|
-
- app/assets/javascripts/sharing_tags/share.coffee
|
292
|
+
- app/assets/javascripts/sharing_tags/share.js.coffee
|
292
293
|
- app/assets/javascripts/sharing_tags/share/facebook.coffee
|
293
294
|
- app/assets/stylesheets/sharing_tags.css.sass
|
294
295
|
- app/assets/stylesheets/sharing_tags/icons.css.sass
|