1/* 2 * jquery.socialshareprivacy.js | 2 Klicks fuer mehr Datenschutz 3 * 4 * Copyright (c) 2012 Mathias Panzenböck 5 * 6 * is released under the MIT License http://www.opensource.org/licenses/mit-license.php 7 * 8 * Spread the word, link to us if you can. 9 */ 10(function ($, undefined) { 11 "use strict"; 12 13 function getQuote (options, uri, settings) { 14 var text = $('article, p').text(); 15 16 if (text.length <= 600) { 17 return text; 18 } 19 20 var abbrev = text.slice(0, 597); 21 if (!/\W/.test(text.charAt(length - 3))) { 22 var match = /^(.*)\s\S*$/.exec(abbrev); 23 if (match) { 24 abbrev = match[1]; 25 } 26 } 27 return abbrev + "\u2026"; 28 } 29 30 function getClickthru (options, uri) { 31 return uri + options.referrer_track; 32 } 33 34 function get (self, options, uri, settings, name) { 35 var value = options[name]; 36 if (typeof value === "function") { 37 return value.call(self, options, uri, settings); 38 } 39 return String(value); 40 } 41 42 function openTumblr (event) { 43 var winx = window.screenX || window.screenLeft; 44 var winy = window.screenY || window.screenTop; 45 var winw = window.outerWidth || window.innerWidth; 46 var winh = window.outerHeight || window.innerHeight; 47 var width = 450; 48 var height = 430; 49 var x = Math.round(winx + (winw - width) * 0.5); 50 var y = Math.round(winy + (winh - height) * 0.5); 51 window.open(this.href, 't', 'left='+x+',top='+y+',toolbar=0,resizable=0,status=0,menubar=0,width='+width+',height='+height); 52 event.preventDefault(); 53 } 54 55 $.fn.socialSharePrivacy.settings.services.tumblr = { 56 'status' : true, 57 'privacy' : 'safe', 58 'button_class' : 'tumblr', 59 'txt_info' : 'Post this on Tumblr.', 60 'txt_button' : 'Share on Tubmlr', 61 'display_name' : 'Tumblr', 62 'referrer_track' : '', 63 'type' : 'link', // possible values are 'link', 'quote', 'photo' or 'video' 64 // type: 'link': 65 'name' : $.fn.socialSharePrivacy.getTitle, 66 'description' : $.fn.socialSharePrivacy.getDescription, 67 // type: 'quote': 68 'quote' : getQuote, 69 // type: 'photo': 70 'photo' : $.fn.socialSharePrivacy.getImage, 71 'clickthrou' : getClickthru, 72 // type: 'video': 73 'embed' : $.fn.socialSharePrivacy.getEmbed, 74 // type: 'photo' or 'video': 75 'caption' : $.fn.socialSharePrivacy.getDescription, 76 'button' : function (options, uri, settings) { 77 var $code = $('<a target="_blank">' + options.txt_button + '</a>').click(openTumblr); 78 switch (options.type) { 79 case 'link': 80 return $code.attr('href', 'http://www.tumblr.com/share/link?'+$.param({ 81 url : uri + options.referrer_track, 82 name : get(this, options, uri, settings, 'name'), 83 description : get(this, options, uri, settings, 'description') 84 })); 85 86 case 'quote': 87 return $code.attr('href', 'http://www.tumblr.com/share/quote?'+$.param({ 88 source : uri + options.referrer_track, 89 quote : get(this, options, uri, settings, 'quote') 90 })); 91 92 case 'photo': 93 return $code.attr('href', 'http://www.tumblr.com/share/photo?'+$.param({ 94 source : get(this, options, uri, settings, 'photo'), 95 caption : get(this, options, uri, settings, 'caption'), 96 clickthrou : get(this, options, uri, settings, 'clickthrou') 97 })); 98 99 case 'video': 100 return $code.attr('href', 'http://www.tumblr.com/share/video?'+$.param({ 101 embed : get(this, options, uri, settings, 'embed'), 102 caption : get(this, options, uri, settings, 'caption') 103 })); 104 } 105 } 106 }; 107})(jQuery); 108