Sha256: 79389de7f23aaf276f7a1e78be341f07b4d2768b820078f77c5e65e506e1cfdc

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

$ ->
  # Define editor behavior for date attributes.

  scrivito.on 'editing', ->
    template = ->
      $('<input />')
        .attr('type', 'text')

    onKeyup = (event) ->
      key = event.keyCode || event.which

      switch key
        when 27 # Esc
          # Prevent the property view to close when the ESC key is pressed.
          event.stopPropagation()

    save = (dateTimeText) ->
      element = $(this)
      cmsField = element.data('cmsField')

      if dateTimeText? && dateTimeText.length > 0
        dateTimeText = new Date(dateTimeText)

      cmsField.scrivito('save', dateTimeText)
        .done ->
          cmsField.trigger('scrivito_reload')

    $('body').on 'click', '[data-scrivito-field-type="date"]:not(.hasDatepicker):not([data-editor]), [data-editor="date"]', (event) ->
      event.preventDefault()

      cmsField = $(this)
      content = cmsField.html().trim()
      dateFormat = cmsField.attr('data-date-format') || 'yy-mm-dd'
      timeFormat = cmsField.attr('data-time-format') || 'HH:mm:ss'

      $('body').keyup(onKeyup)

      template()
        .data('cmsField', cmsField)
        .insertAfter(cmsField)
        .val(content)
        .keyup(onKeyup)
        .datetimepicker(
          dateFormat: dateFormat
          timeFormat: timeFormat
          onClose: save
        )
        .focus()

      cmsField.hide()

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
scrivito_editors-0.0.10 app/assets/javascripts/scrivito_editors/date_editor.js.coffee
scrivito_editors-0.0.9 app/assets/javascripts/scrivito_editors/date_editor.js.coffee
scrivito_editors-0.0.8 app/assets/javascripts/scrivito_editors/date_editor.js.coffee