(function ($, window, document, undefined) {
	'use strict';

	$('body').on('mouseenter', '.js-download:not(.tooltipstered)', function(){
		$(this).tooltipster({
			animation: 'fade',
			side: 'top',
			trigger: 'custom',
			interactive: true,
			updateAnimation: null,
			contentAsHTML: true,
			zIndex: 998
		});
	});
	
	$(document).on('click', '.js-download', function (e) {

			var attachment_id = $(this).data('attachment-id');

			$('.js-download[data-attachment-id="'+attachment_id+'"]').tooltipster('content', 'Carregando...').tooltipster('open');;
			
			var formData = {
				'action' : 'getdownloadurl',
				'attachment_id' : attachment_id,
				'attachment_access' : $(this).data('attachment-access')
			};

			$.ajax({
				type: 'POST',
				url: ajaxurl,
				data : formData,
				dataType : 'json',
				success: function(data) {
					// console.log(data);
					$('.js-download[data-attachment-id="'+attachment_id+'"]').tooltipster('content', data.message);
				}
			});
		});
}(jQuery, window, document));

