Joywork/js/ckeditor2/plugins/variables/dialogs/variables.js

67 lines
3.5 KiB
JavaScript
Raw Permalink Normal View History

2026-05-22 20:21:54 +02:00
'use strict';
CKEDITOR.dialog.add( 'variables', function(editor) {
let validNameRegex = /^\$\{[a-zA-z0-9_.]+\}/;
return {
title: "Переменная",
minHeight: 60,
minWidth: 280,
contents: [
{
id: 'info',
label: "Вставить переменную",
title: "Вставить переменную",
elements: [
{
id: 'name',
type: 'select',
style: 'width: 100%;',
className: 'fastselect',
label: "Выберите переменную:",
items: editor.config.customValues.variablesList,
'default': '',
required: true,
validate: CKEDITOR.dialog.validate.regex(validNameRegex, "Неверный формат переменной"),
setup: function(widget) {
this.setValue("${" + widget.data.name + "}");
},
onLoad: function(elem) {
let select_id = '#' + this._.inputId;
let select = $(select_id).clone();
select.find('option').first().before('<option value="0">Не выбрано</option>');
$(select_id).closest('.cke_dialog_ui_labeled_content').html(select);
$(select_id).closest('.cke_dialog_container').removeClass('cke_reset_all');
$(select_id).closest('.cke_dialog_container').find('label[for="'+this._.inputId+'"]').remove();
$(select_id).fastselect({
placeholder: "Выберите переменную"
});
$(select_id).closest(".fstElement").find(".fstControls input.hidenClass").attr('type', "text");
$(select_id).closest(".fstElement").find(".fstControls input.hidenClass").removeClass('hidenClass');
},
onShow: function(widget) {
let select_id = '#' + this._.inputId;
let select = $(select_id).clone();
$(select_id).closest('.cke_dialog_ui_labeled_content').html(select);
$(select_id).closest('.cke_dialog_container').removeClass('cke_reset_all');
$(select_id).closest('.cke_dialog_container').find('label[for="'+this._.inputId+'"]').remove();
$(select_id).fastselect({
placeholder: "Выберите переменную"
});
$(select_id).closest(".fstElement").find(".fstControls input.hidenClass").attr('type', "text");
$(select_id).closest(".fstElement").find(".fstControls input.hidenClass").removeClass('hidenClass');
},
commit: function(widget) {
let variable = this.getValue();
variable = variable.replace("${", "");
variable = variable.replace("}", "");
widget.setData('name', variable);
}
},
]
}
]
};
});