all files / items/ ribbon-gallery.js

98.72% Statements 461/467
87.83% Branches 267/304
100% Functions 41/41
98.71% Lines 460/466
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   57× 57× 57× 57× 57× 57× 57× 57×   8338×   29×   32× 32× 32× 32×       32× 32× 32× 32× 30× 30× 30× 30× 22×           32× 322× 322× 322× 322× 25× 25× 22× 22×               64× 64× 64× 64× 64× 64×   64×       64× 32×   64× 88× 88×       88× 16×   88×   88× 302×         302× 302× 11×   302× 302× 10×     292× 46× 46×     302× 302×   302×     302×     302× 75×   302× 64× 64× 24×     302×     280× 280×     280× 276×     276× 276× 23×     280× 276×         280×   280×     302×   302× 16×   302× 22× 22× 22×     88× 302× 302× 22×   88× 22×   66× 12×     54×   66× 50×       50×     64× 64× 88× 88× 22×   64× 64× 64×           35× 35× 35× 35× 34× 119× 90× 90× 90× 90× 90× 90× 90× 90×   90× 90× 90×           29× 29×   90×   34× 29×     35× 31×     50×       35× 35× 35× 35× 35× 35× 35× 35× 35× 35× 35× 35× 62× 234× 234× 120× 91×   91× 88× 88× 88× 88× 88× 88×     88× 88× 27× 27× 27×             61×             29× 29×                 47× 47× 47× 47× 47× 47× 47× 47× 47× 47× 47×     47× 47× 47× 47× 72× 72× 286× 286× 286× 286× 286×     286× 286× 21× 21× 21×     72× 21× 41×   21× 21×   21×     47× 26× 24× 47×   24×       26× 24×         45× 18×     27×     32×       32× 32×       32× 32×                     32×   26×     17×       10× 16× 12×                                                                                     13× 13× 13× 13× 13× 13× 13× 13×   13× 26× 104× 10×   104× 13×       13× 13× 13× 13×   13×     12× 21×   12×     12×   12× 12× 12× 12× 77×     12×       49× 49×   46×   49×   45×   24× 24×   23× 23× 23× 23× 23× 23× 21×   23× 23× 23× 23×   22× 22×   21× 21× 21×       26× 26× 26× 26×     18× 18× 18×   17×   15×           11×                       16× 16× 16× 16× 16×   16×   16×        
define(["require", "exports", "@syncfusion/ej2-base", "../base/index", "@syncfusion/ej2-splitbuttons", "../base/constant", "@syncfusion/ej2-popups"], function (require, exports, ej2_base_1, index_1, ej2_splitbuttons_1, constants, ej2_popups_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var RibbonGallery = (function () {
        function RibbonGallery(parent) {
            this.count = 0;
            this.isAdded = false;
            this.galleryItemsIndex = 0;
            this.registeredTemplate = {};
            this.parent = parent;
            var ref = 'viewContainerRef';
            ej2_base_1.setValue('registeredTemplate', this.registeredTemplate, this);
            ej2_base_1.setValue(ref, this.parent["" + ref], this);
        }
        RibbonGallery.prototype.getModuleName = function () {
            return 'ribbonGallery';
        };
        RibbonGallery.prototype.destroy = function () {
            this.parent = null;
        };
        RibbonGallery.prototype.createGallery = function (item, itemEle) {
            var _this = this;
            var gallerySettings = item.gallerySettings;
            this.renderGalleryItems(gallerySettings, false, item.id, itemEle);
            var buttonEle = this.parent.createElement('button', {
                id: item.id + '_popupButton',
                className: 'e-ribbon-gallery-button e-icons e-drop-icon'
            });
            buttonEle.setAttribute('aria-label', 'gallerydropdownbutton');
            itemEle.appendChild(buttonEle);
            this.createPopup(item, buttonEle);
            buttonEle.onclick = function (args) {
                var popupEle = document.querySelector('#' + item.id + '_galleryPopup');
                Eif (popupEle) {
                    var popup = ej2_base_1.getComponent(popupEle, ej2_popups_1.Popup);
                    if (popupEle.classList.contains('e-popup-close')) {
                        _this.showPopup(popup, popupEle, args, gallerySettings, item.id);
                    }
                    else {
                        _this.hidePopup(popup, popupEle, args, gallerySettings, item.id);
                    }
                }
            };
            document.onclick = function (args) {
                var popupEle = document.querySelectorAll('.e-ribbon-gallery-popup.e-popup-open');
                var popupID;
                var itemProp;
                for (var i = 0; i < popupEle.length; i++) {
                    var popup = ej2_base_1.getComponent(popupEle[parseInt(i.toString(), 10)], ej2_popups_1.Popup);
                    if (args.target.classList.contains('e-ribbon-gallery-button')) {
                        popupID = (popupEle[parseInt(i.toString(), 10)].id).replace(/_galleryPopup/g, '');
                        if ((args.target.id).replace(/_popupButton/g, '') !== popupID) {
                            itemProp = index_1.getItem(_this.parent.tabs, popupID);
                            _this.hidePopup(popup, popupEle[parseInt(i.toString(), 10)], args, itemProp.item.gallerySettings, popupID);
                            break;
                        }
                    }
                    else {
                        popupID = (popupEle[parseInt(i.toString(), 10)].id).replace(/_galleryPopup/g, '');
                        itemProp = index_1.getItem(_this.parent.tabs, popupID);
                        _this.hidePopup(popup, popupEle[parseInt(i.toString(), 10)], args, itemProp.item.gallerySettings, popupID);
                        break;
                    }
                }
            };
        };
        RibbonGallery.prototype.renderGalleryItems = function (gallerySettings, isPopup, id, itemEle) {
            var _this = this;
            var galleryContainerEle;
            var galleryEle;
            var itemProp = index_1.getItem(this.parent.tabs, id);
            Eif (itemProp && itemProp.group) {
                itemProp.group.isCollapsible = false;
            }
            var galleryWrapper = this.parent.createElement('div', {
                className: 'e-ribbon-gallery-wrapper',
                id: id + '_galleryWrapper'
            });
            if (!isPopup) {
                itemEle.appendChild(galleryWrapper);
            }
            var _loop_1 = function (i) {
                var isHeightDefined = false;
                galleryContainerEle = this_1.parent.createElement('ol', {
                    className: 'e-ribbon-gallery-container',
                    id: id + '_galleryContainer' + i
                });
                if (gallerySettings.groups[parseInt(i.toString(), 10)].itemHeight && gallerySettings.groups[parseInt(i.toString(), 10)].itemHeight !== 'auto') {
                    isHeightDefined = true;
                }
                if (gallerySettings.groups[parseInt(i.toString(), 10)].cssClass) {
                    galleryContainerEle.classList.add(gallerySettings.groups[parseInt(i.toString(), 10)].cssClass);
                }
                var _loop_2 = function (j) {
                    galleryEle = this_1.parent.createElement('li', {
                        className: 'e-ribbon-gallery-item',
                        id: (isPopup ? 'popup_' : '') + galleryContainerEle.id + '_gallery' + j,
                        attrs: { 'tabindex': '0' }
                    });
                    var itemEventArgs = { name: 'beforeItemRender', item: gallerySettings.groups[parseInt(i.toString(), 10)].items[parseInt(j.toString(), 10)] };
                    if (gallerySettings.beforeItemRender) {
                        gallerySettings.beforeItemRender.call(this_1, itemEventArgs);
                    }
                    galleryContainerEle.appendChild(galleryEle);
                    if (gallerySettings.selectedItemIndex && gallerySettings.selectedItemIndex === this_1.count) {
                        galleryEle.classList.add('e-ribbon-gallery-selected');
                    }
                    else {
                        if (!gallerySettings.selectedItemIndex && this_1.count === 0) {
                            galleryEle.classList.add('e-ribbon-gallery-selected');
                            gallerySettings.selectedItemIndex = this_1.count;
                        }
                    }
                    this_1.count = this_1.count + 1;
                    galleryEle.onclick = function (e) {
                        _this.setActiveState(e.currentTarget, gallerySettings, id, true, e, isPopup);
                    };
                    galleryEle.onkeydown = function (e) {
                        Eif (e.key === 'Enter' || e.key === ' ') {
                            _this.setActiveState(e.currentTarget, gallerySettings, id, true, e, isPopup);
                        }
                    };
                    galleryEle.onmouseover = function (e) {
                        var hoverEventArgs = { event: e, name: 'itemHover', item: gallerySettings.groups[parseInt(i.toString(), 10)].items[parseInt(j.toString(), 10)] };
                        Eif (gallerySettings.itemHover) {
                            gallerySettings.itemHover.call(_this, hoverEventArgs);
                        }
                    };
                    if (gallerySettings.groups[parseInt(i.toString(), 10)].itemWidth && gallerySettings.groups[parseInt(i.toString(), 10)].itemWidth !== 'auto') {
                        galleryEle.style.width = gallerySettings.groups[parseInt(i.toString(), 10)].itemWidth + 'px';
                    }
                    if (gallerySettings.groups[parseInt(i.toString(), 10)].itemHeight && gallerySettings.groups[parseInt(i.toString(), 10)].itemHeight !== 'auto') {
                        galleryEle.style.height = gallerySettings.groups[parseInt(i.toString(), 10)].itemHeight + 'px';
                        if (this_1.parent.activeLayout !== 'Simplified' && !isPopup) {
                            galleryContainerEle.style.flexFlow = 'wrap';
                        }
                    }
                    if ((!gallerySettings.template && !gallerySettings.popupTemplate) ||
                        ((gallerySettings.template && !gallerySettings.popupTemplate) && isPopup) ||
                        ((gallerySettings.popupTemplate && !gallerySettings.template) && !isPopup)) {
                        Eif (gallerySettings.groups[parseInt(i.toString(), 10)].items[parseInt(j.toString(), 10)].htmlAttributes) {
                            index_1.setCustomAttributes(galleryEle, gallerySettings.groups[parseInt(i.toString(), 10)]
                                .items[parseInt(j.toString(), 10)].htmlAttributes);
                        }
                        if (gallerySettings.groups[parseInt(i.toString(), 10)].items[parseInt(j.toString(), 10)].iconCss) {
                            var iconEle = this_1.parent.createElement('span', {
                                className: 'e-ribbon-gallery-icons' + ' ' + gallerySettings.groups[parseInt(i.toString(), 10)].items[parseInt(j.toString(), 10)].iconCss
                            });
                            galleryEle.appendChild(iconEle);
                            if (this_1.parent.activeLayout === 'Simplified' && !isPopup) {
                                iconEle.classList.add('e-hidden');
                            }
                        }
                        if (gallerySettings.groups[parseInt(i.toString(), 10)].items[parseInt(j.toString(), 10)].content) {
                            galleryEle.appendChild(this_1.parent.createElement('span', {
                                innerHTML: gallerySettings.groups[parseInt(i.toString(), 10)].items[parseInt(j.toString(), 10)].content,
                                className: 'e-ribbon-gallery-text'
                            }));
                        }
                        if (gallerySettings.groups[parseInt(i.toString(), 10)].items[parseInt(j.toString(), 10)].disabled) {
                            galleryEle.classList.add('e-disabled');
                        }
                        if (gallerySettings.groups[parseInt(i.toString(), 10)].items[parseInt(j.toString(), 10)].cssClass) {
                            galleryEle.classList.add(gallerySettings.groups[parseInt(i.toString(), 10)].items[parseInt(j.toString(), 10)].cssClass);
                        }
                    }
                    if (gallerySettings.template && !isPopup) {
                        this_1.createGalleryTemplate(galleryEle, gallerySettings, id, gallerySettings.groups[parseInt(i.toString(), 10)].items[parseInt(j.toString(), 10)]);
                    }
                    if (gallerySettings.popupTemplate && isPopup) {
                        this_1.createGalleryPopupTemplate(galleryEle, gallerySettings, id, gallerySettings.groups[parseInt(i.toString(), 10)].items[parseInt(j.toString(), 10)]);
                    }
                    if ((!isPopup && !isHeightDefined && (gallerySettings.itemCount === this_1.count))) {
                        galleryWrapper.appendChild(galleryContainerEle);
                        this_1.isAdded = true;
                        return "break";
                    }
                };
                for (var j = 0; j < gallerySettings.groups[parseInt(i.toString(), 10)].items.length; j++) {
                    var state_2 = _loop_2(j);
                    if (state_2 === "break")
                        break;
                }
                if (this_1.isAdded && !isPopup) {
                    return "break";
                }
                if (!isPopup) {
                    galleryWrapper.appendChild(galleryContainerEle);
                }
                else {
                    itemEle.appendChild(galleryContainerEle);
                }
                if (isPopup && gallerySettings.groups[parseInt(i.toString(), 10)].header) {
                    var headerEle = (this_1.parent.createElement('div', {
                        className: 'e-ribbon-gallery-header',
                        innerHTML: gallerySettings.groups[parseInt(i.toString(), 10)].header
                    }));
                    itemEle.insertBefore(headerEle, galleryContainerEle);
                }
            };
            var this_1 = this;
            for (var i = 0; i < gallerySettings.groups.length; i++) {
                var state_1 = _loop_1(i);
                if (state_1 === "break")
                    break;
            }
            this.count = 0;
            this.isAdded = false;
            Iif (this.parent.isReact) {
                this.parent.portals = this.parent.portals.concat(this['portals']);
                this.parent['renderReactTemplates']();
                this['portals'] = undefined;
            }
        };
        RibbonGallery.prototype.setWrapperWidth = function (itemCount, galleryWrapper, gallerySettings, itemID) {
            var count = 1;
            var itemsWidth = 0;
            var isWidthApplied = false;
            for (var i = 0; i < gallerySettings.groups.length; i++) {
                for (var j = 0; j < gallerySettings.groups[parseInt(i.toString(), 10)].items.length; j++) {
                    if (itemCount >= count) {
                        var galleryItemEle = galleryWrapper.querySelector('#' + itemID + '_galleryContainer' + i + '_gallery' + j);
                        Eif (galleryItemEle) {
                            itemsWidth += galleryItemEle.offsetWidth;
                            var itemStyles = window.getComputedStyle(galleryItemEle);
                            Eif (itemStyles) {
                                var paddingWidth = parseFloat(itemStyles.paddingLeft) + parseFloat(itemStyles.paddingRight);
                                Eif (!(ej2_base_1.isNullOrUndefined(paddingWidth))) {
                                    itemsWidth += paddingWidth;
                                }
                                var marginWidth = parseFloat(itemStyles.marginLeft) + parseFloat(itemStyles.marginRight);
                                Eif (!(ej2_base_1.isNullOrUndefined(marginWidth))) {
                                    itemsWidth += marginWidth;
                                }
                            }
                        }
                    }
                    else {
                        isWidthApplied = true;
                        break;
                    }
                    count++;
                }
                if (isWidthApplied) {
                    break;
                }
            }
            if (itemsWidth > 0) {
                galleryWrapper.style.width = itemsWidth + 'px';
            }
        };
        RibbonGallery.prototype.setWrapperStyle = function (popup, popupContainerItems) {
            if (popup.width !== 'auto') {
                popupContainerItems.forEach(function (ele) {
                    ele.style.flexFlow = 'wrap';
                });
            }
        };
        RibbonGallery.prototype.checkAvailableHeight = function (activeContent) {
            var galleryWrapperItems = activeContent.querySelectorAll('.e-ribbon-gallery-wrapper');
            for (var n = 0; n < galleryWrapperItems.length; n++) {
                var count = 0;
                var simplifiedItemsCount = 0;
                var isHeight = false;
                var galleryWrapper = galleryWrapperItems[parseInt(n.toString(), 10)];
                var itemID = galleryWrapper.id.replace(/_galleryWrapper/g, '');
                var galleryWrapperHeight = galleryWrapper.offsetHeight;
                var itemProp = index_1.getItem(this.parent.tabs, itemID);
                Eif (itemProp) {
                    this.setWrapperWidth(itemProp.item.gallerySettings.itemCount, galleryWrapper, itemProp.item.gallerySettings, itemID);
                    for (var i = 0; i < itemProp.item.gallerySettings.groups.length; i++) {
                        for (var j = 0; j < itemProp.item.gallerySettings.groups[parseInt(i.toString(), 10)].items.length; j++) {
                            var galleryItemEle = galleryWrapper.querySelector('#' + itemID + '_galleryContainer' + i + '_gallery' + j);
                            if (galleryItemEle) {
                                if (this.parent.activeLayout === 'Classic') {
                                    if (galleryItemEle.classList.contains('e-hidden')) {
                                        galleryItemEle.classList.remove('e-hidden');
                                    }
                                    if (!isHeight) {
                                        var itemsValues = 0;
                                        var itemStyles = window.getComputedStyle(galleryItemEle);
                                        Eif (itemStyles) {
                                            var marginWidth = parseFloat(itemStyles.marginTop) + parseFloat(itemStyles.marginBottom);
                                            Eif (!(ej2_base_1.isNullOrUndefined(marginWidth))) {
                                                itemsValues += marginWidth;
                                            }
                                        }
                                        count++;
                                        if (itemProp.item.gallerySettings.itemCount === count) {
                                            count = 0;
                                            Eif (galleryWrapperHeight >= (galleryItemEle.offsetHeight + itemsValues)) {
                                                galleryWrapperHeight -= (galleryItemEle.offsetHeight + itemsValues);
                                            }
                                            else {
                                                isHeight = true;
                                                galleryItemEle.remove();
                                            }
                                        }
                                        else if (galleryWrapperHeight < (galleryItemEle.offsetHeight + itemsValues)) {
                                            isHeight = true;
                                            galleryItemEle.remove();
                                        }
                                    }
                                    else {
                                        galleryItemEle.remove();
                                    }
                                }
                                else {
                                    simplifiedItemsCount++;
                                    if (simplifiedItemsCount > itemProp.item.gallerySettings.itemCount) {
                                        galleryItemEle.classList.add('e-hidden');
                                    }
                                }
                            }
                        }
                    }
                }
            }
        };
        RibbonGallery.prototype.checkCollision = function (popup, popupEle, offsetValue) {
            if (offsetValue === void 0) { offsetValue = 0; }
            var paddingWidth = 0;
            var marginWidth = 0;
            Eif (popupEle) {
                var windowWidth = window.innerWidth;
                var screenWidth = offsetValue === 0 ? windowWidth : Math.abs(windowWidth - (windowWidth - offsetValue));
                var paddingStyles = window.getComputedStyle(popupEle);
                Eif (paddingStyles) {
                    paddingWidth = parseFloat(paddingStyles.paddingLeft) + parseFloat(paddingStyles.paddingRight);
                    Eif (!(ej2_base_1.isNullOrUndefined(paddingWidth))) {
                        screenWidth = screenWidth - paddingWidth;
                    }
                }
                var popupContainerItems = popupEle.querySelectorAll('.e-ribbon-gallery-container');
                this.setWrapperStyle(popup, popupContainerItems);
                var isCollideOccurs = false;
                for (var i = 0; i < popupContainerItems.length; i++) {
                    var itemsWidth = 0;
                    for (var j = 0; j < popupContainerItems[parseInt(i.toString(), 10)].querySelectorAll('.e-ribbon-gallery-item').length; j++) {
                        var popupItemStyles = window.getComputedStyle(popupContainerItems[parseInt(i.toString(), 10)].querySelectorAll('.e-ribbon-gallery-item')[parseInt(j.toString(), 10)]);
                        Eif (popupItemStyles) {
                            marginWidth = parseFloat(popupItemStyles.marginLeft) + parseFloat(popupItemStyles.marginRight);
                            Eif (!(ej2_base_1.isNullOrUndefined(marginWidth))) {
                                itemsWidth += marginWidth;
                            }
                        }
                        itemsWidth += Math.round(parseFloat(popupItemStyles.width));
                        if (((screenWidth <= itemsWidth) && popup.width === 'auto') || ((popup.width !== 'auto') && (screenWidth <= parseInt(popup.width.toString(), 10)) && (screenWidth <= itemsWidth))) {
                            popupEle.style.width = ((itemsWidth + Math.abs(paddingWidth - marginWidth)) - Math.round(parseFloat(popupItemStyles.width))) + 'px';
                            isCollideOccurs = true;
                            break;
                        }
                    }
                    if (isCollideOccurs) {
                        popupContainerItems.forEach(function (ele) {
                            ele.style.flexFlow = 'wrap';
                        });
                        Eif (popup.height === 'auto') {
                            this.setGalleryPopupHeight(popupEle, parseFloat(paddingStyles.height), parseFloat(paddingStyles.top));
                        }
                        break;
                    }
                }
                if (!isCollideOccurs) {
                    if (popup.width === 'auto') {
                        popupContainerItems.forEach(function (ele) {
                            ele.style.flexFlow = 'nowrap';
                        });
                        popupEle.style.width = 'auto';
                    }
                    else {
                        popupEle.style.width = (popup.width).toString();
                    }
                    if (popup.height === 'auto') {
                        this.setGalleryPopupHeight(popupEle, parseFloat(paddingStyles.height), parseFloat(paddingStyles.top));
                    }
                }
            }
        };
        RibbonGallery.prototype.setGalleryPopupHeight = function (popupEle, popupHeight, popupTop) {
            if (window.innerHeight < popupHeight || window.innerHeight < Math.round(popupHeight + popupTop)) {
                popupEle.style.height = (window.innerHeight - popupTop) + 'px';
            }
            else {
                popupEle.style.height = 'auto';
            }
        };
        RibbonGallery.prototype.createPopup = function (item, buttonEle) {
            var popupContainer = this.parent.createElement('div', {
                className: 'e-ribbon-popup-container',
                id: item.id + '_popupContainer'
            });
            this.renderGalleryItems(item.gallerySettings, true, item.id, popupContainer);
            var gallerypopupElement = this.parent.createElement('div', {
                className: 'e-ribbon-gallery-popup',
                id: item.id + '_galleryPopup'
            });
            document.body.append(gallerypopupElement);
            var galleryPopup = new ej2_popups_1.Popup(gallerypopupElement, {
                relateTo: buttonEle,
                content: popupContainer,
                collision: { X: 'fit', Y: 'flip' },
                actionOnScroll: 'hide',
                targetType: 'relative',
                position: { X: 'left', Y: 'bottom' },
                enableRtl: this.parent.enableRtl,
                width: item.gallerySettings.popupWidth,
                height: item.gallerySettings.popupHeight
            });
            galleryPopup.hide();
        };
        RibbonGallery.prototype.switchGalleryItems = function (activeLayout, itemID) {
            var itemEle = this.parent.element.querySelector('#' + itemID + constants.CONTAINER_ID);
            var itemProp = index_1.getItem(this.parent.tabs, itemID);
            Eif (itemEle) {
                var galleryIcons = itemEle.querySelectorAll('.e-ribbon-gallery-icons');
                var galleryContainer = itemEle.querySelectorAll('.e-ribbon-gallery-container');
                Eif (galleryIcons.length) {
                    for (var i = 0; i < galleryIcons.length; i++) {
                        if (activeLayout === 'Simplified') {
                            galleryIcons[parseInt(i.toString(), 10)].classList.add('e-hidden');
                        }
                        else {
                            galleryIcons[parseInt(i.toString(), 10)].classList.remove('e-hidden');
                        }
                    }
                }
                Eif (galleryContainer.length && itemProp) {
                    for (var n = 0; n < itemProp.item.gallerySettings.groups.length; n++) {
                        for (var i = 0; i < galleryContainer.length; i++) {
                            if (itemProp.item.gallerySettings.groups[parseInt(n.toString(), 10)].itemHeight && itemProp.item.gallerySettings.groups[parseInt(n.toString(), 10)].itemHeight !== 'auto') {
                                if (itemID + '_galleryContainer' + n === galleryContainer[parseInt(i.toString(), 10)].id) {
                                    if (activeLayout === 'Simplified') {
                                        galleryContainer[parseInt(i.toString(), 10)].style.flexFlow = 'nowrap';
                                    }
                                    else {
                                        galleryContainer[parseInt(i.toString(), 10)].style.flexFlow = 'wrap';
                                    }
                                }
                            }
                        }
                    }
                }
                var activeContent = this.parent.tabObj.element.querySelector('#' + this.parent.tabs[this.parent.selectedTab].id + constants.CONTENT_ID);
                Eif (activeContent) {
                    this.checkAvailableHeight(activeContent);
                }
            }
        };
        RibbonGallery.prototype.addOverFlowEvents = function (item, itemEle) {
            var _this = this;
            Eif (itemEle.closest('.e-ribbon-overflow-target')) {
                var buttonEle = this.parent.createElement('button', {
                    id: item.id
                });
                itemEle.appendChild(buttonEle);
                Iif (itemEle.querySelector('.e-ribbon-gallery-wrapper').classList.contains('e-disabled')) {
                    buttonEle.classList.add('e-disabled');
                }
                itemEle.querySelector('.e-ribbon-gallery-wrapper').classList.add('e-hidden');
                itemEle.querySelectorAll('.e-ribbon-gallery-container').forEach(function (ele) {
                    ele.classList.add('e-hidden');
                });
                var popupButton = itemEle.querySelector('#' + item.id + '_popupButton');
                Eif (popupButton) {
                    popupButton.classList.add('e-hidden');
                }
                var itemProp = index_1.getItem(this.parent.tabs, item.id);
                var iconCss = itemProp && itemProp.group.groupIconCss ? itemProp.group.groupIconCss : '';
                var content = itemProp && itemProp.group.header ? itemProp.group.header : '';
                if (!iconCss) {
                    for (var i = 0; i < item.gallerySettings.groups.length; i++) {
                        for (var j = 0; j < item.gallerySettings.groups[parseInt(i.toString(), 10)].items.length; j++) {
                            Eif (item.gallerySettings.groups[parseInt(i.toString(), 10)].items[parseInt(j.toString(), 10)].iconCss) {
                                iconCss = item.gallerySettings.groups[parseInt(i.toString(), 10)].items[parseInt(j.toString(), 10)].iconCss;
                                break;
                            }
                        }
                        Eif (iconCss) {
                            break;
                        }
                    }
                }
                var popupEle = document.querySelector('#' + item.id + '_galleryPopup');
                var popup_1 = ej2_base_1.getComponent(popupEle, ej2_popups_1.Popup);
                var popupContainerEle_1 = document.querySelector('#' + item.id + '_galleryPopup .e-ribbon-popup-container');
                var dropdown = new ej2_splitbuttons_1.DropDownButton({
                    iconCss: iconCss,
                    content: content,
                    target: popupContainerEle_1,
                    enableRtl: this.parent.enableRtl,
                    cssClass: 'e-ribbon-gallery-dropdown',
                    disabled: item.disabled,
                    open: function () {
                        var popupContainerItems = popupContainerEle_1.querySelectorAll('.e-ribbon-gallery-container');
                        _this.setWrapperStyle(popup_1, popupContainerItems);
                        _this.setFoucsToFirstItem(popupContainerEle_1, true, item.id);
                    },
                    beforeClose: function (args) {
                        var isCancelled = _this.popupEvents(args.event, item.gallerySettings, 'popupClose', false);
                        if (isCancelled) {
                            args.cancel = true;
                        }
                    }
                }, buttonEle);
                if (popup_1.width !== 'auto') {
                    dropdown.dropDown.width = ej2_base_1.formatUnit(popup_1.width);
                }
                if (popup_1.height !== 'auto') {
                    dropdown.dropDown.height = ej2_base_1.formatUnit(popup_1.height);
                    dropdown.dropDown.element.style.height = (popup_1.height).toString();
                }
            }
        };
        RibbonGallery.prototype.removeOverFlowEvents = function (item, itemEle) {
            var popupButton = itemEle.querySelector('#' + item.id + '_popupButton');
            Eif (popupButton) {
                popupButton.classList.remove('e-hidden');
            }
            itemEle.querySelector('.e-ribbon-gallery-wrapper').classList.remove('e-hidden');
            itemEle.querySelectorAll('.e-ribbon-gallery-container').forEach(function (ele) {
                ele.classList.remove('e-hidden');
            });
            var galleryDDBEle = document.querySelector('#' + item.id);
            Eif (galleryDDBEle) {
                var popupEle = document.querySelector('#' + item.id + '_galleryPopup');
                var dropdown = ej2_base_1.getComponent(galleryDDBEle, ej2_splitbuttons_1.DropDownButton);
                popupEle.appendChild(dropdown.target);
                dropdown.destroy();
                ej2_base_1.remove(galleryDDBEle);
            }
        };
        RibbonGallery.prototype.setActiveState = function (galleryEle, gallerySettings, itemID, isInteracted, event, isPopup) {
            var previousItem;
            var currentItem;
            var itemEle = document.querySelector('#' + itemID + constants.CONTAINER_ID);
            var selctedGalleryItem = Array.prototype.slice.call(itemEle.querySelectorAll('.e-ribbon-gallery-selected'));
            var popupEle = document.querySelector('#' + itemID + '_popupContainer');
            var popupGalleryItem = Array.prototype.slice.call(popupEle.querySelectorAll('.e-ribbon-gallery-selected'));
            Eif (popupGalleryItem.length) {
                selctedGalleryItem = selctedGalleryItem.concat(popupGalleryItem);
            }
            for (var i = 0; i < gallerySettings.groups.length; i++) {
                for (var j = 0; j < gallerySettings.groups[parseInt(i.toString(), 10)].items.length; j++) {
                    if (selctedGalleryItem[0].id === itemID + '_galleryContainer' + i + '_gallery' + j) {
                        previousItem = gallerySettings.groups[parseInt(i.toString(), 10)].items[parseInt(j.toString(), 10)];
                    }
                    if (galleryEle.id === (isPopup ? 'popup_' : '') + itemID + '_galleryContainer' + i + '_gallery' + j) {
                        currentItem = gallerySettings.groups[parseInt(i.toString(), 10)].items[parseInt(j.toString(), 10)];
                    }
                }
            }
            var galleryItem = document.getElementById(galleryEle.id);
            var galleryItemPopup;
            var selectingEventArgs = { cancel: false, name: 'beforeSelect', previousItem: previousItem, currentItem: currentItem, isInteracted: isInteracted, event: event };
            if (gallerySettings.beforeSelect) {
                gallerySettings.beforeSelect.call(this, selectingEventArgs);
            }
            if (selectingEventArgs.cancel) {
                return;
            }
            else {
                for (var i = 0; i < selctedGalleryItem.length; i++) {
                    selctedGalleryItem[parseInt(i.toString(), 10)].classList.remove('e-ribbon-gallery-selected');
                }
                if (!galleryItem.id.startsWith('popup_')) {
                    galleryItemPopup = document.getElementById('popup_' + galleryEle.id);
                }
                else if (document.getElementById(galleryItem.id.slice(6))) {
                    galleryItemPopup = document.getElementById(galleryItem.id.slice(6));
                }
                if (galleryItemPopup) {
                    galleryItemPopup.classList.add('e-ribbon-gallery-selected');
                }
                galleryItem.classList.add('e-ribbon-gallery-selected');
                var selectedEventArgs = { previousItem: previousItem, currentItem: currentItem, name: 'select', isInteracted: isInteracted, event: event };
                var galleryPopupItems = document.querySelectorAll('#' + itemID + '_popupContainer .e-ribbon-gallery-item');
                for (var i = 0; i < galleryPopupItems.length; i++) {
                    if (galleryPopupItems[parseInt(i.toString(), 10)].id === galleryEle.id) {
                        gallerySettings.selectedItemIndex = i;
                        break;
                    }
                }
                if (gallerySettings.select) {
                    gallerySettings.select.call(this, selectedEventArgs);
                }
            }
        };
        RibbonGallery.prototype.popupEvents = function (args, gallerySettings, name, isOpen) {
            var popupEventArgs = { cancel: false, event: args, name: name };
            if (isOpen && gallerySettings.popupOpen) {
                gallerySettings.popupOpen.call(this, popupEventArgs);
            }
            else if (!isOpen && gallerySettings.popupClose) {
                gallerySettings.popupClose.call(this, popupEventArgs);
            }
            if (popupEventArgs.cancel) {
                return true;
            }
            return false;
        };
        RibbonGallery.prototype.showPopup = function (popup, popupEle, args, gallerySettings, itemID) {
            var isCancelled = this.popupEvents(args, gallerySettings, 'popupOpen', true);
            if (isCancelled) {
                return;
            }
            popup.show();
            this.checkCollision(popup, popupEle);
            var buttonEle = document.querySelector('#' + itemID + '_popupButton');
            buttonEle.classList.add('e-gallery-button-active');
            var buttonPosition = buttonEle.getBoundingClientRect();
            if (popupEle.offsetWidth > buttonPosition.left) {
                this.checkCollision(popup, popupEle, buttonPosition.left);
            }
            var offsetX = Math.abs((popupEle.offsetWidth - buttonPosition.left)) + buttonEle.offsetWidth;
            popupEle.style.left = offsetX + 'px';
            popupEle.style.top = popupEle.getBoundingClientRect().top + 2 + 'px';
            this.setFoucsToFirstItem(popupEle, false, itemID, popup, gallerySettings);
        };
        RibbonGallery.prototype.hidePopup = function (popup, popupEle, args, gallerySettings, itemID) {
            var isCancelled = this.popupEvents(args, gallerySettings, 'popupClose', false);
            if (isCancelled) {
                return;
            }
            popup.hide();
            var buttonEle = document.querySelector('#' + itemID + '_popupButton');
            buttonEle.classList.remove('e-gallery-button-active');
        };
        RibbonGallery.prototype.showGalleryPopup = function (id) {
            var itemProp = index_1.getItem(this.parent.tabs, id);
            var popupEle = document.querySelector('#' + id + '_galleryPopup');
            var popup = ej2_base_1.getComponent(popupEle, ej2_popups_1.Popup);
            this.showPopup(popup, popupEle, null, itemProp.item.gallerySettings, id);
        };
        RibbonGallery.prototype.hideGalleryPopup = function (id) {
            var itemProp = index_1.getItem(this.parent.tabs, id);
            var popupEle = document.querySelector('#' + id + '_galleryPopup');
            var popup = ej2_base_1.getComponent(popupEle, ej2_popups_1.Popup);
            this.hidePopup(popup, popupEle, null, itemProp.item.gallerySettings, id);
        };
        RibbonGallery.prototype.setFoucsToFirstItem = function (popupEle, isDropdown, itemID, popup, gallerySettings) {
            var _this = this;
            popupEle.querySelectorAll('.e-ribbon-gallery-item')[0].focus();
            this.galleryItemsIndex = 0;
            popupEle.onkeydown = function (e) {
                _this.handleGalleryPopupNavigation(e, popupEle, isDropdown, itemID, popup, gallerySettings);
            };
        };
        RibbonGallery.prototype.handleGalleryPopupNavigation = function (e, popupEle, isDropdown, itemID, popup, gallerySettings) {
            var galleryPopupEle = popupEle.querySelectorAll('.e-ribbon-gallery-item');
            Eif (galleryPopupEle) {
                if (e.key === 'Home') {
                    this.galleryItemsIndex = 0;
                    galleryPopupEle[this.galleryItemsIndex].focus();
                }
                else if (e.key === 'End') {
                    this.galleryItemsIndex = galleryPopupEle.length - 1;
                    galleryPopupEle[this.galleryItemsIndex].focus();
                }
                else if (e.key === 'ArrowRight' || e.key === 'ArrowDown') {
                    this.galleryItemsIndex++;
                    if (this.galleryItemsIndex !== galleryPopupEle.length) {
                        Eif (galleryPopupEle && (galleryPopupEle[this.galleryItemsIndex])) {
                            galleryPopupEle[this.galleryItemsIndex].focus();
                        }
                    }
                    else {
                        this.galleryItemsIndex = 0;
                        galleryPopupEle[this.galleryItemsIndex].focus();
                    }
                }
                else if (e.key === 'ArrowLeft' || e.key === 'ArrowUp') {
                    if (this.galleryItemsIndex !== 0) {
                        this.galleryItemsIndex--;
                        Eif (galleryPopupEle && (galleryPopupEle[this.galleryItemsIndex])) {
                            galleryPopupEle[this.galleryItemsIndex].focus();
                        }
                    }
                    else {
                        this.galleryItemsIndex = galleryPopupEle.length - 1;
                        galleryPopupEle[this.galleryItemsIndex].focus();
                    }
                }
                else Eif ((e.key === 'Enter' || e.code === 'Space') || (e.key === 'Escape' && !isDropdown)) {
                    this.hidePopup(popup, popupEle, e, gallerySettings, itemID);
                }
            }
        };
        RibbonGallery.prototype.createGalleryTemplate = function (galleryItemEle, gallerySettings, id, items) {
            galleryItemEle.classList.add('e-ribbon-gallery-template');
            var templateName = 'ribbon' + id + 'galleryTemplate';
            this.parent['clearTemplate']([templateName]);
            var templateFunction = index_1.getTemplateFunction(gallerySettings.template);
            if (items.disabled) {
                galleryItemEle.classList.add('e-disabled');
            }
            if (items.cssClass) {
                galleryItemEle.classList.add(items.cssClass);
            }
            ej2_base_1.append(templateFunction({ items: items }, this, templateName, (id + 'galleryTemplate'), this.parent.isStringTemplate, null, null, this.parent), galleryItemEle);
        };
        RibbonGallery.prototype.createGalleryPopupTemplate = function (galleryItemEle, gallerySettings, id, items) {
            galleryItemEle.classList.add('e-ribbon-gallery-popup-template');
            var templateName = 'ribbon' + id + 'galleryPopupTemplate';
            this.parent['clearTemplate']([templateName]);
            var templateFunction = index_1.getTemplateFunction(gallerySettings.popupTemplate);
            if (items.disabled) {
                galleryItemEle.classList.add('e-disabled');
            }
            if (items.cssClass) {
                galleryItemEle.classList.add(items.cssClass);
            }
            ej2_base_1.append(templateFunction({ items: items }, this, templateName, (id + 'galleryPopupTemplate'), this.parent.isStringTemplate, null, null, this.parent), galleryItemEle);
        };
        return RibbonGallery;
    }());
    exports.RibbonGallery = RibbonGallery;
});