Sha256: 7f8772a6772fa725266f4ebe8b7c992c90f49c3926f0008f21ff7a7c5eb6aa81
Contents?: true
Size: 1.68 KB
Versions: 82
Compression:
Stored size: 1.68 KB
Contents
(function() { var activate, handleClick, renderTemplate, save; 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); }); 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(value, validValues) { var i, len, li, ul, validValue; ul = $('<ul class="scrivito_enum_editor"></ul>'); for (i = 0, len = validValues.length; i < len; i++) { validValue = validValues[i]; li = $('<li></li>'); li.text(validValue); if (validValue === value) { li.addClass('scrivito_enum_active'); } ul.append(li); } return ul; }; handleClick = function(cmsField, clickedItem) { if (clickedItem.hasClass('scrivito_enum_active')) { clickedItem.removeClass('scrivito_enum_active'); save(cmsField, null); } else { cmsField.find('li').removeClass('scrivito_enum_active'); clickedItem.addClass('scrivito_enum_active'); save(cmsField, clickedItem.text()); } return false; }; save = function(cmsField, value) { return cmsField.scrivito('save', value).done(function() { cmsField.trigger('scrivito_editors:save'); return cmsField.trigger('scrivito_editors:blur'); }); }; }).call(this);
Version data entries
82 entries across 82 versions & 1 rubygems