$ -> # Integrates a content browser based editor for reference CMS attributes. scrivito.on 'load', -> if scrivito.in_editable_view() $('body').on 'click', '[data-scrivito-field-type="reference"]:not([data-editor]), [data-editor~="reference"]', (event) -> event.preventDefault() cmsField = $(event.currentTarget) selected = [cmsField.scrivito('content')].filter (element) -> element filters = cmsField.data('filters') || cmsField.data('filter') # Open content browser with current reference selected. scrivito.content_browser.open selection: selected filters: filters selection_mode: 'single' .done (selection) => onContentBrowserSave(selection, cmsField) # Save single reference when content browser calls "save". onContentBrowserSave = (selection, cmsField) -> value = selection[0] || null cmsField.scrivito('save', value) .done -> cmsField.trigger('save.scrivito_editors') cmsField.scrivito('reload') true