(function($){
"use strict";
/*
* helper functions
*/
// abbreviate at last blank before length and add "\u2026" (horizontal ellipsis)
function abbreviateText(text, length) {
var abbreviated = decodeURIComponent(text);
if (abbreviated.length <= length) {
return text;
}
var lastWhitespaceIndex = abbreviated.substring(0, length - 1).lastIndexOf(' ');
abbreviated = encodeURIComponent(abbreviated.substring(0, lastWhitespaceIndex)) + "\u2026";
return abbreviated;
}
// returns content of tags or '' if empty/non existant
function getMeta(name) {
var metaContent = $('meta[name="' + name + '"]').attr('content');
return metaContent || '';
}
// create tweet text from content of and
// fallback to content of
tag
function getTweetText() {
var title = getMeta('DC.title');
var creator = getMeta('DC.creator');
if (title.length > 0 && creator.length > 0) {
title += ' - ' + creator;
} else {
title = $('title').text();
}
return encodeURIComponent(title);
}
// build URI from rel="canonical" or document.location
function getURI() {
var uri = document.location.href;
var canonical = $("link[rel=canonical]").attr("href");
if (canonical && canonical.length > 0) {
if (canonical.indexOf("http") < 0) {
canonical = document.location.protocol + "//" + document.location.host + canonical;
}
uri = canonical;
}
return uri;
}
function cookieSet(name, value, days, path, domain) {
var expires = new Date();
expires.setTime(expires.getTime() + (days * 24 * 60 * 60 * 1000));
document.cookie = name + '=' + value + '; expires=' + expires.toUTCString() + '; path=' + path + '; domain=' + domain;
}
function cookieDel(name, value, path, domain) {
var expires = new Date();
expires.setTime(expires.getTime() - 100);
document.cookie = name + '=' + value + '; expires=' + expires.toUTCString() + '; path=' + path + '; domain=' + domain;
}
$.fn.socialSharePrivacy = function(options){
var defaults = {
'services' : {
'facebook' : {
'status' : 'on',
'app_id' : '',
'dummy_img' : '',
'txt_info' : '2 Klicks für mehr Datenschutz: Erst wenn Sie hier klicken, wird der Button aktiv und Sie können Ihre Empfehlung an Facebook senden. Schon beim Aktivieren werden Daten an Dritte übertragen – siehe i.',
'txt_fb_off' : 'nicht mit Facebook verbunden',
'txt_fb_on' : 'mit Facebook verbunden',
'perma_option' : 'on',
'display_name' : 'Facebook',
'referrer_track' : '',
'the_permalink' : document.location.host,
'language' : 'de_DE',
'action' : 'recommend'
},
'twitter' : {
'status' : 'on',
'dummy_img' : '',
'txt_info' : '2 Klicks für mehr Datenschutz: Erst wenn Sie hier klicken, wird der Button aktiv und Sie können Ihre Empfehlung an Twitter senden. Schon beim Aktivieren werden Daten an Dritte übertragen – siehe i.',
'txt_twitter_off' : 'nicht mit Twitter verbunden',
'txt_twitter_on' : 'mit Twitter verbunden',
'perma_option' : 'on',
'display_name' : 'Twitter',
'reply_to' : '',
'tweet_text' : '',
'referrer_track' : '',
'the_permalink' : document.location.host,
'language' : 'de'
},
'gplus' : {
'status' : 'on',
'dummy_img' : '',
'txt_info' : '2 Klicks für mehr Datenschutz: Erst wenn Sie hier klicken, wird der Button aktiv und Sie können Ihre Empfehlung an Google+ senden. Schon beim Aktivieren werden Daten an Dritte übertragen – siehe i.',
'txt_gplus_off' : 'nicht mit Google+ verbunden',
'txt_plus_on' : 'mit Google+ verbunden',
'perma_option' : 'on',
'display_name' : 'Google+',
'referrer_track' : '',
'the_permalink' : document.location.host
}
},
'info_link' : 'http://www.heise.de/ct/artikel/2-Klicks-fuer-mehr-Datenschutz-1333879.html',
'txt_help' : 'Wenn Sie diese Felder durch einen Klick aktivieren, werden Informationen an Facebook, Twitter oder Google in die USA übertragen und unter Umständen auch dort gespeichert. Näheres erfahren Sie durch einen Klick auf das i.',
'settings_perma' : 'Dauerhaft aktivieren und Datenübertragung zustimmen:',
'cookie_path' : '/',
'cookie_domain' : document.location.host,
'cookie_expires' : '365',
'css_path' : ''
};
var options = $.extend(true, defaults, options);
var facebook_on = (options.services.facebook.status === 'on');
var twitter_on = (options.services.twitter.status === 'on');
var gplus_on = (options.services.gplus.status === 'on');
// check if at least one service is "on"
if (!facebook_on && !twitter_on && !gplus_on) {
return;
}
// insert stylesheet into document and prepend target element
if (options.css_path.length > 0) {
$('head').append('');
}
$(this).prepend('
');
var context = $('.social_share_privacy_area', this);
// canonical uri that will be shared
var uri = options.uri;
if (typeof uri === 'function') {
uri = uri();
}
// // Text kuerzen und am Ende mit … versehen, sofern er abgekuerzt werden musste
// function abbreviateText(text, length){
// var abbreviated = decodeURIComponent(text);
// if(abbreviated.length <= length){
// return text;
// }
//
// var lastWhitespaceIndex = abbreviated.substring(0, length - 1).lastIndexOf(' ');
// abbreviated = encodeURIComponent(abbreviated.substring(0, lastWhitespaceIndex)) + "…";
//
// return abbreviated;
// }
//
// // Meta-Wert abfragen
// function getMeta(name){
// var metaContent = jQuery('meta[name="' + name + '"]').attr('content');
// return metaContent ? metaContent : '';
// }
return this.each(function(){
// Facebook
// if(options.services.facebook.status == 'on'){
// // Kontrolle ob Facebook App-ID hinterlegt ist, da diese noetig fuer den Empfehlen-Button ist
// if(options.services.facebook.app_id != '__FB_APP-ID__'){
// var fb_enc_uri = encodeURIComponent(options.services.facebook.the_permalink+options.services.facebook.referrer_track);
// var fb_code = '';
// var fb_dummy_btn = '';
//
// if(context) {
// context.append('
');
// }
//
// var $container_gplus = $('li.gplus', context);
//
// $('li.gplus div.gplusone img,li.gplus span.switch', context).live('click', function(){
// if($container_gplus.find('span.switch').hasClass('off')){
// $container_gplus.addClass('info_off');
// $container_gplus.find('span.switch').addClass('on').removeClass('off').html(options.services.gplus.txt_gplus_on);
// $container_gplus.find('img.gplus_one_dummy').replaceWith(gplus_code);
// } else {
// $container_gplus.removeClass('info_off');
// $container_gplus.find('span.switch').addClass('off').removeClass('on').html(options.services.gplus.txt_gplus_off);
// $container_gplus.find('.gplusone').html(gplus_dummy_btn);
// }
// });
// }
//
// Google+
//
if (gplus_on) {
// fuer G+ wird die URL nicht encoded, da das zu einem Fehler fuehrt
var gplus_uri = options.services.gplus.the_permalink+options.services.gplus.referrer_track;
// we use the Google+ "asynchronous" code, standard code is flaky if inserted into dom after load
var gplus_code = '';
var gplus_dummy_btn = '';
context.append('