Sha256: 19d3eb62ddf7a953b264d66a5043917e170a1a1d368f40998551e572b9348c42

Contents?: true

Size: 1.22 KB

Versions: 15

Compression:

Stored size: 1.22 KB

Contents

$ ->
  # Define editor behavior for multienum attributes.

  scrivito.on 'load', ->
    if scrivito.in_editable_view()
      template = (values) ->
        element = $('<select></select>')
          .attr('multiple', 'true')
          .addClass('form-control')

        $.each values, (index, value) ->
          $('<option></option>')
            .attr('value', value)
            .text(value)
            .appendTo(element)

        element

      save = (event) ->
        element = $(event.currentTarget)
        cmsField = element.data('cmsField')
        content = element.val() ? []
        cmsField.scrivito('save', content).done ->
          cmsField.trigger('save.scrivito_editors')

      multienumEditSelector = '[data-values][data-scrivito-field-type="multienum"]' +
          ':not([data-editor]), [data-editor~="multienum"]'

      $(document).on 'click', multienumEditSelector, (event) ->
        cmsField = $(event.currentTarget)
        selected = cmsField.scrivito('content')
        values = cmsField.data('values')

        template(values)
          .data('cmsField', cmsField)
          .val(selected)
          .insertAfter(cmsField)
          .change(save)
          .focusout(save)
          .focus()

        cmsField.hide()

Version data entries

15 entries across 15 versions & 1 rubygems

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