all files / document-editor-container/ribbon/table-design-tab/ shading-group.js

81.36% Statements 48/59
44.44% Branches 8/18
60% Functions 9/15
81.36% Lines 48/59
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117   14× 14× 14× 14× 14× 14× 14×   14× 14× 14× 14× 14× 14× 14× 14× 14× 14×                             14×                             14× 14×                                                         17× 17×   17× 17× 17×         14× 14× 14×   14× 14× 14×   14× 14×        
define(["require", "exports", "@syncfusion/ej2-ribbon", "../ribbon-base/ribbon-constants", "./constants", "@syncfusion/ej2-inputs"], function (require, exports, ej2_ribbon_1, ribbon_constants_1, constants_1, ej2_inputs_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.SHADING_BUTTON_ID = '_SHADING_BUTTON';
    var ShadingGroup = (function () {
        function ShadingGroup(container) {
            this.currentShadingColor = '#ffffff';
            this.container = container;
            this.localObj = this.container.localObj;
            this.commonID = this.container.element.id + ribbon_constants_1.RIBBON_ID;
            this.colorPickerId = this.commonID + constants_1.SHADING_COLOR_PICKER_ID;
            this.shadingButtonId = this.commonID + exports.SHADING_BUTTON_ID;
            this.createColorPickerElement();
        }
        ShadingGroup.prototype.createColorPickerElement = function () {
            var _this = this;
            this.colorPickerElement = document.createElement('div');
            this.colorPickerElement.id = this.commonID + '_cellShadingColorPickerContainer';
            this.colorPickerElement.style.display = 'none';
            var colorPickerInput = document.createElement('input');
            colorPickerInput.id = this.commonID + '_cellShadingColorPicker';
            colorPickerInput.type = 'color';
            this.colorPickerElement.appendChild(colorPickerInput);
            document.body.appendChild(this.colorPickerElement);
            this.colorPicker = new ej2_inputs_1.ColorPicker({
                inline: true,
                value: this.currentShadingColor,
                change: function (args) {
                    _this.currentShadingColor = args.currentValue.hex;
                    _this.applyShadingColor(_this.currentShadingColor);
                },
                open: function () {
                    _this.container.documentEditor.focusIn();
                }, beforeClose: function () {
                    return true;
                },
                cssClass: 'e-cell-shading-picker'
            }, '#' + this.commonID + '_cellShadingColorPicker');
        };
        ShadingGroup.prototype.getShadingGroup = function () {
            return {
                id: this.commonID + constants_1.SHADING_GROUP_ID,
                header: this.localObj.getConstant('Cell'),
                orientation: 'Row',
                enableGroupOverflow: true,
                overflowHeader: this.localObj.getConstant('Cell'),
                collections: [
                    {
                        items: [
                            this.getShadingSplitButton()
                        ]
                    }
                ]
            };
        };
        ShadingGroup.prototype.getShadingSplitButton = function () {
            var _this = this;
            return {
                type: ej2_ribbon_1.RibbonItemType.SplitButton,
                id: this.shadingButtonId,
                allowedSizes: ej2_ribbon_1.RibbonItemSize.Large,
                splitButtonSettings: {
                    iconCss: 'e-icons e-de-ctnr-paint-bucket',
                    content: this.localObj.getConstant('Shading'),
                    target: '.e-cell-shading-picker',
                    click: function () {
                        _this.applyShadingColor(_this.currentShadingColor);
                    },
                    beforeOpen: function () {
                    }
                },
                ribbonTooltipSettings: {
                    content: this.localObj.getConstant('Fill color')
                }
            };
        };
        ShadingGroup.prototype.showColorPicker = function () {
            this.colorPicker.value = this.currentShadingColor;
        };
        ShadingGroup.prototype.applyShadingColor = function (color) {
            if (this.container.documentEditor.selection) {
                this.container.documentEditor.selection.cellFormat.background = color;
                this.currentShadingColor = color;
            }
            var colorPopupElement = document.getElementById(this.container.element.id + ribbon_constants_1.RIBBON_ID + '_SHADING_BUTTON_dropdownbtn-popup');
            if (colorPopupElement) {
                colorPopupElement.style.display = 'none';
            }
        };
        ShadingGroup.prototype.updateShadingColor = function () {
            Eif (this.container.documentEditor.selection) {
                Eif (this.container.documentEditor.selection.contextType === 'TableText' ||
                    this.container.documentEditor.selection.contextType === 'TableImage') {
                    var currentBackground = this.container.documentEditor.selection.cellFormat.background;
                    Eif (currentBackground) {
                        this.currentShadingColor = currentBackground;
                    }
                }
            }
        };
        ShadingGroup.prototype.destroy = function () {
            Eif (this.colorPicker) {
                this.colorPicker.destroy();
                this.colorPicker = undefined;
            }
            Eif (this.colorPickerElement && this.colorPickerElement.parentNode) {
                this.colorPickerElement.parentNode.removeChild(this.colorPickerElement);
                this.colorPickerElement = undefined;
            }
            this.container = undefined;
            this.localObj = undefined;
        };
        return ShadingGroup;
    }());
    exports.ShadingGroup = ShadingGroup;
});