all files / rich-text-editor/renderer/ toolbar-renderer.js

94.15% Statements 386/410
87.74% Branches 279/318
95.92% Functions 47/49
94.15% Lines 386/410
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   3841× 3841× 3841× 3840×   3841×   3841× 3841× 3841×   285×   285×     1850× 1850× 1850×   5723× 1690×     3742×   1215×     1215× 1215× 1211×     281× 281×   1809×   1801×                             324×   24× 24× 24×   15× 14× 39×       13×   14×     324×   226×   3742× 3742× 3742× 3742×                     3742× 3742× 3742× 3742× 1745×                     1745×         3182× 3182× 3182× 3182× 3182× 42×   3182× 3182×                 293×   292× 278× 278× 278× 278×       275×       278× 278× 657× 149×   657× 657× 28× 21× 21×                 629×   278× 278× 278×             278× 180× 180× 180× 180× 1151×   180× 1433×   180× 180× 1212× 1212× 1212×           172× 172× 172×       1040×         14× 14× 14× 14× 14× 95×   14× 14× 95× 95× 95× 14× 14× 14×       81×         292×           3182× 3182× 3182× 3182× 3182× 3182× 3182×                   1162×     1161×   1161× 1161×       114× 114× 114× 114× 114× 114× 114× 114×               34× 34× 34× 34× 34×       12×       12×           26×     34× 34×       34× 34× 34× 34× 34×     32×           114× 114× 114× 114× 114× 114× 114× 114× 114×   114× 114× 114× 35×   114×     114×   51× 51× 51× 51× 51× 1932× 45×       416× 416× 416× 416× 416× 416× 416× 416× 416× 416×   416× 416×       52×   51× 51× 51× 51× 51×   20× 20×   20× 20× 20× 20× 20×                 19×       20×     31× 31× 31× 31×   31× 10×         31× 31× 31× 31× 29×       31× 29×   31×     15× 15×                                 15×     416× 416× 416× 416× 416× 416× 416× 416× 416× 416× 27×   416×     416×   31×     31× 31×       416× 416× 416× 416×             416× 416× 416×             23684× 23684× 23684× 360× 360× 360× 360×       23684× 419×       11× 11×         11× 11× 11× 11× 11×       10×   11×             416× 416× 416× 416×   3742×   3742×   3742×   5607× 3757×   1850× 1745× 1745× 1745×             1850× 1850× 1850× 1850× 1850× 1850× 1850× 1850×        
define(["require", "exports", "@syncfusion/ej2-base", "@syncfusion/ej2-base", "@syncfusion/ej2-navigations", "@syncfusion/ej2-splitbuttons", "@syncfusion/ej2-popups", "../base/classes", "../base/constant", "../base/classes", "@syncfusion/ej2-inputs", "../base/util", "../../editor-manager/plugin/toolbar-status"], function (require, exports, ej2_base_1, ej2_base_2, ej2_navigations_1, ej2_splitbuttons_1, ej2_popups_1, classes, events, classes_1, ej2_inputs_1, util_1, toolbar_status_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var ToolbarRenderer = (function () {
        function ToolbarRenderer(parent, serviceLocator) {
            this.parent = parent;
            this.isDestroyed = false;
            if (serviceLocator) {
                this.l10n = serviceLocator.getService('rteLocale');
            }
            this.wireEvent();
        }
        ToolbarRenderer.prototype.wireEvent = function () {
            this.parent.on(events.destroy, this.destroy, this);
            this.parent.on(events.destroyTooltip, this.destroyTooltip, this);
            this.parent.on(events.closeTooltip, this.closeTooltip, this);
        };
        ToolbarRenderer.prototype.destroyTooltip = function () {
            var currentDocument = this.parent.iframeSettings.enable ? this.parent.contentModule.getPanel().ownerDocument :
                this.parent.contentModule.getDocument();
            if (!ej2_base_1.isNullOrUndefined(currentDocument.querySelector('.e-tooltip-wrap')) && !ej2_base_1.isNullOrUndefined(currentDocument.querySelector('[data-tooltip-id]'))) {
                var tooltipTargetEle = currentDocument.querySelector('[data-tooltip-id]');
                var event_1 = new MouseEvent('mouseleave', { bubbles: true, cancelable: true });
                tooltipTargetEle.dispatchEvent(event_1);
            }
        };
        ToolbarRenderer.prototype.unWireEvent = function () {
            this.parent.off(events.destroy, this.destroy);
            this.parent.off(events.destroyTooltip, this.destroyTooltip);
            this.parent.off(events.closeTooltip, this.closeTooltip);
        };
        ToolbarRenderer.prototype.toolbarBeforeCreate = function (e) {
            if (this.mode === 'Extended') {
                e.enableCollision = false;
            }
        };
        ToolbarRenderer.prototype.toolbarCreated = function () {
            this.parent.notify(events.toolbarCreated, this);
        };
        ToolbarRenderer.prototype.toolbarClicked = function (args) {
            Iif (!this.parent.enabled) {
                return;
            }
            this.parent.trigger('toolbarClick', args);
            if (!this.parent.readonly || ej2_base_1.isNullOrUndefined(args.item)) {
                this.parent.notify(events.toolbarClick, args);
            }
        };
        ToolbarRenderer.prototype.dropDownSelected = function (args) {
            this.parent.notify(events.dropDownSelect, { element: args.element, item: args.item, originalEvent: args.event });
            this.destroyTooltip();
        };
        ToolbarRenderer.prototype.beforeDropDownItemRender = function (args) {
            if (this.parent.readonly || !this.parent.enabled) {
                return;
            }
            this.parent.notify(events.beforeDropDownItemRender, args);
        };
        ToolbarRenderer.prototype.tooltipBeforeRender = function (args) {
            Eif (!ej2_base_1.isNullOrUndefined(args.target.getAttribute('title'))) {
                var tooltipTarget = args.target.getAttribute('title');
                var tooltipText = void 0;
                switch (tooltipTarget) {
                    case 'Minimize':
                        tooltipText = this.l10n.getConstant('minimize');
                        args.target.setAttribute('title', tooltipText + ' (Esc)');
                        break;
                    case 'Maximize':
                        tooltipText = this.l10n.getConstant('maximize');
                        args.target.setAttribute('title', tooltipText + ' (Ctrl+Shift+F)');
                        break;
                }
            }
            if (args.target.querySelector('.e-active')) {
                args.cancel = true;
                Eif (!ej2_base_1.isNullOrUndefined(args.target.getAttribute('title'))) {
                    this.closeTooltip({ target: args.target, isTitle: true });
                }
            }
        };
        ToolbarRenderer.prototype.dropDownOpen = function (args) {
            if (args.element.parentElement.getAttribute('id').indexOf('TableCell') > -1 && !ej2_base_1.isNullOrUndefined(args.element.parentElement.querySelector('.e-cell-merge')) &&
                (!ej2_base_1.isNullOrUndefined(args.element.parentElement.querySelector('.e-cell-horizontal-split')) || !ej2_base_1.isNullOrUndefined(args.element.parentElement.querySelector('.e-cell-vertical-split')))) {
                var listEle = args.element.querySelectorAll('li');
                var selectedEles_1 = this.parent.inputElement.querySelectorAll('.e-cell-select');
                if (selectedEles_1.length === 1) {
                    ej2_base_1.addClass([listEle[0]], 'e-disabled');
                    ej2_base_1.removeClass([listEle[1], listEle[2]], 'e-disabled');
                }
                else if (selectedEles_1.length > 1) {
                    if (!Array.from(selectedEles_1).every(function (element) {
                        return element.tagName.toLowerCase() === selectedEles_1[0].tagName.toLowerCase();
                    })) {
                        ej2_base_1.addClass([listEle[0]], 'e-disabled');
                    }
                    else {
                        ej2_base_1.removeClass([listEle[0]], 'e-disabled');
                    }
                    ej2_base_1.addClass([listEle[1], listEle[2]], 'e-disabled');
                }
            }
            this.parent.notify(events.selectionSave, args);
        };
        ToolbarRenderer.prototype.dropDownClose = function (args) {
            this.parent.notify(events.selectionRestore, args);
        };
        ToolbarRenderer.prototype.renderToolbar = function (args) {
            this.setPanel(args.target);
            this.renderPanel();
            this.mode = args.overflowMode;
            args.rteToolbarObj.toolbarObj = new ej2_navigations_1.Toolbar({
                items: args.items,
                width: '100%',
                overflowMode: args.overflowMode,
                beforeCreate: this.toolbarBeforeCreate.bind(this),
                created: this.toolbarCreated.bind(this),
                clicked: this.toolbarClicked.bind(this),
                enablePersistence: args.enablePersistence,
                enableRtl: args.enableRtl,
                cssClass: args.cssClass
            });
            args.rteToolbarObj.toolbarObj.isStringTemplate = true;
            args.rteToolbarObj.toolbarObj.createElement = this.parent.createElement;
            args.rteToolbarObj.toolbarObj.appendTo(args.target);
            if (this.parent.showTooltip && args.type === 'toolbar') {
                this.tooltip = new ej2_popups_1.Tooltip({
                    target: '#' + this.parent.getID() + '_toolbar_wrapper [title]',
                    showTipPointer: true,
                    openDelay: 400,
                    opensOn: 'Hover',
                    beforeRender: this.tooltipBeforeRender.bind(this),
                    beforeOpen: this.tooltipBeforeOpen.bind(this),
                    cssClass: this.parent.getCssClass(),
                    windowCollision: true,
                    position: 'BottomCenter'
                });
                this.tooltip.appendTo(args.target.parentElement);
            }
        };
        ToolbarRenderer.prototype.tooltipBeforeOpen = function (args) {
            Eif (args.element) {
                args.element.setAttribute('data-rte-id', this.parent.getID());
            }
        };
        ToolbarRenderer.prototype.renderDropDownButton = function (args) {
            var _this = this;
            var css;
            args.element.classList.add(classes_1.CLS_DROPDOWN_BTN);
            css = args.cssClass + ' ' + classes_1.CLS_RTE_ELEMENTS + ' ' + classes_1.CLS_TB_BTN;
            if (this.parent.inlineMode.enable && ej2_base_1.Browser.isDevice) {
                css = css + ' ' + classes_1.CLS_INLINE_DROPDOWN;
            }
            var proxy = this;
            var dropDown = new ej2_splitbuttons_1.DropDownButton({
                items: args.items,
                iconCss: args.iconCss,
                cssClass: css,
                content: args.content,
                enablePersistence: this.parent.enablePersistence,
                enableRtl: this.parent.enableRtl,
                select: this.dropDownSelected.bind(this),
                beforeOpen: function (args) {
                    if (proxy.parent.readonly || !proxy.parent.enabled) {
                        args.cancel = true;
                        return;
                    }
                    if (proxy.parent.editorMode !== 'Markdown') {
                        var startNode = proxy.parent.getRange().startContainer.parentElement;
                        var tableEle = startNode.closest('table');
                        var trow = startNode.closest('tr');
                        if (!ej2_base_1.isNullOrUndefined(tableEle) && tableEle.classList.contains('e-dashed-border')) {
                            for (var index = 0; index < args.element.childNodes.length; index++) {
                                if (args.element.childNodes[index].classList.contains('e-dashed-borders')) {
                                    ej2_base_1.addClass([args.element.childNodes[index]], 'e-active');
                                }
                            }
                        }
                        else if (!ej2_base_1.isNullOrUndefined(tableEle) && !tableEle.classList.contains('e-dashed-border') && tableEle.classList.contains('e-alternate-rows') && window.getComputedStyle(trow).backgroundColor !== '') {
                            for (var index = 0; index < args.element.childNodes.length; index++) {
                                if (args.element.childNodes[index].classList.contains('e-alternate-rows')) {
                                    ej2_base_1.addClass([args.element.childNodes[index]], 'e-active');
                                }
                            }
                        }
                        var alignEle = proxy.parent.getRange().startContainer;
                        while (alignEle !== proxy.parent.inputElement && !ej2_base_1.isNullOrUndefined(alignEle.parentElement)) {
                            if (alignEle.nodeName === '#text') {
                                alignEle = alignEle.parentElement;
                            }
                            var alignStyle = window.getComputedStyle(alignEle).textAlign;
                            if (!ej2_base_1.isNullOrUndefined(args.items[0]) && args.items[0].command === 'Alignments') {
                                if ((args.items[0].text === 'Align Left' && (alignStyle === 'left') || alignStyle === 'start')) {
                                    ej2_base_1.addClass([args.element.childNodes[0]], 'e-active');
                                    break;
                                }
                                else if (args.items[1].text === 'Align Center' && alignStyle === 'center') {
                                    ej2_base_1.addClass([args.element.childNodes[1]], 'e-active');
                                    break;
                                }
                                else Eif (args.items[2].text === 'Align Right' && alignStyle === 'right') {
                                    ej2_base_1.addClass([args.element.childNodes[2]], 'e-active');
                                    break;
                                }
                                else if (args.items[3].text === 'Align Justify' && alignStyle === 'justify') {
                                    ej2_base_1.addClass([args.element.childNodes[3]], 'e-active');
                                    break;
                                }
                            }
                            alignEle = alignEle.parentElement;
                        }
                        var closestNode = startNode.closest('img');
                        var imageEle = closestNode ? closestNode : startNode.querySelector('img');
                        if (!ej2_base_1.isNullOrUndefined(args.items[0]) && args.items[0].command === 'Images') {
                            Eif (!ej2_base_1.isNullOrUndefined(imageEle)) {
                                var index = void 0;
                                if (imageEle.classList.contains('e-imgleft') || imageEle.classList.contains('e-imginline')) {
                                    index = 0;
                                }
                                else if (imageEle.classList.contains('e-imgcenter') || imageEle.classList.contains('e-imgbreak')) {
                                    index = 1;
                                }
                                else if (imageEle.classList.contains('e-imgright')) {
                                    index = 2;
                                }
                                if (!ej2_base_1.isNullOrUndefined(args.element.childNodes[index])) {
                                    ej2_base_1.addClass([args.element.childNodes[index]], 'e-active');
                                }
                            }
                        }
                        if (!ej2_base_1.isNullOrUndefined(args.items[0]) && (args.items[0].command === 'Formats' || args.items[0].command === 'Font')) {
                            var fontName_1 = [];
                            var formats_1 = [];
                            var hasUpdatedActive = false;
                            _this.parent.format.types.forEach(function (item) {
                                formats_1.push(item.value.toLocaleLowerCase());
                            });
                            _this.parent.fontFamily.items.forEach(function (item) {
                                fontName_1.push(item.value);
                            });
                            var toolbarStatus = toolbar_status_1.ToolbarStatus.get(_this.parent.contentModule.getDocument(), _this.parent.contentModule.getEditPanel(), formats_1, null, fontName_1);
                            for (var index = 0; index < args.element.childNodes.length; index++) {
                                var divNode = _this.parent.createElement('div');
                                divNode.innerHTML = dropDown.content.trim();
                                if (!hasUpdatedActive && ((divNode.textContent.trim() !== ''
                                    && args.element.childNodes[index].textContent.trim() === divNode.textContent.trim()) ||
                                    ((args.items[0].command === 'Formats' && !ej2_base_1.isNullOrUndefined(toolbarStatus.formats) && _this.parent.format.types[index].value.toLowerCase() === toolbarStatus.formats.toLowerCase() && args.element.childNodes[index].classList.contains(_this.parent.format.types[index].cssClass))
                                        || (args.items[0].subCommand === 'FontName' && args.items[0].command === 'Font' && !ej2_base_1.isNullOrUndefined(toolbarStatus.fontname) && !ej2_base_1.isNullOrUndefined(_this.parent.fontFamily.items[index]) && _this.parent.fontFamily.items[index].value.toLowerCase() === toolbarStatus.fontname.toLowerCase() && args.element.childNodes[index].classList.contains(_this.parent.fontFamily.items[index].cssClass)))
                                    || (((args.items[0].subCommand === 'FontName') && _this.parent.fontFamily.items[index].value === '' && ej2_base_1.isNullOrUndefined(toolbarStatus.fontname) && args.element.childNodes[index].classList.contains(_this.parent.fontFamily.items[index].cssClass)) ||
                                        ((args.items[0].subCommand === 'FontSize') && args.element.childNodes[index].textContent === 'Default' && divNode.textContent === 'Font Size' && _this.parent.fontSize.items[index].value === '' && !ej2_base_1.isNullOrUndefined(toolbarStatus.fontsize))))) {
                                    Eif (!args.element.childNodes[index].classList.contains('e-active')) {
                                        ej2_base_1.addClass([args.element.childNodes[index]], 'e-active');
                                        hasUpdatedActive = true;
                                    }
                                }
                                else {
                                    ej2_base_1.removeClass([args.element.childNodes[index]], 'e-active');
                                }
                            }
                        }
                    }
                    else Eif (proxy.parent.editorMode === 'Markdown') {
                        Eif (args.items[0].command === 'Formats') {
                            var formats_2 = [];
                            var hasUpdatedActive = false;
                            _this.parent.format.types.forEach(function (item) {
                                formats_2.push(item.value.toLocaleLowerCase());
                            });
                            var childNodes = args.element.childNodes;
                            for (var index = 0; index < childNodes.length; index++) {
                                var divNode = _this.parent.createElement('div');
                                divNode.innerHTML = dropDown.content.trim();
                                if (!hasUpdatedActive && ((divNode.textContent.trim() !== '' && childNodes[index].textContent.trim() === divNode.textContent.trim()))) {
                                    Eif (!childNodes[index].classList.contains('e-active')) {
                                        ej2_base_1.addClass([childNodes[index]], 'e-active');
                                        hasUpdatedActive = true;
                                    }
                                }
                                else {
                                    ej2_base_1.removeClass([childNodes[index]], 'e-active');
                                }
                            }
                        }
                    }
                    proxy.parent.notify(events.beforeDropDownOpen, args);
                },
                close: this.dropDownClose.bind(this),
                open: this.dropDownOpen.bind(this),
                beforeItemRender: this.beforeDropDownItemRender.bind(this)
            });
            dropDown.isStringTemplate = true;
            dropDown.createElement = proxy.parent.createElement;
            dropDown.appendTo(args.element);
            args.element.tabIndex = -1;
            var popupElement = document.getElementById(dropDown.element.id + '-popup');
            popupElement.setAttribute('aria-owns', this.parent.getID());
            return dropDown;
        };
        ToolbarRenderer.prototype.mouseOutHandler = function () {
            Eif (!ej2_base_1.isNullOrUndefined(this.tooltipTargetEle)) {
                this.tooltipTargetEle.setAttribute('title', this.tooltipTargetEle.getAttribute('data-title'));
            }
            else {
                var currentDocument = this.parent.iframeSettings.enable ? this.parent.contentModule.getPanel().ownerDocument :
                    this.parent.contentModule.getDocument();
                this.tooltipTargetEle = currentDocument.querySelector('[data-title]');
                this.tooltipTargetEle.setAttribute('title', this.tooltipTargetEle.getAttribute('data-title'));
            }
            this.tooltipTargetEle.removeAttribute('data-title');
            ej2_base_1.EventHandler.remove(this.tooltipTargetEle, 'mouseout', this.mouseOutHandler);
        };
        ToolbarRenderer.prototype.closeTooltip = function (args) {
            if (args.isTitle) {
                this.tooltipTargetEle = args.target;
                this.tooltipTargetEle.setAttribute('data-title', this.tooltipTargetEle.getAttribute('title'));
                this.tooltipTargetEle.removeAttribute('title');
                ej2_base_1.EventHandler.add(this.tooltipTargetEle, 'mouseout', this.mouseOutHandler, this);
            }
            else {
                var currentDocument = this.parent.iframeSettings.enable ? this.parent.contentModule.getPanel().ownerDocument :
                    this.parent.contentModule.getDocument();
                this.tooltipTargetEle = ej2_base_2.closest(args.target, '[data-tooltip-id]');
                if (!ej2_base_1.isNullOrUndefined(this.tooltipTargetEle) && this.parent.showTooltip && !ej2_base_1.isNullOrUndefined(currentDocument.querySelector('.e-tooltip-wrap'))) {
                    this.destroyTooltip();
                    this.tooltipTargetEle.setAttribute('data-title', this.tooltipTargetEle.getAttribute('title'));
                    this.tooltipTargetEle.removeAttribute('title');
                    ej2_base_1.EventHandler.add(this.tooltipTargetEle, 'mouseout', this.mouseOutHandler, this);
                }
            }
        };
        ToolbarRenderer.prototype.renderListDropDown = function (args) {
            var _this = this;
            var proxy = this;
            var css = classes_1.CLS_RTE_ELEMENTS + ' ' + classes_1.CLS_TB_BTN + ((this.parent.inlineMode) ? (' ' + classes_1.CLS_INLINE_DROPDOWN) : '');
            css += (' ' + ((args.itemName === 'NumberFormatList') ? classes_1.CLS_NUMBERFORMATLIST_TB_BTN : classes_1.CLS_BULLETFORMATLIST_TB_BTN));
            var content = proxy.parent.createElement('span', { className: classes_1.CLS_LIST_PRIMARY_CONTENT });
            var inlineEle = proxy.parent.createElement('span', { className: args.cssClass });
            content.appendChild(inlineEle);
            var dropDown = new ej2_splitbuttons_1.DropDownButton({
                items: args.items,
                cssClass: css,
                content: args.content,
                enablePersistence: this.parent.enablePersistence,
                enableRtl: this.parent.enableRtl,
                select: this.dropDownSelected.bind(this),
                beforeOpen: function (args) {
                    Eif (proxy.parent.editorMode !== 'Markdown') {
                        var startNode = proxy.parent.getRange().startContainer.parentElement;
                        var listElem = startNode.closest('LI');
                        var currentLiElem = !ej2_base_1.isNullOrUndefined(listElem) ? listElem.parentElement : null;
                        if (!ej2_base_1.isNullOrUndefined(currentLiElem) && (currentLiElem.nodeName === 'OL' || currentLiElem.nodeName === 'UL')) {
                            if (currentLiElem.nodeName === 'UL' && args.items[0].subCommand === 'NumberFormatList') {
                                ej2_base_1.addClass([args.element.childNodes[0]], 'e-active');
                            }
                            else if (currentLiElem.nodeName === 'OL' && args.items[0].subCommand === 'BulletFormatList') {
                                ej2_base_1.addClass([args.element.childNodes[0]], 'e-active');
                            }
                            else {
                                var currentListStyle = currentLiElem.style.listStyleType.split('-').join('').toLocaleLowerCase();
                                currentListStyle = currentListStyle === 'decimal' ? 'number' : currentListStyle;
                                for (var index = 0; index < args.element.childNodes.length; index++) {
                                    Iif (currentListStyle === args.element.childNodes[index].innerHTML.split(' ').join('').toLocaleLowerCase()) {
                                        ej2_base_1.addClass([args.element.childNodes[index]], 'e-active');
                                        break;
                                    }
                                    else if (currentListStyle === '' && args.element.childNodes[index].innerHTML !== 'None') {
                                        ej2_base_1.addClass([args.element.childNodes[index]], 'e-active');
                                        break;
                                    }
                                }
                            }
                        }
                        else {
                            ej2_base_1.addClass([args.element.childNodes[0]], 'e-active');
                        }
                    }
                    _this.closeTooltip({ target: args.event.target });
                    Iif (proxy.parent.readonly || !proxy.parent.enabled) {
                        args.cancel = true;
                        return;
                    }
                    proxy.parent.notify(events.selectionRestore, {});
                    var element = (args.event) ? args.event.target : null;
                    proxy.currentElement = dropDown.element;
                    proxy.currentDropdown = dropDown;
                    if (args.event && args.event.type === 'click' && (element.classList.contains(classes_1.CLS_LIST_PRIMARY_CONTENT)
                        || element.parentElement.classList.contains(classes_1.CLS_LIST_PRIMARY_CONTENT))) {
                        args.cancel = true;
                        return;
                    }
                    proxy.parent.notify(events.beforeDropDownOpen, args);
                },
                close: this.dropDownClose.bind(this),
                open: this.dropDownOpen.bind(this),
                beforeItemRender: this.beforeDropDownItemRender.bind(this)
            });
            dropDown.isStringTemplate = true;
            dropDown.createElement = proxy.parent.createElement;
            dropDown.appendTo(args.element);
            args.element.tabIndex = -1;
            args.element.setAttribute('role', 'button');
            var popupElement = document.getElementById(dropDown.element.id + '-popup');
            popupElement.setAttribute('aria-owns', this.parent.getID());
            Eif (args.element.childElementCount === 1) {
                dropDown.element.insertBefore(content, dropDown.element.querySelector('.e-caret'));
            }
            args.element.tabIndex = -1;
            dropDown.element.removeAttribute('type');
            dropDown.element.onmousedown = function () {
                proxy.parent.notify(events.selectionSave, {});
            };
            dropDown.element.onkeydown = function () {
                proxy.parent.notify(events.selectionSave, {});
            };
            return dropDown;
        };
        ToolbarRenderer.prototype.paletteSelection = function (dropDownArgs, currentElement) {
            var ele = dropDownArgs.element.querySelector('.e-control.e-colorpicker');
            var colorbox = [].slice.call(ej2_base_2.selectAll('.e-tile', ele.parentElement));
            ej2_base_1.removeClass(colorbox, 'e-selected');
            var style = currentElement.querySelector('.' + classes_1.CLS_RTE_ELEMENTS).style.borderBottomColor;
            (colorbox.filter(function (colorbox) {
                if (colorbox.style.backgroundColor === style) {
                    ej2_base_1.addClass([colorbox], 'e-selected');
                }
            }));
        };
        ToolbarRenderer.prototype.renderColorPickerDropDown = function (args, item, colorPicker, defaultColor) {
            var _this = this;
            var proxy = this;
            var css = classes_1.CLS_RTE_ELEMENTS + ' ' + classes_1.CLS_TB_BTN + ((this.parent.inlineMode) ? (' ' + classes_1.CLS_INLINE_DROPDOWN) : '');
            css += (' ' + ((item === 'backgroundcolor') ? classes_1.CLS_BACKGROUND_COLOR_DROPDOWN : classes_1.CLS_FONT_COLOR_DROPDOWN));
            css += this.parent.getCssClass(true);
            var content = proxy.parent.createElement('span', { className: classes_1.CLS_COLOR_CONTENT });
            var inlineEle = proxy.parent.createElement('span', { className: args.cssClass });
            var range;
            var initialBackgroundColor = (ej2_base_1.isNullOrUndefined(defaultColor)) ? proxy.parent.backgroundColor.default : defaultColor;
            inlineEle.style.borderBottomColor = (item === 'backgroundcolor') ?
                initialBackgroundColor : proxy.parent.fontColor.default;
            content.appendChild(inlineEle);
            var dropDown = new ej2_splitbuttons_1.DropDownButton({
                target: colorPicker.element.parentElement, cssClass: css,
                enablePersistence: this.parent.enablePersistence, enableRtl: this.parent.enableRtl,
                beforeOpen: function (dropDownArgs) {
                    if (proxy.parent.readonly || !proxy.parent.enabled) {
                        dropDownArgs.cancel = true;
                        return;
                    }
                    var element = (dropDownArgs.event) ? dropDownArgs.event.target : null;
                    proxy.currentElement = dropDown.element;
                    proxy.currentDropdown = dropDown;
                    proxy.paletteSelection(dropDownArgs, proxy.currentElement);
                    if (dropDownArgs.event && dropDownArgs.event.type === 'click' && (element.classList.contains(classes_1.CLS_COLOR_CONTENT)
                        || element.parentElement.classList.contains(classes_1.CLS_COLOR_CONTENT))) {
                        dropDownArgs.cancel = true;
                        var colorpickerValue = element.classList.contains(classes_1.CLS_RTE_ELEMENTS) ? element.style.borderBottomColor :
                            element.querySelector('.' + classes_1.CLS_RTE_ELEMENTS).style.borderBottomColor;
                        proxy.parent.notify(events.selectionRestore, {});
                        range = proxy.parent.formatter.editorManager.nodeSelection.getRange(proxy.parent.contentModule.getDocument());
                        var parentNode = range.startContainer.parentNode;
                        var closestElement = ej2_base_2.closest(range.startContainer.parentNode, 'table');
                        if ((range.startContainer.nodeName === 'TD' || range.startContainer.nodeName === 'TH' ||
                            (ej2_base_2.closest(range.startContainer.parentNode, 'td,th')) ||
                            (proxy.parent.iframeSettings.enable && !util_1.hasClass(parentNode.ownerDocument.querySelector('body'), 'e-lib')))
                            && range.collapsed && args.subCommand === 'BackgroundColor' && ej2_base_2.closest(closestElement, '.' + classes.CLS_RTE)) {
                            proxy.parent.notify(events.tableColorPickerChanged, {
                                item: { command: args.command, subCommand: args.subCommand,
                                    value: colorpickerValue }
                            });
                        }
                        else {
                            proxy.parent.notify(events.colorPickerChanged, { item: { command: args.command, subCommand: args.subCommand,
                                    value: colorpickerValue }
                            });
                        }
                        return;
                    }
                    else {
                        var ele = dropDownArgs.element.querySelector('.e-control.e-colorpicker');
                        var inst = ej2_base_2.getInstance(ele, ej2_inputs_1.ColorPicker);
                        inst.showButtons = (dropDownArgs.element.querySelector('.e-color-palette')) ? false : true;
                        inst.dataBind();
                    }
                    dropDownArgs.element.onclick = function (args) {
                        if (args.target.classList.contains('e-cancel')) {
                            dropDown.toggle();
                        }
                    };
                },
                open: function (dropDownArgs) {
                    _this.setColorPickerContentWidth(colorPicker);
                    var focusEle;
                    var ele = dropDownArgs.element.querySelector('.e-control.e-colorpicker');
                    if (dropDownArgs.element.querySelector('.e-color-palette')) {
                        focusEle = ele.parentElement.querySelector('.e-palette');
                    }
                    else {
                        focusEle = ele.parentElement.querySelector('e-handler');
                    }
                    if (focusEle) {
                        focusEle.focus();
                    }
                    _this.pickerRefresh(dropDownArgs);
                },
                beforeClose: function (dropDownArgs) {
                    var element = (dropDownArgs.event) ? dropDownArgs.event.target : null;
                    if (dropDownArgs.event && dropDownArgs.event.type === 'click' && (element.classList.contains(classes_1.CLS_COLOR_CONTENT)
                        || element.parentElement.classList.contains(classes_1.CLS_COLOR_CONTENT))) {
                        var colorpickerValue = element.classList.contains(classes_1.CLS_RTE_ELEMENTS) ? element.style.borderBottomColor :
                            element.querySelector('.' + classes_1.CLS_RTE_ELEMENTS).style.borderBottomColor;
                        range = proxy.parent.formatter.editorManager.nodeSelection.getRange(proxy.parent.contentModule.getDocument());
                        Iif ((range.startContainer.nodeName === 'TD' || range.startContainer.nodeName === 'TH' ||
                            ej2_base_2.closest(range.startContainer.parentNode, 'td,th')) && range.collapsed) {
                            proxy.parent.notify(events.tableColorPickerChanged, { item: {
                                    command: args.command, subCommand: args.subCommand,
                                    value: colorpickerValue
                                }
                            });
                        }
                        else {
                            proxy.parent.notify(events.colorPickerChanged, { item: { command: args.command, subCommand: args.subCommand,
                                    value: colorpickerValue }
                            });
                        }
                        return;
                    }
                },
                close: function () {
                    proxy.parent.notify(events.selectionRestore, {});
                }
            });
            dropDown.isStringTemplate = true;
            dropDown.createElement = proxy.parent.createElement;
            args.element.setAttribute('role', 'button');
            dropDown.appendTo(args.element);
            var popupElement = document.getElementById(dropDown.element.id + '-popup');
            popupElement.setAttribute('aria-owns', this.parent.getID());
            dropDown.element.insertBefore(content, dropDown.element.querySelector('.e-caret'));
            args.element.tabIndex = -1;
            dropDown.element.removeAttribute('type');
            dropDown.element.onmousedown = function () {
                proxy.parent.notify(events.selectionSave, {});
            };
            dropDown.element.onkeydown = function () {
                proxy.parent.notify(events.selectionSave, {});
            };
            return dropDown;
        };
        ToolbarRenderer.prototype.pickerRefresh = function (dropDownArgs) {
            if (this.parent.backgroundColor.mode === 'Picker') {
                var popupElem = dropDownArgs.element.parentElement;
                popupElem.style.width = (popupElem.offsetWidth + 5).toString() + 'px';
                ej2_base_2.getInstance(popupElem, ej2_popups_1.Popup).refreshPosition(popupElem);
                popupElem.style.width = (popupElem.offsetWidth - 5).toString() + 'px';
            }
        };
        ToolbarRenderer.prototype.setColorPickerContentWidth = function (colorPicker) {
            var colorPickerContent = colorPicker.element.nextSibling;
            if (colorPickerContent.style.width === '0px') {
                colorPickerContent.style.width = '';
                var borderWidth = parseInt(getComputedStyle(colorPickerContent).borderBottomWidth, 10);
                colorPickerContent.style.width = ej2_base_1.formatUnit(colorPickerContent.children[0].offsetWidth
                    + borderWidth + borderWidth);
            }
        };
        ToolbarRenderer.prototype.renderColorPicker = function (args, item) {
            var _this = this;
            var proxy = this;
            var value;
            var colorPicker = new ej2_inputs_1.ColorPicker({
                enablePersistence: this.parent.enablePersistence,
                enableRtl: this.parent.enableRtl,
                inline: true,
                value: null,
                cssClass: ((item === 'backgroundcolor') ? classes_1.CLS_BACKGROUND_COLOR_PICKER : classes_1.CLS_FONT_COLOR_PICKER) + ' ' + args.cssClass + ' ' + 'e-rte-picker-init',
                created: function () {
                    var value = (item === 'backgroundcolor') ? proxy.parent.backgroundColor.default : proxy.parent.fontColor.default;
                    var cssClass = ((item === 'backgroundcolor') ? classes_1.CLS_BACKGROUND_COLOR_PICKER : classes_1.CLS_FONT_COLOR_PICKER) + ' ' + args.cssClass;
                    colorPicker.setProperties({ value: value, cssClass: cssClass });
                },
                mode: ((item === 'backgroundcolor') ? proxy.parent.backgroundColor.mode : proxy.parent.fontColor.mode),
                modeSwitcher: ((item === 'backgroundcolor') ? proxy.parent.backgroundColor.modeSwitcher : proxy.parent.fontColor.modeSwitcher),
                presetColors: (item === 'backgroundcolor') ? this.parent.backgroundColor.colorCode : this.parent.fontColor.colorCode,
                columns: (item === 'backgroundcolor') ? this.parent.backgroundColor.columns : this.parent.fontColor.columns,
                beforeTileRender: function (args) {
                    args.element.classList.add(classes_1.CLS_COLOR_PALETTE);
                    args.element.classList.add(classes_1.CLS_CUSTOM_TILE);
                    if (!ej2_base_1.isNullOrUndefined(_this.parent.cssClass)) {
                        var allClassName = _this.parent.getCssClass().split(' ');
                        for (var i = 0; i < allClassName.length; i++) {
                            Eif (allClassName[i].trim() !== '') {
                                args.element.classList.add(allClassName[i]);
                            }
                        }
                    }
                    if (args.value === '') {
                        args.element.classList.add(classes_1.CLS_NOCOLOR_ITEM);
                    }
                },
                change: function (colorPickerArgs) {
                    var colorpickerValue = colorPickerArgs.currentValue.rgba;
                    colorPickerArgs.item = {
                        command: args.command,
                        subCommand: args.subCommand,
                        value: colorpickerValue
                    };
                    proxy.parent.notify(events.selectionRestore, {});
                    proxy.currentElement.querySelector('.' + classes_1.CLS_RTE_ELEMENTS).style.borderBottomColor = colorpickerValue;
                    var range = proxy.parent.formatter.editorManager.nodeSelection.getRange(proxy.parent.contentModule.getDocument());
                    var closestElement = ej2_base_2.closest(range.startContainer.parentNode, 'table');
                    if ((range.startContainer.nodeName === 'TD' || range.startContainer.nodeName === 'TH' || range.startContainer.nodeName === 'BODY' ||
                        ej2_base_2.closest(range.startContainer.parentNode, 'td,th')) && range.collapsed && args.subCommand === 'BackgroundColor' && ej2_base_2.closest(closestElement, '.' + classes.CLS_RTE)) {
                        proxy.parent.notify(events.tableColorPickerChanged, colorPickerArgs);
                    }
                    else {
                        proxy.parent.notify(events.colorPickerChanged, colorPickerArgs);
                    }
                    proxy.currentDropdown.toggle();
                },
                beforeModeSwitch: function (args) {
                    value = colorPicker.value;
                    Iif (value === '') {
                        colorPicker.setProperties({ value: ((args.mode === 'Picker') ? '#008000ff' : '') }, true);
                    }
                    colorPicker.showButtons = args.mode === 'Palette' ? false : true;
                }
            });
            colorPicker.isStringTemplate = true;
            colorPicker.createElement = this.parent.createElement;
            colorPicker.appendTo(document.getElementById(args.target));
            return colorPicker;
        };
        ToolbarRenderer.prototype.renderPanel = function () {
            this.getPanel().classList.add(classes_1.CLS_TOOLBAR);
        };
        ToolbarRenderer.prototype.getPanel = function () {
            return this.toolbarPanel;
        };
        ToolbarRenderer.prototype.setPanel = function (panel) {
            this.toolbarPanel = panel;
        };
        ToolbarRenderer.prototype.destroy = function () {
            if (this.isDestroyed) {
                return;
            }
            if (this.tooltip && !this.tooltip.isDestroyed) {
                this.tooltip.destroy();
                var tooltipElements = document.querySelectorAll('[data-rte-id="' + this.parent.getID() + '"]');
                for (var i = 0; i < tooltipElements.length; i++) {
                    var tooltipEle = tooltipElements[i];
                    if (this.parent.getID() === tooltipEle.getAttribute('data-rte-id')) {
                        ej2_base_1.detach(tooltipEle);
                    }
                }
            }
            this.unWireEvent();
            this.mode = null;
            this.toolbarPanel = null;
            this.currentElement = null;
            this.currentDropdown = null;
            this.tooltip = null;
            this.tooltipTargetEle = null;
            this.isDestroyed = true;
        };
        return ToolbarRenderer;
    }());
    exports.ToolbarRenderer = ToolbarRenderer;
});