<commit_before>angular.module('fileManager').
directive('zoneSelection', (Selection, $document)->
  return {
    restrict: 'A'
    link: (scope, element, attrs)->
      w    = window
      e    = window.document.documentElement
      g    = window.document.getElementsByTagName('body')[0]
      body = window.document.getElementsByTagName('body')[0]
      zone = window.document.getElementById('zone')
      scope.last = 0

      # Creation
      if not zone?
        zone = window.document.createElement('div')
        zone.className = "zone-selection"
        zone.setAttribute('id', 'zone')


      # IsInSelection
      isInSelection = (file)->
        x = w.innerWidth || e.clientWidth || g.clientWidth
        y = w.innerHeight|| e.clientHeight|| g.clientHeight

        selection = zone.getBoundingClientRect()
        selection.right  = x-selection.right
        selection.bottom = y-selection.right

        file = file.getBoundingClientRect()
        file.right  = x-file.right
        file.bottom = y-file.bottom

        if (file.top <= selection.top <= file.bottom or
        file.top <= selection.bottom <= file.bottom or
        selection.top <= file.top <= file.bottom <= selection.bottom) and
        (selection.left <= file.left <= selection.right or
        selection.left <=  file.right <= selection.right or
        file.left <= selection.left <= selection.right <= file.right)
          return true

        return false


      element.on('mousedown', ($event)->
        if $event.buttons == 1 and not $event.target.className.match(/^file.*/)
          Selection.clear()
          body.appendChild(zone)
          scope.start = $event
          scope.files = window.document.getElementsByClassName('file')
      )
      $document.on('mousemove', ($event)->
        actual = new Date().getTime()
        if scope.start? and scope.last+30<actual
          scope.last = actual
          scope.end  = $event

          x = w.innerWidth || e.clientWidth || g.clientWidth
          y = w.innerHeight|| e.clientHeight|| g.clientHeight

          if scope.start.clientY < scope.end.clientY
            zone.style.top    = "#{scope.start.clientY}px"
            zone.style.bottom = "#{y-scope.end.clientY}px"
          else
            zone.style.top    = "#{scope.end.clientY}px"
            zone.style.bottom = "#{y-scope.start.clientY}px"

          if scope.start.clientX < scope.end.clientX
            zone.style.left  = "#{scope.start.clientX}px"
            zone.style.right = "#{x-scope.end.clientX}px"
          else
            zone.style.left  = "#{scope.end.clientX}px"
            zone.style.right = "#{x-scope.start.clientX}px"

          for file in scope.files
            obj = angular.element(file).scope().file
            if isInSelection(file)
              Selection.add(obj)
            else
              Selection.remove(obj)
      )
      $document.on('mouseup', ($event)->
        angular.element(zone).remove?()
        zone.style = {}
        scope.start = null<commit_msg>Support Chrome for the ZoneSelection. Make the interface refresh a little bit more.<commit_after>angular.module('fileManager').
directive('zoneSelection', (Selection, $document)->
  return {
    restrict: 'A'
    link: (scope, element, attrs)->
      w    = window
      e    = window.document.documentElement
      g    = window.document.getElementsByTagName('body')[0]
      body = window.document.getElementsByTagName('body')[0]
      zone = window.document.getElementById('zone')
      scope.last = 0

      # Creation
      if not zone?
        zone = window.document.createElement('div')
        zone.className = "zone-selection"
        zone.setAttribute('id', 'zone')


      # IsInSelection
      isInSelection = (file)->
        x = w.innerWidth || e.clientWidth || g.clientWidth
        y = w.innerHeight|| e.clientHeight|| g.clientHeight

        selection = zone.getBoundingClientRect()
        selection.right  = x-selection.right
        selection.bottom = y-selection.right

        file = file.getBoundingClientRect()
        file.right  = x-file.right
        file.bottom = y-file.bottom

        if (file.top <= selection.top <= file.bottom or
        file.top <= selection.bottom <= file.bottom or
        selection.top <= file.top <= file.bottom <= selection.bottom) and
        (selection.left <= file.left <= selection.right or
        selection.left <=  file.right <= selection.right or
        file.left <= selection.left <= selection.right <= file.right)
          return true

        return false


      element.on('mousedown', ($event)->
        if ($event.buttons == 1 or $event.button == 0) and not $event.target.className.match(/^file.*/)
          Selection.clear()
          body.appendChild(zone)
          scope.start = $event
          scope.files = window.document.getElementsByClassName('file')
      )
      $document.on('mousemove', ($event)->
        actual = new Date().getTime()
        if scope.start? and scope.last+20<actual
          scope.last = actual
          scope.end  = $event

          x = w.innerWidth || e.clientWidth || g.clientWidth
          y = w.innerHeight|| e.clientHeight|| g.clientHeight

          if scope.start.clientY < scope.end.clientY
            zone.style.top    = "#{scope.start.clientY}px"
            zone.style.bottom = "#{y-scope.end.clientY}px"
          else
            zone.style.top    = "#{scope.end.clientY}px"
            zone.style.bottom = "#{y-scope.start.clientY}px"

          if scope.start.clientX < scope.end.clientX
            zone.style.left  = "#{scope.start.clientX}px"
            zone.style.right = "#{x-scope.end.clientX}px"
          else
            zone.style.left  = "#{scope.end.clientX}px"
            zone.style.right = "#{x-scope.start.clientX}px"

          for file in scope.files
            obj = angular.element(file).scope().file
            if isInSelection(file)
              Selection.add(obj)
            else
              Selection.remove(obj)
      )
      $document.on('mouseup', ($event)->
        angular.element(zone).remove?()
        zone.style = {}
        scope.start = null
{'fraction_non_alphanumeric': 0.13283289817232377, 'fraction_numerical': 0.0021214099216710185, 'mean_word_length': 2.058383233532934, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 15, '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': '7580461', 'n_tokens_mistral': 1774, 'n_tokens_neox': 1740, 'n_words': 338}