backoffice: insert variable tag in last used textarea (#46097)

This commit is contained in:
Frédéric Péters 2020-08-25 18:07:17 +02:00
parent b6b343a53d
commit 72db95d069
1 changed files with 9 additions and 3 deletions

View File

@ -8,13 +8,19 @@ $(function() {
$('h4.foldable.folded').next().hide();
/* insert variable code in textarea when clicking on them */
var latest_textarea = null;
if ($('textarea').length == 1) {
latest_textarea = $('textarea');
}
$('textarea').on('focus', function() { latest_textarea = this; });
$('#substvars td:nth-child(2)').css('cursor', 'pointer').click(function() {
var current_val = $('textarea').val();
position = $('textarea').get(0).selectionStart;
if (latest_textarea === null) return true;
var current_val = $(latest_textarea).val();
position = $(latest_textarea).get(0).selectionStart;
if (position >= 0) {
var code = $(this).text();
var new_val = current_val.substr(0, position) + code + current_val.substr(position);
$('textarea').val(new_val);
$(latest_textarea).val(new_val);
}
return true;
});