-
Notifications
You must be signed in to change notification settings - Fork 1
/
rsb.js
87 lines (65 loc) · 3.47 KB
/
rsb.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
/* Global Variables */
var globalUrl = encodeURI(document.location);
var globalMessage = document.title;
var rsb = function(settings) {
var defaultSettings = {
selector: '.rsb',
position: 'top',
zIndex: 10,
facebookShareUrl: globalUrl,
twitterShareUrl: globalUrl,
twitterShareMessage: globalMessage,
twitterUsername: '',
pinterestShareUrl: globalUrl,
pinterestDescription: globalMessage,
googleplusUrl: globalUrl,
emailSubject: globalMessage,
emailMessage: globalUrl,
emailTo: ''
};
settings = $.extend(defaultSettings, settings);
/* Add default class used in css */
$(settings.selector).addClass('rsb-wrapper');
/* Append our html code */
$(settings.selector).append('<div class="rsb-trigger"></div><div class="rsb-buttons"><a class="facebook">Facebook</a><a class="twitter">Twitter</a><a class="pinterest">Twitter</a><a class="googleplus">Email</a><a class="email">E-mail</a></div>');
/* Set main class to determine where the buttons go, working values are top, and bottom. Default is top, any incorrect value will return top */
if(settings.position === 'bottom') {
$(settings.selector).addClass(settings.position);
}
else {
$(settings.selector).addClass('top');
}
/* Add child classes instead of using :nth-child in css. This could probably look also look at the social media class instead. */
$(settings.selector).find('.rsb-buttons').each(function() {
$(this).find('a').each(function(i) {
$(this).addClass("rsb-item-"+(i+1));
});
});
/* Set z-index from variable so we can play nicely with other z-index objects */
$(settings.selector).css('z-index', settings.zIndex);
$(settings.selector).find('.rsb-trigger').css('z-index', settings.zIndex+15);
$(settings.selector).find('.rsb-buttons').css('z-index', settings.zIndex+5);
$(settings.selector).find('.rsb-buttons a').css('z-index', settings.zIndex+10);
/* Link customization */
/* Twitter */
if(settings.twitterUsername != '') {
settings.twitterUsername = "&via=" + settings.twitterUsername;
}
/* Links */
$(settings.selector).find('.rsb-buttons a:not(.email)').attr("onclick", "javascript:window.open(this.href,'', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=335,width=600');return false;");
$(settings.selector).find('.rsb-buttons .facebook').attr('href', "https://www.facebook.com/sharer/sharer.php?u=" + settings.facebookShareUrl);
$(settings.selector).find('.rsb-buttons .twitter').attr('href', "http://twitter.com/share?url=" + settings.twitterShareUrl + settings.twitterUsername + "&text=" + settings.twitterShareMessage);
$(settings.selector).find('.rsb-buttons .pinterest').attr('href', "http://pinterest.com/pin/create/link/?url=" + settings.pinterestShareUrl + "&description=" + settings.pinterestDescription);
$(settings.selector).find('.rsb-buttons .googleplus').attr({
href: "https://plus.google.com/share?url=" + settings.googleplusUrl,
onclick: "javascript:window.open(this.href,'', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;"
});
$(settings.selector).find('.rsb-buttons .email').attr('href', "mailto:" + settings.emailTo + "?Subject=" + settings.emailSubject + "&Body=" + settings.emailMessage);
/* Do stuff! */
$(settings.selector).find('.rsb-trigger').each(function() {
$(this).click(function() {
$(this).parent().toggleClass('open');
});
});
console.log(settings.globalShareUrl);
};