2
2
3
3
Social share widget supporting: wechat, weibo, linkedin, github, google+, rss, twitter, facebook and more.
4
4
5
- Demo: http://harttle.com/social-share/
5
+ Live Demo: http://harttle.com/social-share/
6
6
7
- Dependencies [ Fontawesome] [ font ] , [ jQuery ] [ jq ] .
7
+ Dependencies: [ Fontawesome] [ font ]
8
8
9
- ## Usage
9
+ ## Installation
10
10
11
- ### Import
12
-
13
- Import jQuery and Fontawesome:
11
+ Import Fontawesome:
14
12
15
13
``` html
16
14
<link rel =" stylesheet" href =" https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" >
17
- <script src =" https://code.jquery.com/jquery-2.1.4.min.js" ></script >
18
15
```
19
16
20
17
Import Social Share:
@@ -24,54 +21,114 @@ Import Social Share:
24
21
<script src =" path/to/social-share.min.js" ></script >
25
22
```
26
23
27
- ### Mininal Usage
24
+ ## Mininal Usage
28
25
29
- ``` javascript
30
- $ (' div' ).socialShare ({
31
- facebook: ' https://www.facebook.com/harttle' ,
32
- wechat: location .href ,
33
- rss: ' http://harttle.com/feed.xml'
34
- });
26
+ ``` html
27
+ <div id =" share-area" ></div >
35
28
```
36
29
37
- ### Ordered Links
30
+ ``` javascript
31
+ var el = document .getElementById (' share-area' );
32
+ var links = [{
33
+ url: ' http://harttle.com' ,
34
+ target: ' _qrcode'
35
+ }, {
36
+ plugin: ' github' ,
37
+ url: ' http://github.com/harttle'
38
+ }, {
39
+ plugin: ' github' ,
40
+ args: {
41
+ id: ' harttle'
42
+ }
43
+ }];
44
+ window .socialShare (el, links);
45
+ ```
38
46
39
- In case you want these links be ordered, put them into an array:
47
+ ## Full Usage
40
48
41
49
``` javascript
42
50
var links = [{
43
- style: ' facebook' ,
44
- url: ' https://www.facebook.com/harttle'
45
- },{
46
- style: ' google-plus' ,
47
- url: ' https://plus.google.com/+杨珺' ,
48
- },{
49
- style: ' weibo' ,
50
- url: ' http://v.t.sina.com.cn/share/share.php?url=xxx&title=xxx&appid=xxx'
51
+ url: ' http://harttle.com' ,
52
+ target: ' _qrcode' ,
53
+ color: ' #fff' ,
54
+ background: ' #b5b5b5' ,
55
+ icon: ' fa-code-fork' ,
56
+ plugin: ' github' ,
57
+ args: {
58
+ id
59
+ }
51
60
}];
52
-
53
- $ (' div' ).socialShare (links);
61
+ var options = {
62
+ size: ' md'
63
+ };
64
+ window .socialShare (el, links, options);
54
65
```
55
66
56
- ### Available Styles
67
+ ## Options
68
+
69
+ ### links.url
57
70
58
- These are available styles:
71
+ Type: ` String `
59
72
60
- ` qrcode ` , ` facebook ` , ` google-plus ` , ` weibo ` , ` wechat ` , ` linkedin ` , ` rss ` , ` github ` , ` twitter ` .
73
+ Default: ` location.href `
61
74
62
- > Feel free to contribute yours!
75
+ The url of this icon. Typically, ` links.url ` will be set to the ` href ` attribute
76
+ of the corresponding anchor.
63
77
64
- ## Options
78
+ ### links.target
65
79
66
- ### $.fn.socialShare(links, options)
80
+ Type: ` String `
81
+
82
+ Default: ` "" `
83
+
84
+ This will be set to the ` target ` attribute of the anchor.
85
+ Available targets: ` "_self" ` , ` "_parent" ` , ` "_blank" ` , ` "_top" ` , ` "_qrcode" `
86
+ If set to ` _qrcode ` , the ` links.url ` will be opened as a qrcode image within a modal.
87
+
88
+ ### links.icon
89
+
90
+ Type: ` String `
91
+
92
+ Default: ` 'fa-code-fork' `
93
+
94
+ The Fontawesome icon class for the share button.
95
+
96
+ ### links.color
97
+
98
+ Type: ` String `
67
99
68
- ### links
100
+ Defalt: ` '#fff' `
101
+
102
+ The color of the Fontawesome icon.
103
+
104
+ ### links.background
105
+
106
+ Type: ` String `
107
+
108
+ Default: ` '#b5b5b5' `
109
+
110
+ The background of the Fontawesome icon.
111
+
112
+ ### links.plugin
113
+
114
+ Type: ` String `
115
+
116
+ Default: ` undefined `
117
+
118
+ The plugin to use. Typically, a plugin is used to generage
119
+ the above settings, according to the arguments set by ` links.args ` .
120
+
121
+ Note: Settings within ` links ` will override the settings returned by a plugin.
122
+ For example, ` github ` plugin responds with the url ` //foo ` ,
123
+ while ` links.url ` is set to ` //bar ` . The result url will be ` //bar ` .
124
+
125
+ ### links.args
69
126
70
127
Type: ` Object `
71
128
72
129
Default: ` {} `
73
130
74
- Share buttons are set in ` links ` object .
131
+ The arguments passed to the plugin, which is specified by ` links.plugin ` .
75
132
76
133
### options.size
77
134
@@ -86,25 +143,165 @@ Size of the buttons, available values:
86
143
* ` "sm" ` (small)
87
144
* ` "xs" ` (exteme small)
88
145
89
- ### options.blank
146
+ ## Plugin List
90
147
91
- Type: ` Boolean `
148
+ ### Weibo(微博)
92
149
93
- Default: ` true `
150
+ All args will be append to URL query string.
94
151
95
- Should the links open in new window? If set ` true ` , ` target="_blank" ` will be set.
152
+ ``` javascript
153
+ var link = {
154
+ plugin: ' weibo' ,
155
+ args: {
156
+ appid: ' <your App ID>' , // Default: ''
157
+ title: ' About Harttle' , // Default: document.title
158
+ url: ' //harttle.com/about.html' // Default: location.href
159
+ source: ' http://harttle.com' // Any other query string you need...
160
+ }
161
+ };
162
+ ```
96
163
97
- ## links. url
164
+ > ` appid ` 是微博认证的App ID,便于微博跟踪。 ` title ` 和 ` url ` 用于微博分享内容和参考链接。
98
165
99
- Type: ` String `
166
+ ### Wechat(微信)
100
167
101
- The ` href ` attribute for the the share button. For ` "wechat" ` , ` links.url ` is the url encoded within the qrcode img.
168
+ ``` javascript
169
+ var link = {
170
+ plugin: ' wechat'
171
+ };
172
+ ```
173
+
174
+ ` wechat ` plugin accept no arguments, while you can still set ` links ` properties:
175
+
176
+ ``` javascript
177
+ var link = {
178
+ plugin: ' wechat' ,
179
+ url: ' //yet.another.url' ,
180
+ color: ' yellow'
181
+ };
182
+ ```
183
+
184
+ ### QR Code(二维码)
185
+
186
+ ``` javascript
187
+ var link = {
188
+ plugin: ' qrcode'
189
+ };
190
+ ```
191
+
192
+ Just like ` wechat ` plugin, with different background and icon.
193
+
194
+ ### RSS
195
+
196
+ ``` javascript
197
+ var link = {
198
+ plugin: ' rss'
199
+ };
200
+ ```
201
+
202
+ ### Github
203
+
204
+ ``` javascript
205
+ var link = {
206
+ plugin: ' github' ,
207
+ args: {
208
+ id: ' harttle' // Your Github ID
209
+ }
210
+ };
211
+ ```
212
+
213
+ ### Linkedin
214
+
215
+ ``` javascript
216
+ var link = {
217
+ plugin: ' linkedin' ,
218
+ args: {
219
+ id: ' harttle' // Your linkedin ID
220
+ }
221
+ };
222
+ ```
223
+
224
+ ### Google Plus
225
+
226
+ ``` javascript
227
+ var link = {
228
+ plugin: ' google-plus' ,
229
+ args: {
230
+ id: ' harttle' // Your Google+ ID
231
+ }
232
+ };
233
+ ```
234
+
235
+ ### Twitter
236
+
237
+ ``` javascript
238
+ var link = {
239
+ plugin: ' twitter' ,
240
+ args: {
241
+ id: ' harttleharttle' // Your twitter ID
242
+ }
243
+ };
244
+ ```
245
+
246
+ ### Facebook
247
+
248
+ ``` javascript
249
+ var link = {
250
+ plugin: ' facebook' ,
251
+ args: {
252
+ id: ' harttle' // Your facebook ID
253
+ }
254
+ }
255
+ ```
256
+
257
+ ## How to Write Plugins
258
+
259
+ Plugins are used to generate a ` link ` Object according to the ` links.args ` .
260
+ For example, the ` github ` plugin:
261
+
262
+ ``` javascript
263
+ (function (socialShare ) {
264
+ socialShare .plugin (' github' , function (args ) {
265
+ return {
266
+ url: ' https://github.com/' + args .id ,
267
+ background: ' #b5b5b5' ,
268
+ icon: ' fa-github'
269
+ };
270
+ });
271
+ })(window .socialShare );
272
+ ```
273
+
274
+ To use this plugin, simply set ` plugin ` to ` "github" ` , and specify the args:
275
+
276
+ ``` js
277
+ var links = [{
278
+ plugin: ' github' ,
279
+ args: {
280
+ id: ' harttle'
281
+ }
282
+ }];
283
+ ```
284
+
285
+ Which is equavalent to:
286
+
287
+ ``` js
288
+ var links = [{
289
+ url: ' https://github.com/harttle' ,
290
+ background: ' #b5b5b5' ,
291
+ icon: ' fa-github'
292
+ }];
293
+ ```
102
294
103
- ## links.index
295
+ ## Contribution Guideline
104
296
105
- Type: ` Number `
297
+ It's wellcome to make contributions by any means.
298
+ While we suggest the following guide lines:
106
299
107
- Optional, share buttons are sorted by ` links.index ` .
300
+ 1 . Fork this repo.
301
+ 2 . Add your plugin within ` src/plugins/ ` .
302
+ 3 . Run ` grunt ` to build the ` dist/ ` files.
303
+ 4 . Test your plugin in ` demo/index.js `
304
+ 4 . Commit and make a pull request.
108
305
109
306
[ font ] : http://fontawesome.io/
110
307
[ jq ] : http://jquery.com/
0 commit comments