(function() { var activate, handleClick, renderTemplate, 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; }; scrivito.editors.multienum_editor = { can_edit: function(element) { return $(element).is('[data-scrivito-field-type=multienum]'); }, activate: function(element) { return activate($(element)); } }; scrivito.on('load', function() { return scrivito.define_editor('multienum', scrivito.editors.enum_editor); }); activate = function(cmsField) { cmsField.html(renderTemplate(cmsField.scrivito('content'), cmsField.scrivito('valid_values'))); return cmsField.find('.scrivito_enum_editor li').on('click', function() { return handleClick(cmsField, $(this)); }); }; renderTemplate = function(values, validValues) { var i, len, li, ul, validValue; ul = $(''); for (i = 0, len = validValues.length; i < len; i++) { validValue = validValues[i]; li = $('
  • '); li.text(validValue); if (indexOf.call(values, validValue) >= 0) { li.addClass('scrivito_enum_active'); } ul.append(li); } return ul; }; handleClick = function(cmsField, clickedItem) { var values; clickedItem.toggleClass('scrivito_enum_active'); values = $.map(cmsField.find('li.scrivito_enum_active'), function(item) { return $(item).text(); }); cmsField.scrivito('save', values).done(function() { cmsField.trigger('scrivito_editors:save'); return cmsField.trigger('scrivito_editors:blur'); }); return false; }; }).call(this);