all files / document-editor-container/ribbon/home-tab/ font-group.js

86.17% Statements 162/188
68.33% Branches 41/60
75.47% Functions 40/53
85.95% Lines 159/185
11 statements, 6 functions, 9 branches Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481          14× 14× 14× 14×   14× 14× 14×                                                                                                                                                                                                                                                                                                                                                                                                                                                           118×     118× 118× 118× 118× 118× 118× 118× 118× 118× 118× 118×   114×       118× 118× 118×     118× 118× 118× 118× 118× 118×                   118× 118× 118× 118× 118×         118× 118× 118× 114×   118× 118× 118× 118×           708× 708× 708× 708× 708× 149× 149×     559× 559×         28×   14× 14× 14×     14×         14× 14× 224× 224× 224× 224× 224× 224×   14× 14× 14× 14× 14× 14× 14× 14× 14× 14×         224×                                                                                         14× 238× 238×     14×        
/* istanbul ignore next */ 
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
define(["require", "exports", "../ribbon-interfaces", "@syncfusion/ej2-ribbon", "@syncfusion/ej2-base", "../../helper/font-helper", "@syncfusion/ej2-dropdowns"], function (require, exports, ribbon_interfaces_1, ej2_ribbon_1, ej2_base_1, font_helper_1, ej2_dropdowns_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.FONT_GROUP_ID = '_font_group';
    exports.FONT_FAMILY_ID = '_font_family';
    exports.FONT_SIZE_ID = '_font_size';
    exports.BOLD_ID = '_bold';
    exports.ITALIC_ID = '_italic';
    exports.UNDERLINE_ID = '_underline';
    exports.STRIKETHROUGH_ID = '_strikethrough';
    exports.SUPERSCRIPT_ID = '_superscript';
    exports.SUBSCRIPT_ID = '_subscript';
    exports.FONT_COLOR_ID = '_font_color';
    exports.HIGHLIGHT_COLOR_ID = '_highlight_color';
    exports.CLEAR_FORMAT_ID = '_clear_format';
    exports.GROW_FONT_ID = '_grow_format';
    exports.SHRINK_FONT_ID = '_shrink_format';
    exports.CHANGE_CASE_ID = '_change_case';
    var FontGroup = (function (_super) {
        __extends(FontGroup, _super);
        function FontGroup() {
            var _this = _super !== null && _super.apply(this, arguments) || this;
            _this.appliedHighlightColor = 'rgb(255, 255, 0)';
            _this.highlightColorHandlers = [];
            return _this;
        }
        FontGroup.prototype.getGroupModel = function () {
            var _this = this;
            var id = this.ribbonId;
            return {
                id: id + exports.FONT_GROUP_ID,
                cssClass: 'e-font-group',
                groupIconCss: 'e-icons e-de-ctnr-fontcolor',
                header: this.localObj.getConstant('Font'),
                isCollapsible: false,
                enableGroupOverflow: true,
                overflowHeader: this.localObj.getConstant('More Font Options'),
                orientation: 'Row',
                showLauncherIcon: true,
                launcherIconKeyTip: 'FG',
                collections: [
                    {
                        id: id + '_font-collection',
                        items: [
                            {
                                type: 'ComboBox',
                                keyTip: 'FF',
                                allowedSizes: ej2_ribbon_1.RibbonItemSize.Small,
                                comboBoxSettings: {
                                    dataSource: this.container.documentEditorSettings.fontFamilies,
                                    label: this.localObj.getConstant('Font'),
                                    width: '150px',
                                    popupHeight: '250px',
                                    popupWidth: '150px',
                                    cssClass: 'e-de-prop-dropdown',
                                    allowFiltering: true,
                                    change: function () {
                                        _this.changeFontFamily();
                                    }
                                },
                                id: id + exports.FONT_FAMILY_ID,
                                ribbonTooltipSettings: { content: this.localObj.getConstant('Font') }
                            },
                            {
                                type: 'ComboBox',
                                keyTip: 'FS',
                                allowedSizes: ej2_ribbon_1.RibbonItemSize.Small,
                                comboBoxSettings: {
                                    label: this.localObj.getConstant('Font Size'),
                                    dataSource: ['8', '9', '10', '11', '12', '14', '16', '18', '20', '22', '24', '26', '28', '36', '48', '72', '96'],
                                    width: '65px',
                                    cssClass: 'e-de-prop-dropdown',
                                    showClearButton: false,
                                    change: function () {
                                        _this.changeFontSize();
                                    }
                                },
                                id: id + exports.FONT_SIZE_ID,
                                ribbonTooltipSettings: { content: this.localObj.getConstant('Font Size') }
                            }, {
                                type: 'Button',
                                keyTip: 'FG',
                                allowedSizes: ej2_ribbon_1.RibbonItemSize.Small,
                                buttonSettings: {
                                    content: this.localObj.getConstant('Grow Font Size'),
                                    iconCss: 'e-icons e-de-ctnr-increase-fontsize',
                                    clicked: function () {
                                        _this.increaseFontSize();
                                    }
                                },
                                id: id + exports.GROW_FONT_ID,
                                ribbonTooltipSettings: { content: this.localObj.getConstant('Grow Font Size') }
                            },
                            {
                                type: 'Button',
                                keyTip: 'FK',
                                allowedSizes: ej2_ribbon_1.RibbonItemSize.Small,
                                buttonSettings: {
                                    content: this.localObj.getConstant('Shrink Font Size'),
                                    iconCss: 'e-icons e-de-ctnr-decrease-fontsize',
                                    clicked: function () {
                                        _this.decreaseFontSize();
                                    }
                                },
                                id: id + exports.SHRINK_FONT_ID,
                                ribbonTooltipSettings: { content: this.localObj.getConstant('Shrink Font Size') }
                            }, {
                                type: 'DropDown',
                                keyTip: 'CC',
                                allowedSizes: ej2_ribbon_1.RibbonItemSize.Small,
                                dropDownSettings: {
                                    iconCss: 'e-icons e-de-ctnr-change-case',
                                    content: this.localObj.getConstant('Change case Tooltip'),
                                    items: font_helper_1.FontHelper.getChangeCaseItems(this.localObj, id),
                                    select: function (args) {
                                        _this.changeCaseAction(args);
                                    }
                                },
                                id: id + exports.CHANGE_CASE_ID,
                                ribbonTooltipSettings: { content: this.localObj.getConstant('Change case Tooltip') }
                            }
                        ]
                    }, {
                        items: [{
                                type: 'Button',
                                keyTip: '1',
                                allowedSizes: ej2_ribbon_1.RibbonItemSize.Small,
                                buttonSettings: {
                                    content: this.localObj.getConstant('Bold Tooltip'),
                                    cssClass: 'e-de-icon-Bold',
                                    iconCss: 'e-icons e-de-ctnr-bold',
                                    isToggle: true,
                                    clicked: function () {
                                        _this.boldAction();
                                    }
                                },
                                id: id + exports.BOLD_ID,
                                ribbonTooltipSettings: { content: this.localObj.getConstant('Bold Tooltip') }
                            },
                            {
                                type: 'Button',
                                keyTip: '2',
                                allowedSizes: ej2_ribbon_1.RibbonItemSize.Small,
                                buttonSettings: {
                                    content: this.localObj.getConstant('Italic Tooltip'),
                                    cssClass: 'e-de-icon-Italic',
                                    iconCss: 'e-icons e-de-ctnr-italic',
                                    isToggle: true,
                                    clicked: function () {
                                        _this.italicAction();
                                    }
                                },
                                id: id + exports.ITALIC_ID,
                                ribbonTooltipSettings: { content: this.localObj.getConstant('Italic Tooltip') }
                            },
                            {
                                type: 'Button',
                                keyTip: '3',
                                allowedSizes: ej2_ribbon_1.RibbonItemSize.Small,
                                buttonSettings: {
                                    content: this.localObj.getConstant('Underline Tooltip'),
                                    cssClass: 'e-de-icon-Underline',
                                    iconCss: 'e-icons e-de-ctnr-underline',
                                    isToggle: true,
                                    clicked: function () {
                                        _this.underlineAction();
                                    }
                                },
                                id: id + exports.UNDERLINE_ID,
                                ribbonTooltipSettings: { content: this.localObj.getConstant('Underline Tooltip') }
                            },
                            {
                                type: 'Button',
                                keyTip: '4',
                                allowedSizes: ej2_ribbon_1.RibbonItemSize.Small,
                                buttonSettings: {
                                    content: this.localObj.getConstant('Strikethrough'),
                                    cssClass: 'e-de-icon-Strikethrough',
                                    iconCss: 'e-icons e-de-ctnr-strikethrough',
                                    isToggle: true,
                                    clicked: function () {
                                        _this.strikethroughAction();
                                    }
                                },
                                id: id + exports.STRIKETHROUGH_ID,
                                ribbonTooltipSettings: { content: this.localObj.getConstant('Strikethrough') }
                            },
                            {
                                type: 'Button',
                                keyTip: '5',
                                allowedSizes: ej2_ribbon_1.RibbonItemSize.Small,
                                buttonSettings: {
                                    content: this.localObj.getConstant('Superscript Tooltip'),
                                    cssClass: 'e-de-icon-Superscript',
                                    iconCss: 'e-icons e-de-ctnr-superscript',
                                    isToggle: true,
                                    clicked: function () {
                                        _this.superscriptAction();
                                    }
                                },
                                id: id + exports.SUPERSCRIPT_ID,
                                ribbonTooltipSettings: { content: this.localObj.getConstant('Superscript Tooltip') }
                            },
                            {
                                type: 'Button',
                                keyTip: '6',
                                allowedSizes: ej2_ribbon_1.RibbonItemSize.Small,
                                buttonSettings: {
                                    content: this.localObj.getConstant('Subscript Tooltip'),
                                    cssClass: 'e-de-icon-Subscript',
                                    iconCss: 'e-icons e-de-ctnr-subscript',
                                    isToggle: true,
                                    clicked: function () {
                                        _this.subscriptAction();
                                    }
                                },
                                id: id + exports.SUBSCRIPT_ID,
                                ribbonTooltipSettings: { content: this.localObj.getConstant('Subscript Tooltip') }
                            },
                            {
                                type: 'ColorPicker',
                                keyTip: 'I',
                                allowedSizes: ej2_ribbon_1.RibbonItemSize.Small,
                                colorPickerSettings: {
                                    label: this.localObj.getConstant('Font color'),
                                    htmlAttributes: { 'aria-label': this.localObj.getConstant('Font color') },
                                    value: '#000000',
                                    change: function (args) {
                                        _this.changeFontColor(args);
                                    }
                                },
                                id: id + exports.FONT_COLOR_ID,
                                ribbonTooltipSettings: { content: this.localObj.getConstant('Font color') }
                            },
                            {
                                type: 'SplitButton',
                                keyTip: 'FC',
                                allowedSizes: ej2_ribbon_1.RibbonItemSize.Small,
                                splitButtonSettings: this.createHighlightColorSplitButton(),
                                id: id + exports.HIGHLIGHT_COLOR_ID,
                                ribbonTooltipSettings: { content: this.localObj.getConstant('Text highlight color') }
                            },
                            {
                                type: 'Button',
                                keyTip: 'E',
                                allowedSizes: ej2_ribbon_1.RibbonItemSize.Small,
                                buttonSettings: {
                                    content: this.localObj.getConstant('Clear all formatting'),
                                    iconCss: 'e-icons e-de-ctnr-clearall',
                                    clicked: function () {
                                        _this.clearFormatAction();
                                    }
                                },
                                id: id + exports.CLEAR_FORMAT_ID,
                                ribbonTooltipSettings: { content: this.localObj.getConstant('Clear all formatting') }
                            }
                        ]
                    }
                ]
            };
        };
        FontGroup.prototype.updateSelection = function () {
            Iif (!this.documentEditor.selection) {
                return;
            }
            var characterFormat = this.documentEditor.selection.characterFormat;
            var id = this.ribbonId;
            this.updateToggleButtonState(id + exports.BOLD_ID, characterFormat.bold);
            this.updateToggleButtonState(id + exports.ITALIC_ID, characterFormat.italic);
            this.updateToggleButtonState(id + exports.UNDERLINE_ID, characterFormat.underline !== 'None');
            this.updateToggleButtonState(id + exports.STRIKETHROUGH_ID, characterFormat.strikethrough !== 'None');
            this.updateToggleButtonState(id + exports.SUPERSCRIPT_ID, characterFormat.baselineAlignment === 'Superscript');
            this.updateToggleButtonState(id + exports.SUBSCRIPT_ID, characterFormat.baselineAlignment === 'Subscript');
            Eif (characterFormat.fontFamily) {
                var fontFamily = void 0;
                if (!ej2_base_1.isNullOrUndefined(characterFormat.renderedFontFamily) &&
                    !ej2_base_1.isNullOrUndefined(characterFormat.fontFamily)) {
                    fontFamily = characterFormat.renderedFontFamily;
                }
                else {
                    fontFamily = characterFormat.fontFamily;
                }
                var fontFamilyElement = document.getElementById(id + exports.FONT_FAMILY_ID);
                Eif (fontFamilyElement) {
                    fontFamilyElement.value = fontFamily;
                }
            }
            Eif (characterFormat.fontSize) {
                var fontSize = characterFormat.fontSize.toString();
                var fontSizeElement = document.getElementById(id + exports.FONT_SIZE_ID);
                Eif (fontSizeElement) {
                    var fontSizeInstance = ej2_base_1.getInstance(fontSizeElement, ej2_dropdowns_1.ComboBox);
                    fontSizeInstance.value = fontSize;
                }
            }
            else {
                var fontSizeElement = document.getElementById(id + exports.FONT_SIZE_ID);
                if (fontSizeElement) {
                    var fontSizeInstance = ej2_base_1.getInstance(fontSizeElement, ej2_dropdowns_1.ComboBox);
                    fontSizeInstance.value = null;
                }
            }
            Eif (characterFormat.highlightColor) {
                var highlightColor = document.getElementById(id + exports.HIGHLIGHT_COLOR_ID);
                Eif (highlightColor) {
                    var highlightColorElement = highlightColor.querySelector('.e-split-btn-icon');
                    Iif (highlightColorElement) {
                        highlightColorElement.style.backgroundColor = this.getBackgroundColorFromHighlightColor(characterFormat.highlightColor);
                    }
                }
            }
            Eif (characterFormat.fontColor) {
                var fontColor = characterFormat.fontColor;
                if (fontColor === 'empty' || fontColor === '#00000000') {
                    fontColor = '#000000';
                }
                var fontColorElement = document.getElementById(id + exports.FONT_COLOR_ID);
                Eif (fontColorElement) {
                    var fontColorInput = fontColorElement.querySelector('input');
                    Iif (fontColorInput) {
                        fontColorInput.value = fontColor;
                    }
                }
            }
        };
        FontGroup.prototype.updateToggleButtonState = function (buttonId, isActive) {
            var ribbonObj = this.container.ribbon.ribbon;
            Eif (ribbonObj) {
                var button = document.getElementById(buttonId);
                Eif (button) {
                    if (isActive) {
                        button.classList.add('e-active');
                        button.setAttribute('aria-pressed', 'true');
                    }
                    else {
                        button.classList.remove('e-active');
                        button.setAttribute('aria-pressed', 'false');
                    }
                }
            }
        };
        FontGroup.prototype.getHighlightColorItems = function () {
            return font_helper_1.FontHelper.getHighlightColorItems(this.localObj, this.ribbonId);
        };
        FontGroup.prototype.createHighlightColorSplitButton = function () {
            var _this = this;
            var highlightIconCss = 'e-de-ctnr-highlight e-icons';
            Iif (this.isRtl) {
                highlightIconCss += ' e-de-flip';
            }
            var highlightColorElement = ej2_base_1.createElement('div', {
                id: this.ribbonId + '_ribbon_highlight_color',
                styles: 'display:none;width:157px',
                className: 'e-de-cntr-highlight-pane'
            });
            var highlightColors = this.getHighlightColorItems();
            highlightColors.forEach(function (color) {
                var colorDiv = ej2_base_1.createElement('div', { className: 'e-de-ctnr-hglt-btn' });
                colorDiv.style.backgroundColor = color.backgroundColor;
                highlightColorElement.appendChild(colorDiv);
                var handler = _this.onHighlightColorClick.bind(_this, color.backgroundColor);
                colorDiv.addEventListener('click', handler);
                _this.highlightColorHandlers.push({ element: colorDiv, handler: handler });
            });
            var noColorDiv = ej2_base_1.createElement('div');
            highlightColorElement.appendChild(noColorDiv);
            var noColorSpan = ej2_base_1.createElement('span', { className: 'e-de-ctnr-hglt-no-color' });
            noColorSpan.textContent = this.localObj.getConstant('No color');
            noColorDiv.appendChild(noColorSpan);
            noColorDiv.addEventListener('click', this.onHighlightColorClick.bind(this, 'transparent'));
            var noColorHandler = this.onHighlightColorClick.bind(this, 'transparent');
            noColorDiv.addEventListener('click', noColorHandler);
            this.highlightColorHandlers.push({ element: noColorDiv, handler: noColorHandler });
            return {
                target: highlightColorElement,
                iconCss: highlightIconCss,
                content: this.localObj.getConstant('Text highlight color'),
                htmlAttributes: { 'aria-label': this.localObj.getConstant('Text highlight color') },
                items: this.getHighlightColorItems().map(function (color) { return ({ id: color.id, text: color.text }); }),
                select: function (args) {
                    _this.applyHighlightColor(args.item.backgroundColor);
                },
                beforeOpen: function () {
                    highlightColorElement.style.display = 'block';
                },
                beforeClose: function () {
                    highlightColorElement.style.display = 'none';
                },
                click: function () {
                    _this.applyHighlightColor(_this.appliedHighlightColor);
                }
            };
        };
        FontGroup.prototype.onHighlightColorClick = function (color, event) {
            this.applyHighlightColor(color);
            this.closePopup();
            event.currentTarget.parentElement.querySelectorAll('.e-color-selected').forEach(function (child) {
                child.classList.remove('e-color-selected');
            });
            event.currentTarget.classList.add('e-color-selected');
        };
        FontGroup.prototype.closePopup = function () {
            var highlightColorElement = document.getElementById(this.ribbonId + '_ribbon_highlight_color');
            if (highlightColorElement) {
                highlightColorElement.style.display = 'none';
            }
        };
        FontGroup.prototype.applyHighlightColor = function (color) {
            this.appliedHighlightColor = font_helper_1.FontHelper.applyHighlightColor(this.documentEditor, color);
        };
        FontGroup.prototype.getBackgroundColorFromHighlightColor = function (highlightColor) {
            return font_helper_1.FontHelper.getBackgroundColorFromHighlightColor(highlightColor);
        };
        FontGroup.prototype.boldAction = function () {
            font_helper_1.FontHelper.applyFontFormatting(this.documentEditor, 'bold');
        };
        FontGroup.prototype.italicAction = function () {
            font_helper_1.FontHelper.applyFontFormatting(this.documentEditor, 'italic');
        };
        FontGroup.prototype.underlineAction = function () {
            font_helper_1.FontHelper.applyFontFormatting(this.documentEditor, 'underline');
        };
        FontGroup.prototype.strikethroughAction = function () {
            font_helper_1.FontHelper.applyFontFormatting(this.documentEditor, 'strikethrough');
        };
        FontGroup.prototype.superscriptAction = function () {
            font_helper_1.FontHelper.applyFontFormatting(this.documentEditor, 'superscript');
        };
        FontGroup.prototype.subscriptAction = function () {
            font_helper_1.FontHelper.applyFontFormatting(this.documentEditor, 'subscript');
        };
        FontGroup.prototype.changeCaseAction = function (args) {
            font_helper_1.FontHelper.applyChangeCase(this.documentEditor, this.localObj, args.item.text);
        };
        FontGroup.prototype.changeFontFamily = function () {
            var fontFamily = document.getElementById(this.ribbonId + exports.FONT_FAMILY_ID).value;
            font_helper_1.FontHelper.changeFontFamily(this.documentEditor, fontFamily);
        };
        FontGroup.prototype.changeFontSize = function () {
            var fontSize = document.getElementById(this.ribbonId + exports.FONT_SIZE_ID).value;
            font_helper_1.FontHelper.changeFontSize(this.documentEditor, fontSize);
        };
        FontGroup.prototype.changeFontColor = function (args) {
            font_helper_1.FontHelper.changeFontColor(this.documentEditor, args.currentValue.hex);
        };
        FontGroup.prototype.clearFormatAction = function () {
            font_helper_1.FontHelper.applyFontFormatting(this.documentEditor, 'clearFormat');
        };
        FontGroup.prototype.increaseFontSize = function () {
            font_helper_1.FontHelper.increaseFontSize(this.documentEditor);
        };
        FontGroup.prototype.decreaseFontSize = function () {
            font_helper_1.FontHelper.decreaseFontSize(this.documentEditor);
        };
        FontGroup.prototype.destroy = function () {
            this.highlightColorHandlers.forEach(function (item) {
                Eif (item.element && item.handler) {
                    item.element.removeEventListener('click', item.handler);
                }
            });
            this.highlightColorHandlers = [];
        };
        return FontGroup;
    }(ribbon_interfaces_1.RibbonGroupBase));
    exports.FontGroup = FontGroup;
});