-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (52 loc) · 1.76 KB
/
index.js
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
var module.exports = exports = {}
exports.popit = function(method, params) {
params = params || {}
function _open(url, p) {
p = p || {}
var props = 'toolbar=0,' +
'status=0,' +
'width=%%,'.replace('%%', p['width'] || '1024') +
'height=%%,'.replace('%%', p['height'] || '500') +
'top=%%,'.replace('%%', p['top'] || '50') +
'left=%%'.replace('%%', p['left'] || '50')
return window.open(url, '_blank', props)
}
function _buildUrl(url, params, defaults) {
var lst = []
, _encuri = encodeURIComponent
if (defaults) {
for (var index in defaults) {
params[index] = params[index] || defaults[index]
}
}
for (var index in params) {
lst.push('%key=%val'.replace('%key', index)
.replace('%val', _encuri(params[index])))
}
return url + lst.join('&')
}
var defaults = {
fb: {
app_id: '334899416630508'
,redirect_uri: 'http://jsbin.com/ezoqac/2'
}
}
, url
if (method == 'facebook-update') {
url = _buildUrl('https://www.facebook.com/dialog/feed?',
params,
defaults.fb)
return _open(url, {title: 'Share on Facebook'})
}
if (method == 'twitter-tweet') {
url = _buildUrl('https://twitter.com/intent/tweet?', params)
return _open(url, {
width: '550'
,height: '420'
,top: '300'
,left: '300'
,title: 'Share on Twitter'
})
}
return
}