Joywork/js/ckeditor2/plugins/variables/dialogs/variables.js
2026-05-22 21:21:54 +03:00

67 lines
3.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'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);
}
},
]
}
]
};
});