-
Notifications
You must be signed in to change notification settings - Fork 1
/
depage-social.js
189 lines (168 loc) · 6.78 KB
/
depage-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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
;(function($) {
if (!$.depage) {
$.depage = {};
}
$.depage.socialButtons = function(el, options){
// To avoid scope issues, use 'base' instead of 'this' to reference this class from internal events and functions.
var base = this;
// Access to jQuery and DOM versions of element
base.$el = $(el);
base.el = el;
// Add a reverse reference to the DOM object
base.$el.data("depage.socialButtons", base);
// {{{ init
base.init = function(){
base.options = $.extend({}, $.depage.socialButtons.defaultOptions, options);
if (base.options.url !== "") {
base.url = base.options.url;
} else if (base.$el.attr("data-share-url") !== undefined) {
base.url = base.$el.attr("data-share-url");
} else {
base.url = document.location.href;
}
if (base.options.title !== "") {
base.title = base.options.title;
} else if (base.$el.attr("data-share-title") !== undefined) {
base.title = base.$el.attr("data-share-title");
} else {
base.title = document.title;
}
base.title = encodeURIComponent(base.title);
base.url = encodeURIComponent(base.url);
base.$el.empty();
$.each(base.options.services, function(i, name) {
// normalize name
name = name.toLowerCase();
name = name.charAt(0).toUpperCase() + name.slice(1);
var functionName = 'add' + name;
if (typeof base[functionName] === 'function') {
base[functionName](name, location);
} else if (window.console) {
console.log("social button type '" + name + "' unknown.");
}
});
};
// }}}
// {{{ addSocialButton
base.addSocialButton = function(name, link, text) {
var html = "";
html += "<a class=\"" + name + "\" title=\"" + name + "\">";
if (base.options.assetPath !== "") {
// image link
html += "<img src=\"" + base.options.assetPath + name.toLowerCase() + ".png\" alt=\"" + name + "\">";
} else {
// text link
html += "<span class=\"" + name.toLowerCase() + "\">" + text + "</span>";
}
html += "</a>";
var $link = $(html).appendTo(base.$el);
if (link !== "") {
$link.attr("href", link);
}
if (link.substr(0, 4) == "http") {
$link.attr("target", "_blank");
$link.click(function() {
var w = 850;
var h = 500;
var options = "height=" + h + ",width=" + w + ",fullscreen=0,dependent=0,location=0,menubar=0,resizable=1,scrollbars=0,status=1,titlebar=0,toolbar=0";
return !window.open(this.href, name, options);
});
}
return $link;
};
// }}}
// {{{ addTwitter
base.addTwitter = function(name) {
var link = "http://twitter.com/share?text=" + base.title + "&url=" + base.url;
base.addSocialButton(name, link, "t");
};
// }}}
// {{{ addFacebookshare
base.addFacebookshare = function(name) {
var link = "http://www.facebook.com/sharer.php?t=" + base.title + "&u=" + base.url;
base.addSocialButton(name, link, "f");
};
// }}}
// {{{ addFacebooklike
base.addFacebooklike = function(name) {
if ($.browser && $.browser.msie && parseInt($.browser.version, 10) < 9) {
// opacity not supported
return;
}
var link = "";
var iframe = "<span class=\"over\"><iframe id=\"facebook\" src=\"//www.facebook.com/plugins/like.php?href=" + base.url + "&send=false&layout=standard&width=30&show_faces=false&action=like&colorscheme=light&height=30\" scrolling=\"no\" frameborder=\"0\" style=\"border:none; overflow:hidden; width:30px; height:30px;\" allowTransparency=\"true\"></iframe><span>";
base.addSocialButton(name, link, "♥");
$(iframe).appendTo(base.$el);
};
// }}}
// {{{ addGoogleplusshare
base.addGoogleplusshare = function(name) {
var link = "https://plusone.google.com/_/+1/confirm?url=" + base.url;
base.addSocialButton(name, link, "+1");
};
// }}}
// {{{ addLinkedin
base.addLinkedin = function(name) {
var link = "http://www.linkedin.com/cws/share?url=" + base.url;
base.addSocialButton(name, link, "li");
};
// }}}
// {{{ addXing
base.addXing = function(name) {
var link = "https://www.xing.com/app/user?op=share&url=" + base.url + ";title=" + base.title + ";";
base.addSocialButton(name, link, "xing");
};
// }}}
// {{{ addDigg
base.addDigg = function(name) {
var link = "http://digg.com/submit?url=" + base.url;
base.addSocialButton(name, link, "digg");
};
// }}}
// {{{ addReddit
base.addReddit = function(name) {
var link = "http://www.reddit.com/submit?url=" + base.url;
base.addSocialButton(name, link, "reddit");
};
// }}}
// {{{ addMail
base.addMail = function(name) {
var link = "mailto:?subject=" + base.title + "&body=" + base.url;
base.addSocialButton(name, link, "mail");
};
// }}}
// Run initializer
base.init();
};
/**
* Options
*
* @param assetPath - path to the asset-folder (with flash-player and images for buttons)
* @param twitter - add twitter buztton
* @param facebookShare - add facebook share button
* @param googleplusShare - add google+ share button
* @param facebookLike - add facebook like button
*/
$.depage.socialButtons.defaultOptions = {
assetPath: '',
url: '',
title: '',
services: [
'twitter',
'facebookShare',
'googleplusShare',
'facebookLike',
'mail',
'linkedin',
'xing',
'digg',
'reddit'
]
};
$.fn.depageSocialButtons = function(options) {
return this.each(function(){
(new $.depage.socialButtons(this, options));
});
};
})(jQuery);
/* vim:set ft=javascript sw=4 sts=4 fdm=marker : */