cirandas.net

ref: master

plugins/social_share_privacy/public/socialshareprivacy/javascripts/modules/tumblr.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
/*
 * jquery.socialshareprivacy.js | 2 Klicks fuer mehr Datenschutz
 *
 * Copyright (c) 2012 Mathias Panzenböck
 *
 * is released under the MIT License http://www.opensource.org/licenses/mit-license.php
 *
 * Spread the word, link to us if you can.
 */
(function ($, undefined) {
	"use strict";

	function getQuote (options, uri, settings) {
		var text = $.trim($('article, p').text());
		
		if (text.length <= 600) {
			return text;
		}

		var abbrev = text.slice(0, 597);
		if (/^\w+$/.test(text.slice(596,598))) {
			var match = /^(.*)\s\S*$/.exec(abbrev);
			if (match) {
				abbrev = match[1];
			}
		}
		return $.trim(abbrev) + "\u2026";
	}

	function getClickthru (options, uri) {
		return uri + options.referrer_track;
	}

	function get (self, options, uri, settings, name) {
		var value = options[name];
		if (typeof value === "function") {
			return value.call(self, options, uri, settings);
		}
		return String(value);
	}

	function openTumblr (event) {
		var winx = window.screenX || window.screenLeft;
		var winy = window.screenY || window.screenTop;
		var winw = window.outerWidth || window.innerWidth;
		var winh = window.outerHeight || window.innerHeight;
		var width = 450;
		var height = 430;
		var x = Math.round(winx + (winw - width)  * 0.5);
		var y = Math.round(winy + (winh - height) * 0.5);
		window.open(this.href, 't', 'left='+x+',top='+y+',toolbar=0,resizable=0,status=0,menubar=0,width='+width+',height='+height);
		event.preventDefault();
	}

	$.fn.socialSharePrivacy.settings.services.tumblr = {
		'status'            : true,
		'privacy'           : 'safe',
		'button_class'      : 'tumblr',
		'line_img'          : 'images/tumblr.png',
		'box_img'           : 'images/box_tumblr.png',
		'txt_info'          : 'Post this on Tumblr.',
		'txt_button'        : 'Share on Tubmlr',
		'display_name'      : 'Tumblr',
		'referrer_track'    : '',
		'type'              : 'link', // possible values are 'link', 'quote', 'photo' or 'video'
		// type: 'link':
		'name'              : $.fn.socialSharePrivacy.getTitle,
		'description'       : $.fn.socialSharePrivacy.getDescription,
		// type: 'quote':
		'quote'             : getQuote,
		// type: 'photo':
		'photo'             : $.fn.socialSharePrivacy.getImage,
		'clickthrou'        : getClickthru,
		// type: 'video':
		'embed'             : $.fn.socialSharePrivacy.getEmbed,
		// type: 'photo' or 'video':
		'caption'           : $.fn.socialSharePrivacy.getDescription,
		'button'            : function (options, uri, settings) {
			var $code = $('<a target="_blank"/>').click(openTumblr);
			$('<img>', {
				alt: options.txt_button,
				src: options.path_prefix + (settings.layout === 'line' ? options.line_img : options.box_img)
			}).appendTo($code);
			switch (options.type) {
				case 'link':
					return $code.attr('href', 'https://www.tumblr.com/share/link?'+$.param({
						url         : uri + options.referrer_track,
						name        : get(this, options, uri, settings, 'name'),
						description : get(this, options, uri, settings, 'description')
					}));

				case 'quote':
					return $code.attr('href', 'https://www.tumblr.com/share/quote?'+$.param({
						source      : uri + options.referrer_track,
						quote       : get(this, options, uri, settings, 'quote')
					}));

				case 'photo':
					return $code.attr('href', 'https://www.tumblr.com/share/photo?'+$.param({
						source      : get(this, options, uri, settings, 'photo'),
						caption     : get(this, options, uri, settings, 'caption'),
						clickthrou  : get(this, options, uri, settings, 'clickthrou')
					}));

				case 'video':
					return $code.attr('href', 'https://www.tumblr.com/share/video?'+$.param({
						embed       : get(this, options, uri, settings, 'embed'),
						caption     : get(this, options, uri, settings, 'caption')
					}));
			}
		}
	};
})(jQuery);