#2196 Small fixes in ElemPeer.js

morokhovets Wed 16 Oct 2013

Hello,

I'm now working with javascript part of dom pod and found some minor issues.

  1. ElemPeer get and set methods are not complementary. get() uses this.elem[name] to access element's attributes while set() uses setAttribute. The problem is this.elem[name] does not return custom attributes. I changed this call to this.elem.getAttribute(name) and it works as it should.
  2. ElemPeer find and findAll have the same typo in the code. Argument function name is f, but it is also referred as func - clearly untested use cases.

I've tried to insert some code chunks here but failed with formatting. Cheatsheet does not help much :)

andy Wed 16 Oct 2013

Hey @morokhovets - thanks for reporting. The best way to get us patches is send a pull request on BitBucket:

https://bitbucket.org/fantom/fan-1.0

I've tried to insert some code chunks here but failed with formatting.

Indent all your code 2 spaces to mark as <pre> block.

SlimerDude Wed 16 Oct 2013

I find indenting spaces a bit of a chore and do this instead:

pre>

...code stuff here...

<pre

morokhovets Thu 17 Oct 2013

Now trying with pre

fan.dom.ElemPeer.prototype.find = function(self, f)
{
  var kids = this.children(self);
  for (var i=0; i<kids.length; i++)
  {
    var kid = kids[i];
    if (f.call(kid)) return kid;
    kid = kid.find(func);
    if (kid != null) return kid;
  }
  return null;
}

fan.dom.ElemPeer.prototype.findAll = function(self, f, acc)
{
  if (acc == null) acc = new Array();
  var kids = this.children(self);
  for (var i=0; i<kids.length; i++)
  {
    var kid = kids[i];
    if (f.call(kid)) acc.push(kid);
    kid.findAll(func, acc);
  }
  return acc;
}

Notice func references.

Looks like pre works! Thanks!

andy Mon 18 Nov 2013

FYI - this patch landed - thanks @morokhovets!

Login or Signup to reply.