Sha256: 61c0a27776a6e8e9a3e9a23325bdccd87340f27d4fa6d0f3375295d5343bdbba

Contents?: true

Size: 1.9 KB

Versions: 9

Compression:

Stored size: 1.9 KB

Contents

(function() {
  var activate, clear, save, template,
    indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };

  clear = '__scrivito_editors_enum_clear';

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

  save = function(event) {
    var cmsField, content, element;
    element = $(event.currentTarget);
    cmsField = element.data('cmsField');
    content = element.val();
    if (content === clear) {
      content = null;
    }
    return cmsField.scrivito('save', content).done(function() {
      return cmsField.trigger('save.scrivito_editors');
    });
  };

  activate = function(element) {
    var cmsField;
    cmsField = $(element);
    return cmsField.on('click', function() {
      var content, selected, values;
      content = cmsField.scrivito('content');
      values = cmsField.scrivito('allowed_values');
      if (indexOf.call(values, '') < 0) {
        values.push(clear);
      }
      if (content) {
        selected = content;
      } else {
        selected = clear;
      }
      template(values).data('cmsField', cmsField).val(selected).insertAfter(cmsField).change(save).focusout(save).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

9 entries across 9 versions & 1 rubygems

Version Path
scrivito_editors-1.0.0 app/assets/javascripts/scrivito_editors/enum_editor.js
scrivito_editors-1.0.0.rc4 app/assets/javascripts/scrivito_editors/enum_editor.js
scrivito_editors-1.0.0.rc3 app/assets/javascripts/scrivito_editors/enum_editor.js
scrivito_editors-1.0.0.rc2 app/assets/javascripts/scrivito_editors/enum_editor.js
scrivito_editors-1.0.0.rc1 app/assets/javascripts/scrivito_editors/enum_editor.js
scrivito_editors-0.90.0 app/assets/javascripts/scrivito_editors/enum_editor.js
scrivito_editors-0.90.0.rc3 app/assets/javascripts/scrivito_editors/enum_editor.js
scrivito_editors-0.90.0.rc2 app/assets/javascripts/scrivito_editors/enum_editor.js
scrivito_editors-0.90.0.rc1 app/assets/javascripts/scrivito_editors/enum_editor.js