all files / common/utils/ print.js

100% Statements 43/43
95% Branches 19/20
100% Functions 5/5
100% Lines 43/43
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   26×   26× 26× 26× 26×     26× 26× 20×     26× 26×               21×   26× 29× 29× 29× 54× 54× 54×   49× 27× 27×   54× 32× 32×     29×   26×        
define(["require", "exports", "@syncfusion/ej2-base", "../utils/helper", "../model/constants"], function (require, exports, ej2_base_1, helper_1, constants_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    var PrintUtils = (function () {
        function PrintUtils(control) {
            this.control = control;
        }
        PrintUtils.prototype.print = function (elements) {
            this.printWindow = window.open('', 'print', 'height=' + window.outerHeight + ',width=' + window.outerWidth + ',tabbar=no');
            this.printWindow.moveTo(0, 0);
            this.printWindow.resizeTo(screen.availWidth, screen.availHeight);
            var argsData = {
                cancel: false, htmlContent: this.getHTMLContent(elements), name: constants_1.beforePrint
            };
            this.control.trigger(constants_1.beforePrint, argsData);
            if (!argsData.cancel) {
                ej2_base_1.print(argsData.htmlContent, this.printWindow);
            }
        };
        PrintUtils.prototype.getHTMLContent = function (elements) {
            var div = ej2_base_1.createElement('div');
            if (elements) {
                if (elements instanceof Array) {
                    for (var j = 0; j < elements.length; j++) {
                        var value = elements[j];
                        div.appendChild(helper_1.getElement(value).cloneNode(true));
                    }
                }
                else if (elements instanceof Element) {
                    div.appendChild(elements.cloneNode(true));
                }
                else {
                    div.appendChild(helper_1.getElement(elements).cloneNode(true));
                }
            }
            else {
                div.appendChild(this.control.element.cloneNode(true));
            }
            for (var index = 0; index < div.children.length; index++) {
                var backgroundColor = (this.control.theme.indexOf('Dark') > -1 || this.control.theme.indexOf('HighContrast') > -1) ? 'rgba(0, 0, 0, 1)' : 'rgba(255, 255, 255, 1)';
                var svg = div.children[index];
                for (var childIndex = 0; childIndex < svg.children.length; childIndex++) {
                    var actualBackgroundColor = void 0;
                    var isSVG = false;
                    if (svg.id.indexOf('_stockChart_svg') > -1) {
                        actualBackgroundColor = svg.children[0].getAttribute('fill');
                        isSVG = true;
                    }
                    else if (svg.children[childIndex].id.indexOf('_svg') > -1) {
                        actualBackgroundColor = svg.children[childIndex].children[0].getAttribute('fill');
                        isSVG = true;
                    }
                    if (isSVG) {
                        actualBackgroundColor = actualBackgroundColor === 'transparent' ? backgroundColor : actualBackgroundColor;
                        svg.children[childIndex].children[0].setAttribute('fill', actualBackgroundColor);
                    }
                }
                div[index] = svg;
            }
            return div;
        };
        return PrintUtils;
    }());
    exports.PrintUtils = PrintUtils;
});