'use strict'; jQuery(function ($) { $('[data-head-settings]').each(function () { const $details = $(this); const source = $details.find('[data-head-source]').get(0); let editor; $details.on('toggle', () => { if (!this.open || !window.CodeMirror) return; if (!editor) { editor = window.CodeMirror.fromTextArea(source, { mode: 'htmlmixed', lineNumbers: true, lineWrapping: true, indentUnit: 2, tabSize: 2, }); editor.getInputField().setAttribute('aria-labelledby', 'head-source-label'); editor.on('change', () => editor.save()); } editor.refresh(); }); $details.on('click', '[data-head-asset]', function () { const mime = this.dataset.headAsset; $('#media-picker').trigger('studio:pick', [mime, (file) => { const tag = mime === 'text/css' ? $('', {rel: 'stylesheet', href: file.url}) : $('