<commit_before>/**
 * @author: +HampusAhlgren
 * 
 * Click anywhere else but in the directive element and it will trigger
 * the given function. 
 * 
 * 
 */
 var ClickHide = angular.module('ClickHide', []);
ClickHide.directive('clickHide', function( $document, $parse, $timeout ){

	return{
		scope: true,
		link: function( $scope, element, attr ){
			var self = this;
			$scope.attr = attr;
			
			self._init = function(){

				$scope.$watch( $scope.attr.chActivate, self.onActivationChange);
				
			}

			self.onActivationChange = function( newValue ){
				
				if( newValue == true ){
					$scope.listenForClick();
				}
				// in the case that the user changed the activation
				// condition without clicking outside the parentElement
				// ex. Clicking close instead. We then wan't to make sure 
				// we unbind the click listener - otherwise we'll get some
				// funky behaviour.
				else if( newValue == false ){
					
					console.log('ClickHide: Not listening now');
					$document.unbind('click', $scope.onClick);
				} 
			}

			$scope.listenForClick = function(){
				
				console.log('ClickHide: Starting to listen for global click!');
				
				$timeout(function(){
					$document.on('click', $scope.onClick);	
				}, 10);
			}

			/**
			 * First click after activating. 
			 */
			$scope.onClick = function( e ){
				console.log('ClickHide: Catching click');

				// check if the user has clicked outside of the 
				// element
				if( !self._isDecendantOfParent(e.target, element) ){ // yes he did

					// parse and execute the click
					// action
					$scope.$apply(function(){
						$parse($scope.attr.chClick)($scope.$parent);	
					});
					
					console.log('ClickHide: Not listening now');
					$document.unbind('click', $scope.onClick); // now we don't have to listen anymore
				}
			}
			
			/**
			 * 
			 */
			self._isDecendantOfParent = function( decendantElement, parentElement ){
				
				var currentParent = decendantElement; 
				while( currentParent ){
					if( currentParent == parentElement[0]){ return true }
					
					currentParent = currentParent.parentNode;
				}
				return false;
			}
			self._init();
		}
	}
});<commit_msg>Solved stupid scope error - removed isolate scope requirement<commit_after>/**
 * @author: +HampusAhlgren
 * 
 * Click anywhere else but in the directive element and it will trigger
 * the given function. 
 * 
 */
var ClickHide = angular.module('ClickHide', []);

ClickHide.directive('clickHide', function( $document, $parse, $timeout ){

	return{
		link: function( $scope, element, attr ){
			var self = this;
			
			self._init = function(){

				$scope.$watch( attr.chActivate, self.onActivationChange );
			}

			self.onActivationChange = function( newValue ){
				
				if( newValue == true ){
					$scope.listenForClick();
				}
				// in the case that the user changed the activation
				// condition without clicking outside the parentElement
				// ex. Clicking close instead. We then wan't to make sure 
				// we unbind the click listener - otherwise we'll get some
				// funky behaviour.
				else if( newValue == false ){
					
					console.log('ClickHide: Not listening now');
					$document.unbind('click', $scope.onClick);
				} 
			}

			$scope.listenForClick = function(){
				
				console.log('ClickHide: Starting to listen for global click!');
				
				$timeout(function(){
					$document.on('click', $scope.onClick);	
				}, 10);
			}

			/**
			 * First click after activating. 
			 */
			$scope.onClick = function( e ){
				console.log('ClickHide: Catching click');

				// check if the user has clicked outside of the 
				// element
				if( !self._isDecendantOfParent(e.target, element) ){ // yes he did

					// parse and execute the click
					// action
					$scope.$apply(function(){
						$parse(attr.chClick)($scope);	
					});
					
					console.log('ClickHide: Not listening now');
					$document.unbind('click', $scope.onClick); // now we don't have to listen anymore
				}
			}
			
			/**
			 * 
			 */
			self._isDecendantOfParent = function( decendantElement, parentElement ){
				
				var currentParent = decendantElement; 
				while( currentParent ){
					if( currentParent == parentElement[0]){ return true }
					
					currentParent = currentParent.parentNode;
				}
				return false;
			}
			self._init();
		}
	}
});
{'fraction_non_alphanumeric': 0.12979214780600462, 'fraction_numerical': 0.0013856812933025404, 'mean_word_length': 2.6182121971595658, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '3248043', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1251, 'n_words': 355}