-
Notifications
You must be signed in to change notification settings - Fork 1
/
sharefree.js
85 lines (75 loc) · 3.63 KB
/
sharefree.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
/**
* ShareFree - Free social bookmarks for your site.
*
* Copyright 2013 by Gregor Gresak <[email protected]>
*
* ShareFree free software: you can redistribute
* it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* Some open source application is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*
* @license GPL-3.0+ <http://spdx.org/licenses/GPL-3.0+>
*/
(function($) {
$.fn.sharefree = function(options) {
var defaults = {
sfDialogWidth: 600,
sfDialogHeight: 450,
template: 'smallicons',
templates:{
smallicons:'<div class="sharefree">\n\
<a class="sf-facebook" href="#"><img src="img/facebook16.gif" alt="fb" class="sf-image"></a>\n\
<a class="sf-twitter" href="#"><img src="img/twitter16.jpg" alt="tw" class="sf-image"></a>\n\
<a class="sf-gplus" href="#"><img src="img/gplus16.jpg" alt="g+" class="sf-image"></a>\n\
<a class="sf-pinterest" href="#"><img src="img/pinterest16.png" alt="p" class="sf-image"></a>\n\
<a class="sf-email" href="#"><img src="img/email16.gif" alt="@" class="sf-image"></a>\n\
</div>\n',
bigicons:'<div class="sharefree">\n\
<a class="sf-facebook" href="#"><img src="img/facebook.png" alt="fb" class="sf-image"></a>\n\
<a class="sf-twitter" href="#"><img src="img/twitter.gif" alt="tw" class="sf-image"></a>\n\
<a class="sf-gplus" href="#"><img src="img/gplus.jpg" alt="g+" class="sf-image"></a>\n\
<a class="sf-pinterest" href="#"><img src="img/pinterest.png" alt="p" class="sf-image"></a>\n\
<a class="sf-email" href="#"><img src="img/email.png" alt="@" class="sf-image"></a>\n\
</div>\n'}
};
var options = $.extend(defaults, options);
var sfTitle = encodeURIComponent($("title").text());
var currentUrl= encodeURIComponent($(location).attr('href'))
var fblink= "https://www.facebook.com/sharer/sharer.php?u=" + currentUrl
var twlink = "http://twitter.com/share?text=" + sfTitle + "&url=" + currentUrl
var gplink = "https://plus.google.com/share?url=" + currentUrl
var pilink = "http://pinterest.com/pin/find/?url=" + currentUrl
var emlink = "mailto:?subject=" + sfTitle + "&body=" + currentUrl
function createDOM(obj){
$(obj).append(options.templates[options.template]);
}
return this.each(function() {
createDOM(this);
$(".sf-facebook").click(function(event){
event.preventDefault();
window.open(fblink, 'fbshare', 'width=' + options.sfDialogWidth + ',height=' + options.sfDialogHeight);
});
$(".sf-twitter").click(function(event){
event.preventDefault();
window.open(twlink, 'twittershare', 'width=' + options.sfDialogWidth + ',height=' + options.sfDialogHeight);
});
$(".sf-gplus").click(function(event){
event.preventDefault();
window.open(gplink, 'gplusshare', 'width=' + options.sfDialogWidth + ',height=' + options.sfDialogHeight);
});
$(".sf-pinterest").click(function(event){
event.preventDefault();
window.open(pilink, 'pinshare', 'width=' + options.sfDialogWidth + ',height=' + options.sfDialogHeight);
});
$(".sf-email").attr("href",emlink);
});
}
})(jQuery)