devextreme
Version:
HTML5 JavaScript Component Suite for Responsive Web Development
90 lines (89 loc) • 3.23 kB
JavaScript
/**
* DevExtreme (esm/__internal/ui/text_box/texteditor_button_collection/m_custom.js)
* Version: 25.2.3
* Build date: Fri Dec 12 2025
*
* Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
import {
name as clickEventName
} from "../../../../common/core/events/click";
import eventsEngine from "../../../../common/core/events/core/events_engine";
import {
end,
start
} from "../../../../common/core/events/hover";
import $ from "../../../../core/renderer";
import Button from "../../../../ui/button";
import TextEditorButton, {
isButtonInstance
} from "./m_button";
const CUSTOM_BUTTON_HOVERED_CLASS = "dx-custom-button-hovered";
export default class CustomButton extends TextEditorButton {
_attachEvents(instance, $element) {
eventsEngine.on($element, start, (() => {
var _this$editor;
null === (_this$editor = this.editor) || void 0 === _this$editor || _this$editor.$element().addClass("dx-custom-button-hovered")
}));
eventsEngine.on($element, end, (() => {
var _this$editor2;
null === (_this$editor2 = this.editor) || void 0 === _this$editor2 || _this$editor2.$element().removeClass("dx-custom-button-hovered")
}));
eventsEngine.on($element, clickEventName, (e => {
e.stopPropagation()
}))
}
_create() {
const {
editor: editor
} = this;
if (!editor) {
return
}
const $element = $("<div>");
this._addToContainer($element);
const instance = editor._createComponent($element, Button, Object.assign({}, this.options, {
ignoreParentReadOnly: true,
disabled: this._isDisabled(),
integrationOptions: this._prepareIntegrationOptions(editor)
}));
return {
instance: instance,
$element: $element
}
}
_prepareIntegrationOptions(editor) {
return Object.assign({}, editor.option("integrationOptions"), {
skipTemplates: ["content"]
})
}
update() {
const isUpdated = super.update();
if (isButtonInstance(this.instance)) {
this.instance.option("disabled", this._isDisabled())
}
return isUpdated
}
_isVisible() {
var _this$editor3;
const {
visible: visible
} = (null === (_this$editor3 = this.editor) || void 0 === _this$editor3 ? void 0 : _this$editor3.option()) ?? {};
return !!visible
}
_isDisabled() {
var _this$editor4;
const isDefinedByUser = void 0 !== this.options.disabled;
if (isDefinedByUser) {
if (isButtonInstance(this.instance)) {
return this.instance.option("disabled")
}
return this.options.disabled
}
const {
readOnly: readOnly
} = (null === (_this$editor4 = this.editor) || void 0 === _this$editor4 ? void 0 : _this$editor4.option()) ?? {};
return readOnly
}
}