all files / barcode/utility/ dom-util.js

93.22% Statements 55/59
60% Branches 6/10
100% Functions 7/7
93.22% Lines 55/59
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   258× 258× 258×   258×   2275× 2275× 2275×                 2275×   2275×   2275× 2275× 2275× 2275× 2275× 2275×   2275× 2275× 2275× 2275× 2275×   965× 965× 2657×     707× 707× 707×   719× 719× 119×       119× 119× 119× 119× 119× 119× 119× 119× 119× 119× 119×     600×        
define(["require", "exports", "@syncfusion/ej2-base", "../primitives/size"], function (require, exports, ej2_base_1, size_1) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    function createHtmlElement(elementType, attribute) {
        var element = ej2_base_1.createElement(elementType);
        Eif (attribute) {
            setAttribute(element, attribute);
        }
        return element;
    }
    exports.createHtmlElement = createHtmlElement;
    function getChildNode(node) {
        var child;
        var collection = [];
        Iif (ej2_base_1.Browser.info.name === 'msie' || ej2_base_1.Browser.info.name === 'edge') {
            for (var i = 0; i < node.childNodes.length; i++) {
                child = node.childNodes[parseInt(i.toString(), 10)];
                if (child.nodeType === 1) {
                    collection.push(child);
                }
            }
        }
        else {
            collection = node.children;
        }
        return collection;
    }
    exports.getChildNode = getChildNode;
    function measureText(textContent) {
        var measureElement = 'barcodeMeasureElement';
        window["" + measureElement].style.visibility = 'visible';
        var svg = window["" + measureElement].children[1];
        var text = getChildNode(svg)[0];
        text.textContent = textContent.string;
        text.setAttribute('style', 'font-size:' + textContent.stringSize + 'px; font-family:'
            + textContent.fontStyle + ';font-weight:');
        var bBox = new size_1.Size(0, 0);
        bBox.width = text.getBBox().width;
        bBox.height = text.getBBox().height;
        window["" + measureElement].style.visibility = 'hidden';
        return bBox;
    }
    exports.measureText = measureText;
    function setAttribute(element, attributes) {
        var keys = Object.keys(attributes);
        for (var i = 0; i < keys.length; i++) {
            element.setAttribute(keys[parseInt(i.toString(), 10)], attributes[keys[parseInt(i.toString(), 10)]]);
        }
    }
    exports.setAttribute = setAttribute;
    function createSvgElement(elementType, attribute) {
        var element = document.createElementNS('http://www.w3.org/2000/svg', elementType);
        setAttribute(element, attribute);
        return element;
    }
    exports.createSvgElement = createSvgElement;
    function createMeasureElements() {
        var measureElement = 'barcodeMeasureElement';
        if (!window["" + measureElement]) {
            var divElement = createHtmlElement('div', {
                id: 'barcodeMeasureElement', class: 'barcodeMeasureElement',
                style: 'visibility:hidden ; height: 0px ; width: 0px; overflow: hidden;'
            });
            var text = createHtmlElement('span', { 'style': 'display:inline-block ; line-height: normal' });
            divElement.appendChild(text);
            var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
            svg.setAttribute('xlink', 'http://www.w3.org/1999/xlink');
            divElement.appendChild(svg);
            var tSpan = document.createElementNS('http://www.w3.org/2000/svg', 'text');
            tSpan.setAttributeNS('http://www.w3.org/XML/1998/namespace', 'xml:space', 'preserve');
            svg.appendChild(tSpan);
            window["" + measureElement] = divElement;
            window["" + measureElement].usageCount = 1;
            document.body.appendChild(divElement);
        }
        else {
            window["" + measureElement].usageCount += 1;
        }
    }
    exports.createMeasureElements = createMeasureElements;
});