Sha256: 4da70c0add64ca7c7a7adfc11cc78a10cb720635b845b7f11b94dfbaec44570c

Contents?: true

Size: 1.12 KB

Versions: 7

Compression:

Stored size: 1.12 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')

      $(document).on 'click', '[data-scrivito-field-type="multienum"]:not([data-editor]), [data-editor~="multienum"]', (event) ->
        cmsField = $(event.currentTarget)
        selected = cmsField.scrivito('content')
        values = cmsField.data('values')

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

        cmsField.hide()

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
scrivito_editors-0.30.1 app/assets/javascripts/scrivito_editors/multienum_editor.js.coffee
scrivito_editors-0.30.0 app/assets/javascripts/scrivito_editors/multienum_editor.js.coffee
scrivito_editors-0.1.0 app/assets/javascripts/scrivito_editors/multienum_editor.js.coffee
scrivito_editors-0.0.16 app/assets/javascripts/scrivito_editors/multienum_editor.js.coffee
scrivito_editors-0.0.15 app/assets/javascripts/scrivito_editors/multienum_editor.js.coffee
scrivito_editors-0.0.14 app/assets/javascripts/scrivito_editors/multienum_editor.js.coffee
scrivito_editors-0.0.13 app/assets/javascripts/scrivito_editors/multienum_editor.js.coffee