PageSourceSearch

https://www.tjam.jus.br/modules/mod_bw_social_share/js/rrssb.js

js tjam.jus.br collected 2026-10-02 06:17:05 UTC 12,110 bytes, 376 lines download raw bytes

1/*!
2 Ridiculously Responsive Social Sharing Buttons
3 Team: @dbox, @joshuatuscan
4 Site: http://www.rrssb.ml
5 Twitter: @therealkni
6        ___           ___
7       /__/|         /__/\        ___
8      |  |:|         \  \:\      /  /\
9      |  |:|          \  \:\    /  /:/
10    __|  |:|      _____\__\:\  /__/::\
11   /__/\_|:|____ /__/::::::::\ \__\/\:\__
12   \  \:\/:::::/ \  \:\~~\~~\/    \  \:\/\
13    \  \::/~~~~   \  \:\  ~~~      \__\::/
14     \  \:\        \  \:\          /__/:/
15      \  \:\        \  \:\         \__\/
16       \__\/         \__\/
17*/
18
19+(function(window, $, undefined) {
20	'use strict';
21
22	var support = {
23		calc : false
24	};
25
26	/*
27	 * Public Function
28	 */
29
30	$.fn.rrssb = function( options ) {
31
32		// Settings that $.rrssb() will accept.
33		var settings = $.extend({
34			description: undefined,
35			emailAddress: undefined,
36			emailBody: undefined,
37			emailSubject: undefined,
38			image: undefined,
39			title: undefined,
40			url: undefined
41		}, options );
42
43		// use some sensible defaults if they didn't specify email settings
44		settings.emailSubject = settings.emailSubject || settings.title;
45		settings.emailBody = settings.emailBody ||
46			(
47				(settings.description ? settings.description : '') +
48				(settings.url ? '\n\n' + settings.url : '')
49			);
50
51		// Return the encoded strings if the settings have been changed.
52		for (var key in settings) {
53			if (settings.hasOwnProperty(key) && settings[key] !== undefined) {
54				settings[key] = encodeString(settings[key]);
55			}
56		};
57
58		if (settings.url !== undefined) {
59			$(this).find('.rrssb-facebook a').attr('href', 'https://www.facebook.com/sharer/sharer.php?u=' + settings.url);
60			$(this).find('.rrssb-tumblr a').attr('href', 'http://tumblr.com/share/link?url=' + settings.url + (settings.title !== undefined ? '&name=' + settings.title : '')  + (settings.description !== undefined ? '&description=' + settings.description : ''));
61			$(this).find('.rrssb-linkedin a').attr('href', 'http://www.linkedin.com/shareArticle?mini=true&url=' + settings.url + (settings.title !== undefined ? '&title=' + settings.title : '') + (settings.description !== undefined ? '&summary=' + settings.description : ''));
62			$(this).find('.rrssb-twitter a').attr('href', 'https://twitter.com/intent/tweet?text=' + (settings.description !== undefined ? settings.description : '') + '%20' + settings.url);
63			$(this).find('.rrssb-hackernews a').attr('href', 'https://news.ycombinator.com/submitlink?u=' + settings.url + (settings.title !== undefined ? '&text=' + settings.title : ''));
64			$(this).find('.rrssb-vk a').attr('href', 'https://vk.com/share.php?url=' + settings.url);
65			$(this).find('.rrssb-reddit a').attr('href', 'http://www.reddit.com/submit?url=' + settings.url + (settings.description !== undefined ? '&text=' + settings.description : '') + (settings.title !== undefined ? '&title=' + settings.title : ''));
66			$(this).find('.rrssb-googleplus a').attr('href', 'https://plus.google.com/share?url=' + settings.url);
67			$(this).find('.rrssb-pinterest a').attr('href', 'http://pinterest.com/pin/create/button/?url=' + settings.url + ((settings.image !== undefined) ? '&media=' + settings.image : '') + (settings.description !== undefined ? '&description=' + settings.description : ''));
68			$(this).find('.rrssb-pocket a').attr('href', 'https://getpocket.com/save?url=' + settings.url);
69			$(this).find('.rrssb-github a').attr('href', settings.url);
70			$(this).find('.rrssb-print a').attr('href', 'javascript:window.print()');
71			$(this).find('.rrssb-whatsapp a').attr('href', 'whatsapp://send?text=' + (settings.description !== undefined ? settings.description + '%20' : (settings.title !== undefined ? settings.title + '%20' : '')) + settings.url);
72		}
73
74		if (settings.emailAddress !== undefined || settings.emailSubject) {
75			$(this).find('.rrssb-email a').attr('href', 'mailto:' + (settings.emailAddress ? settings.emailAddress : '') + '?' + (settings.emailSubject !== undefined ? 'subject=' + settings.emailSubject : '') + (settings.emailBody !== undefined ? '&body=' + settings.emailBody : ''));
76		}
77
78	};
79
80	/*
81	 * Utility functions
82	 */
83	var detectCalcSupport = function(){
84		//detect if calc is natively supported.
85		var el = $('<div>');
86		var calcProps = [
87			'calc',
88			'-webkit-calc',
89			'-moz-calc'
90		];
91
92		$('body').append(el);
93
94		for (var i=0; i < calcProps.length; i++) {
95			el.css('width', calcProps[i] + '(1px)');
96			if(el.width() === 1){
97				support.calc = calcProps[i];
98				break;
99			}
100		}
101
102		el.remove();
103	};
104
105	var encodeString = function(string) {
106		// Recursively decode string first to ensure we aren't double encoding.
107		if (string !== undefined && string !== null) {
108			if (string.match(/%[0-9a-f]{2}/i) !== null) {
109				string = decodeURIComponent(string);
110				encodeString(string);
111			} else {
112				return encodeURIComponent(string);
113			}
114		}
115	};
116
117	var setPercentBtns = function() {
118		// loop through each instance of buttons
119		$('.rrssb-buttons').each(function(index) {
120			var self = $(this);
121			var buttons = $('li:visible', self);
122			var numOfButtons = buttons.length;
123			var initBtnWidth = 100 / numOfButtons;
124
125			// set initial width of buttons
126			buttons.css('width', initBtnWidth + '%').attr('data-initwidth',initBtnWidth);
127		});
128	};
129
130	var makeExtremityBtns = function() {
131		// loop through each instance of buttons
132		$('.rrssb-buttons').each(function(index) {
133			var self = $(this);
134			//get button width
135			var containerWidth = self.width();
136			var buttonWidth = $('li', self).not('.small').eq(0).width();
137			var buttonCountSmall = $('li.small', self).length;
138
139			// enlarge buttons if they get wide enough
140			if (buttonWidth > 170 && buttonCountSmall < 1) {
141				self.addClass('large-format');
142				var fontSize = buttonWidth / 12 + 'px';
143				self.css('font-size', fontSize);
144			} else {
145				self.removeClass('large-format');
146				self.css('font-size', '');
147			}
148
149			if (containerWidth < buttonCountSmall * 25) {
150				self.removeClass('small-format').addClass('tiny-format');
151			} else {
152				self.removeClass('tiny-format');
153			}
154		});
155	};
156
157	var backUpFromSmall = function() {
158		// loop through each instance of buttons
159		$('.rrssb-buttons').each(function(index) {
160			var self = $(this);
161
162			var buttons = $('li', self);
163			var smallButtons = buttons.filter('.small');
164			var totalBtnSze = 0;
165			var totalTxtSze = 0;
166			var upCandidate = smallButtons.eq(0);
167			var nextBackUp = parseFloat(upCandidate.attr('data-size')) + 55;
168			var smallBtnCount = smallButtons.length;
169
170			if (smallBtnCount === buttons.length) {
171				var btnCalc = smallBtnCount * 42;
172				var containerWidth = self.width();
173
174				if ((btnCalc + nextBackUp) < containerWidth) {
175					self.removeClass('small-format');
176					smallButtons.eq(0).removeClass('small');
177
178					sizeSmallBtns();
179				}
180
181			} else {
182				buttons.not('.small').each(function(index) {
183					var button = $(this);
184					var txtWidth = parseFloat(button.attr('data-size')) + 55;
185					var btnWidth = parseFloat(button.width());
186
187					totalBtnSze = totalBtnSze + btnWidth;
188					totalTxtSze = totalTxtSze + txtWidth;
189				});
190
191				var spaceLeft = totalBtnSze - totalTxtSze;
192
193				if (nextBackUp < spaceLeft) {
194					upCandidate.removeClass('small');
195					sizeSmallBtns();
196				}
197			}
198		});
199	};
200
201	var checkSize = function(init) {
202		// loop through each instance of buttons
203		$('.rrssb-buttons').each(function(index) {
204
205			var self = $(this);
206			var buttons = $('li', self);
207
208			// get buttons in reverse order and loop through each
209			$(buttons.get().reverse()).each(function(index, count) {
210
211				var button = $(this);
212
213				if (button.hasClass('small') === false) {
214					var txtWidth = parseFloat(button.attr('data-size')) + 55;
215					var btnWidth = parseFloat(button.width());
216
217					if (txtWidth > btnWidth) {
218						var btn2small = buttons.not('.small').last();
219						$(btn2small).addClass('small');
220						sizeSmallBtns();
221					}
222				}
223
224				if (!--count) backUpFromSmall();
225			});
226		});
227
228		// if first time running, put it through the magic layout
229		if (init === true) {
230			rrssbMagicLayout(sizeSmallBtns);
231		}
232	};
233
234	var sizeSmallBtns = function() {
235		// loop through each instance of buttons
236		$('.rrssb-buttons').each(function(index) {
237			var self = $(this);
238			var regButtonCount;
239			var regPercent;
240			var pixelsOff;
241			var magicWidth;
242			var smallBtnFraction;
243			var buttons = $('li', self);
244			var smallButtons = buttons.filter('.small');
245
246			// readjust buttons for small display
247			var smallBtnCount = smallButtons.length;
248
249			// make sure there are small buttons
250			if (smallBtnCount > 0 && smallBtnCount !== buttons.length) {
251				self.removeClass('small-format');
252
253				//make sure small buttons are square when not all small
254				smallButtons.css('width','42px');
255				pixelsOff = smallBtnCount * 42;
256				regButtonCount = buttons.not('.small').length;
257				regPercent = 100 / regButtonCount;
258				smallBtnFraction = pixelsOff / regButtonCount;
259
260				// if calc is not supported. calculate the width on the fly.
261				if (support.calc === false) {
262					magicWidth = ((self.innerWidth()-1) / regButtonCount) - smallBtnFraction;
263					magicWidth = Math.floor(magicWidth*1000) / 1000;
264					magicWidth += 'px';
265				} else {
266					magicWidth = support.calc+'('+regPercent+'% - '+smallBtnFraction+'px)';
267				}
268
269				buttons.not('.small').css('width', magicWidth);
270
271			} else if (smallBtnCount === buttons.length) {
272				// if all buttons are small, change back to percentage
273				self.addClass('small-format');
274				setPercentBtns();
275			} else {
276				self.removeClass('small-format');
277				setPercentBtns();
278			}
279		}); //end loop
280
281		makeExtremityBtns();
282	};
283
284	var rrssbInit = function() {
285		$('.rrssb-buttons').each(function(index) {
286			$(this).addClass('rrssb-'+(index + 1));
287		});
288
289		detectCalcSupport();
290
291		setPercentBtns();
292
293		// grab initial text width of each button and add as data attr
294		$('.rrssb-buttons li .rrssb-text').each(function(index) {
295			var buttonTxt = $(this);
296			var txtWdth = buttonTxt.width();
297			buttonTxt.closest('li').attr('data-size', txtWdth);
298		});
299
300		checkSize(true);
301	};
302
303	var rrssbMagicLayout = function(callback) {
304		//remove small buttons before each conversion try
305		$('.rrssb-buttons li.small').removeClass('small');
306
307		checkSize();
308
309		callback();
310	};
311
312	var popupCenter = function(url, title, w, h) {
313		// Fixes dual-screen position                         Most browsers      Firefox
314		var dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left;
315		var dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top;
316
317		var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
318		var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
319
320		var left = ((width / 2) - (w / 2)) + dualScreenLeft;
321		var top = ((height / 3) - (h / 3)) + dualScreenTop;
322
323		var newWindow = window.open(url, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
324
325		// Puts focus on the newWindow
326		if (newWindow && newWindow.focus) {
327			newWindow.focus();
328		}
329	};
330
331	var waitForFinalEvent = (function () {
332		var timers = {};
333		return function (callback, ms, uniqueId) {
334			if (!uniqueId) {
335				uniqueId = "Don't call this twice without a uniqueId";
336			}
337			if (timers[uniqueId]) {
338				clearTimeout (timers[uniqueId]);
339			}
340			timers[uniqueId] = setTimeout(callback, ms);
341		};
342	})();
343
344	// init load
345	$(document).ready(function(){
346		/*
347		 * Event listners
348		 */
349
350		try {
351			$(document).on('click', '.rrssb-buttons a.popup', {}, function popUp(e) {
352				var self = $(this);
353				popupCenter(self.attr('href'), self.find('.rrssb-text').html(), 580, 470);
354				e.preventDefault();
355			});
356		}
357		catch (e) { // catching this adds partial support for jQuery 1.3
358		}
359
360		// resize function
361		$(window).resize(function () {
362
363			rrssbMagicLayout(sizeSmallBtns);
364
365			waitForFinalEvent(function(){
366				rrssbMagicLayout(sizeSmallBtns);
367			}, 200, "finished resizing");
368		});
369
370		rrssbInit();
371	});
372
373	// Make global
374	window.rrssbInit = rrssbInit;
375
376})(window, 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.