1/* 2 * jquery.socialshareprivacy.js | 2 Klicks fuer mehr Datenschutz 3 * 4 * http://www.heise.de/extras/socialshareprivacy/ 5 * http://www.heise.de/ct/artikel/2-Klicks-fuer-mehr-Datenschutz-1333879.html 6 * 7 * Copyright (c) 2011 Hilko Holweg, Sebastian Hilbig, Nicolas Heiringhoff, Juergen Schmidt, 8 * Heise Zeitschriften Verlag GmbH & Co. KG, http://www.heise.de 9 * 10 * is released under the MIT License http://www.opensource.org/licenses/mit-license.php 11 * 12 * Spread the word, link to us if you can. 13 */ 14function loadSocialSharePrivacy($) { 15 16 "use strict"; 17 18 /* 19 * helper functions 20 */ 21 22 // abbreviate at last blank before length and add "\u2026" (horizontal ellipsis) 23 function abbreviateText(text, length) { 24 var abbreviated = decodeURIComponent(text); 25 if (abbreviated.length <= length) { 26 return text; 27 } 28 29 var lastWhitespaceIndex = abbreviated.substring(0, length - 1).lastIndexOf(' '); 30 abbreviated = encodeURIComponent(abbreviated.substring(0, lastWhitespaceIndex)) + "\u2026"; 31 32 return abbreviated; 33 } 34 35 // returns content of <meta name="" content=""> tags or '' if empty/non existant 36 function getMeta(name) { 37 var metaContent = $('meta[name="' + name + '"]').attr('content'); 38 return metaContent || ''; 39 } 40 41 // create tweet text from content of <meta name="DC.title"> and <meta name="DC.creator"> 42 // fallback to content of <title> tag 43 function getTweetText() { 44 var title = getMeta('DC.title'); 45 var creator = getMeta('DC.creator'); 46 47 if (title.length > 0 && creator.length > 0) { 48 title += ' - ' + creator; 49 } else { 50 title = $('title').text(); 51 } 52 53 return encodeURIComponent(title); 54 } 55 56 // build URI from rel="canonical" or document.location 57 function getURI() { 58 var uri = document.location.href; 59 var canonical = $("link[rel=canonical]").attr("href"); 60 61 if (canonical && canonical.length > 0) { 62 if (canonical.indexOf("http") < 0) { 63 canonical = document.location.protocol + "//" + document.location.host + canonical; 64 } 65 uri = canonical; 66 } 67 68 return uri; 69 } 70 71 function cookieSet(name, value, days, path, domain) { 72 var expires = new Date(); 73 expires.setTime(expires.getTime() + (days * 24 * 60 * 60 * 1000)); 74 document.cookie = name + '=' + value + '; expires=' + expires.toUTCString() + '; path=' + path + '; domain=' + domain; 75 } 76 function cookieDel(name, value, path, domain) { 77 var expires = new Date(); 78 expires.setTime(expires.getTime() - 100); 79 document.cookie = name + '=' + value + '; expires=' + expires.toUTCString() + '; path=' + path + '; domain=' + domain; 80 } 81 82 // extend jquery with our plugin function 83 $.fn.socialSharePrivacy = function (settings) { 84 var defaults = { 85 'services' : { 86 'facebook' : { 87 'status' : 'on', 88 'dummy_img' : 'socialshareprivacy/images/dummy_facebook.png', 89 '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 <em>i</em>.', 90 'txt_fb_off' : 'nicht mit Facebook verbunden', 91 'txt_fb_on' : 'mit Facebook verbunden', 92 'perma_option' : 'on', 93 'display_name' : 'Facebook', 94 'referrer_track' : '', 95 'language' : 'de_DE', 96 'action' : 'recommend' 97 }, 98 'twitter' : { 99 'status' : 'on', 100 'dummy_img' : 'socialshareprivacy/images/dummy_twitter.png', 101 '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 <em>i</em>.', 102 'txt_twitter_off' : 'nicht mit Twitter verbunden', 103 'txt_twitter_on' : 'mit Twitter verbunden', 104 'perma_option' : 'on', 105 'display_name' : 'Twitter', 106 'referrer_track' : '', 107 'tweet_text' : getTweetText, 108 'language' : 'en' 109 } 110 }, 111 'info_link' : 'http://www.heise.de/ct/artikel/2-Klicks-fuer-mehr-Datenschutz-1333879.html', 112 'txt_help' : 'Wenn Sie diese Felder durch einen Klick aktivieren, werden Informationen an Facebook oder Twitter in die USA übertragen und unter Umständen auch dort gespeichert. Nä
112heres erfahren Sie durch einen Klick auf das <em>i</em>.', 113 'settings_perma' : 'Dauerhaft aktivieren und Datenüber­tragung zustimmen:', 114 'cookie_path' : '/', 115 'cookie_domain' : document.location.host, 116 'cookie_expires' : '365', 117 'css_path' : 'socialshareprivacy/socialshareprivacy.css', 118 'uri' : getURI 119 }; 120 121 // Standardwerte des Plug-Ings mit den vom User angegebenen Optionen ueberschreiben 122 var options = $.extend(true, defaults, settings); 123 124 var facebook_on = (options.services.facebook.status === 'on'); 125 var twitter_on = (options.services.twitter.status === 'on'); 126 127 // check if at least one service is "on" 128 if (!facebook_on && !twitter_on) { 129 return; 130 } 131 132 // insert stylesheet into document and prepend target element 133 if (options.css_path.length > 0) { 134 // IE fix (noetig fuer IE < 9 - wird hier aber fuer alle IE gemacht) 135 if (document.createStyleSheet) { 136 document.createStyleSheet(options.css_path); 137 } else { 138 $('head').append('<link rel="stylesheet" type="text/css" href="' + options.css_path + '" />'); 139 } 140 } 141 142 return this.each(function () { 143 144 $(this).prepend('<ul class="social_share_privacy_area"></ul>'); 145 var context = $('.social_share_privacy_area', this); 146 147 // canonical uri that will be shared 148 var uri = options.uri; 149 if (typeof uri === 'function') { 150 uri = uri(context); 151 } 152 153 // 154 // Facebook 155 // 156 if (facebook_on) { 157 var fb_enc_uri = encodeURIComponent(uri + options.services.facebook.referrer_track); 158 var fb_code = '<iframe src="https://www.facebook.com/plugins/like.php?locale=' + options.services.facebook.language + '&href=' + fb_enc_uri + '&send=false&layout=button_count&width=120&show_faces=false&action=' + options.services.facebook.action + '&colorscheme=light&font&height=21" style="border:none; overflow:hidden; width:145px; height:21px;" allowTransparency="true"></iframe>'; 159 var fb_dummy_btn = '<img src="' + options.services.facebook.dummy_img + '" alt="Facebook "Like"-Dummy" class="fb_like_privacy_dummy" />'; 160 161 context.append('<li class="facebook help_info"><span class="info">' + options.services.facebook.txt_info + '</span><span class="switch off">' + options.services.facebook.txt_fb_off + '</span><div class="fb_like dummy_btn">' + fb_dummy_btn + '</div></li>'); 162 163 var $container_fb = $('li.facebook', context); 164 165 $('li.facebook div.fb_like img.fb_like_privacy_dummy,li.facebook span.switch', context).live('click', function () { 166 if ($container_fb.find('span.switch').hasClass('off')) { 167 $container_fb.addClass('info_off'); 168 $container_fb.find('span.switch').addClass('on').removeClass('off').html(options.services.facebook.txt_fb_on); 169 $container_fb.find('img.fb_like_privacy_dummy').replaceWith(fb_code); 170 } else { 171 $container_fb.removeClass('info_off'); 172 $container_fb.find('span.switch').addClass('off').removeClass('on').html(options.services.facebook.txt_fb_off); 173 $container_fb.find('.fb_like').html(fb_dummy_btn); 174 } 175 }); 176 } 177 178 // 179 // Twitter 180 // 181 if (twitter_on) { 182 var text = options.services.twitter.tweet_text; 183 if (typeof text === 'function') { 184 text = text(); 185 } 186 // 120 is the max character count left after twitters automatic url shortening with t.co 187 text = abbreviateText(text, '120'); 188 189 var twitter_enc_uri = encodeURIComponent(uri + options.services.twitter.referrer_track); 190 var twitter_count_url = encodeURIComponent(uri); 191 var twitter_code = '<iframe allowtransparency="true" src="https://platform.twitter.com/widgets/tweet_button.html?url=' + twitter_enc_uri + '&counturl=' + twitter_count_url + '&
191text=' + text + '&count=horizontal&lang=' + options.services.twitter.language + '" style="border:none; overflow:hidden; width:130px; height:25px;"></iframe>'; 192 var twitter_dummy_btn = '<img src="' + options.services.twitter.dummy_img + '" alt=""Tweet this"-Dummy" class="tweet_this_dummy" />'; 193 194 context.append('<li class="twitter help_info"><span class="info">' + options.services.twitter.txt_info + '</span><span class="switch off">' + options.services.twitter.txt_twitter_off + '</span><div class="tweet dummy_btn">' + twitter_dummy_btn + '</div></li>'); 195 196 var $container_tw = $('li.twitter', context); 197 198 $('li.twitter div.tweet img,li.twitter span.switch', context).live('click', function () { 199 if ($container_tw.find('span.switch').hasClass('off')) { 200 $container_tw.addClass('info_off'); 201 $container_tw.find('span.switch').addClass('on').removeClass('off').html(options.services.twitter.txt_twitter_on); 202 $container_tw.find('img.tweet_this_dummy').replaceWith(twitter_code); 203 } else { 204 $container_tw.removeClass('info_off'); 205 $container_tw.find('span.switch').addClass('off').removeClass('on').html(options.services.twitter.txt_twitter_off); 206 $container_tw.find('.tweet').html(twitter_dummy_btn); 207 } 208 }); 209 } 210 211 // 212 // Der Info/Settings-Bereich wird eingebunden 213 // 214 context.append('<li class="settings_info"><div class="settings_info_menu off perma_option_off"><a href="' + options.info_link + '"><span class="help_info icon"><span class="info">' + options.txt_help + '</span></span></a></div></li>'); 215 216 // Info-Overlays mit leichter Verzoegerung einblenden 217 $('.help_info:not(.info_off)', context).live('mouseenter', function () { 218 var $info_wrapper = $(this); 219 var timeout_id = window.setTimeout(function () { $($info_wrapper).addClass('display'); }, 500); 220 $(this).data('timeout_id', timeout_id); 221 }); 222 $('.help_info', context).live('mouseleave', function () { 223 var timeout_id = $(this).data('timeout_id'); 224 window.clearTimeout(timeout_id); 225 if ($(this).hasClass('display')) { 226 $(this).removeClass('display'); 227 } 228 }); 229 230 var facebook_perma = (options.services.facebook.perma_option === 'on'); 231 var twitter_perma = (options.services.twitter.perma_option === 'on'); 232 233 // Menue zum dauerhaften Einblenden der aktiven Dienste via Cookie einbinden 234 // Die IE7 wird hier ausgenommen, da er kein JSON kann und die Cookies hier ueber JSON-Struktur abgebildet werden 235 if (((facebook_on && facebook_perma) 236 || (twitter_on && twitter_perma)) 237 && (!$.browser.msie || ($.browser.msie && $.browser.version > 7.0))) { 238 239 // Cookies abrufen 240 var cookie_list = document.cookie.split(';'); 241 var cookies = '{'; 242 var i = 0; 243 for (; i < cookie_list.length; i += 1) { 244 var foo = cookie_list[i].split('='); 245 cookies += '"' + $.trim(foo[0]) + '":"' + $.trim(foo[1]) + '"'; 246 if (i < cookie_list.length - 1) { 247 cookies += ','; 248 } 249 } 250 cookies += '}'; 251 cookies = JSON.parse(cookies); 252 253 // Container definieren 254 var $container_settings_info = $('li.settings_info', context); 255 256 // Klasse entfernen, die das i-Icon alleine formatiert, da Perma-Optionen eingeblendet werden 257 $container_settings_info.find('.settings_info_menu').removeClass('perma_option_off'); 258 259 // Perma-Optionen-Icon (.settings) und Formular (noch versteckt) einbinden 260 $container_settings_info.find('.settings_info_menu').append('<span class="settings">Einstellungen</span><form><fieldset><legend>' + options.settings_perma + '</legend></fieldset></form>'); 261 262 263 // Die Dienste mit <input> und <label>, sowie checked-Status laut Cookie, schreiben 264 var checked = ' checked="checked"'; 265 if (facebook_on && facebook_perma) { 266 var perma_status_facebook = cookies.socialSharePrivacy_facebook === 'perma_on' ? checked : ''; 267 $container_settings_info.find('form fieldset').append( 268 '<input type="checkbox" name="perma_status_facebook" id="perma_status_facebook"' 269 + perma_status_facebook + ' /><label for="perma_status_facebook">' 270 + options.services.facebook.display_name + '</label>' 271 ); 272 } 273 274 if (twitter_on && twitter_perma) { 275 var perma_status_twitter = cookies.socialSharePrivacy_twitter === 'perma_on' ? checked : ''; 276 $container_settings_info.find('form fieldset').append( 277 '<input type="checkbox" name="perma_status_twitter" id="perma_status_twitter"' 278 + perma_status_twitter + ' /><label for="perma_status_twitter">' 279 + options.services.twitter.display_name + '</label>' 280 ); 281 } 282 283 // Cursor auf Pointer setzen fuer das Zahnrad 284 $container_settings_info.find('span.settings').css('cursor', 'pointer'); 285 286 // Einstellungs-Menue bei mouseover ein-/ausblenden 287 $($container_settings_info.find('span.settings'), context).live('mouseenter', function () { 288 var timeout_id = window.setTimeout(function () { $container_settings_info.find('.settings_info_menu').removeClass('off').addClass('on'); }, 500); 289 $(this).data('timeout_id', timeout_id); 290 }); 291 $($container_settings_info, context).live('mouseleave', function () { 292 var timeout_id = $(this).data('timeout_id'); 293 window.clearTimeout(timeout_id); 294 $container_settings_info.find('.settings_info_menu').removeClass('on').addClass('off'); 295 }); 296 297 // Klick-Interaktion auf <input> um Dienste dauerhaft ein- oder auszuschalten (Cookie wird gesetzt oder geloescht) 298 $($container_settings_info.find('fieldset input')).live('click', function (event) { 299 var click = event.target.id; 300 var service = click.substr(click.lastIndexOf('_') + 1, click.length); 301 var cookie_name = 'socialSharePrivacy_' + service; 302 303 if ($('#' + event.target.id + ':checked').length) { 304 cookieSet(cookie_name, 'perma_on', options.cookie_expires, options.cookie_path, options.cookie_domain); 305 $('form fieldset label[for=' + click + ']', context).addClass('checked'); 306 } else { 307 cookieDel(cookie_name, 'perma_on', options.cookie_path, options.cookie_domain); 308 $('form fieldset label[for=' + click + ']', context).removeClass('checked'); 309 } 310 }); 311
312 // Dienste automatisch einbinden, wenn entsprechendes Cookie vorhanden ist 313 if (facebook_on && facebook_perma && cookies.socialSharePrivacy_facebook === 'perma_on') { 314 $('li.facebook span.switch', context).click(); 315 } 316 if (twitter_on && twitter_perma && cookies.socialSharePrivacy_twitter === 'perma_on') { 317 $('li.twitter span.switch', context).click(); 318 } 319 } 320 }); // this.each(function () 321 }; // $.fn.socialSharePrivacy = function (settings) { 322}; 323loadSocialSharePrivacy(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.