<commit_before>_                 = require 'underscore'
Backbone          = require 'backbone'
mediator          = require '../../lib/mediator.coffee'
modalTemplate     = -> require('./modal.jade') arguments...
Transition        = require '../mixins/transition.coffee'
{ isTouchDevice } = require '../../components/util/device.coffee'

module.exports = class ModalView extends Backbone.View
  id: 'modal'
  container: '#modal-container'

  template: ->
    'Requires a template'

  templateData: {}

  events: ->
    'click .modal-backdrop': 'close'
    'click .modal-close': 'close'
    'click .modal-dialog': '_intercept'

  initialize: (options = {}) ->
    { @width } = _.defaults options, width: '400px'

    _.extend @templateData, autofocus: @autofocus()

    @resize = _.debounce @updatePosition, 100

    @$window = $(window)
    @$window.on 'keyup', @escape
    @$window.on 'resize', @resize

    mediator.on 'modal:close', @close, this
    mediator.on 'modal:opened', @updatePosition, this

    @open()

  _intercept: (e) ->
    e.stopPropagation()

  escape: (e) ->
    return unless e.which is 27

    mediator.trigger 'modal:close'

  updatePosition: =>
    @$dialog.css
      top:  ((@$el.height() - @$dialog.height()) / 2) + 'px'
      left: ((@$el.width() - @$dialog.width()) / 2) + 'px'

  autofocus: ->
    if isTouchDevice() then undefined else true

  isLoading: ->
    @$el.addClass 'is-loading'
    @$dialog.hide().addClass 'is-notransition'
<commit_msg>Trigger events for child views to listen to<commit_after>_                 = require 'underscore'
Backbone          = require 'backbone'
mediator          = require '../../lib/mediator.coffee'
modalTemplate     = -> require('./modal.jade') arguments...
Transition        = require '../mixins/transition.coffee'
{ isTouchDevice } = require '../../components/util/device.coffee'

module.exports = class ModalView extends Backbone.View
  id: 'modal'
  container: '#modal-container'

  template: ->
    'Requires a template'

  templateData: {}

  events: ->
    'click.handler .modal-backdrop' : 'close'
    'click.handler .modal-close'    : 'close'

    'click.internal .modal-dialog'   : '__intercept__'
    'click.internal .modal-close'    : '__announceCloseButtonClick__'
    'click.internal .modal-backdrop' : '__announceBackdropClick__'

  initialize: (options = {}) ->
    { @width } = _.defaults options, width: '400px'

    _.extend @templateData, autofocus: @autofocus()

    @resize = _.debounce @updatePosition, 100

    @$window = $(window)
    @$window.on 'keyup', @escape
    @$window.on 'resize', @resize

    mediator.on 'modal:close', @close, this
    mediator.on 'modal:opened', @updatePosition, this

    @open()

  __intercept__: (e) ->
    e.stopPropagation()

  __announceCloseButtonClick__: ->
    @trigger 'click:close'

  __announceBackdropClick__: ->
    @trigger 'click:backdrop'

  escape: (e) ->
    return unless e.which is 27

    mediator.trigger 'modal:close'

  updatePosition: =>
    @$dialog.css
      top:  ((@$el.height() - @$dialog.height()) / 2) + 'px'
      left: ((@$el.width() - @$dialog.width()) / 2) + 'px'

  autofocus: ->
    if isTouchDevice() then undefined else true

  isLoading: ->
    @$el.addClass 'is-loading'
    @$dialog.hide().addClass 'is-notransition'

{'fraction_non_alphanumeric': 0.16276239732278674, 'fraction_numerical': 0.0060845756008518406, 'mean_word_length': 2.900355871886121, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '490909', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1054, 'n_words': 239}