all files / modules/ ribbon-filemenu.js

99.39% Statements 164/165
89.19% Branches 66/74
100% Functions 31/31
99.39% Lines 162/163
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   30×   8338×   16× 14×   16×   15× 15×   14×     14× 14× 14× 14×         14×             14×     11×   14× 14× 14×   22×     22×     20×   20×   20×     15× 15× 15× 15×     92× 92× 76× 76×                 92×   12× 12×     12× 12×                             12×                       44× 44×                 10×                                           10×   15× 12× 12×     14× 14× 14× 14× 14× 14× 14× 14× 14×   22× 22× 22×     22× 22×                            
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-splitbuttons", "@syncfusion/ej2-navigations", "../base/index", "../base/constant"], function (require, exports, ej2_base_1, ej2_splitbuttons_1, ej2_navigations_1, index_1, constants) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var RibbonFileMenu = (function () {
        function RibbonFileMenu(parent) {
            this.parent = parent;
        }
        RibbonFileMenu.prototype.getModuleName = function () {
            return 'ribbonFileMenu';
        };
        RibbonFileMenu.prototype.destroy = function () {
            if (this.fileMenuDDB) {
                this.destroyDDB();
            }
            this.parent = null;
        };
        RibbonFileMenu.prototype.createFileMenu = function (fileMenuOptions) {
            var _this = this;
            if (!fileMenuOptions.visible) {
                return;
            }
            this.ddbElement = this.parent.createElement('button', {
                id: this.parent.element.id + constants.RIBBON_FILE_MENU_ID
            });
            var tabEle = this.parent.tabObj.element;
            var toolbarEle = tabEle.querySelector('.e-toolbar');
            tabEle.insertBefore(this.ddbElement, toolbarEle);
            this.fileMenuDDB = new ej2_splitbuttons_1.DropDownButton({
                content: fileMenuOptions.text,
                enableRtl: this.parent.enableRtl,
                cssClass: 'e-ribbon-file-menu e-caret-hide',
                created: function () {
                    tabEle.style.setProperty(constants.RIBBON_FILE_MENU_WIDTH, _this.ddbElement.offsetWidth + 'px');
                },
                beforeClose: this.ddbBeforeEvent.bind(this, false),
                beforeOpen: this.ddbBeforeEvent.bind(this, true),
                close: this.ddbAfterEvent.bind(this, false),
                open: this.ddbAfterEvent.bind(this, true)
            }, this.ddbElement);
            if (this.parent.fileMenu.popupTemplate) {
                this.fileMenuDDB.setProperties({ target: this.parent.fileMenu.popupTemplate });
            }
            else {
                this.createRibbonMenu(fileMenuOptions);
            }
            this.parent.tabObj.refreshActiveTabBorder();
            this.addFileMenuTooltip(fileMenuOptions);
            this.addFileMenuKeytip();
        };
        RibbonFileMenu.prototype.addFileMenuTooltip = function (fileMenuOptions) {
            if (index_1.isTooltipPresent(fileMenuOptions.ribbonTooltipSettings)) {
                this.ddbElement.classList.add(constants.RIBBON_TOOLTIP_TARGET);
                this.parent.tooltipData.push({ id: this.ddbElement.id, data: fileMenuOptions.ribbonTooltipSettings });
            }
        };
        RibbonFileMenu.prototype.addFileMenuKeytip = function () {
            if (this.parent.fileMenu.keyTip) {
                this.parent.keyTipElements['filemenu'] = [];
                this.parent.keyTipElements['filemenu'].push({ id: this.ddbElement.id, type: 'filemenu', keyTip: this.parent.fileMenu.keyTip });
            }
        };
        RibbonFileMenu.prototype.ddbBeforeEvent = function (isOpen, args) {
            if (!isOpen && args.event && args.event.target.closest('.e-ribbon-menu')) {
                args.cancel = true;
            }
            var event = isOpen ? this.parent.fileMenu.beforeOpen :
                this.parent.fileMenu.beforeClose;
            if (event) {
                var eventArgs = { cancel: args.cancel, element: args.element, event: args.event };
                event.call(this, eventArgs);
                args.cancel = eventArgs.cancel;
            }
        };
        RibbonFileMenu.prototype.ddbAfterEvent = function (isOpen, args) {
            var element = isOpen ? this.fileMenuDDB.target : this.fileMenuDDB.element;
            element.focus();
            var event = isOpen ? this.parent.fileMenu.open : this.parent.fileMenu.close;
            if (event) {
                var eventArgs = { element: args.element };
                event.call(this, eventArgs);
            }
        };
        RibbonFileMenu.prototype.cloneMenuItem = function (items) {
            var itemsList = [];
            for (var i = 0; i < items.length; i++) {
                var item = items[parseInt(i.toString(), 10)];
                itemsList.push({
                    iconCss: item.iconCss,
                    id: item.id,
                    separator: item.separator,
                    text: item.text,
                    url: item.url,
                    items: this.cloneMenuItem(item.items)
                });
            }
            return itemsList;
        };
        RibbonFileMenu.prototype.createRibbonMenu = function (menuOptions) {
            var _this = this;
            var ulElem = this.parent.createElement('ul', {
                id: this.parent.element.id + constants.RIBBON_FILE_MENU_LIST
            });
            this.fileMenuDDB.setProperties({ target: ulElem });
            this.menuctrl = new ej2_navigations_1.Menu({
                orientation: 'Vertical',
                enableRtl: this.parent.enableRtl,
                cssClass: 'e-ribbon-menu',
                animationSettings: menuOptions.animationSettings,
                items: this.cloneMenuItem(menuOptions.menuItems),
                showItemOnClick: menuOptions.showItemOnClick,
                template: menuOptions.itemTemplate,
                beforeClose: this.menuBeforeEvent.bind(this, false),
                beforeOpen: this.menuBeforeEvent.bind(this, true),
                beforeItemRender: this.beforeItemRender.bind(this),
                onClose: this.menuAfterEvent.bind(this, false),
                onOpen: this.menuAfterEvent.bind(this, true),
                select: this.menuSelect.bind(this)
            }, ulElem);
            ej2_base_1.EventHandler.add(ulElem, 'keydown', function (e) {
                Eif (e.key === 'Tab') {
                    _this.fileMenuDDB.toggle();
                }
            }, this);
        };
        RibbonFileMenu.prototype.menuBeforeEvent = function (isOpen, args) {
            var event = isOpen ? this.parent.fileMenu.beforeOpen :
                this.parent.fileMenu.beforeClose;
            if (event) {
                var eventArgs = {
                    cancel: args.cancel, element: args.element, event: args.event,
                    items: args.items, parentItem: args.parentItem
                };
                event.call(this, eventArgs);
                args.cancel = eventArgs.cancel;
            }
        };
        RibbonFileMenu.prototype.menuAfterEvent = function (isOpen, args) {
            var event = isOpen ? this.parent.fileMenu.open : this.parent.fileMenu.close;
            if (event) {
                var eventArgs = { element: args.element, items: args.items, parentItem: args.parentItem };
                event.call(this, eventArgs);
            }
        };
        RibbonFileMenu.prototype.beforeItemRender = function (args) {
            var event = this.parent.fileMenu.beforeItemRender;
            if (event) {
                var eventArgs = { element: args.element, item: args.item };
                event.call(this, eventArgs);
            }
        };
        RibbonFileMenu.prototype.menuSelect = function (args) {
            var event = this.parent.fileMenu.select;
            if (event) {
                var eventArgs = { element: args.element, item: args.item, event: args.event };
                event.call(this, eventArgs);
            }
            var menuOpen = !!args.element.closest('.e-ribbon-menu.e-popup-open');
            var fileTriggerOpen = !!args.element.closest('.e-ribbon-file-menu.e-popup-open');
            var fileMenuOpen = !!document.querySelector('.e-ribbon-file-menu.e-popup-open');
            var isMenuOpen = fileTriggerOpen || (menuOpen && fileMenuOpen);
            if (!args.element.classList.contains('e-menu-caret-icon') && isMenuOpen) {
                this.fileMenuDDB.toggle();
            }
        };
        RibbonFileMenu.prototype.setCommonProperties = function (commonProp) {
            Eif (this.fileMenuDDB) {
                this.fileMenuDDB.setProperties(commonProp);
                Eif (this.menuctrl) {
                    this.menuctrl.setProperties(commonProp);
                }
            }
        };
        RibbonFileMenu.prototype.updateFileMenu = function (fileMenuOptions) {
            if (fileMenuOptions.visible) {
                if (this.fileMenuDDB) {
                    Eif (fileMenuOptions.text) {
                        this.fileMenuDDB.setProperties({
                            content: fileMenuOptions.text
                        });
                        this.parent.tabObj.element.style.setProperty(constants.RIBBON_FILE_MENU_WIDTH, this.ddbElement.offsetWidth + 'px');
                    }
                    if (fileMenuOptions.popupTemplate) {
                        if (this.menuctrl) {
                            this.destroyMenu();
                        }
                        this.fileMenuDDB.setProperties({ target: fileMenuOptions.popupTemplate });
                    }
                    else {
                        if (this.menuctrl) {
                            this.menuctrl.setProperties({
                                animationSettings: fileMenuOptions.animationSettings,
                                items: this.cloneMenuItem(fileMenuOptions.menuItems),
                                showItemOnClick: fileMenuOptions.showItemOnClick,
                                template: fileMenuOptions.itemTemplate
                            });
                        }
                        else {
                            this.createRibbonMenu(fileMenuOptions);
                        }
                    }
                    this.removeFileMenuTooltip();
                    this.removeFileMenuKeytip();
                    this.addFileMenuTooltip(fileMenuOptions);
                    this.addFileMenuKeytip();
                }
                else {
                    this.createFileMenu(fileMenuOptions);
                }
            }
            else Iif (this.fileMenuDDB) {
                this.destroyDDB();
            }
            this.parent.tabObj.refreshActiveTabBorder();
        };
        RibbonFileMenu.prototype.destroyMenu = function () {
            if (this.menuctrl) {
                this.menuctrl.destroy();
                this.menuctrl = null;
            }
        };
        RibbonFileMenu.prototype.destroyDDB = function () {
            this.removeFileMenuTooltip();
            this.removeFileMenuKeytip();
            var tabEle = this.parent.tabObj.element;
            tabEle.style.removeProperty(constants.RIBBON_FILE_MENU_WIDTH);
            this.destroyMenu();
            this.fileMenuDDB.destroy();
            this.fileMenuDDB = null;
            ej2_base_1.remove(this.ddbElement);
            this.ddbElement = null;
        };
        RibbonFileMenu.prototype.removeFileMenuTooltip = function () {
            var _this = this;
            var index = index_1.getIndex(this.parent.tooltipData, function (e) { return e.id === _this.ddbElement.id; });
            if (index !== -1) {
                this.ddbElement.classList.remove(constants.RIBBON_TOOLTIP_TARGET);
                this.parent.tooltipData.splice(index, 1);
            }
        };
        RibbonFileMenu.prototype.removeFileMenuKeytip = function () {
            var _this = this;
            if (this.parent.keyTipElements['filemenu']) {
                var index = index_1.getIndex(this.parent.keyTipElements['filemenu'], function (e) { return e.id === _this.ddbElement.id; });
                Eif (index !== -1) {
                    this.parent.keyTipElements['filemenu'].splice(index, 1);
                }
            }
        };
        RibbonFileMenu.prototype.addItems = function (items, target, isAfter, isUniqueId) {
            if (isAfter) {
                this.menuctrl.insertAfter(items, target, isUniqueId);
            }
            else {
                this.menuctrl.insertBefore(items, target, isUniqueId);
            }
            this.parent.fileMenu.setProperties({ menuItems: this.menuctrl.items }, true);
        };
        RibbonFileMenu.prototype.removeItems = function (items, isUniqueId) {
            this.menuctrl.removeItems(items, isUniqueId);
            this.parent.fileMenu.setProperties({ menuItems: this.menuctrl.items }, true);
        };
        RibbonFileMenu.prototype.enableItems = function (items, isUniqueId) {
            this.menuctrl.enableItems(items, true, isUniqueId);
            this.parent.fileMenu.setProperties({ menuItems: this.menuctrl.items }, true);
        };
        RibbonFileMenu.prototype.disableItems = function (items, isUniqueId) {
            this.menuctrl.enableItems(items, false, isUniqueId);
            this.parent.fileMenu.setProperties({ menuItems: this.menuctrl.items }, true);
        };
        RibbonFileMenu.prototype.setItem = function (item, id, isUniqueId) {
            this.menuctrl.setItem(item, id, isUniqueId);
            this.menuctrl.refresh();
            this.parent.fileMenu.setProperties({ menuItems: this.menuctrl.items }, true);
        };
        return RibbonFileMenu;
    }());
    exports.RibbonFileMenu = RibbonFileMenu;
});