<?xml version="1.0" encoding="ISO-8859-1"?>

<product productid="sharingimplementation" active="1">
	<title>Sharing Button</title>
	<description>Sample Social Sharing Button</description>
	<version>1.0</version>
	<url />
	<versioncheckurl />
	<dependencies>
	</dependencies>
	<codes>
	</codes>
	<templates>
		<template name="sample_facebook_share_button" templatetype="template" date="1504223979" username="David Grove" version="1.0"><![CDATA[<vb:if condition="$vboptions['sample_sharing_facebook']">
	<li class="b-sharing-menu__item js-sharing-menu__item--sample-sharing-facebook">

		<vb:comment>Store data to re-initialize the button when 
		transforming to the Responsive menu</vb:comment>
		<div class="h-hide js-sample-sharing-facebook-data" data-fbdivclass="fb-share-button" data-fbdivlayout="button" data-fbdivsize="small" data-fbdivmobile-iframe="true" data-fbdivhref="{vb:var url}" data-fbaclass="fb-xfbml-parse-ignore" data-fbatarget="_blank" data-fbahref="https://www.facebook.com/sharer/sharer.php"></div>

		<vb:comment>Handle any Javascript changes that need to be made for
		the button when changing between Responsive sizes.</vb:comment>
		<script>
		<vb:literal>
		(function()
		{
			function wait(callback)
			{
				if (typeof vBulletin == 'undefined' || typeof vBulletin.CompMenuHorizontal == 'undefined' || typeof vBulletin.CompMenuHorizontal.registerMenuChangeFilter == 'undefined')
				{
					window.setTimeout(function()
					{
						wait(callback);
					}, 50);
				}
				else
				{
					callback();
				}
			}

			window.sample_sharing_facebook_registered = false;

			wait(function()
			{
				if (!window.sample_sharing_facebook_registered)
				{
					window.sample_sharing_facebook_registered = true;

					vBulletin.CompMenuHorizontal.registerMenuChangeFilter(function($menu, $dropdown, setState)
					{
						// check if this is the menu we want to work on
						if (!$menu.is('.js-sharing-menu'))
						{
							return;
						}

						if (setState == 'dropdown')
						{
							// The facebook share button needs to be reloaded when 
							// changing to Responsive.
							// Only do this once.
							var $trigger = $dropdown.find('.js-comp-menu-dropdown__trigger');
							$trigger.one('click', function(e)
							{
								var $trigger = $(this),
									$menu = $trigger.closest('.js-comp-menu-dropdown'),
									$item = $menu.find('.js-sharing-menu__item--sample-sharing-facebook');

								if ($item.length > 0)
								{
									var $data = $item.find('.js-sample-sharing-facebook-data'),
										fbdivclass = $data.data('fbdivclass'),
										// Always remove the fb div (instead of only removing when it was
										// previously initialized) otherwise it doesn't load in
										// responsive. See VBV-17653. Previously this only removed the
										// element if it had been initialized, (had .fb_iframe_widget)
										$remove = $item.find('.' + fbdivclass);

									$remove.remove();

									if (!$item.find('.' + fbdivclass).length)
									{
										var fbdivlayout = $data.data('fbdivlayout'),
											fbdivsize = $data.data('fbdivsize'),
											fbdivmobileiframe = $data.data('fbdivmobile-iframe'),
											fbdivhref = $data.data('fbdivhref'),
											fbaclass = $data.data('fbaclass'),
											fbatarget = $data.data('fbatarget'),
											fbahref = $data.data('fbahref');

										var $newdiv = $('<div />')
											.attr('class', fbdivclass)
											.attr('data-layout', fbdivlayout)
											.attr('data-size', fbdivsize)
											.attr('data-mobile-iframe', fbdivmobileiframe)
											.attr('href', fbdivhref);

										$('<a />').attr('class', fbaclass)
											.attr('target', fbatarget)
											.attr('href', fbahref)
											.appendTo($newdiv);

										$newdiv.appendTo($item);
									}

									FB.XFBML.parse($item.get(0));
								}
								// handle adding a reply via ajax
								$(document).on('vb-loadnewposts', function (e, data)
								{
									var haveFb = FB && FB.XFBML && FB.XFBML.parse;

									if (!haveFb)
									{
										return;
									}

									// We may insert multiple posts into the DOM. This needs to loop
									// to init the menu in each new post. The alternative would be
									// to get the parent element, but that would re-initialize all
									// the menus in all posts on the page.
									$(data.insertedHtml).each(function()
									{
										var $item = $(this);
										if ($item.is('.js-post'))
										{
											var post = $item.get(0);

											// try initializing fb buttons (if present)
											if (haveFb)
											{
												FB.XFBML.parse(post);
											}
										}
									});

									// change to/from responsive state if needed
									vBulletin.CompMenuHorizontal.checkHorizontalMenuState();
								});
							});
						}
						else // horizontal
						{
							// If the page loaded in Responsive size the menu will be a dropdown.
							// Ensure that the desktop menu is initialized if it isn't already
							var $item = $menu.find('.js-sharing-menu__item--sample-sharing-facebook'),
								$data = $item.find('.js-sample-sharing-facebook-data'),
								fbdivclass = $data.data('fbdivclass'),
								$toinit = $item.find('.' + fbdivclass + ':not(.fb_iframe_widget)');

							if ($toinit.length > 0)
							{
								FB.XFBML.parse($item.get(0));
							}
						}

					});
				}
			});

		})();
		</vb:literal>
		</script>

		{vb:js js/facebook.js}
		<div class="fb-share-button" data-layout="button" data-size="small" data-mobile-iframe="true" data-href="{vb:var url}"><a class="fb-xfbml-parse-ignore" target="_blank" href="https://www.facebook.com/sharer/sharer.php"></a></div>

	</li>
</vb:if>]]></template>
	</templates>
	<stylevardfns>
	</stylevardfns>
	<stylevars>
	</stylevars>
	<hooks>
		<hook>
			<hookname>conversation_sharing</hookname>
			<title>Button template</title>
			<active>1</active>
			<hookorder>10</hookorder>
			<template>sample_facebook_share_button</template>
			<arguments><![CDATA[a:1:{s:3:"url";a:1:{s:3:"url";i:1;}}]]></arguments>
		</hook>
	</hooks>
	<phrases>
		<phrasetype name="vBulletin Settings" fieldname="vbsettings">
			<phrase name="setting_sample_sharing_facebook_desc" date="1501808154" username="kevin" version="1.0"><![CDATA[Duplicate share button for Product Sample]]></phrase>
			<phrase name="setting_sample_sharing_facebook_title" date="1501808154" username="kevin" version="1.0"><![CDATA[Enable Share Topics to Facebook (Sample)?]]></phrase>
		</phrasetype>
	</phrases>
	<options>
		<settinggroup name="showthread" displayorder="430">
			<setting varname="sample_sharing_facebook" displayorder="400">
				<datatype>boolean</datatype>
				<optioncode>yesno</optioncode>
				<defaultvalue>1</defaultvalue>
				<public>1</public>
			</setting>
		</settinggroup>
	</options>
	<helptopics>
	</helptopics>
	<cronentries>
	</cronentries>
	<faqentries>
	</faqentries>
	<widgets>
	</widgets>
	<pagetemplates>
	</pagetemplates>
	<pages>
	</pages>
	<channels>
	</channels>
	<routes>
	</routes>
</product>
