ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • trumbowyg color picker bug
    DEV/other things 2024. 9. 4. 15:17

    Problem with color selection.

     

    trumbowyg.color.js

    // Original code
    
    function colorTagHandler(element, trumbowyg) {
        var tags = [];
    
        if (!element.style) {
            return tags;
        }
    
        // background color
        if (element.style.backgroundColor !== '') {
            var backColor = colorToHex(element.style.backgroundColor);
            if (trumbowyg.o.plugins.colors.colorList.indexOf(backColor) >= 0) {
                tags.push('backColor' + backColor);
            } else {
                tags.push('backColorFree');
            }
        }
    
        // text color
        var foreColor;
        if (element.style.color !== '') {
            foreColor = colorToHex(element.style.color);
        } else if (element.hasAttribute('color')) {
            foreColor = colorToHex(element.getAttribute('color'));
        }
        if (foreColor) {
            if (trumbowyg.o.plugins.colors.colorList.indexOf(foreColor) >= 0) {
                tags.push('foreColor' + foreColor);
            } else {
                tags.push('foreColorFree');
            }
        }
    
        return tags;
    }
    
    // fixed code
    function colorTagHandler(element, trumbowyg) {
        var tags = [];
        trumbowyg.o.plugins.colors.colorList = [];
    
        if (!element.style) {
            return tags;
        }
    
        // background color
        if (element.style.backgroundColor !== '') {
            var backColor = colorToHex(element.style.backgroundColor);
            if (trumbowyg.o.plugins.colors.colorList.indexOf(backColor) >= 0) {
                tags.push('backColor' + backColor);
            } else {
                tags.push('backColorFree');
            }
        }
    
        // text color
        var foreColor;
        if (element.style.color !== '') {
            foreColor = colorToHex(element.style.color);
        } else if (element.hasAttribute('color')) {
            foreColor = colorToHex(element.getAttribute('color'));
        }
        if (foreColor) {
            if (trumbowyg.o.plugins.colors.colorList.indexOf(foreColor) >= 0) {
                tags.push('foreColor' + foreColor);
            } else {
                tags.push('foreColorFree');
            }
        }
    
        return tags;
    }

    댓글

Designed by Tistory.