all files / breadcrumb/ breadcrumb.js

94.72% Statements 466/492
91% Branches 384/422
97.83% Functions 45/46
94.65% Lines 460/486
5 statements, 2 functions, 11 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 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 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759  1× 1× 1× 1× 1× 1×   1× 33× 33× 33×       1× 352× 352× 352× 352×   1×   1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1×   1× 1× 1× 397×   1×     1×     1×     1×     1×     1×   1× 1× 1× 1× 93× 93× 93×   1×   1× 94× 94× 94×   1× 94× 94× 80×   94× 7×   94× 2×   94× 2× 2×   94× 5×   89× 4×   94× 94×   1× 180× 11× 11×   180× 132× 74× 74× 74×     58×       1× 85× 85× 85× 7× 42× 7×         78×   85×   1× 95× 3× 3× 3× 3× 2× 2× 2×     1× 1×   3× 3× 7× 7× 7×     3×     1× 189× 189× 189× 189× 189× 189× 189× 189× 189× 189× 189× 189× 189× 189× 189× 189× 189× 189× 189× 83×   189×         987× 987× 182× 182× 120×     987× 6×   987× 40×   987×       987× 987× 987× 987× 82×   987×       987×     987× 12×   987× 68× 68×   32× 32×     987× 987× 182× 182×     805×   987× 979×       189× 1327×   1327× 76×   1251×   63×   1188× 511× 511× 499× 304×       12×   511× 511× 511×     677× 677× 6× 6×     671×   677×     677× 68×   677× 677× 182×     1188× 1188× 1188× 478× 201×     277× 277× 61×       710× 91× 9×     82×     987× 987× 987×                   987× 41×   987× 14× 14× 14×   987× 77× 77× 77×   987× 103×   884×       189×           189× 9×   189× 189× 189×       1× 189× 167× 167× 167× 167× 167× 139× 139× 139× 139×   167× 137× 76× 76×   66× 66× 66×     10×       61×               61× 61×         22× 16× 16× 16× 13× 62×   13× 13× 7×     6×         1× 189× 589× 88×     101×   1× 216×   1× 979× 979× 4× 7× 4×       979× 4× 4× 3× 1× 1×     2×     1× 1× 1× 1×             979× 6× 6× 1× 1×               1× 95× 1× 1× 1× 1×   95× 95×   1× 29× 29× 1×   29× 6× 6× 1×     5×   6× 3× 1× 1× 1× 1×     2×                     2× 2×       3×   6× 1× 1× 1×   1×   6×   6× 6×     6× 6×   6×   29× 1× 1×   29× 21×     1× 24× 24× 24× 24× 24×             24× 15×       24× 24×   1× 5555× 8× 8× 8× 8×     1× 1× 1× 1×   1× 1× 1× 1×     1× 1× 1×     1× 1× 1×     1× 30× 33× 33×   1× 1×     13× 13× 13× 13×     6× 6× 6× 6× 2×   4× 2×   6× 2×   4× 2×   6×   1× 1× 1×   9× 8×   9× 9×   9×     5×   9×   2× 2×   1× 1× 1×       1× 94× 94× 94× 94× 94×   1× 24× 24×   1× 89× 89× 89× 89× 89× 17× 17×     1× 2×   1× 1944×   1× 89× 89× 9× 9× 9×   89× 89× 89× 12×   89× 4×   89× 1× 1×   89× 5×   84× 4×   89× 89× 89× 89× 90×   89×   1×     1×     1×     1×     1×     1×     1×     1×     1×     1×     1×     1×     1×     1×     1×     1×     1×   1×    
/* 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;
    Iif (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) Eif (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-lists", "@syncfusion/ej2-popups"], function (require, exports, ej2_base_1, ej2_lists_1, ej2_popups_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ICONRIGHT = 'e-icon-right';
    var ITEMTEXTCLASS = 'e-breadcrumb-text';
    var ICONCLASS = 'e-breadcrumb-icon';
    var MENUCLASS = 'e-breadcrumb-menu';
    var ITEMCLASS = 'e-breadcrumb-item';
    var POPUPCLASS = 'e-breadcrumb-popup';
    var WRAPMODECLASS = 'e-breadcrumb-wrap-mode';
    var SCROLLMODECLASS = 'e-breadcrumb-scroll-mode';
    var TABINDEX = 'tabindex';
    var DISABLEDCLASS = 'e-disabled';
    var ARIADISABLED = 'aria-disabled';
    var DOT = '.';
    var BreadcrumbOverflowMode;
    (function (BreadcrumbOverflowMode) {
        BreadcrumbOverflowMode["Hidden"] = "Hidden";
        BreadcrumbOverflowMode["Collapsed"] = "Collapsed";
        BreadcrumbOverflowMode["Menu"] = "Menu";
        BreadcrumbOverflowMode["Wrap"] = "Wrap";
        BreadcrumbOverflowMode["Scroll"] = "Scroll";
        BreadcrumbOverflowMode["None"] = "None";
    })(BreadcrumbOverflowMode = exports.BreadcrumbOverflowMode || (exports.BreadcrumbOverflowMode = {}));
    var BreadcrumbItem = (function (_super) {
        __extends(BreadcrumbItem, _super);
        function BreadcrumbItem() {
            return _super !== null && _super.apply(this, arguments) || this;
        }
        __decorate([
            ej2_base_1.Property('')
        ], BreadcrumbItem.prototype, "text", void 0);
        __decorate([
            ej2_base_1.Property('')
        ], BreadcrumbItem.prototype, "id", void 0);
        __decorate([
            ej2_base_1.Property('')
        ], BreadcrumbItem.prototype, "url", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], BreadcrumbItem.prototype, "iconCss", void 0);
        __decorate([
            ej2_base_1.Property(false)
        ], BreadcrumbItem.prototype, "disabled", void 0);
        return BreadcrumbItem;
    }(ej2_base_1.ChildProperty));
    exports.BreadcrumbItem = BreadcrumbItem;
    var Breadcrumb = (function (_super) {
        __extends(Breadcrumb, _super);
        function Breadcrumb(options, element) {
            var _this = _super.call(this, options, element) || this;
            _this.isPopupCreated = false;
            return _this;
        }
        Breadcrumb.prototype.preRender = function () {
        };
        Breadcrumb.prototype.render = function () {
            this.initialize();
            this.renderItems(this.items);
            this.wireEvents();
        };
        Breadcrumb.prototype.initialize = function () {
            this._maxItems = this.maxItems;
            if (ej2_base_1.isNullOrUndefined(this.element.getAttribute('aria-label'))) {
                this.element.setAttribute('aria-label', 'breadcrumb');
            }
            if (this.cssClass) {
                ej2_base_1.addClass([this.element], this.cssClass.replace(/\s+/g, ' ').trim().split(' '));
            }
            if (this.enableRtl) {
                this.element.classList.add('e-rtl');
            }
            if (this.disabled) {
                this.element.classList.add(DISABLEDCLASS);
                this.element.setAttribute(ARIADISABLED, 'true');
            }
            if (this.overflowMode === 'Wrap') {
                this.element.classList.add(WRAPMODECLASS);
            }
            else if (this.overflowMode === 'Scroll') {
                this.element.classList.add(SCROLLMODECLASS);
            }
            this.initItems();
            this.initPvtProps();
        };
        Breadcrumb.prototype.initPvtProps = function () {
            if (this.overflowMode === 'Hidden' && this._maxItems > 0) {
                this.endIndex = this.getEndIndex();
                this.startIndex = this.endIndex + 1 - (this._maxItems - 1);
            }
            if (this.overflowMode === 'Menu') {
                if (this._maxItems >= 0) {
                    this.startIndex = this._maxItems > 1 ? 1 : 0;
                    this.endIndex = this.getEndIndex();
                    this.popupUl = this.createElement('ul', { attrs: { TABINDEX: '0', 'role': 'menu' } });
                }
                else {
                    this.startIndex = this.endIndex = null;
                }
            }
        };
        Breadcrumb.prototype.getEndIndex = function () {
            var _this = this;
            var endIndex;
            if (this.activeItem) {
                this.items.forEach(function (item, idx) {
                    if (item.url === _this.activeItem || item.text === _this.activeItem) {
                        endIndex = idx;
                    }
                });
            }
            else {
                endIndex = this.items.length - 1;
            }
            return endIndex;
        };
        Breadcrumb.prototype.initItems = function () {
            if (!this.items.length) {
                var baseUri = void 0;
                var uri = void 0;
                var items = [];
                if (this.url) {
                    var url = new URL(this.url, window.location.origin);
                    baseUri = url.origin + '/';
                    uri = url.href.split(baseUri)[1].split('/');
                }
                else {
                    baseUri = window.location.origin + '/';
                    uri = window.location.href.split(baseUri)[1].split('/');
                }
                items.push({ iconCss: 'e-icons e-home', url: baseUri });
                for (var i = 0; i < uri.length; i++) {
                    Eif (uri[i]) {
                        items.push({ text: uri[i], url: baseUri + uri[i] });
                        baseUri += uri[i] + '/';
                    }
                }
                this.setProperties({ items: items }, true);
            }
        };
        Breadcrumb.prototype.renderItems = function (items) {
            var _this = this;
            var item;
            var isSingleLevel;
            var isIconRight = this.element.classList.contains(ICONRIGHT);
            var itemsLength = items.length;
            Eif (itemsLength) {
                var isActiveItem = void 0;
                var isLastItem = void 0;
                var isLastItemInPopup_1;
                var j_1 = 0;
                var wrapDiv = void 0;
                var len = (itemsLength * 2) - 1;
                var isItemCancelled_1 = false;
                var ol = this.createElement('ol', { className: this.overflowMode === 'Wrap' ? 'e-breadcrumb-wrapped-ol' : '' });
                var firstOl = this.createElement('ol', { className: this.overflowMode === 'Wrap' ? 'e-breadcrumb-first-ol' : '' });
                var showIcon = this.hasField(items, 'iconCss');
                var isCollasped = (this.overflowMode === 'Collapsed' && this._maxItems > 0 && itemsLength > this._maxItems && !this.isExpanded);
                var isDefaultOverflowMode_1 = (this.overflowMode === 'Hidden' && this._maxItems > 0);
                if (this.overflowMode === 'Menu' && this.popupUl) {
                    this.popupUl.innerHTML = '';
                }
                var listBaseOptions = {
                    moduleName: this.getModuleName(),
                    showIcon: showIcon,
                    itemNavigable: true,
                    itemCreated: function (args) {
                        var isLastItem = args.curData.isLastItem;
                        if (isLastItem && args.item.children.length && !_this.itemTemplate) {
                            delete args.curData.isLastItem;
                            if (!isLastItemInPopup_1 && !_this.enableActiveItemNavigation) {
                                args.item.innerHTML = _this.createElement('span', { className: ITEMTEXTCLASS, innerHTML: args.item.children[0].innerHTML }).outerHTML;
                            }
                        }
                        if (args.curData.iconCss && !args.curData.text && !_this.itemTemplate) {
                            args.item.classList.add('e-icon-item');
                        }
                        if (isDefaultOverflowMode_1) {
                            args.item.setAttribute('item-index', j_1.toString());
                        }
                        var eventArgs = {
                            item: ej2_base_1.extend({}, args.curData.properties ?
                                args.curData.properties : args.curData), element: args.item, cancel: false
                        };
                        _this.trigger('beforeItemRender', eventArgs);
                        isItemCancelled_1 = eventArgs.cancel;
                        var containsRightIcon = (isIconRight || eventArgs.element.classList.contains(ICONRIGHT));
                        if (containsRightIcon && args.curData.iconCss && !_this.itemTemplate) {
                            args.item.querySelector('.e-anchor-wrap').appendChild(args.item.querySelector(DOT + ICONCLASS));
                        }
                        Iif (eventArgs.item.disabled) {
                            args.item.setAttribute(ARIADISABLED, 'true');
                            args.item.classList.add(DISABLEDCLASS);
                        }
                        Iif (eventArgs.item.id) {
                            args.item.setAttribute('id', eventArgs.item.id);
                        }
                        if ((eventArgs.item.disabled || _this.disabled) && args.item.children.length && !_this.itemTemplate) {
                            args.item.children[0].setAttribute(TABINDEX, '-1');
                        }
                        if (args.curData.isEmptyUrl) {
                            args.item.children[0].removeAttribute('href');
                            if ((!isLastItem || (isLastItem && _this.enableActiveItemNavigation)) && !(eventArgs.item.disabled
                                || _this.disabled)) {
                                args.item.children[0].setAttribute(TABINDEX, '0');
                                ej2_base_1.EventHandler.add(args.item.children[0], 'keydown', _this.keyDownHandler, _this);
                            }
                        }
                        args.item.removeAttribute('role');
                        if (isLastItem) {
                            args.item.setAttribute('data-active-item', '');
                            args.item.setAttribute('aria-current', 'page');
                        }
                        else {
                            args.item.removeAttribute('aria-current');
                        }
                        if (!_this.itemTemplate) {
                            _this.beforeItemRenderChanges(args.curData, eventArgs.item, args.item, containsRightIcon);
                        }
                    }
                };
                for (var i = 0; i < len; (i % 2 && j_1++), i++) {
                    isActiveItem = (this.activeItem && (this.activeItem === items[j_1].url ||
                        this.activeItem === items[j_1].text));
                    if (isCollasped && i > 1 && i < len - 2) {
                        continue;
                    }
                    else if (isDefaultOverflowMode_1 && ((j_1 < this.startIndex || j_1 > this.endIndex)
                        && (i % 2 ? j_1 !== this.startIndex - 1 : true)) && j_1 !== 0) {
                        continue;
                    }
                    if (i % 2) {
                        wrapDiv = this.createElement('div', { className: 'e-breadcrumb-item-wrapper' });
                        if ((this.separatorTemplate && this.separatorTemplate === '/') || ej2_base_1.isNullOrUndefined(this.separatorTemplate)) {
                            listBaseOptions.template = ej2_base_1.initializeCSPTemplate(function () {
                                return '/';
                            });
                        }
                        else {
                            listBaseOptions.template = this.separatorTemplate;
                        }
                        listBaseOptions.itemClass = 'e-breadcrumb-separator';
                        isSingleLevel = false;
                        item = [{ previousItem: items[j_1], nextItem: items[j_1 + 1] }];
                    }
                    else {
                        listBaseOptions.itemClass = '';
                        if (this.itemTemplate) {
                            listBaseOptions.template = this.itemTemplate;
                            isSingleLevel = false;
                        }
                        else {
                            isSingleLevel = true;
                        }
                        item = [ej2_base_1.extend({}, items[j_1].properties ?
                                items[j_1].properties
                                : items[j_1])];
                        if (!item[0].url && !this.itemTemplate) {
                            item = [ej2_base_1.extend({}, item[0], { isEmptyUrl: true, url: '#' })];
                        }
                        isLastItem = (isDefaultOverflowMode_1 || this.overflowMode === 'Menu') && (j_1 === this.endIndex);
                        if (((i === len - 1 || isLastItem) && !this.itemTemplate) || isActiveItem) {
                            item[0].isLastItem = true;
                        }
                    }
                    var parent_1 = ol;
                    var lastPopupItemIdx = this.startIndex + this.endIndex - this._maxItems;
                    if (this.overflowMode === 'Menu' && ((j_1 >= this.startIndex && (j_1 <= lastPopupItemIdx && (i % 2 ? !(j_1 === lastPopupItemIdx) : true)) && this.endIndex >= this._maxItems && this._maxItems > 0) || this._maxItems === 0)) {
                        if (i % 2) {
                            continue;
                        }
                        else {
                            parent_1 = this.popupUl;
                            if (isLastItem) {
                                isLastItemInPopup_1 = true;
                            }
                        }
                    }
                    else if (this.overflowMode === 'Wrap') {
                        if (i === 0) {
                            parent_1 = firstOl;
                        }
                        else {
                            parent_1 = wrapDiv;
                        }
                    }
                    var li = ej2_lists_1.ListBase.createList(this.createElement, item, listBaseOptions, isSingleLevel, this).childNodes;
                    Eif (!isItemCancelled_1) {
                        ej2_base_1.append(li, parent_1);
                    }
                    else if (isDefaultOverflowMode_1 || isCollasped || this.overflowMode === 'Menu' || this.overflowMode === 'Wrap') {
                        items.splice(j_1, 1);
                        this.initPvtProps();
                        return this.reRenderItems();
                    }
                    else if ((i === len - 1 || isLastItem)) {
                        ej2_base_1.remove(parent_1.lastElementChild);
                    }
                    if (this.overflowMode === 'Wrap' && i !== 0 && i % 2 === 0) {
                        ol.appendChild(wrapDiv);
                    }
                    if (isCollasped && i === 1) {
                        var li_1 = this.createElement('li', { className: 'e-icons e-breadcrumb-collapsed', attrs: { TABINDEX: '0' } });
                        ej2_base_1.EventHandler.add(li_1, 'keyup', this.expandHandler, this);
                        ol.appendChild(li_1);
                    }
                    if (this.overflowMode === 'Menu' && this.startIndex === i && this.endIndex >= this._maxItems && this._maxItems >= 0) {
                        var menu = this.getMenuElement();
                        ej2_base_1.EventHandler.add(menu, 'keyup', this.keyDownHandler, this);
                        ol.appendChild(menu);
                    }
                    if (isActiveItem || isLastItem) {
                        break;
                    }
                    Iif (isItemCancelled_1) {
                        i++;
                    }
                }
                Iif (this.isReact) {
                    this.renderReactTemplates();
                    setTimeout(function () {
                        _this.calculateMaxItems();
                    }, 5);
                }
                if (this.overflowMode === 'Wrap') {
                    this.element.appendChild(firstOl);
                }
                this.element.appendChild(ol);
                Eif (!this.isReact) {
                    this.calculateMaxItems();
                }
            }
        };
        Breadcrumb.prototype.calculateMaxItems = function () {
            if (this.overflowMode === 'Hidden' || this.overflowMode === 'Collapsed' || this.overflowMode === 'Menu') {
                var maxItems = void 0;
                var width = this.element.offsetWidth;
                var liElems = [].slice.call(this.element.children[0].children).reverse();
                var liWidth = this.overflowMode === 'Menu' ? 0 : liElems[liElems.length - 1].offsetWidth + (liElems[liElems.length - 2] ? liElems[liElems.length - 2].offsetWidth : 0);
                if (this.overflowMode === 'Menu') {
                    var menuEle = this.getMenuElement();
                    this.element.appendChild(menuEle);
                    liWidth += menuEle.offsetWidth;
                    ej2_base_1.remove(menuEle);
                }
                for (var i = 0; i < liElems.length - 2; i++) {
                    if (liWidth > width) {
                        maxItems = Math.ceil((i - 1) / 2) + ((this.overflowMode === 'Menu' && i <= 2) ? 0 : 1);
                        if (((this.maxItems > maxItems && !(this.maxItems > -1 && maxItems === -1)) ||
                            this.maxItems === -1) && this._maxItems !== maxItems) {
                            this._maxItems = maxItems;
                            this.initPvtProps();
                            return this.reRenderItems();
                        }
                        else {
                            break;
                        }
                    }
                    else {
                        Iif (this.overflowMode === 'Menu' && i === 2) {
                            liWidth += liElems[liElems.length - 1].offsetWidth + liElems[liElems.length - 2].offsetWidth;
                            if (liWidth > width) {
                                this._maxItems = 1;
                                this.initPvtProps();
                                return this.reRenderItems();
                            }
                        }
                        Eif (!(this.overflowMode === 'Menu' && liElems[i].classList.contains(MENUCLASS))) {
                            liWidth += liElems[i].offsetWidth;
                        }
                    }
                }
            }
            else if ((this.overflowMode === 'Wrap' || this.overflowMode === 'Scroll') && this._maxItems > 0) {
                var width = 0;
                var liElems = this.element.querySelectorAll(DOT + ITEMCLASS);
                if (liElems.length > this._maxItems + this._maxItems - 1) {
                    for (var i = this.overflowMode === 'Wrap' ? 1 : 0; i < this._maxItems + this._maxItems - 1; i++) {
                        width += liElems[i].offsetWidth;
                    }
                    width = width + 5 + (parseInt(getComputedStyle(this.element.children[0]).paddingLeft, 10) * 2);
                    if (this.overflowMode === 'Wrap') {
                        this.element.querySelector('.e-breadcrumb-wrapped-ol').style.width = width + 'px';
                    }
                    else {
                        this.element.style.width = width + 'px';
                    }
                }
            }
        };
        Breadcrumb.prototype.hasField = function (items, field) {
            for (var i = 0, len = items.length; i < len; i++) {
                if (items[i]["" + field]) {
                    return true;
                }
            }
            return false;
        };
        Breadcrumb.prototype.getMenuElement = function () {
            return this.createElement('li', { className: 'e-icons e-breadcrumb-menu', attrs: { TABINDEX: '0' } });
        };
        Breadcrumb.prototype.beforeItemRenderChanges = function (prevItem, currItem, elem, isRightIcon) {
            var wrapElem = elem.querySelector('.e-anchor-wrap');
            if (currItem.text !== prevItem.text && wrapElem) {
                wrapElem.childNodes.forEach(function (child) {
                    if (child.nodeType === Node.TEXT_NODE) {
                        child.textContent = currItem.text;
                    }
                });
            }
            if (currItem.iconCss !== prevItem.iconCss && wrapElem) {
                var iconElem = elem.querySelector(DOT + ICONCLASS);
                if (iconElem) {
                    if (currItem.iconCss) {
                        ej2_base_1.removeClass([iconElem], prevItem.iconCss.split(' '));
                        ej2_base_1.addClass([iconElem], currItem.iconCss.split(' '));
                    }
                    else {
                        ej2_base_1.remove(iconElem);
                    }
                }
                else Eif (currItem.iconCss) {
                    var iconElem_1 = this.createElement('span', { className: ICONCLASS + ' ' + currItem.iconCss });
                    Eif (isRightIcon) {
                        ej2_base_1.append([iconElem_1], wrapElem);
                    }
                    else {
                        wrapElem.insertBefore(iconElem_1, wrapElem.childNodes[0]);
                    }
                }
            }
            if (currItem.url !== prevItem.url && this.enableNavigation) {
                var anchor = elem.querySelector('a.' + ITEMTEXTCLASS);
                if (anchor) {
                    Eif (currItem.url) {
                        anchor.setAttribute('href', currItem.url);
                    }
                    else {
                        anchor.removeAttribute('href');
                    }
                }
            }
        };
        Breadcrumb.prototype.reRenderItems = function () {
            if (this.overflowMode === 'Menu' && this.popupObj && this.popupObj.element.classList.contains('e-popup-open') && this.popupObj.element.querySelector('.e-edit-template')) {
                this.popupObj.hide();
                this.popupObj.destroy();
                this.isPopupCreated = false;
                ej2_base_1.detach(this.popupObj.element);
            }
            this.element.innerHTML = '';
            this.renderItems(this.items);
        };
        Breadcrumb.prototype.clickHandler = function (e) {
            var li = ej2_base_1.closest(e.target, DOT + ITEMCLASS + ':not(.e-breadcrumb-separator)');
            if (!this.enableNavigation) {
                e.preventDefault();
            }
            if (li && (ej2_base_1.closest(e.target, DOT + ITEMTEXTCLASS) || this.itemTemplate)) {
                var idx = void 0;
                if (this.overflowMode === 'Wrap') {
                    idx = [].slice.call(this.element.querySelectorAll(DOT + ITEMCLASS)).indexOf(li);
                }
                else {
                    idx = [].slice.call(li.parentElement.children).indexOf(li);
                }
                if (this.overflowMode === 'Menu') {
                    if (ej2_base_1.closest(e.target, DOT + POPUPCLASS)) {
                        idx += this.startIndex;
                        this.endIndex = idx;
                        Eif (e.type === 'keydown') {
                            this.documentClickHandler(e);
                        }
                    }
                    else Iif (this.element.querySelector(DOT + MENUCLASS)) {
                        if (idx > [].slice.call(this.element.children[0].children).indexOf(this.element.querySelector(DOT + MENUCLASS))) {
                            idx += (this.popupUl.childElementCount * 2) - 2;
                            idx = Math.floor(idx / 2);
                            this.endIndex = idx;
                        }
                        else {
                            this.startIndex = this.endIndex = idx;
                        }
                    }
                    else {
                        idx = Math.floor(idx / 2);
                        this.startIndex = this.endIndex = idx;
                    }
                }
                else {
                    idx = Math.floor(idx / 2);
                }
                if (this.overflowMode === 'Hidden' && this._maxItems > 0 && this.endIndex !== 0) {
                    idx = parseInt(li.getAttribute('item-index'), 10);
                    Eif (this.startIndex > 1) {
                        this.startIndex -= (this.endIndex - idx);
                    }
                    this.endIndex = idx;
                }
                var itemClickArgs = { element: li,
                    item: this.items[idx], event: e, cancel: false };
                this.trigger('itemClick', itemClickArgs);
                Iif (itemClickArgs.cancel) {
                    return;
                }
                Eif (this.items[idx]) {
                    this.activeItem = this.items[idx].url || this.items[idx].text;
                }
                this.dataBind();
            }
            if (e.target.classList.contains('e-breadcrumb-collapsed')) {
                this.isExpanded = true;
                this.reRenderItems();
            }
            if (e.target.classList.contains(MENUCLASS) && !this.isPopupCreated) {
                this.renderPopup();
            }
        };
        Breadcrumb.prototype.renderPopup = function () {
            var _this = this;
            var wrapper = this.createElement('div', { className: POPUPCLASS + ' ' + this.cssClass + (this.enableRtl ? ' e-rtl' : '') });
            document.body.appendChild(wrapper);
            this.isPopupCreated = true;
            this.popupObj = new ej2_popups_1.Popup(wrapper, {
                content: this.popupUl,
                relateTo: this.element.querySelector(DOT + MENUCLASS),
                enableRtl: this.enableRtl,
                position: { X: 'left', Y: 'bottom' },
                collision: { X: 'fit', Y: 'flip' },
                open: function () {
                    if (_this.popupUl) {
                        _this.popupUl.focus();
                    }
                }
            });
            this.popupWireEvents();
            this.popupObj.show();
        };
        Breadcrumb.prototype.documentClickHandler = function (e) {
            if (this.overflowMode === 'Menu' && this.popupObj && this.popupObj.element.classList.contains('e-popup-open') && !ej2_base_1.closest(e.target, DOT + MENUCLASS) && !ej2_base_1.closest(e.target, DOT + 'e-edit-template')) {
                this.popupObj.hide();
                this.popupObj.destroy();
                this.isPopupCreated = false;
                ej2_base_1.detach(this.popupObj.element);
            }
        };
        Breadcrumb.prototype.resize = function (e) {
            this._maxItems = this.maxItems;
            this.initPvtProps();
            this.reRenderItems();
        };
        Breadcrumb.prototype.expandHandler = function (e) {
            Eif (e.key === 'Enter') {
                this.isExpanded = true;
                this.reRenderItems();
            }
        };
        Breadcrumb.prototype.keyDownHandler = function (e) {
            Eif (e.key === 'Enter') {
                this.clickHandler(e);
            }
        };
        Breadcrumb.prototype.popupKeyDownHandler = function (e) {
            Eif (e.key === 'Escape') {
                this.documentClickHandler(e);
            }
        };
        Breadcrumb.prototype.onPropertyChanged = function (newProp, oldProp) {
            for (var _i = 0, _a = Object.keys(newProp); _i < _a.length; _i++) {
                var prop = _a[_i];
                switch (prop) {
                    case 'enableActiveItemNavigation':
                        this.reRenderItems();
                        break;
                    case 'items':
                    case 'activeItem':
                        this._maxItems = this.maxItems;
                        this.initPvtProps();
                        this.reRenderItems();
                        break;
                    case 'overflowMode':
                    case 'maxItems':
                        this._maxItems = this.maxItems;
                        this.initPvtProps();
                        this.reRenderItems();
                        if (oldProp.overflowMode === 'Wrap') {
                            this.element.classList.remove(WRAPMODECLASS);
                        }
                        else if (newProp.overflowMode === 'Wrap') {
                            this.element.classList.add(WRAPMODECLASS);
                        }
                        if (oldProp.overflowMode === 'Scroll') {
                            this.element.classList.remove(SCROLLMODECLASS);
                        }
                        else if (newProp.overflowMode === 'Scroll') {
                            this.element.classList.add(SCROLLMODECLASS);
                        }
                        break;
                    case 'url':
                        this.initItems();
                        this.reRenderItems();
                        break;
                    case 'cssClass':
                        if (oldProp.cssClass) {
                            ej2_base_1.removeClass([this.element], oldProp.cssClass.split(' '));
                        }
                        Eif (newProp.cssClass) {
                            ej2_base_1.addClass([this.element], newProp.cssClass.replace(/\s+/g, ' ').trim().split(' '));
                        }
                        if ((oldProp.cssClass && oldProp.cssClass.indexOf(ICONRIGHT) > -1) && !(newProp.cssClass &&
                            newProp.cssClass.indexOf(ICONRIGHT) > -1) || !(oldProp.cssClass && oldProp.cssClass.indexOf(ICONRIGHT) > -1) &&
                            (newProp.cssClass && newProp.cssClass.indexOf(ICONRIGHT) > -1)) {
                            this.reRenderItems();
                        }
                        break;
                    case 'enableRtl':
                        this.element.classList.toggle('e-rtl');
                        break;
                    case 'disabled':
                        this.element.classList.toggle(DISABLEDCLASS);
                        this.element.setAttribute(ARIADISABLED, newProp.disabled + '');
                        break;
                }
            }
        };
        Breadcrumb.prototype.wireEvents = function () {
            this.delegateClickHanlder = this.documentClickHandler.bind(this);
            ej2_base_1.EventHandler.add(document, 'click', this.delegateClickHanlder, this);
            ej2_base_1.EventHandler.add(this.element, 'click', this.clickHandler, this);
            this.resizeHandler = this.resize.bind(this);
            window.addEventListener('resize', this.resizeHandler);
        };
        Breadcrumb.prototype.popupWireEvents = function () {
            ej2_base_1.EventHandler.add(this.popupObj.element, 'click', this.clickHandler, this);
            ej2_base_1.EventHandler.add(this.popupObj.element, 'keydown', this.popupKeyDownHandler, this);
        };
        Breadcrumb.prototype.unWireEvents = function () {
            ej2_base_1.EventHandler.remove(document, 'click', this.delegateClickHanlder);
            ej2_base_1.EventHandler.remove(this.element, 'click', this.clickHandler);
            window.removeEventListener('resize', this.resizeHandler);
            this.resizeHandler = null;
            if (this.popupObj) {
                ej2_base_1.EventHandler.remove(this.popupObj.element, 'click', this.clickHandler);
                ej2_base_1.EventHandler.remove(this.popupObj.element, 'keydown', this.popupKeyDownHandler);
            }
        };
        Breadcrumb.prototype.getPersistData = function () {
            return this.addOnPersist(['activeItem']);
        };
        Breadcrumb.prototype.getModuleName = function () {
            return 'breadcrumb';
        };
        Breadcrumb.prototype.destroy = function () {
            var _this = this;
            if (this.popupObj && this.popupObj.element.classList.contains('e-popup-open')) {
                this.popupObj.destroy();
                this.isPopupCreated = false;
                ej2_base_1.detach(this.popupObj.element);
            }
            var classes = [];
            var attributes = ['aria-label'];
            if (this.cssClass) {
                classes.concat(this.cssClass.split(' '));
            }
            if (this.enableRtl) {
                classes.push('e-rtl');
            }
            if (this.disabled) {
                classes.push(DISABLEDCLASS);
                attributes.push(ARIADISABLED);
            }
            if (this.overflowMode === 'Wrap') {
                classes.push(WRAPMODECLASS);
            }
            else if (this.overflowMode === 'Scroll') {
                classes.push(SCROLLMODECLASS);
            }
            this.unWireEvents();
            this.element.innerHTML = '';
            ej2_base_1.removeClass([this.element], classes);
            attributes.forEach(function (attribute) {
                _this.element.removeAttribute(attribute);
            });
            _super.prototype.destroy.call(this);
        };
        __decorate([
            ej2_base_1.Property('')
        ], Breadcrumb.prototype, "url", void 0);
        __decorate([
            ej2_base_1.Collection([], BreadcrumbItem)
        ], Breadcrumb.prototype, "items", void 0);
        __decorate([
            ej2_base_1.Property('')
        ], Breadcrumb.prototype, "activeItem", void 0);
        __decorate([
            ej2_base_1.Property(-1)
        ], Breadcrumb.prototype, "maxItems", void 0);
        __decorate([
            ej2_base_1.Property('Menu')
        ], Breadcrumb.prototype, "overflowMode", void 0);
        __decorate([
            ej2_base_1.Property('')
        ], Breadcrumb.prototype, "cssClass", void 0);
        __decorate([
            ej2_base_1.Property(null)
        ], Breadcrumb.prototype, "itemTemplate", void 0);
        __decorate([
            ej2_base_1.Property('/')
        ], Breadcrumb.prototype, "separatorTemplate", void 0);
        __decorate([
            ej2_base_1.Property(true)
        ], Breadcrumb.prototype, "enableNavigation", void 0);
        __decorate([
            ej2_base_1.Property(false)
        ], Breadcrumb.prototype, "enableActiveItemNavigation", void 0);
        __decorate([
            ej2_base_1.Property(false)
        ], Breadcrumb.prototype, "disabled", void 0);
        __decorate([
            ej2_base_1.Property('')
        ], Breadcrumb.prototype, "locale", void 0);
        __decorate([
            ej2_base_1.Event()
        ], Breadcrumb.prototype, "beforeItemRender", void 0);
        __decorate([
            ej2_base_1.Event()
        ], Breadcrumb.prototype, "itemClick", void 0);
        __decorate([
            ej2_base_1.Event()
        ], Breadcrumb.prototype, "created", void 0);
        Breadcrumb = __decorate([
            ej2_base_1.NotifyPropertyChanges
        ], Breadcrumb);
        return Breadcrumb;
    }(ej2_base_1.Component));
    exports.Breadcrumb = Breadcrumb;
});