hexonaut / haxe-dom

A cross-platform implementation of the DOM. Built to reduce duplicate code across server and client.
MIT License
47 stars 4 forks source link

addClass() and removeClass() seem to work in js dom but not in neko #29

Closed cambiata closed 9 years ago

cambiata commented 9 years ago

Hi Sam!

It seem to me that the DomTools addClass() and removeClass() methods only works as expected when used in js dom. When I try using them in a neko context, they do nothing. Is this a bug, or am I doing something wrong?

In the example below, in js I get

<div class="testclass1 testclass2">Text ind childDiv.</div>

but in neko I get

<div class="testclass1">Text ind childDiv.</div>

Here's my example:

class Main  {
    static function main() 
    {
        // --------------------- Setting up things...
        var doc: Document = null;
        var parentDiv:Element = null;
        #if js
            doc = Browser.document;
        #else // neko
            var indexHtml = '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"/><title>hxdom-test</title><meta name="description" content="" /></head><body><div id="parentDiv">Text in parentDiv</div></body></html>';
            doc  = new Parser(new BasicContentSink()).parse(indexHtml);
        #end
        parentDiv = doc.getElementById('parentDiv');                
        var childDiv:EDiv = new EDiv();     
        childDiv.addText('Text ind childDiv.');     

        // --------------------- Here's the problem!

        childDiv.setAttr('class', 'testclass1');    // <- This works in neko and js
        childDiv.addClass('testclass2');            // <- This works only in js, not in neko

        parentDiv.appendChild(childDiv.node);

        #if neko
            var html = new Serializer().serializeToString(doc).htmlUnescape();
            trace(html);
            //sys.io.File.saveContent('test-index.html', html);
        #end                
    }
}
hexonaut commented 9 years ago

Yes that appears to be a bug. To get around it for now you should work with the classes via addClass, removeClass only.

cambiata commented 9 years ago

Works correctly now.