<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">define(["jquery"], function($) {

	// badge animation reset
	$(".likes-badge").one('webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend', function() {
		$(this).removeClass("animated bounceIn");
	});

	var Like = {

		initialize : function() {	
			this.bindEvents();			
		},

		bindEvents : function() {			
			$("[data-like]").on('click', function(event) { 
				// prevent event
				event.preventDefault();

				// check state
				var liked = $(this).hasClass('liked');

				// only if has not liked yet
				if(!liked) {					
					Like.vote(this, 'up');
				} else {
					Like.vote(this, 'down');
				}
			});
		},

		vote: function(el, direction) {						
			// current url
			var url = $(el).attr('href');

			// ajax call
			$.ajax({
				url: url,
				dataType: 'json',
				type: "GET",
				data: { "direction": direction },
				beforeSend: function(xhr){
		    		xhr.setRequestHeader('X-PJAX', 'true')
		  		},
				success: function(data) {										
					if (data.success == true) {
						Like.parse(el, data, direction);
					} else {
						console.log('Error on voting...');
					}
				},
				error : function() {
					console.log('Transport error...');
				}

			});
		},

		parse : function(el, data, direction) {
			var $badge   = $(el).find('span.likes-badge'),
				current  = parseInt($badge.text());

			// new total
			if (direction == 'up') {
				total = current += 1;
				$(el).addClass('liked');
			} else {
				total = current -= 1
				$(el).removeClass('liked');
			}
			
			// and animate		
			$badge.addClass('animated bounceIn').text(total);					
		}

		
	};

	return Like;

});</pre></body></html>