diff --git a/plugins/editors/codemirror/layouts/editors/codemirror/element.php b/plugins/editors/codemirror/layouts/editors/codemirror/element.php index 0a87c9ca22f52..0a719b8e0330d 100644 --- a/plugins/editors/codemirror/layouts/editors/codemirror/element.php +++ b/plugins/editors/codemirror/layouts/editors/codemirror/element.php @@ -20,17 +20,19 @@ $buttons = $displayData->buttons; $modifier = $params->get('fullScreenMod', '') !== '' ? implode($params->get('fullScreenMod', ''), ' + ') . ' + ' : ''; -JFactory::getDocument()->addScriptDeclaration(' - jQuery(function () { - var id = ' . json_encode($id) . ', options = ' . json_encode($options) . '; - /** Register Editor */ - Joomla.editors.instances[id] = CodeMirror.fromTextArea(document.getElementById(id), options); - }); -'); ?> +

get('fullScreen', 'F10')); ?>

-', $content, ''; ?> -buttons; ?> +', $content, ''; +?> + + diff --git a/plugins/editors/codemirror/layouts/editors/codemirror/init.php b/plugins/editors/codemirror/layouts/editors/codemirror/init.php index 5215c3c8d441f..0a85ac97f4e37 100644 --- a/plugins/editors/codemirror/layouts/editors/codemirror/init.php +++ b/plugins/editors/codemirror/layouts/editors/codemirror/init.php @@ -61,7 +61,7 @@ // jQuery's ready function. $(function () { // Some browsers do something weird with the fieldset which doesn't work well with CodeMirror. Fix it. - $(editor.getTextArea()).parent('fieldset').css('min-width', 0); + $(editor.getWrapperElement()).parent('fieldset').css('min-width', 0); // Listen for Bootstrap's 'shown' event. If this editor was in a hidden element when created, it may need to be refreshed. $(document.body).on("shown shown.bs.tab shown.bs.modal", function () { editor.refresh(); }); }); @@ -80,6 +80,24 @@ function makeMarker() marker.className = "CodeMirror-markergutter-mark"; return marker; } + + // Initialize any CodeMirrors on page load and when a subform is added + $(function ($) { + initCodeMirror(); + $('body').on('subform-row-add', initCodeMirror); + }); + + function initCodeMirror(event, container) + { + container = container || document; + $(container).find('textarea.codemirror-source').each(function () { + var input = $(this).removeClass('codemirror-source'); + var id = input.prop('id'); + + Joomla.editors.instances[id] = cm.fromTextArea(this, input.data('options')); + }); + } + }(CodeMirror, jQuery)); JS );