/* SimpleShare buttons (c) 2013-03-04 Schuttelaar & Partners */
(function($) {
$.fn.simpleShare = function(options) {
var getSource = function() {
var title = $('title').text();
var seperator = ' - ';
var lastIndex = title.lastIndexOf(seperator);
if (lastIndex === false) return false;
return title.substring(lastIndex + seperator.length);
}
var getTitleWithoutSource = function() {
var title = $('title').text();
var seperator = ' - ';
var lastIndex = title.lastIndexOf(seperator);
if (lastIndex === false) return false;
return title.substring(0, lastIndex);
}
var getDescr = function() {
var m = $('meta[name=description]');
if (m.length) return m.attr('content');
return false;
}
var settings = {
'title' : $('title').text(),
'descr' : getDescr(),
'url' : window.location.href,
'source' : getSource(),
'titleWithoutSource' : getTitleWithoutSource(),
'linkedin' : true,
'twitter' : true,
'facebook' : true,
'pinterest' : true,
'email' : true,
'whatsapp' : true,
'tracker' : false
};
if (options) {
$.extend(settings, options);
}
return this.each(function() {
var html = '';
var title = encodeURIComponent(settings.title);
var titleWithoutSource = encodeURIComponent(settings.titleWithoutSource);
var url = encodeURIComponent(settings.url);
var descr = encodeURIComponent(settings.descr);
var source = encodeURIComponent(settings.source);
var summaryPart = ''
if (settings.descr) summaryPart = '&summary=' + descr;
var berichtPart = ''
if (settings.descr) berichtPart = '&bericht=' + descr;
var sourcePart = '';
if (settings.source) sourcePart = '&source=' + source;
if (settings.linkedin) html += 'Share on LinkedIn';
if (settings.twitter) {
var via = $('meta[name="twitter:creator"]').attr('content');
if (!via) via = $('meta[name="twitter:site"]').attr('content');
via = (!via) ? '' : ' via ' + via;
html += '';
}
if (settings.facebook) html += 'Share on FaceBook';
if (settings.pinterest) {
var media = null;
var media = $('meta[property="og:image"]').attr('content');
if (!media) {
$('img').each(function() {
if (!media) media = this;
if ($(this).width() * $(this).height() > $(media).width() * $(media).height()) media = this;
});
media = $(media).prop('src');
}
if (media) html += 'Share on Pinterest';
}
if (settings.email) html += 'Share by email';
if (settings.whatsapp) html += 'Share by WhatsApp';
$(this).html(html);
if (settings.tracker) {
$('a', this).click(function() {
var match = this.className.match('(linkedin|twitter|facebook|pinterest)');
var service = (match[0]) ? match[0] : '';
window.location = settings.tracker + '?service=' + service + '&source=' + encodeURIComponent(window.location) + '&href=' + encodeURIComponent(this.href);
return false;
});
}
});
};
})(jQuery);