Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make CodeMirror work in repeatable subforms #12542

Merged
merged 3 commits into from
Apr 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions plugins/editors/codemirror/layouts/editors/codemirror/element.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
');
?>

<p class="label">
<?php echo JText::sprintf('PLG_CODEMIRROR_TOGGLE_FULL_SCREEN', $modifier, $params->get('fullScreen', 'F10')); ?>
</p>
<?php echo '<textarea name="', $name, '" id="', $id, '" cols="', $cols, '" rows="', $rows, '">', $content, '</textarea>'; ?>

<?php echo $displayData->buttons; ?>
<?php
echo '<textarea class="codemirror-source" name="', $name,
'" id="', $id,
'" cols="', $cols,
'" rows="', $rows,
'" data-options="', htmlspecialchars(json_encode($options)),
'">', $content, '</textarea>';
?>

<?php echo $buttons; ?>
20 changes: 19 additions & 1 deletion plugins/editors/codemirror/layouts/editors/codemirror/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(); });
});
Expand All @@ -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
);