<commit_before>$                  = require 'jquery'
KD                 = require './kd'
KDController       = require './controller'

###
todo:

  - make addLayer implementation more clear, by default adding a layer
    should set a listener for next ReceivedClickElsewhere and remove the layer automatically
    2012/5/21 Sinan
  - do not self-invoke (:293) -og

###


module.exports = class KDWindowController extends KDController

  addListener     = (eventName, listener, capturePhase = yes) ->
    window.addEventListener eventName, listener, capturePhase

  constructor:(options,data)->

    @windowResizeListeners = {}
    @keyEventsToBeListened = ['keydown', 'keyup', 'keypress']
    @keyView               = null
    @dragView              = null
    @layers                = []
    @unloadListeners       = {}
    @focusListeners        = []
    @focused               = yes

    @bindEvents()

    super options, data


  addLayer: (layer)->

    unless layer in @layers
      # log "layer added", layer
      @layers.push layer
      layer.on 'KDObjectWillBeDestroyed', =>
        @removeLayer layer


  removeLayer: (layer)->

    if layer in @layers
      # log "layer removed", layer
      index = @layers.indexOf(layer)
      @layers.splice index, 1


  bindEvents:->

    for eventName in @keyEventsToBeListened
      window.addEventListener eventName, @bound 'key'

    window.addEventListener 'resize', @bound 'notifyWindowResizeListeners'

    document.addEventListener 'scroll', do =>
      timer  = null
      {body} = document<commit_msg>winctrl: ocd<commit_after>$                  = require 'jquery'
KD                 = require './kd'
KDController       = require './controller'

###
todo:

  - make addLayer implementation more clear, by default adding a layer
    should set a listener for next ReceivedClickElsewhere and remove the layer automatically
    2012/5/21 Sinan
  - do not self-invoke (:293) -og

###


module.exports = class KDWindowController extends KDController

  addListener     = (eventName, listener, capturePhase = yes) ->
    window.addEventListener eventName, listener, capturePhase

  constructor:(options,data)->

    @windowResizeListeners = {}
    @keyEventsToBeListened = ['keydown', 'keyup', 'keypress']
    @keyView               = null
    @dragView              = null
    @layers                = []
    @unloadListeners       = {}
    @focusListeners        = []
    @focused               = yes

    @bindEvents()

    super options, data


  addLayer: (layer)->

    unless layer in @layers
      @layers.push layer
      layer.on 'KDObjectWillBeDestroyed', =>
        @removeLayer layer


  removeLayer: (layer)->

    if layer in @layers
      index = @layers.indexOf(layer)
      @layers.splice index, 1


  bindEvents:->

    for eventName in @keyEventsToBeListened
      window.addEventListener eventName, @bound 'key'

    window.addEventListener 'resize', @bound 'notifyWindowResizeListeners'

    document.addEventListener 'scroll', do =>
      timer  = null
      {body} = document
{'fraction_non_alphanumeric': 0.09859154929577464, 'fraction_numerical': 0.007206026858827383, 'mean_word_length': 2.408482142857143, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, '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': '7298156', 'n_tokens_mistral': 869, 'n_tokens_neox': 807, 'n_words': 238}