Sha256: 4cc1691b429270b13dabb6b0fbc8bc715bde9270ae595253f5e8957253868bb6

Contents?: true

Size: 1.78 KB

Versions: 11

Compression:

Stored size: 1.78 KB

Contents

$ ->
  # Define editor behavior for date attributes.

  scrivito.on 'load', ->
    if scrivito.in_editable_view()
      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 = (datetimepickerElement, dateTimeText, additionalDoneEvent) ->
        cmsField = datetimepickerElement.data('cmsField')
        datetime = datetimepickerElement.datetimepicker('getDate')
        cmsField.scrivito('save', datetime)
          .done ->
            cmsField.trigger('save.scrivito_editors')
            if additionalDoneEvent
              cmsField.trigger(additionalDoneEvent)

      onClose = (dateTimeText) ->
        save $(this), dateTimeText, 'scrivito_editors:blur'

      onSelect = (dateTimeText) ->
        save $(this), dateTimeText

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

        cmsField = $(this)
        content = cmsField.text().trim()

        $('body').keyup(onKeyup)

        dateFormat = cmsField.attr('data-date-format')
        timeFormat = cmsField.attr('data-time-format')

        options =
          onClose: onClose
          onSelect: onSelect

        options.dateFormat = dateFormat || 'yy-mm-dd'
        options.timeFormat = timeFormat if timeFormat

        template()
          .data('cmsField', cmsField)
          .insertAfter(cmsField)
          .keyup(onKeyup)
          .datetimepicker(options)
          .datetimepicker('setDate', $(cmsField).scrivito('content'))
          .focus()

        cmsField.hide()

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
scrivito_editors-0.70.2 app/assets/javascripts/scrivito_editors/date_editor.js.coffee
scrivito_editors-0.71.2 app/assets/javascripts/scrivito_editors/date_editor.js.coffee
scrivito_editors-0.71.1 app/assets/javascripts/scrivito_editors/date_editor.js.coffee
scrivito_editors-0.70.1 app/assets/javascripts/scrivito_editors/date_editor.js.coffee
scrivito_editors-0.71.0 app/assets/javascripts/scrivito_editors/date_editor.js.coffee
scrivito_editors-0.71.0.rc2 app/assets/javascripts/scrivito_editors/date_editor.js.coffee
scrivito_editors-0.71.0.rc1 app/assets/javascripts/scrivito_editors/date_editor.js.coffee
scrivito_editors-0.70.0 app/assets/javascripts/scrivito_editors/date_editor.js.coffee
scrivito_editors-0.70.0.rc3 app/assets/javascripts/scrivito_editors/date_editor.js.coffee
scrivito_editors-0.70.0.rc2 app/assets/javascripts/scrivito_editors/date_editor.js.coffee
scrivito_editors-0.70.0.rc1 app/assets/javascripts/scrivito_editors/date_editor.js.coffee