(function() { var DELETE_BUTTON_TEMPLATE, activate, activateUi, save; activate = function(element) { var cmsField, objId; cmsField = $(element); scrivito.editors.applyPlaceholder(cmsField); if (cmsField.is('[data-scrivito-editors-allow-delete=true]')) { activateUi(cmsField); } if (cmsField.not('video, audio, img')) { objId = cmsField.scrivito('content'); if (objId && !cmsField.children().length) { scrivito.description_for_editor([objId]).then(function(results) { return cmsField.text(results[0]); }); } } return cmsField.on('click', function(event) { var filterContext, filters, isImage, selected; event.preventDefault(); selected = [cmsField.scrivito('content')].filter(function(element) { return element; }); isImage = cmsField.is('img'); filters = cmsField.data('scrivitoEditorsFilters'); filterContext = $.extend({ _image: isImage }, cmsField.data('scrivitoEditorsFilterContext')); return scrivito.content_browser.open({ filters: filters, filter_context: filterContext, selection: selected, selection_mode: 'single' }).done((function(_this) { return function(selection) { return save(cmsField, selection[0] || null); }; })(this)); }); }; activateUi = function(cmsField) { var container; container = scrivito.editors._setupButtonContainer(cmsField); if (cmsField.scrivito('content')) { return $(DELETE_BUTTON_TEMPLATE).prependTo(container).click(function() { save(cmsField, null); return false; }); } }; DELETE_BUTTON_TEMPLATE = "\n \n"; save = function(cmsField, value) { cmsField.scrivito('save', value).done(function() { cmsField.trigger('scrivito_editors:save'); cmsField.trigger('scrivito_editors:blur'); return cmsField.scrivito('reload'); }); return true; }; scrivito.editors.reference_editor = { can_edit: function(element) { return $(element).is('[data-scrivito-field-type=reference]'); }, activate: function(element) { return activate(element); } }; scrivito.on('load', function() { return scrivito.define_editor('reference', scrivito.editors.reference_editor); }); }).call(this);