Sha256: 22a0719f73f97e3eaa1136654a30cccf9e4ec0bb8ee7b4cf774d01202e2d3fae

Contents?: true

Size: 1.74 KB

Versions: 5

Compression:

Stored size: 1.74 KB

Contents

(function() {
  var activate, blur, change, save, template;

  template = function(values) {
    var element;
    element = $('<select></select>').addClass('form-control');
    $.each(values, function(index, value) {
      return $('<option></option>').attr('value', value).text(value).appendTo(element);
    });
    return element;
  };

  save = function(event, options) {
    var cmsField, content, element;
    element = $(event.currentTarget);
    cmsField = element.data('scrivitoEditorsCmsField');
    content = element.val();
    if (content === '') {
      content = null;
    }
    return cmsField.scrivito('save', content).done(function() {
      cmsField.trigger('scrivito_editors:save');
      if (options != null ? options.blur : void 0) {
        return cmsField.trigger('scrivito_editors:blur');
      }
    });
  };

  change = function(event) {
    return save(event);
  };

  blur = function(event) {
    return save(event, {
      blur: true
    });
  };

  activate = function(element) {
    var cmsField;
    cmsField = $(element);
    return cmsField.on('click', function() {
      var content, values;
      content = cmsField.scrivito('content');
      values = cmsField.scrivito('allowed_values');
      values.unshift('');
      template(values).data('scrivitoEditorsCmsField', cmsField).val(content || '').insertAfter(cmsField).change(change).blur(blur).focus();
      return cmsField.hide();
    });
  };

  scrivito.editors.enum_editor = {
    can_edit: function(element) {
      return $(element).is('[data-scrivito-field-type=enum]');
    },
    activate: function(element) {
      return activate(element);
    }
  };

  scrivito.on('load', function() {
    return scrivito.define_editor('enum', scrivito.editors.enum_editor);
  });

}).call(this);

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
scrivito_editors-1.1.1 app/assets/javascripts/scrivito_editors/enum_editor.js
scrivito_editors-1.1.0 app/assets/javascripts/scrivito_editors/enum_editor.js
scrivito_editors-1.1.0.rc3 app/assets/javascripts/scrivito_editors/enum_editor.js
scrivito_editors-1.1.0.rc2 app/assets/javascripts/scrivito_editors/enum_editor.js
scrivito_editors-1.1.0.rc1 app/assets/javascripts/scrivito_editors/enum_editor.js