<commit_before>Hammer = require "hammerjs"

class exports.GestureManagerElement

	constructor: (@element) ->
		
		@_events = {}
		@_manager = null
	
	_getEventFamily: (eventName) ->
		
		eventFamily = undefined
		
		switch eventName
			
			when Events.Pan, Events.PanStart, Events.PanMove, Events.PanEnd, Events.PanCancel, Events.PanLeft, Events.PanRight,	Events.PanUp, Events.PanDown
				eventFamily = Events.Pan
			
			when Events.Pinch, Events.PinchStart, Events.PinchMove, Events.PinchEnd, Events.PinchCancel, Events.PinchIn, Events.PinchOut
				eventFamily = Events.Pinch
			
			when Events.Press, Events.PressUp
				eventFamily = Events.Press
			
			when Events.Rotate, Events.RotateStart, Events.RotateMove, Events.RotateEnd, Events.RotateCancel
				eventFamily = Events.Rotate
			
			when Events.Swipe, Events.SwipeLeft, Events.SwipeRight, Events.SwipeUp, Events.SwipeDown
				eventFamily = Events.Swipe
			
			when Events.Tap, Events.SingleTap
				eventFamily = Events.Tap
			
			when Events.DoubleTap # Tap and DoubleTap need different type of recognizers
				eventFamily = Events.DoubleTap
			
			else
		
		return eventFamily


	_getExistingRecognizersForEventFamily: (eventFamily) ->

		# We need to mix recognizers for some gestures to be detected together
		# All these dependencies come from https://cdn.rawgit.com/hammerjs/hammer.js/master/tests/manual/visual.html
		existingRecognizers = []
		
		switch eventFamily
			
			when Events.Pan # Pan depends on Swipe, Rotate and Pinch
				if swipe = @_manager.get(Events.Swipe)
					existingRecognizers.push(swipe)
				if rotate = @_manager.get(Events.Rotate)
					existingRecognizers.push(rotate)
				if pinch = @_manager.get(Events.Pinch)
					existingRecognizers.push(pinch)
			
			when Events.Swipe # Swipe depends on Pan
				if pan = @_manager.get(Events.Pan)
					existingRecognizers.push(pan)
			
			when Events.Rotate # Rotate depends on Pan and Pinch
				if pan = @_manager.get(Events.Pan)
					existingRecognizers.push(pan)
				if pinch = @_manager.get(Events.Pinch)
					existingRecognizers.push(pinch)
			
			when Events.Pinch # Pinch depends on Pan and Rotate
				if pan = @_manager.get(Events.Pan)
					existingRecognizers.push(pan)
				if rotate = @_manager.get(Events.Pinch)
					existingRecognizers.push(rotate)
			else
		
		return existingRecognizers			


	addEventListener: (eventName, listener) ->
		#Lazy creation
		@_manager ?= new Hammer.Manager(@element)
		
		validEvent = true
		recognizer = undefined

		# Get event family to add different recognizers
		eventFamily = @_getEventFamily(eventName)

		# Add recognizer if needed
		switch eventFamily
			
			when Events.Pan
				if not @_manager.get(Events.Pan)
					recognizer = new Hammer.Pan({ event: Events.Pan})
			
			when Events.Pinch
				if not @_manager.get(Events.Pinch)
					recognizer = new Hammer.Pinch({ event: Events.Pinch})
			
			when Events.Press
				if not @_manager.get(Events.Press)
					recognizer = new Hammer.Press({ event: Events.Press})
			
			when Events.Rotate
				if not @_manager.get(Events.Rotate)
					recognizer = new Hammer.Rotate({ event: Events.Rotate})
			
			when Events.Swipe
				if not @_manager.get(Events.Swipe)
					recognizer = new Hammer.Swipe({ event: Events.Swipe})
			
			when Events.Tap
				if not @_manager.get(Events.Tap)
					recognizer = new Hammer.Tap({ event: Events.Tap})
			
			when Events.DoubleTap
				if not @_manager.get(Events.DoubleTap)
					recognizer = new Hammer.Tap({ event: Events.DoubleTap, taps: 2})
			
			else
				validEvent = false

		if recognizer
			# Add other recognizers if they existed already
			existingRecognizers = @_getExistingRecognizersForEventFamily(eventFamily)
			if existingRecognizers.length > 0
				@_manager.add(recognizer).recognizeWith(existingRecognizers)
			else
				@_manager.add recognizer

		if validEvent
			@_manager.on eventName, listener

	removeEventListener: (eventName, listener) -><commit_msg>Adding Tap as dependency of Tap<commit_after>Hammer = require "hammerjs"

