File size: 1,006 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import i18n from 'i18n-calypso';
import { stringify } from 'qs';

const baseUrl = '//widgets.wp.com/sharing-buttons-preview/';

export default {
	generatePreviewUrlFromButtons: function ( buttons, showMore ) {
		let numberOfCustomButtons = 0;
		const query = {};

		// Build the query parameter array of services names to be rendered
		// by the official sharing buttons preview widget
		buttons.forEach( function ( button ) {
			let index;

			if ( button.custom ) {
				// Custom buttons previews are specified by index using the
				// name and a URL to the icon
				index = numberOfCustomButtons++;
				query[ 'custom[' + index + '][name]' ] = encodeURIComponent( button.name );
				query[ 'custom[' + index + '][icon]' ] = encodeURIComponent( button.icon );
			} else {
				query[ 'service[]' ] = query[ 'service[]' ] || [];
				query[ 'service[]' ].push( button.ID );
			}
		} );

		if ( showMore ) {
			query.more = i18n.translate( 'More' );
		}

		return baseUrl + '?' + stringify( query );
	},
};