forked from laysense/laysite
Prepare LaySite 1.4.4 editor templates and MCP settings
This commit is contained in:
+34
-9
@@ -379,6 +379,7 @@ jQuery(function ($) {
|
||||
const $commands = $toolbar.find('[data-canvas-command]');
|
||||
const $format = $toolbar.find('[data-canvas-format]');
|
||||
const $fontSize = $toolbar.find('[data-canvas-font-size]');
|
||||
const $fontPreset = $toolbar.find('[data-font-preset]');
|
||||
const $color = $toolbar.find('[data-canvas-color]');
|
||||
const $clearColor = $toolbar.find('[data-clear-color]');
|
||||
const $imageDisplay = $toolbar.find('[data-canvas-image-display]');
|
||||
@@ -749,7 +750,7 @@ jQuery(function ($) {
|
||||
|
||||
function syncFormatControls() {
|
||||
const target = doc && formatTarget();
|
||||
$format.add($fontSize).prop('disabled', !target);
|
||||
$format.add($fontSize).add($fontPreset).prop('disabled', !target);
|
||||
const sample = target && (selectedText()[0]?.node || target);
|
||||
const computed = sample ? doc.defaultView.getComputedStyle(sample.nodeType === 1 ? sample : sample.parentElement) : null;
|
||||
if (!$fontSize.is(':focus')) $fontSize.val(computed ? Math.round(parseFloat(computed.fontSize)) : '');
|
||||
@@ -811,8 +812,12 @@ jQuery(function ($) {
|
||||
});
|
||||
$toolbar.on('mousedown', '[data-canvas-format], [data-clear-color]', (event) => event.preventDefault());
|
||||
$format.on('click', function () { applyTextStyle(this.dataset.canvasFormat); });
|
||||
$fontPreset.on('change', function () {
|
||||
applyTextStyle('size', this.value);
|
||||
this.value = '';
|
||||
});
|
||||
$fontSize.on('change', function () {
|
||||
if (this.validity.valid) applyTextStyle('size', this.value);
|
||||
if (this.validity.valid) applyTextStyle('size', this.value === '' ? '' : String(this.valueAsNumber));
|
||||
}).on('keydown', function (event) {
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault();
|
||||
@@ -820,20 +825,38 @@ jQuery(function ($) {
|
||||
}
|
||||
});
|
||||
|
||||
function syncSpacingPreset($fields) {
|
||||
const values = $fields.find('[data-spacing-side]').map((_, input) => input.value).get();
|
||||
const same = values.every((value) => value === values[0]);
|
||||
const $preset = $fields.find('[data-spacing-preset]');
|
||||
const presets = $preset.data('spacingPreset');
|
||||
const index = same && values[0] !== '' ? presets.indexOf(Number(values[0])) : -1;
|
||||
const label = !same ? '自定义' : (values[0] === '' ? '默认' : values[0] + ' px');
|
||||
$preset.val(index === -1 ? $preset.prop('defaultValue') : index).attr('aria-valuetext', label);
|
||||
$fields.find('[data-spacing-readout]').text(label);
|
||||
}
|
||||
|
||||
$elementTools.on('click', '[data-element-spacing]', () => {
|
||||
spacingTarget = styleTarget(selectedElement);
|
||||
if (!spacingTarget) return;
|
||||
const styles = classesOf(spacingTarget);
|
||||
$spacingForm.find('input').each(function () {
|
||||
$spacingForm.find('[data-spacing-side]').each(function () {
|
||||
this.value = styles[this.name]?.slice(('studio-style-' + this.name + '-').length) || '';
|
||||
});
|
||||
$spacingForm.find('[data-spacing-preset]').val('');
|
||||
$spacingForm.find('fieldset').each((_, fields) => syncSpacingPreset($(fields)));
|
||||
$spacing.get(0).showModal();
|
||||
});
|
||||
$spacingForm.on('change', '[data-spacing-preset]', function () {
|
||||
if (this.value !== '') $(this).closest('fieldset').find('input').val(this.value === 'template' ? '' : this.value);
|
||||
}).on('input', 'input', function () {
|
||||
$(this).closest('fieldset').find('[data-spacing-preset]').val('');
|
||||
$spacingForm.on('input', '[data-spacing-preset]', function () {
|
||||
const $preset = $(this);
|
||||
const $fields = $preset.closest('fieldset');
|
||||
$fields.find('[data-spacing-side]').val($preset.data('spacingPreset')[this.valueAsNumber]);
|
||||
syncSpacingPreset($fields);
|
||||
}).on('input', '[data-spacing-side]', function () {
|
||||
syncSpacingPreset($(this).closest('fieldset'));
|
||||
}).on('click', '[data-spacing-reset]', function () {
|
||||
const $fields = $(this).closest('fieldset');
|
||||
$fields.find('[data-spacing-side]').val('');
|
||||
syncSpacingPreset($fields);
|
||||
});
|
||||
$elementTools.on('click', '[data-element-parent]', () => {
|
||||
const parent = parentElement(selectedElement);
|
||||
@@ -847,7 +870,9 @@ jQuery(function ($) {
|
||||
$spacingForm.on('submit', (event) => {
|
||||
event.preventDefault();
|
||||
if (spacingTarget?.isConnected) {
|
||||
$spacingForm.find('input').each(function () { putStyle(spacingTarget, this.name, this.value); });
|
||||
$spacingForm.find('[data-spacing-side]').each(function () {
|
||||
putStyle(spacingTarget, this.name, this.value === '' ? '' : String(this.valueAsNumber));
|
||||
});
|
||||
}
|
||||
$spacing.get(0).close();
|
||||
positionSelection();
|
||||
|
||||
Reference in New Issue
Block a user