Question

I have come across strange behavior with htmlpurifier:

If I have a compound border definition like

border: solid 10px rgb(00,00,00);

It works fine. Now if I have the border split up in subgroups like this:

border-style: solid;
border-width: 10px;
border-color: rgb(00,00,00);

htmlpurifier drops the color altogether, leaving me with transparent borders (which is my default behaviour when no inline style color is defined).

To add to the strangeness, doing like this below works fine:

border-style: solid;
border-width: 10px;
border-color: #000000;

The problem is that even if I set the border-color to a hex value with jQuery, the browser (chrome, firefox) still renders it as an rgb value, which is then dropped upon save.

UPDATE

And it gets odder... this behaviour is only on IMG tags receiving a border-color, if I do the same operation on a DIV tag it works without a problem.

Was it helpful?

Solution

I solved my problem by creating a compound border attribute every time I set the border color, like this:

        change: function(hex) {
            //console.log(hex + ' - ' + opacity);           
            var curObj = window.curObj; 
            var inner = '#' + $(curObj).attr("id") + ' .object_inner';
            $(inner).css('border-color', hex);

            //hack for chrome to get around htmlpurifier bug dropping border-color defined in rgb on IMG tags.
            var border_all = $(inner).css('border');

            if (border_all == '') { //ff returns empty string so we'll have to uild our own compound object
                var width = $(inner).css('border-top-width');
                var color = $(inner).css('border-top-color');
                $(inner).css('border','solid '+width+' ' + color);
            }
            else { //but for chrome it is enough to pull the compound out, then set it hard. The browser does the work.
                $(inner).css('border',border_all);
            }
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top