-
Notifications
You must be signed in to change notification settings - Fork 1
/
social.js
143 lines (128 loc) · 5.13 KB
/
social.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
(function($) {
'use strict';
var isOpera = !!navigator.userAgent.match(/Opera|OPR\//);
var defaults = {
// pinterest
//cover: 'assets/image/cover.png',
settings: {
envelope: {
height: 1,
url: 'mailto:?subject={{title}}&body={{summary}} {{url}}',
width: 1
},
facebook: {
height: 436,
url: 'https://www.facebook.com/sharer/sharer.php?u={{url}}',
width: 626
},
'google-plus': {
url: 'https://plus.google.com/share?url={{url}}'
},
linkedin: {
url: 'https://www.linkedin.com/shareArticle?mini=true&summary={{summary}}&title={{title}}&url={{url}}'
},
/*
pinterest: {
height: 500,
url: 'http://pinterest.com/pin/create/button/?description={{summary}}&media={{cover}}&url={{url}}',
width: 685
},
*/
star: {
height: 350,
unencoded: 1,
url: (isOpera) ? '{{url}}/#feedback-container' : '{{url}}/reviews',
width: 900
},
twitter: {
caller: 'rickypc2000',
height: 500,
url: 'https://twitter.com/share?text={{summary}}&url={{url}}&via={{caller}}',
width: 685
}
},
// all, except fb and g+
summary: 'Selenium Page Object Generator is a nimble and flexible #Selenium ' +
'#PageObjectModel #Generator to improve #Agile #Testing process velocity.',
target: (isOpera) ? 'https://addons.opera.com/en/extensions/details/selenium-page-object-generator' :
'https://chrome.google.com/webstore/detail/' + chrome.runtime.id,
// linkedin
title: 'Selenium Page Object Generator - to improve agile testing process velocity.'
};
function getFeatures(input) {
var features = {
copyhistory: 'no',
directories: 'no',
'location': 'no',
menubar: 'no',
resizable: 'no',
scrollbars: 'no',
'status': 'no',
toolbar: 'no'
};
var height = screen.height;
var left = window.screenLeft || screen.left;
var setting = input.context.settings[input.type] || {};
var top = window.screenTop || screen.top;
var width = screen.width;
features.height = setting.height || 600;
features.width = setting.width || 600;
features.left = (width / 2) - (features.width / 2);
features.top = (height / 2) - (features.height / 2);
return Object.keys(features).map(function(key) { return key + '=' + features[key]; }).join(',');
}
function getUrl(input) {
var context = input.context;
var setting = context.settings[input.type] || {};
var url = setting.url || '';
if (typeof(setting.caller) !== 'undefined') {
url = url.replace(/{{caller}}/g, encodeURIComponent(setting.caller));
}
if (!!setting.unencoded) {
url = url.replace(/{{cover}}/g, context.cover).
replace(/{{summary}}/g, context.summary).
replace(/{{title}}/g, context.title).
replace(/{{url}}/g, context.target);
}
else {
url = url.replace(/{{cover}}/g, encodeURIComponent(context.cover)).
replace(/{{summary}}/g, encodeURIComponent(context.summary)).
replace(/{{title}}/g, encodeURIComponent(context.title)).
replace(/{{url}}/g, encodeURIComponent(context.target));
}
return url;
}
$.fn.social = function (options) {
var context = $.extend({}, defaults, options);
return this.each(function() {
var $this = $(this);
var type = $this.attr('class').replace(/fa\s+|fa-/g, '');
$this.data('type', type);
if (type === 'envelope') {
$this[0].href = getUrl({ context: context, type: type });
$this[0].target = '_blank';
}
$this.bind('click', function (e) {
var $target = $(e.target);
var data = $target.data();
var win = true;
ga('send', 'event', data.type, 'click');
if (data.type !== 'envelope') {
if (!data.features) {
var features = getFeatures({ context:context, type:type });
$target.data('features', features);
data.features = features;
}
if (!data.url) {
var url = getUrl({ context: context, type: type });
$target.data('url', url);
data.url = url;
}
e.preventDefault();
win = window.open(data.url, data.type + '_window', data.features);
}
return win;
});
});
};
}(jQuery));