<commit_before>class View extends SimpleModule
  opts:
    cls: ''

  inputTpl: '<input class="momentpicker-input" />'
  panelTpl: ''

  _init: ->
    @id = @opts.id
    @parent = @opts.parent
    @moment = @opts.moment

    @_render()
    @_bind()

  _render: ->
    @_renderInput()
    @_renderPanel()
    if @opts.inline
      @el.hide()
      @panel.show()
    else
      @_setPosition()

  _renderInput: ->
    @el = $(@inputTpl).addClass("#{@name}-input").attr
      'type': 'text'
      'placeholder': @parent.el.attr 'placeholder'
    @el.appendTo(@parent.el.parent())
    @el.val(@moment.format(@opts.format)) if @parent.el.val()

  _renderPanel: ->
    @panel = $(@panelTpl).html(@_getPanelTpl()).addClass(@opts.cls).attr('id', "#{@name}-#{@id}")
    if @opts.inline
      @panel.insertAfter(@parent.el)
    else
      @panel.appendTo('body')

  _getPanelTpl: ->
    @panelTpl

  _reRenderPanel: ->
    @panel.html(@_getPanelTpl())
    @_setPosition() if not @opts.inline

  _setPosition: ->
    offset = @el.offset()
    @panel.css
      'position': 'absolute'
      'left': offset.left
      'top': offset.top + @el.outerHeight(true)

  _bind: ->
    @_bindEl()
    @_bindPanel()

    $(document).on "mousedown.momentpicker-#{@id}", (e)=>
      return if @el.is(e.target) or !!@panel.has(e.target).length or @panel.is(e.target)
      @hide() unless @opts.inline
    $(window).on "resize.momentpicker-#{@id}", (e)=>
      @_setPosition()

  _bindEl: ->
    @el.on 'focus', => 
      @show()
    .on 'click', ->
      @select()
    .on 'keydown', (e)=><commit_msg>panel 改为 append 到 el 之后<commit_after>class View extends SimpleModule
  opts:
    cls: ''

  inputTpl: '<input class="momentpicker-input" />'
  panelTpl: ''

  _init: ->
    @id = @opts.id
    @parent = @opts.parent
    @moment = @opts.moment

    @_render()
    @_bind()

  _render: ->
    @_renderInput()
    @_renderPanel()
    if @opts.inline
      @el.hide()
      @panel.show()
    else
      @_setPosition()

  _renderInput: ->
    @el = $(@inputTpl).addClass("#{@name}-input").attr
      'type': 'text'
      'placeholder': @parent.el.attr 'placeholder'
    @el.appendTo(@parent.el.parent())
    @el.val(@moment.format(@opts.format)) if @parent.el.val()

  _renderPanel: ->
    @panel = $(@panelTpl).html(@_getPanelTpl()).addClass(@opts.cls).attr('id', "#{@name}-#{@id}")
    @panel.insertAfter(@el)

  _getPanelTpl: ->
    @panelTpl

  _reRenderPanel: ->
    @panel.html(@_getPanelTpl())
    @_setPosition() if not @opts.inline

  _setPosition: ->
    position = @el.position()
    @panel.css
      'position': 'absolute'
      'left': position.left
      'top': position.top + @el.outerHeight(true)

  _bind: ->
    @_bindEl()
    @_bindPanel()

    $(document).on "mousedown.momentpicker-#{@id}", (e)=>
      return if @el.is(e.target) or !!@panel.has(e.target).length or @panel.is(e.target)
      @hide() unless @opts.inline
    $(window).on "resize.momentpicker-#{@id}", (e)=>
      @_setPosition()

  _bindEl: ->
    @el.on 'focus', => 
      @show()
    .on 'click', ->
      @select()
    .on 'keydown', (e)=>
{'fraction_non_alphanumeric': 0.20174306003873466, 'fraction_numerical': 0.0, 'mean_word_length': 2.7563636363636363, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '2045485', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1135, 'n_words': 196}