-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathshareit.coffee
80 lines (72 loc) · 2.64 KB
/
shareit.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
script_loader = (url, id, d = document) ->
unless d.getElementById id
fjs = d.getElementsByTagName('script')[0]
js = d.createElement 'script'
js.async = true
js.id = id
js.src = url
fjs.parentNode.insertBefore js, fjs
ShareIt =
# plain location is wrong on spiderable.
location:
host: Meteor.bindEnvironment () ->
Meteor.absoluteUrl().replace(/^http:\/\/|^https:\/\//, '').replace(/\/$/, '')
href: Meteor.bindEnvironment () ->
Meteor.absoluteUrl().replace(/\/$/, '') + location.pathname
origin: Meteor.bindEnvironment () ->
Meteor.absoluteUrl().replace(/\/$/, '')
pathname: Meteor.bindEnvironment () ->
location.pathname # "/showcontent/awjdaf2384" whatever the server location
hostname: Meteor.bindEnvironment () ->
Meteor.absoluteUrl().replace(/^http:\/\/|^https:\/\//, '').replace(/\/$/, '')
settings:
autoInit: true
buttons: 'responsive'
sites:
facebook:
'appId': null
'version': 'v2.3'
'description': ''
'buttonText': 'Share on Facebook'
twitter:
'description': ''
'buttonText': 'Share on Twitter'
googleplus:
'description': ''
'buttonText': 'Share on Google+'
pinterest:
'description': ''
'buttonText': 'Share on Pinterest'
instagram:
'description': ''
'buttonText': 'Share on Instagram'
siteOrder: []
classes: 'large btn'
iconOnly: false
faSize: ''
faClass: ''
applyColors: true
configure: (params) ->
$.extend true, @settings, params if params?
helpers:
classes: -> ShareIt.settings.classes
showText: (text) -> not ShareIt.settings.iconOnly and " #{text}"
applyColors: (cssClasses) -> ShareIt.settings.applyColors and " #{cssClasses}"
faSize: -> ShareIt.settings.faSize
faClass: -> ShareIt.settings.faClass and "-#{ShareIt.settings.faClass}"
buttonText: ->
facebook: ShareIt.settings.sites.facebook.buttonText
twitter: ShareIt.settings.sites.twitter.buttonText
googleplus: ShareIt.settings.sites.googleplus.buttonText
pinterest: ShareIt.settings.sites.pinterest.buttonText
instagram: ShareIt.settings.sites.instagram.buttonText
init: (params) ->
@configure params if params?
# Twitter
script_loader '//platform.twitter.com/widgets.js', 'twitter-wjs'
# Facebook
if @settings.autoInit and @settings.sites.facebook?
window.fbAsyncInit = =>
FB.init @settings.sites.facebook
$('<div id="fb-root"></div>').appendTo 'body' unless $('#fb-root').get(0)?
script_loader '//connect.facebook.net/en_US/sdk.js', 'facebook-jssdk'