cirandas.net

ref: master

plugins/social_share_privacy/public/socialshareprivacy/javascripts/modules/disqus.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
/*
 * jquery.socialshareprivacy.js
 *
 * Copyright (c) 2012 Mathias Panzenböck
 *
 * is released under the MIT License http://www.opensource.org/licenses/mit-license.php
 *
 */
(function ($, undefined) {
	"use strict";

	var DISQUSWIDGETS = {
		displayCount: function (data) {
			$('.social_share_privacy_area .disqus .disqus-widget:not(.init)').each(function () {
				var $widget = $(this);
				var uri = data.counts[0].id;
				if ($widget.attr("data-uri") === uri) {
					var key = $widget.attr("data-count");
					var count = data.counts[0][key];
					var text = data.text[key];
					var scount = $.fn.socialSharePrivacy.formatNumber(count);
					$widget.attr('title', count === 0 ? text.zero : count === 1 ? text.one : text.multiple.replace('{num}', scount));
					$widget.find('.count a').text(scount);
					$widget.addClass('init');
				}
			});
		}
	};

	$.fn.socialSharePrivacy.settings.services.disqus = {
		'status'            : true,
		'dummy_line_img'    : 'images/dummy_disqus.png',
		'dummy_box_img'     : 'images/dummy_box_disqus.png',
		'dummy_alt'         : '"Disqus"-Dummy',
		'txt_info'          : 'Two clicks for more privacy: The Disqus button will be enabled once you click here. Activating the button already sends data to Disqus &ndash; see <em>i</em>.',
		'txt_off'           : 'not connected to Disqus',
		'txt_on'            : 'connected to Disqus',
		'perma_option'      : true,
		'display_name'      : 'Disqus',
		'referrer_track'    : '',
		'shortname'         : '',
		'count'             : 'comments',
		'onclick'           : null,
		'button'            : function (options, uri, settings) {
			var shortname = options.shortname || window.disqus_shortname || '';
			var $code;
			if (settings.layout === 'line') {
				$code = $('<div class="disqus-widget">'+
					'<a href="#disqus_thread" class="name">Disq<span class="us">us</span></a>'+
					'<span class="count"><i></i><u></u><a href="#disqus_thread">&nbsp;</a></span></div>');
			}
			else {
				$code = $('<div class="disqus-widget">'+
					'<div class="count"><i></i><u></u><a href="#disqus_thread">&nbsp;</a></div>'+
					'<a href="#disqus_thread" class="name">Disq<span class="us">us</span></a></div>');
			}

			$code.attr({
				'data-count'     : options.count,
				'data-shortname' : shortname,
				'data-uri'       : uri + options.referrer_track
			});

			if (options.onclick) {
				$code.find('a').click(typeof options.onclick === "function" ?
					options.onclick : new Function("event", options.onclick));
			}

			// this breaks every other usage of the disqus count API:
			window.DISQUSWIDGETS = DISQUSWIDGETS;

			$.getScript('https://'+shortname+'.disqus.com/count-data.js?2='+encodeURIComponent(uri + options.referrer_track));

			return $code;
		}
	};
})(jQuery);