all files / rich-text-editor/actions/ html-attributes.js

100% Statements 31/31
100% Branches 22/22
100% Functions 2/2
100% Lines 31/31
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   1822× 1822×     1819×   1822× 26× 70× 70×   65×   63×   60×   58×   57×     55× 55× 28×     27×              
define(["require", "exports"], function (require, exports) {
    "use strict";
    Object.defineProperty(exports, "__esModule", { value: true });
    function setAttributes(htmlAttributes, rte, isFrame, initial) {
        var target;
        if (isFrame) {
            var iFrame = rte.contentModule.getDocument();
            target = iFrame.querySelector('body');
        }
        else {
            target = rte.element;
        }
        if (Object.keys(htmlAttributes).length) {
            for (var _i = 0, _a = Object.keys(htmlAttributes); _i < _a.length; _i++) {
                var htmlAttr = _a[_i];
                if (htmlAttr === 'class') {
                    target.classList.add(htmlAttributes["" + htmlAttr]);
                }
                else if (htmlAttr === 'disabled' && htmlAttributes["" + htmlAttr] === 'disabled') {
                    rte.enabled = false;
                    rte.setEnable();
                }
                else if (htmlAttr === 'readonly' && htmlAttributes["" + htmlAttr] === 'readonly') {
                    rte.readonly = true;
                    rte.setReadOnly(initial);
                }
                else if (htmlAttr === 'style') {
                    target.setAttribute('style', htmlAttributes["" + htmlAttr]);
                }
                else if (htmlAttr === 'tabindex') {
                    rte.inputElement.setAttribute('tabindex', htmlAttributes["" + htmlAttr]);
                }
                else if (htmlAttr === 'placeholder') {
                    rte.placeholder = htmlAttributes["" + htmlAttr];
                    rte.setPlaceHolder();
                }
                else {
                    var validateAttr = ['name', 'required'];
                    if (validateAttr.indexOf(htmlAttr) > -1) {
                        rte.valueContainer.setAttribute(htmlAttr, htmlAttributes["" + htmlAttr]);
                    }
                    else {
                        target.setAttribute(htmlAttr, htmlAttributes["" + htmlAttr]);
                    }
                }
            }
        }
    }
    exports.setAttributes = setAttributes;
});