Sha256: 9d43363682e6479eb056fee45264a10483e2f4d4082bd62959bb4110347f09e2

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

#= require tao/form/shared/fields/moment_picker/element/base

class Tao.Form.MomentPicker.Element extends Tao.Form.MomentPicker.ElementBase

  _bind: ->
    super

    @on 'show', 'tao-moment-picker-segment-list', (e) =>
      @_positionList()

  _activeChanged: ->
    @_unbindDocumentMousedown()
    if @active
      @segmentList.setMoment(@moment)
      @_bindDocumentMousedown()

    @result.active = @active
    @segmentList.active = @active

  _unbindDocumentMousedown: ->
    $(document).off "mousedown.tao-moment-picker-#{@taoId}"

  _bindDocumentMousedown: ->
    $(document).on "mousedown.tao-moment-picker-#{@taoId}", (e) =>
      return if $.contains(@, e.target) && !(@multiple && @result == e.target)
      @active = false
      @_unbindDocumentMousedown()

  _positionList: ->
    rect = @getBoundingClientRect()
    offsetToWindowTop = rect.top
    offsetToWindowBottom = $(window).height() - rect.bottom
    listHeight = @segmentList.jq.outerHeight()

    @segmentList.direction = if offsetToWindowBottom < listHeight && offsetToWindowTop > offsetToWindowBottom
      'up'
    else
      'down'

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tao_form-0.1.2 lib/assets/javascripts/tao/form/fields/moment_picker/element.coffee
tao_form-0.1.1 lib/assets/javascripts/tao/form/fields/moment_picker/element.coffee
tao_form-0.1.0 lib/assets/javascripts/tao/form/fields/moment_picker/element.coffee