all files / items/ ribbon-splitbutton.js

95.6% Statements 152/159
88.1% Branches 74/84
100% Functions 34/34
95.48% Lines 148/155
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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 2411×   1× 1× 1× 711×   1× 8683×   1× 371×   1× 257× 257×     257× 257× 257×   257×                       13×           16× 16× 16× 1×   16×         13× 13× 7×         28× 28× 1×         2× 1×       257× 257× 1×   257×   257× 257× 2× 1× 1×     257× 257× 257× 257×   1× 101× 101× 101× 101× 101× 101× 101× 101× 101× 101× 2× 1× 1×     101× 2× 1× 1× 1×     101× 101× 3× 3× 3× 3×     3×       101× 10× 1×   10×   101× 4× 2×   4× 3×     101× 10× 4×   10× 10× 7× 7×         1× 34× 34× 34× 34× 119× 34× 34× 34× 1×       34× 2× 1×     34× 1×     1×     1× 355× 355×   1× 5× 5×   1× 1×   1× 1×   1× 3× 3×     3× 2×     1× 11× 11× 1×   10× 10× 10× 1×   9× 9× 3× 3×   3×   9× 9× 9× 9× 9× 9× 9× 2×     1× 96× 96× 96× 20×     180×   96× 96× 96×   1×   1×    
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-splitbuttons", "../base/index", "../base/constant"], function (require, exports, ej2_base_1, ej2_splitbuttons_1, index_1, constant_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var RibbonSplitButton = (function () {
        function RibbonSplitButton(parent) {
            this.parent = parent;
        }
        RibbonSplitButton.prototype.getModuleName = function () {
            return 'ribbonSplitButton';
        };
        RibbonSplitButton.prototype.destroy = function () {
            this.parent = null;
        };
        RibbonSplitButton.prototype.createSplitButton = function (item, itemEle) {
            var _this = this;
            var buttonEle = this.parent.createElement('button', {
                id: item.id
            });
            itemEle.appendChild(buttonEle);
            var splitButtonSettings = item.splitButtonSettings;
            var cssClass = (constant_1.ITEM_VERTICAL_CENTER + constant_1.SPACE + constant_1.RIBBON_CONTROL + constant_1.SPACE + (splitButtonSettings.cssClass ?
                splitButtonSettings.cssClass : '')).trim();
            var splitbutton = new ej2_splitbuttons_1.SplitButton({
                locale: this.parent.locale,
                enableRtl: this.parent.enableRtl,
                enablePersistence: this.parent.enablePersistence,
                iconPosition: item.activeSize === index_1.RibbonItemSize.Large ? 'Top' : 'Left',
                closeActionEvents: splitButtonSettings.closeActionEvents,
                cssClass: cssClass + ((item.activeSize === index_1.RibbonItemSize.Large) ? (constant_1.SPACE + constant_1.VERTICAL_DDB) : ''),
                disabled: item.disabled,
                iconCss: splitButtonSettings.iconCss,
                items: splitButtonSettings.items,
                target: splitButtonSettings.target,
                beforeClose: function (e) {
                    Iif (splitButtonSettings.beforeClose) {
                        splitButtonSettings.beforeClose.call(_this, e);
                    }
                },
                beforeItemRender: splitButtonSettings.beforeItemRender,
                beforeOpen: function () {
                    var popupEl = splitbutton.dropDown.element;
                    var target = _this.parent.getAppendToElement();
                    if (popupEl && !target.contains(popupEl)) {
                        target.appendChild(popupEl);
                    }
                    Iif (splitButtonSettings.beforeOpen) {
                        splitButtonSettings.beforeOpen.call(_this);
                    }
                },
                close: function () {
                    splitbutton['wrapper'].classList.remove(constant_1.RIBBON_POPUP_OPEN);
                    if (splitButtonSettings.close) {
                        splitButtonSettings.close.call(_this);
                    }
                },
                created: splitButtonSettings.created,
                open: function () {
                    splitbutton['wrapper'].classList.add(constant_1.RIBBON_POPUP_OPEN);
                    if (splitButtonSettings.open) {
                        splitButtonSettings.open.call(_this);
                    }
                },
                select: splitButtonSettings.select,
                click: function (e) {
                    if (splitButtonSettings.click) {
                        splitButtonSettings.click.call(_this, e);
                    }
                }
            }, buttonEle);
            Eif (splitButtonSettings.htmlAttributes) {
                if (splitButtonSettings.htmlAttributes.id) {
                    delete splitButtonSettings.htmlAttributes.id;
                }
                index_1.setCustomAttributes(buttonEle, splitButtonSettings.htmlAttributes);
            }
            var dropdownEle = buttonEle.parentElement.querySelector('.e-dropdown-btn');
            dropdownEle.onkeydown = function (e) {
                if (e.key === 'Enter') {
                    e.stopImmediatePropagation();
                    dropdownEle.click();
                }
            };
            this.setContent(item, splitbutton);
            var wrapper = splitbutton['wrapper'];
            ej2_base_1.EventHandler.add(wrapper, 'mouseenter', function () { wrapper.classList.add(constant_1.RIBBON_HOVER); }, this);
            ej2_base_1.EventHandler.add(wrapper, 'mouseleave', function () { wrapper.classList.remove(constant_1.RIBBON_HOVER); }, this);
        };
        RibbonSplitButton.prototype.addOverFlowEvents = function (item, itemEle, overflowButton) {
            var _this = this;
            var splitButtonEle = itemEle.querySelector('#' + item.id);
            splitButtonEle.setAttribute('data-control', item.type.toString());
            var splitbutton = ej2_base_1.getComponent(splitButtonEle, ej2_splitbuttons_1.SplitButton);
            splitbutton.cssClass = splitbutton.cssClass + constant_1.SPACE + constant_1.RIBBON_POPUP_CONTROL;
            splitbutton.dataBind();
            var dropdownEle = splitButtonEle.parentElement.querySelector('.e-dropdown-btn');
            var ddbId = dropdownEle.getAttribute('id');
            var popupEle = document.querySelector('#' + ddbId + '-popup');
            dropdownEle.onkeydown = function (e) {
                if (e.key === 'Enter') {
                    e.stopImmediatePropagation();
                    dropdownEle.click();
                }
            };
            popupEle.onkeydown = function (e) {
                if (e.key === 'Enter') {
                    e.preventDefault();
                    splitbutton['wrapper'].classList.remove('e-ribbon-open');
                    popupEle.querySelector('.e-focused').click();
                }
            };
            var target;
            splitbutton.beforeOpen = function () {
                var splitBtn = ej2_base_1.getComponent(splitButtonEle, ej2_splitbuttons_1.SplitButton);
                var popupEl = splitBtn && splitBtn.dropDown ? splitBtn.dropDown.element : null;
                var target = _this.parent.getAppendToElement();
                Iif (popupEl && !target.contains(popupEl)) {
                    target.appendChild(popupEl);
                }
                Iif (item.splitButtonSettings.beforeOpen) {
                    item.splitButtonSettings.beforeOpen.call(_this);
                }
            };
            splitbutton.beforeClose = function (e) {
                if (item.splitButtonSettings.beforeClose) {
                    item.splitButtonSettings.beforeClose.call(_this, e);
                }
                target = e.event ? e.event.target : null;
            };
            splitbutton.click = function (e) {
                if (item.splitButtonSettings.click) {
                    item.splitButtonSettings.click.call(_this, e);
                }
                if (overflowButton.element.classList.contains('e-active')) {
                    overflowButton.toggle();
                }
            };
            splitbutton.close = function (e) {
                if (item.splitButtonSettings.close) {
                    item.splitButtonSettings.close.call(_this, e);
                }
                splitbutton['wrapper'].classList.remove(constant_1.RIBBON_POPUP_OPEN);
                if (target && !target.closest('.e-ribbon-group-overflow-ddb')) {
                    Eif (overflowButton.element.classList.contains('e-active')) {
                        overflowButton.toggle();
                    }
                }
            };
        };
        RibbonSplitButton.prototype.removeOverFlowEvents = function (item, itemEle) {
            var _this = this;
            var splitButtonEle = itemEle.querySelector('#' + item.id);
            var splitbutton = ej2_base_1.getComponent(splitButtonEle, ej2_splitbuttons_1.SplitButton);
            var cssClass = splitbutton.cssClass.split(constant_1.SPACE);
            cssClass = cssClass.filter(function (value) { return value !== constant_1.RIBBON_POPUP_CONTROL; });
            splitbutton.cssClass = cssClass.join(constant_1.SPACE);
            splitbutton.dataBind();
            splitbutton.beforeClose = function (e) {
                Iif (item.splitButtonSettings.beforeClose) {
                    item.splitButtonSettings.beforeClose.call(_this, e);
                }
            };
            splitbutton.click = function (e) {
                if (item.splitButtonSettings.click) {
                    item.splitButtonSettings.click.call(_this, e);
                }
            };
            splitbutton.close = function (e) {
                Iif (item.splitButtonSettings.close) {
                    item.splitButtonSettings.close.call(_this, e);
                }
                splitbutton['wrapper'].classList.remove(constant_1.RIBBON_POPUP_OPEN);
            };
        };
        RibbonSplitButton.prototype.setContent = function (item, control) {
            control['primaryBtnObj'].setProperties({ content: (item.activeSize === index_1.RibbonItemSize.Medium) ? item.splitButtonSettings.content : '' });
            control['secondaryBtnObj'].setProperties({ content: (item.activeSize === index_1.RibbonItemSize.Large) ? item.splitButtonSettings.content : '' });
        };
        RibbonSplitButton.prototype.getSplitButtonObj = function (controlId) {
            var splitButtonEle = index_1.getItemElement(this.parent, controlId);
            return ej2_base_1.getComponent(splitButtonEle, ej2_splitbuttons_1.SplitButton);
        };
        RibbonSplitButton.prototype.addItems = function (controlId, Items, text) {
            this.getSplitButtonObj(controlId).addItems(Items, text);
        };
        RibbonSplitButton.prototype.removeItems = function (controlId, Items, isUniqueId) {
            this.getSplitButtonObj(controlId).removeItems(Items, isUniqueId);
        };
        RibbonSplitButton.prototype.toggle = function (controlId) {
            var splitBtnObj = this.getSplitButtonObj(controlId);
            Iif (!splitBtnObj) {
                return;
            }
            if (!splitBtnObj.disabled) {
                splitBtnObj.toggle();
            }
        };
        RibbonSplitButton.prototype.updateSplitButton = function (prop, id) {
            var itemProp = index_1.getItem(this.parent.tabs, id);
            if (!itemProp) {
                return;
            }
            ej2_base_1.merge(itemProp.item.splitButtonSettings, prop);
            var btnEle = index_1.getItemElement(this.parent, id, itemProp);
            if (!btnEle) {
                return;
            }
            var control = ej2_base_1.getComponent(btnEle, ej2_splitbuttons_1.SplitButton);
            if (prop.cssClass) {
                prop.cssClass = (constant_1.RIBBON_CONTROL + constant_1.SPACE + constant_1.ITEM_VERTICAL_CENTER + constant_1.SPACE + prop.cssClass).trim();
                prop.cssClass = itemProp.item.activeSize === index_1.RibbonItemSize.Large ?
                    (constant_1.VERTICAL_DDB + constant_1.SPACE + prop.cssClass).trim() : prop.cssClass;
                control.cssClass = prop.cssClass;
            }
            delete prop.beforeOpen;
            delete prop.open;
            delete prop.click;
            delete prop.close;
            delete prop.beforeClose;
            control.setProperties(prop);
            if (prop.content) {
                this.setContent(itemProp.item, control);
            }
        };
        RibbonSplitButton.prototype.updateSplitButtonSize = function (element, item) {
            var control = ej2_base_1.getComponent(element, ej2_splitbuttons_1.SplitButton);
            var cssClass = control.cssClass.split(constant_1.SPACE);
            if (item.activeSize === index_1.RibbonItemSize.Large) {
                cssClass.push(constant_1.VERTICAL_DDB);
            }
            else {
                cssClass = cssClass.filter(function (value) { return value !== constant_1.VERTICAL_DDB; });
            }
            control.cssClass = cssClass.join(constant_1.SPACE);
            control.setProperties({ iconPosition: item.activeSize === index_1.RibbonItemSize.Large ? 'Top' : 'Left' });
            this.setContent(item, control);
        };
        return RibbonSplitButton;
    }());
    exports.RibbonSplitButton = RibbonSplitButton;
});