all files / items/ ribbon-dropdown.js

98.64% Statements 217/220
90% Branches 135/150
100% Functions 33/33
98.61% Lines 213/216
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 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353   687×   8338×   353×   344× 344×     344× 344× 344×   344×                           10×             10×             344× 344×   344×     137× 137× 137× 137× 137× 137× 137× 137× 13×   13×   137× 13×   13×         26× 26× 26× 26× 89× 26× 26× 26×     26×         149× 149× 149×     149× 149× 149×                   18×     149× 149× 149× 149×   46× 46× 46× 46× 46× 46× 46× 26×       46× 40×         46×   46× 27×   46× 17×       44×   44×   44× 27×   27×     13× 13×   27×     27×       17× 10× 10×   17×     17×     44×               11× 11× 11× 11×   11×           38× 38× 22× 14× 12×                       20×   38× 14×   38×   149× 149× 149× 149× 149× 149×   184× 184× 184×   17× 17× 17×                 10× 10×             97× 97× 97× 11×     195×   97× 97× 97×        
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-splitbuttons", "@syncfusion/ej2-popups", "../base/index", "../base/constant"], function (require, exports, ej2_base_1, ej2_splitbuttons_1, ej2_popups_1, index_1, constant_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var RibbonDropDown = (function () {
        function RibbonDropDown(parent) {
            this.parent = parent;
        }
        RibbonDropDown.prototype.getModuleName = function () {
            return 'ribbonDropDown';
        };
        RibbonDropDown.prototype.destroy = function () {
            this.parent = null;
        };
        RibbonDropDown.prototype.createDropDown = function (item, itemEle) {
            var _this = this;
            var buttonEle = this.parent.createElement('button', {
                id: item.id
            });
            itemEle.appendChild(buttonEle);
            var dropDownSettings = item.dropDownSettings;
            var cssClass = (constant_1.ITEM_VERTICAL_CENTER + constant_1.SPACE + constant_1.RIBBON_CONTROL + constant_1.SPACE + (dropDownSettings.cssClass ?
                dropDownSettings.cssClass : '')).trim();
            new ej2_splitbuttons_1.DropDownButton({
                locale: this.parent.locale,
                enableRtl: this.parent.enableRtl,
                enablePersistence: this.parent.enablePersistence,
                iconPosition: item.activeSize === index_1.RibbonItemSize.Large ? 'Top' : 'Left',
                closeActionEvents: dropDownSettings.closeActionEvents,
                content: item.activeSize === index_1.RibbonItemSize.Small ? '' : dropDownSettings.content,
                cssClass: cssClass + ((item.activeSize === index_1.RibbonItemSize.Large) ? (constant_1.SPACE + constant_1.VERTICAL_DDB) : ''),
                disabled: item.disabled,
                iconCss: dropDownSettings.iconCss,
                items: dropDownSettings.items,
                target: dropDownSettings.target,
                createPopupOnClick: dropDownSettings.createPopupOnClick,
                beforeClose: function (e) {
                    Iif (dropDownSettings.beforeClose) {
                        dropDownSettings.beforeClose.call(_this, e);
                    }
                },
                beforeItemRender: dropDownSettings.beforeItemRender,
                beforeOpen: dropDownSettings.beforeOpen,
                close: function (e) {
                    if (dropDownSettings.close) {
                        dropDownSettings.close.call(_this, e);
                    }
                },
                created: dropDownSettings.created,
                open: dropDownSettings.open,
                select: dropDownSettings.select
            }).appendTo(buttonEle);
            Eif (dropDownSettings.htmlAttributes) {
                if (dropDownSettings.htmlAttributes.id) {
                    delete dropDownSettings.htmlAttributes.id;
                }
                index_1.setCustomAttributes(buttonEle, dropDownSettings.htmlAttributes);
            }
        };
        RibbonDropDown.prototype.addOverFlowEvents = function (item, itemEle, overflowButton) {
            var _this = this;
            var dropdownElement = itemEle.querySelector('#' + item.id);
            dropdownElement.setAttribute('data-control', item.type.toString());
            var dropdown = ej2_base_1.getComponent(dropdownElement, ej2_splitbuttons_1.DropDownButton);
            dropdown.cssClass = dropdown.cssClass + constant_1.SPACE + constant_1.RIBBON_POPUP_CONTROL;
            dropdown.dataBind();
            var target;
            dropdown.beforeClose = function (e) {
                if (item.dropDownSettings.beforeClose) {
                    item.dropDownSettings.beforeClose.call(_this, e);
                }
                target = e.event ? e.event.target : null;
            };
            dropdown.close = function (e) {
                if (item.dropDownSettings.close) {
                    item.dropDownSettings.close.call(_this, e);
                }
                if (target && !target.closest('.e-ribbon-group-overflow-ddb')) {
                    Eif (overflowButton.element.classList.contains('e-active')) {
                        overflowButton.toggle();
                    }
                }
            };
        };
        RibbonDropDown.prototype.removeOverFlowEvents = function (item, itemEle) {
            var _this = this;
            var dropdownElement = itemEle.querySelector('#' + item.id);
            var dropdown = ej2_base_1.getComponent(dropdownElement, ej2_splitbuttons_1.DropDownButton);
            var cssClass = dropdown.cssClass.split(constant_1.SPACE);
            cssClass = cssClass.filter(function (value) { return value !== constant_1.RIBBON_POPUP_CONTROL; });
            dropdown.cssClass = cssClass.join(constant_1.SPACE);
            dropdown.dataBind();
            dropdown.close = function (e) {
                if (item.dropDownSettings.close) {
                    item.dropDownSettings.close.call(_this, e);
                }
            };
            dropdown.beforeClose = function (e) {
                Iif (item.dropDownSettings.beforeClose) {
                    item.dropDownSettings.beforeClose.call(_this, e);
                }
            };
        };
        RibbonDropDown.prototype.createOverFlowDropDown = function (id, name, iconCss, groupEle, overflowEle, enableRtl) {
            var _this = this;
            this.enableRtl = enableRtl;
            var buttonEle = this.parent.createElement('button', {
                id: id + constant_1.OVERFLOW_ID + constant_1.DROPDOWN_ID
            });
            groupEle.setAttribute('tabindex', '0');
            overflowEle.appendChild(buttonEle);
            var dropdown = new ej2_splitbuttons_1.DropDownButton({
                iconCss: iconCss,
                target: groupEle,
                locale: this.parent.locale,
                enableRtl: this.parent.enableRtl,
                enablePersistence: this.parent.enablePersistence,
                cssClass: constant_1.VERTICAL_DDB + constant_1.SPACE + constant_1.RIBBON_GROUP_OVERFLOW_DDB,
                iconPosition: 'Top',
                content: name,
                beforeClose: function (args) {
                    args.cancel = !ej2_base_1.isNullOrUndefined(args.event && ej2_base_1.closest(args.event.target, '.' + constant_1.RIBBON_POPUP_CONTROL));
                }
            }, buttonEle);
            index_1.createTooltip(groupEle, this.parent);
            buttonEle.onclick = buttonEle.onkeydown = function () { _this.itemIndex = 0; };
            groupEle.onkeydown = function (e) { _this.keyActionHandler(e, groupEle), _this; };
            return dropdown;
        };
        RibbonDropDown.prototype.keyActionHandler = function (e, target) {
            var controlElements = Array.prototype.slice.call(target.querySelectorAll('.e-control'));
            var templateElements = Array.prototype.slice.call(target.querySelectorAll('.e-ribbon-template'));
            var items = controlElements.concat(templateElements);
            var comboBoxElements = target.querySelectorAll('.e-combobox');
            var comboBoxEle;
            Eif (comboBoxElements) {
                for (var i = 0; i < comboBoxElements.length; i++) {
                    if (comboBoxElements[parseInt(i.toString(), 10)].closest('.e-input-focus')) {
                        comboBoxEle = comboBoxElements[parseInt(i.toString(), 10)];
                    }
                }
            }
            if (comboBoxEle) {
                for (var i = 0; i < items.length; i++) {
                    if (items[parseInt(i.toString(), 10)].classList.contains('e-combobox')) {
                        Eif (items[parseInt(i.toString(), 10)].closest('.e-input-focus')) {
                            this.itemIndex = i;
                        }
                    }
                }
            }
            Eif (e.target.classList.contains('e-control') || e.target.classList.contains('e-ribbon-template') || e.target.classList.contains('e-ribbon-launcher-icon') ||
                e.target.classList.contains('e-ribbon-last-item') || e.target.classList.contains('e-ribbon-first-item')) {
                if (e.key === 'ArrowRight' || (!e.shiftKey && e.key === 'Tab')) {
                    this.handleNavigation(e, !this.enableRtl, items);
                }
                if (e.key === 'ArrowLeft' || (e.shiftKey && e.key === 'Tab')) {
                    this.handleNavigation(e, this.enableRtl, items);
                }
            }
        };
        RibbonDropDown.prototype.handleNavigation = function (e, enableRtl, items) {
            if (!(items[0].classList.contains('e-ribbon-first-item'))) {
                items[0].classList.add('e-ribbon-first-item');
            }
            if (!(items[items.length - 1].classList.contains('e-ribbon-last-item'))) {
                items[items.length - 1].classList.add('e-ribbon-last-item');
            }
            if (enableRtl) {
                if (this.itemIndex === 0 && items[parseInt(this.itemIndex.toString(), 10)].classList.contains('e-ribbon-first-item')) {
                    this.updateItemIndex(e, items, true);
                }
                if (!e.target.classList.contains('e-combobox') && !e.target.classList.contains('e-ribbon-last-item') &&
                    !e.target.classList.contains('e-ribbon-group-container') && (e.target.classList.contains('e-ribbon-first-item')
                    || this.itemIndex !== 0) && (e.target.classList.contains('e-control') || e.target.classList.contains('e-ribbon-template'))) {
                    this.itemIndex++;
                    this.updateItemIndex(e, items, true);
                }
                if (e.target.classList.contains('e-ribbon-last-item')) {
                    var launcherIcon = false;
                    launcherIcon = this.focusLauncherIcon(e, items);
                    if (!launcherIcon) {
                        this.itemIndex = 0;
                        this.updateItemIndex(e, items, true);
                    }
                }
                if (e.target.classList.contains('e-ribbon-launcher-icon')) {
                    this.itemIndex = 0;
                    this.updateItemIndex(e, items, true);
                }
            }
            else {
                if (!e.target.classList.contains('e-combobox') && this.itemIndex !== 0) {
                    this.itemIndex--;
                    this.updateItemIndex(e, items, false);
                }
                if (e.target.classList.contains('e-ribbon-first-item')) {
                    var launcherIcon = false;
                    launcherIcon = this.focusLauncherIcon(e, items);
                    if (!launcherIcon) {
                        this.itemIndex = items.length - 1;
                        this.updateItemIndex(e, items, false);
                    }
                }
                if (e.target.classList.contains('e-ribbon-launcher-icon')) {
                    this.itemIndex = items.length - 1;
                    this.updateItemIndex(e, items, false);
                }
            }
            if (e.target.classList.contains('e-combobox') && (e.key === 'Tab')) {
                if (enableRtl) {
                    Eif (this.itemIndex < items.length - 1) {
                        this.itemIndex++;
                    }
                }
                else {
                    Eif (this.itemIndex > 0) {
                        this.itemIndex--;
                    }
                }
            }
        };
        RibbonDropDown.prototype.focusLauncherIcon = function (e, items) {
            var groupContainer = items[parseInt(this.itemIndex.toString(), 10)].closest('.e-ribbon-group-container');
            var launcherIconEle;
            Eif (groupContainer) {
                launcherIconEle = groupContainer.querySelector('.e-ribbon-launcher-icon');
            }
            if (launcherIconEle) {
                if (e.key === 'Tab') {
                    e.preventDefault();
                }
                groupContainer.querySelector('.e-ribbon-launcher-icon').focus();
                return true;
            }
            else {
                return false;
            }
        };
        RibbonDropDown.prototype.updateItemIndex = function (e, items, enableRtl) {
            var ribbonItem = items[this.itemIndex].closest('.e-ribbon-item');
            while (ribbonItem && ribbonItem.classList.contains('e-disabled')) {
                if (enableRtl) {
                    if (this.itemIndex < items.length - 1) {
                        this.itemIndex++;
                    }
                    else {
                        var launcherIcon = false;
                        launcherIcon = this.focusLauncherIcon(e, items);
                        if (launcherIcon) {
                            break;
                        }
                        this.itemIndex = 0;
                    }
                }
                else {
                    if (this.itemIndex > 0) {
                        this.itemIndex--;
                    }
                    else {
                        var launcherIcon = false;
                        launcherIcon = this.focusLauncherIcon(e, items);
                        if (launcherIcon) {
                            break;
                        }
                        this.itemIndex = items.length - 1;
                    }
                }
                ribbonItem = items[this.itemIndex].closest('.e-ribbon-item');
            }
            if (e.key === 'Tab') {
                e.preventDefault();
            }
            items[parseInt(this.itemIndex.toString(), 10)].focus();
        };
        RibbonDropDown.prototype.removeOverFlowDropDown = function (dropdownElement) {
            var dropdown = ej2_base_1.getComponent(dropdownElement, ej2_splitbuttons_1.DropDownButton);
            var tooltip = ej2_base_1.getComponent(dropdown.target, ej2_popups_1.Tooltip);
            tooltip.destroy();
            dropdownElement.parentElement.parentElement.insertBefore(dropdown.target, dropdownElement.parentElement);
            dropdown.destroy();
            ej2_base_1.remove(dropdownElement);
        };
        RibbonDropDown.prototype.getDDBItemElement = function (dropdownElement, id) {
            var dropdown = ej2_base_1.getComponent(dropdownElement, ej2_splitbuttons_1.DropDownButton);
            var dropDownPopup = dropdown.dropDown.element;
            return dropDownPopup.querySelector('#' + id);
        };
        RibbonDropDown.prototype.getOverflowDropDownPopup = function (itemProp, contentEle) {
            var dropdownElement = contentEle.querySelector('#' + this.parent.tabs[itemProp.tabIndex].groups[itemProp.groupIndex].id + constant_1.OVERFLOW_ID + constant_1.DROPDOWN_ID);
            var dropdown = ej2_base_1.getComponent(dropdownElement, ej2_splitbuttons_1.DropDownButton);
            return dropdown.dropDown.element;
        };
        RibbonDropDown.prototype.getDropDownObj = function (controlId) {
            var dropDownEle = index_1.getItemElement(this.parent, controlId);
            return dropDownEle ? ej2_base_1.getComponent(dropDownEle, ej2_splitbuttons_1.DropDownButton) : null;
        };
        RibbonDropDown.prototype.addItems = function (controlId, Items, text) {
            this.getDropDownObj(controlId).addItems(Items, text);
        };
        RibbonDropDown.prototype.removeItems = function (controlId, Items, isUniqueId) {
            this.getDropDownObj(controlId).removeItems(Items, isUniqueId);
        };
        RibbonDropDown.prototype.toggle = function (controlId) {
            var dropdownObj = this.getDropDownObj(controlId);
            Iif (!dropdownObj) {
                return;
            }
            Eif (!dropdownObj.disabled) {
                dropdownObj.toggle();
            }
        };
        RibbonDropDown.prototype.updateDropDown = function (prop, id) {
            var itemProp = index_1.getItem(this.parent.tabs, id);
            if (!itemProp) {
                return;
            }
            ej2_base_1.merge(itemProp.item.dropDownSettings, prop);
            var btnEle = index_1.getItemElement(this.parent, id, itemProp);
            if (!btnEle) {
                return;
            }
            var control = ej2_base_1.getComponent(btnEle, ej2_splitbuttons_1.DropDownButton);
            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.close;
            delete prop.beforeClose;
            if (prop.content) {
                prop.content = itemProp.item.activeSize === index_1.RibbonItemSize.Small ? '' : prop.content;
            }
            control.setProperties(prop);
        };
        RibbonDropDown.prototype.updateDropDownSize = function (element, item) {
            var control = ej2_base_1.getComponent(element, ej2_splitbuttons_1.DropDownButton);
            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' });
            control.setProperties({ content: item.activeSize === index_1.RibbonItemSize.Small ? '' : item.dropDownSettings.content });
        };
        return RibbonDropDown;
    }());
    exports.RibbonDropDown = RibbonDropDown;
});