<commit_before>_ = require 'underscore'
Backbone = require 'backbone'
template = require './templates/index.coffee'
Scrollbar = require '../scrollbar/index.coffee'

module.exports = class Modalize extends Backbone.View
  className: 'modalize'

  defaults: dimensions: width: '400px'

  events:
    'click .js-modalize-backdrop': 'maybeClose'
    'click .js-modalize-close': 'close'

  initialize: (options = {}) ->
    { @subView, @dimensions } = _.defaults options, @defaults
    @scrollbar = new Scrollbar

  state: (state, callback = $.noop) ->
    _.defer =>
      @$el
        .attr 'data-state', state
        .one $.support.transition.end, callback
        .emulateTransitionEnd 250

  render: ->
    @$el.html template()
    @postRender()
    this

  postRender: ->
    @$('.js-modalize-dialog')
      .css @dimensions

    @$('.js-modalize-body')
      .html @subView.render().$el

    @scrollbar.disable()

    @state 'open'

  maybeClose: (e) ->
    @close() if $(e.target).hasClass('js-modalize-backdrop')

  close: (callback) ->
    @scrollbar.reenable()

    @state 'close', =>
      @subView?.remove?()
      @remove()
      callback?()<commit_msg>Only render outer a single time; otherwise just re-render the subview<commit_after>_ = require 'underscore'
Backbone = require 'backbone'
template = require './templates/index.coffee'
Scrollbar = require '../scrollbar/index.coffee'

module.exports = class Modalize extends Backbone.View
  className: 'modalize'

  defaults: dimensions: width: '400px'

  events:
    'click .js-modalize-backdrop': 'maybeClose'
    'click .js-modalize-close': 'close'

  initialize: (options = {}) ->
    { @subView, @dimensions } = _.defaults options, @defaults
    @scrollbar = new Scrollbar

  state: (state, callback = $.noop) ->
    _.defer =>
      @$el
        .attr 'data-state', state
        .one $.support.transition.end, callback
        .emulateTransitionEnd 250

  render: ->
    unless @__rendered__
      @$el.html template()
      @__rendered__ = true
    @postRender()
    this

  postRender: ->
    unless @__postRendered__
      @$('.js-modalize-dialog').css @dimensions
      @$('.js-modalize-body').html @subView.render().$el
      @scrollbar.disable()
      @state 'open'
      @__postRendered__ = true
    else
      @subView.render().$el

  maybeClose: (e) ->
    @close() if $(e.target).hasClass('js-modalize-backdrop')

  close: (callback) ->
    @scrollbar.reenable()
    @state 'close', =>
      @subView?.remove?()
      @remove()
      callback?()
{'fraction_non_alphanumeric': 0.15695600475624258, 'fraction_numerical': 0.0047562425683709865, 'mean_word_length': 2.859327217125382, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, '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': '6177723', 'n_tokens_mistral': 842, 'n_tokens_neox': 801, 'n_words': 181}