Sha256: 3d6472f8ac94a614cf0fd8cf76d16e87dccb699e5467da94a884747b63580c71

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

$ ->
  # Slider for integer values stored in a string CMS attribute.

  scrivito.on 'editing', ->
    template = ->
      $('<div></div>')

    onStop = (event, ui) ->
      cmsField = $(@).data('cmsField')
      content = ui.value
      cmsField.scrivito('save', content).done ->
        cmsField.trigger('save.scrivito_editors')
        cmsField.trigger('scrivito_reload')

    onSlide = (event, ui) ->
      cmsField = $(@).data('cmsField')
      content = ui.value
      cmsField.text(ui.value)

    $('body').on 'click', '[data-editor="slider"]:not(.active)', (event) ->
      cmsField = $(event.currentTarget)
      content = cmsField.scrivito('content')
      min = cmsField.attr('data-min') || 1
      max = cmsField.attr('data-max') || 10
      step = cmsField.attr('data-step') || 1

      cmsField.addClass('active')

      template()
        .data('cmsField', cmsField)
        .insertAfter(cmsField)
        .slider(
          min: parseInt(min)
          max: parseInt(max)
          step: parseInt(step)
          value: content
          range: 'min'
          stop: onStop
          slide: onSlide
        )

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scrivito_editors-0.0.11 app/assets/javascripts/scrivito_editors/slider_editor.js.coffee