all files / menu/ menu.js

97.99% Statements 146/149
87.96% Branches 95/108
94.74% Functions 18/19
97.9% Lines 140/143
18 statements, 7 functions, 29 branches Ignored     
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              52× 52× 52×   1202×   52× 52× 52×             50×   52×   52× 52× 52×       45×     52× 11× 11× 10×       57× 57× 57× 57× 57×   30× 30× 31× 31×                                                                           30×   342× 342× 342× 342× 342× 28× 28× 39×     39×   28×     314×                                                  
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
/* istanbul ignore next */ 
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "../common/menu-base"], function (require, exports, ej2_base_1, ej2_base_2, menu_base_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var VMENU = 'e-vertical';
    var SCROLLABLE = 'e-scrollable';
    var HAMBURGER = 'e-hamburger';
    var Menu = (function (_super) {
        __extends(Menu, _super);
        function Menu(options, element) {
            var _this = _super.call(this, options, element) || this;
            _this.tempItems = [];
            return _this;
        }
        Menu.prototype.getModuleName = function () {
            return 'menu';
        };
        Menu.prototype.preRender = function () {
            this.isMenu = true;
            this.element.id = this.element.id || ej2_base_2.getUniqueID('ej2-menu');
            if (this.template) {
                try {
                    Eif (typeof this.template !== 'function' && document.querySelectorAll(this.template).length) {
                        this.template = document.querySelector(this.template).innerHTML.trim();
                        this.clearChanges();
                    }
                }
                catch (e) {
                }
                this.updateMenuItems(this.items);
            }
            else {
                this.updateMenuItems(this.items);
            }
            _super.prototype.preRender.call(this);
        };
        Menu.prototype.initialize = function () {
            _super.prototype.initialize.call(this);
            ej2_base_1.attributes(this.element, { 'role': 'menubar', 'tabindex': '0' });
            if (this.orientation === 'Vertical') {
                this.element.classList.add(VMENU);
                if (this.hamburgerMode && !this.target) {
                    this.element.previousElementSibling.classList.add(VMENU);
                }
                this.element.setAttribute('aria-orientation', 'vertical');
            }
            else {
                if (ej2_base_2.Browser.isDevice && !this.enableScrolling) {
                    this.element.parentElement.classList.add(SCROLLABLE);
                }
            }
            if (this.hamburgerMode) {
                this.element.parentElement.classList.add(HAMBURGER);
                if (this.orientation === 'Horizontal') {
                    this.element.classList.add('e-hide-menu');
                }
            }
        };
        Menu.prototype.updateMenuItems = function (items) {
            this.tempItems = items;
            this.items = [];
            this.tempItems.map(this.createMenuItems, this);
            this.setProperties({ items: this.items }, true);
            this.tempItems = [];
        };
        Menu.prototype.onPropertyChanged = function (newProp, oldProp) {
            var _this = this;
            for (var _i = 0, _a = Object.keys(newProp); _i < _a.length; _i++) {
                var prop = _a[_i];
                switch (prop) {
                    case 'orientation':
                        if (newProp.orientation === 'Vertical') {
                            this.element.classList.add(VMENU);
                            if (this.hamburgerMode) {
                                Eif (!this.target) {
                                    this.element.previousElementSibling.classList.add(VMENU);
                                }
                                this.element.classList.remove('e-hide-menu');
                            }
                            this.element.setAttribute('aria-orientation', 'vertical');
                        }
                        else {
                            this.element.classList.remove(VMENU);
                            if (this.hamburgerMode) {
                                Eif (!this.target) {
                                    this.element.previousElementSibling.classList.remove(VMENU);
                                }
                                this.element.classList.add('e-hide-menu');
                            }
                            this.element.removeAttribute('aria-orientation');
                        }
                        break;
                    case 'items':
                        if (!Object.keys(oldProp.items).length) {
                            this.updateMenuItems(newProp.items);
                        }
                        break;
                    case 'hamburgerMode':
                        if (!this.element.previousElementSibling) {
                            _super.prototype.createHeaderContainer.call(this);
                        }
                        if (newProp.hamburgerMode) {
                            this.element.parentElement.classList.add(HAMBURGER);
                            [].slice.call(this.element.getElementsByClassName('e-blankicon')).forEach(function (li) {
                                li.style[_this.enableRtl ? 'paddingRight' : 'paddingLeft'] = '';
                            });
                        }
                        else {
                            this.element.parentElement.classList.remove(HAMBURGER);
                            Iif (this.orientation === 'Vertical') {
                                this.setBlankIconStyle(this.element);
                            }
                        }
                        if (this.orientation === 'Vertical') {
                            if (!this.target) {
                                this.element.previousElementSibling.classList.add(VMENU);
                            }
                            this.element.classList.remove('e-hide-menu');
                        }
                        else {
                            if (this.target) {
                                this.element.previousElementSibling.classList.add(VMENU);
                            }
                            else {
                                this.element.previousElementSibling.classList.remove(VMENU);
                            }
                            this.element.classList[newProp.hamburgerMode ? 'add' : 'remove']('e-hide-menu');
                        }
                        break;
                    case 'title':
                        if (this.hamburgerMode && this.element.previousElementSibling) {
                            newProp.title = (this.enableHtmlSanitizer) ? ej2_base_2.SanitizeHtmlHelper.sanitize(newProp.title) : newProp.title;
                            this.element.previousElementSibling.querySelector('.e-menu-title').innerHTML = newProp.title;
                        }
                        break;
                    case 'target':
                        Eif (this.hamburgerMode) {
                            this.unWireEvents(oldProp.target);
                            this.wireEvents();
                            Eif (this.orientation === 'Horizontal') {
                                if (!newProp.target) {
                                    Eif (!this.element.previousElementSibling) {
                                        _super.prototype.createHeaderContainer.call(this);
                                    }
                                    this.element.previousElementSibling.classList.remove(VMENU);
                                }
                                else {
                                    this.element.previousElementSibling.classList.add(VMENU);
                                }
                                this.element.classList.add('e-hide-menu');
                            }
                        }
                        break;
                }
            }
            _super.prototype.onPropertyChanged.call(this, newProp, oldProp);
        };
        Menu.prototype.createMenuItems = function (item) {
            var idx;
            var i;
            var items = this.items;
            var pIdField = this.getField('parentId');
            if (item["" + pIdField]) {
                idx = this.getIndex(item["" + pIdField].toString(), true);
                for (i = 0; i < idx.length; i++) {
                    Iif (!items[idx[i]].items) {
                        items[idx[i]].items = [];
                    }
                    items = items[idx[i]].items;
                }
                items.push(item);
            }
            else {
                this.items.push(item);
            }
        };
        Menu.prototype.open = function () {
            _super.prototype.openHamburgerMenu.call(this);
        };
        Menu.prototype.close = function () {
            _super.prototype.closeHamburgerMenu.call(this);
        };
        __decorate([
            ej2_base_1.Property('Horizontal')
        ], Menu.prototype, "orientation", void 0);
        __decorate([
            ej2_base_1.Property('')
        ], Menu.prototype, "target", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], Menu.prototype, "template", void 0);
        __decorate([
            ej2_base_1.Property(false)
        ], Menu.prototype, "enableScrolling", void 0);
        __decorate([
            ej2_base_1.Property(false)
        ], Menu.prototype, "hamburgerMode", void 0);
        __decorate([
            ej2_base_1.Property('Menu')
        ], Menu.prototype, "title", void 0);
        __decorate([
            ej2_base_1.Property(true)
        ], Menu.prototype, "enableHtmlSanitizer", void 0);
        __decorate([
            ej2_base_2.Complex({ itemId: 'id', text: 'text', parentId: 'parentId', iconCss: 'iconCss', url: 'url', separator: 'separator', children: 'items' }, menu_base_1.FieldSettings)
        ], Menu.prototype, "fields", void 0);
        Menu = __decorate([
            ej2_base_1.NotifyPropertyChanges
        ], Menu);
        return Menu;
    }(menu_base_1.MenuBase));
    exports.Menu = Menu;
});