<commit_before>

angular.module('ngTether', [])
  .factory('Utils', function($compile) {
    var Utils = {};

    Utils.extendDeep = function(destination, source) {
      for (var property in source) {
        if (source[property] && source[property].constructor &&
          source[property].constructor === Object) {
          destination[property] = destination[property] || {};
          arguments.callee(destination[property], source[property]);
        } else {
          destination[property] = source[property];
        }
      }
      return destination;
    };

    return Utils;
  })
  .factory('Tether', function ($compile, $rootScope, $window, $animate, $controller, $timeout, $q, $http, $templateCache) {
    return function (config) {
      'use strict';

      if (!(!config.template ^ !config.templateUrl)) {
        throw new Error('Expected one of either `template` or `templateUrl`');
      }

      config.tether = config.tether || {};

      var
        controller    = config.controller || angular.noop,
        controllerAs  = config.controllerAs,
        parentScope   = config.parentScope || $rootScope,
        extend        = angular.extend,
        element       = null,
        scope, html, tether,
        bodyEl = angular.element($window.document.body);

      var target = config.tether.target = config.tether.target || bodyEl;


      // Attach a tether element and the target element.
      function attachTether() {
        tether = new Tether(extend({
          element: element[0]
        }, config.tether));
      }

      if (config.template) {
        var deferred = $q.defer();
        deferred.resolve($templateCache.get(config.template) || config.template);
        html = deferred.promise;
      } else {
        html = $http.get(config.templateUrl, {
          cache: $templateCache
        }).then(function (response) {
          return response.data;
        });
      }

      function create(html, locals) {
        element = angular.element(html);

        scope = parentScope.$new();
        if (locals) {
          scope.$locals = locals;
        }

        if (config.controller) {
          var ctrl = $controller(controller, { $scope: scope });
        }
        if (controllerAs) {
          scope[controllerAs] = ctrl;
        }
        $compile(element)(scope);
        scope.$on('$destroy', destroy);

        $timeout(function(){
          $animate.enter(element, bodyEl);
          attachTether();
          tether.position();

          if (config.leaveOnBlur) {
            bodyEl.on('click', leaveOnBlur);
          }
        })
      }

      function leaveOnBlur(evt) {
        var target = evt.target;
        while (target.parentElement !== null) {
          if (target.parentElement == element[0]) {
            return
          }
          target = target.parentElement;
        }

        bodyEl.off('click', leaveOnBlur);
        return leave();
      }

      // Attach tether and add it to the dom
      function enter(locals) {
        html.then(function (html) {
          create(html, locals);
        });<commit_msg>blur, missing elem fix<commit_after>

angular.module('ngTether', [])
  .factory('Utils', function($compile) {
    var Utils = {};

    Utils.extendDeep = function(destination, source) {
      for (var property in source) {
        if (source[property] && source[property].constructor &&
          source[property].constructor === Object) {
          destination[property] = destination[property] || {};
          arguments.callee(destination[property], source[property]);
        } else {
          destination[property] = source[property];
        }
      }
      return destination;
    };

    return Utils;
  })
  .factory('Tether', function ($compile, $rootScope, $window, $animate, $controller, $timeout, $q, $http, $templateCache) {
    return function (config) {
      'use strict';

      if (!(!config.template ^ !config.templateUrl)) {
        throw new Error('Expected one of either `template` or `templateUrl`');
      }

      config.tether = config.tether || {};

      var
        controller    = config.controller || angular.noop,
        controllerAs  = config.controllerAs,
        parentScope   = config.parentScope || $rootScope,
        extend        = angular.extend,
        element       = null,
        scope, html, tether,
        bodyEl = angular.element($window.document.body);

      var target = config.tether.target = config.tether.target || bodyEl;


      // Attach a tether element and the target element.
      function attachTether() {
        tether = new Tether(extend({
          element: element[0]
        }, config.tether));
      }

      if (config.template) {
        var deferred = $q.defer();
        deferred.resolve($templateCache.get(config.template) || config.template);
        html = deferred.promise;
      } else {
        html = $http.get(config.templateUrl, {
          cache: $templateCache
        }).then(function (response) {
          return response.data;
        });
      }

      function create(html, locals) {
        element = angular.element(html);

        scope = parentScope.$new();
        if (locals) {
          scope.$locals = locals;
        }

        if (config.controller) {
          var ctrl = $controller(controller, { $scope: scope });
        }
        if (controllerAs) {
          scope[controllerAs] = ctrl;
        }
        $compile(element)(scope);
        scope.$on('$destroy', destroy);

        $timeout(function(){
          $animate.enter(element, bodyEl);
          attachTether();
          tether.position();

          if (config.leaveOnBlur) {
            bodyEl.on('click', leaveOnBlur);
          }
        })
      }

      function leaveOnBlur(evt) {
        var target = evt.target;
        if (!element || target === element[0]) return;
        while (target.parentElement !== null) {
          if (target.parentElement == element[0]) {
            return
          }
          target = target.parentElement;
        }

        bodyEl.off('click', leaveOnBlur);
        return leave();
      }

      // Attach tether and add it to the dom
      function enter(locals) {
        html.then(function (html) {
          create(html, locals);
        });
{'fraction_non_alphanumeric': 0.13079629037416055, 'fraction_numerical': 0.0007994883274704189, 'mean_word_length': 2.00288046087374, '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': '6053314', 'n_tokens_mistral': 1726, 'n_tokens_neox': 1682, 'n_words': 374}