class exports.GestureManagerElement

	constructor: (@element) ->
		
		@_events = {}
		@_manager = null
	
	_getEventFamily: (eventName) ->
		
		eventFamily = undefined
		
		switch eventName
			
			when Events.Pan, Events.PanStart, Events.PanMove, Events.PanEnd, Events.PanCancel, Events.PanLeft, Events.PanRight,	Events.PanUp, Events.PanDown
				eventFamily = Events.Pan
			
			when Events.Pinch, Events.PinchStart, Events.PinchMove, Events.PinchEnd, Events.PinchCancel, Events.PinchIn, Events.PinchOut
				eventFamily = Events.Pinch
			
			when Events.Press, Events.PressUp
				eventFamily = Events.Press
			
			when Events.Rotate, Events.RotateStart, Events.RotateMove, Events.RotateEnd, Events.RotateCancel
				eventFamily = Events.Rotate
			
			when Events.Swipe, Events.SwipeLeft, Events.SwipeRight, Events.SwipeUp, Events.SwipeDown
				eventFamily = Events.Swipe
			
			when Events.Tap, Events.SingleTap
				eventFamily = Events.Tap
			
			when Events.DoubleTap # Tap and DoubleTap need different type of recognizers
				eventFamily = Events.DoubleTap
			
			else
		
		return eventFamily


	_getDependentRecognizersForEventFamily: (eventFamily) ->

		# We need to add simultaneous recognition for certain gestures to be detected together
		# See http://hammerjs.github.io/recognize-with/
		# All these dependencies come from https://cdn.rawgit.com/hammerjs/hammer.js/master/tests/manual/visual.html
		existingRecognizers = []
		
		switch eventFamily
			
			when Events.Pan # Pan depends on Swipe, Rotate and Pinch
				if swipe = @_manager.get(Events.Swipe)
					existingRecognizers.push(swipe)
				if rotate = @_manager.get(Events.Rotate)
					existingRecognizers.push(rotate)
				if pinch = @_manager.get(Events.Pinch)
					existingRecognizers.push(pinch)
			
			when Events.Swipe # Swipe depends on Pan
				if pan = @_manager.get(Events.Pan)
					existingRecognizers.push(pan)
			
			when Events.Rotate # Rotate depends on Pan and Pinch
				if pan = @_manager.get(Events.Pan)
					existingRecognizers.push(pan)
				if pinch = @_manager.get(Events.Pinch)
					existingRecognizers.push(pinch)
			
			when Events.Pinch # Pinch depends on Pan and Rotate
				if pan = @_manager.get(Events.Pan)
					existingRecognizers.push(pan)
				if rotate = @_manager.get(Events.Pinch)
					existingRecognizers.push(rotate)

			when Events.DoubleTap # DoubleTap depends on Tap
				if tap = @_manager.get(Events.Tap)
					existingRecognizers.push(tap)
			
			else
		
		return existingRecognizers			


	addEventListener: (eventName, listener) ->
		#Lazy creation
		@_manager ?= new Hammer.Manager(@element)
		
		validEvent = true
		recognizer = undefined

		# Get event family to add different recognizers
		eventFamily = @_getEventFamily(eventName)

		# Add recognizer if needed
		switch eventFamily
			
			when Events.Pan
				if not @_manager.get(Events.Pan)
					recognizer = new Hammer.Pan({ event: Events.Pan})
			
			when Events.Pinch
				if not @_manager.get(Events.Pinch)
					recognizer = new Hammer.Pinch({ event: Events.Pinch})
			
			when Events.Press
				if not @_manager.get(Events.Press)
					recognizer = new Hammer.Press({ event: Events.Press})
			
			when Events.Rotate
				if not @_manager.get(Events.Rotate)
					recognizer = new Hammer.Rotate({ event: Events.Rotate})
			
			when Events.Swipe
				if not @_manager.get(Events.Swipe)
					recognizer = new Hammer.Swipe({ event: Events.Swipe})
			
			when Events.Tap
				if not @_manager.get(Events.Tap)
					recognizer = new Hammer.Tap({ event: Events.Tap})
			
			when Events.DoubleTap
				if not @_manager.get(Events.DoubleTap)
					recognizer = new Hammer.Tap({ event: Events.DoubleTap, taps: 2})
			
			else
				validEvent = false

		if recognizer
			# Add other recognizers if they existed already
			existingRecognizers = @_getDependentRecognizersForEventFamily(eventFamily)
			if existingRecognizers.length > 0
				@_manager.add(recognizer).recognizeWith(existingRecognizers)
			else
				@_manager.add recognizer

		if validEvent
			@_manager.on eventName, listener

	removeEventListener: (eventName, listener) ->
{'fraction_non_alphanumeric': 0.0883335395274032, 'fraction_numerical': 0.0004948657676605221, 'mean_word_length': 3.4271631982475355, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3599512', 'n_tokens_mistral': 3154, 'n_tokens_neox': 2445, 'n_words': 610}