ericdrowell / KineticJS

KineticJS is an HTML5 Canvas JavaScript framework that extends the 2d context by enabling canvas interactivity for desktop and mobile applications.
http://www.kineticjs.com
3.98k stars 752 forks source link

.getParents() with filter function #931

Open moniuch opened 10 years ago

moniuch commented 10 years ago

Please implement Node.getParents() method with filter function as argument, much like Node.getChildren()

lavrton commented 10 years ago

What is use case? Container may have many children. But any node has only one parent. Search in all parent, grandparent, ...? I don't think this function is very useful.

moniuch commented 10 years ago

The use case is when an object is within many containers. The function is as much useful as its jQuery companion. I missed it just a minute ago. On May 20, 2014 11:15 AM, "Anton Lavrenov" notifications@github.com wrote:

What is use case? Container may have many children. But any node has only one parent. Search in all parent, grandparent, ...? I don't think this function is very useful.

— Reply to this email directly or view it on GitHubhttps://github.com/ericdrowell/KineticJS/issues/931#issuecomment-43603131 .

moniuch commented 10 years ago

Imagine having a main container (Group) consisting of other nested containers. They all receive clicks, but the handler has to check for an attribute (say: isEnabled) that is defined on the main container level only. How would I step up the container tree and stop at a given level?

The preferred way would be something like

    shape.getParents(function(node){
        return node.getClassName() === 'Group' && typeof node.getAttr('isEnabled') === true
    })`.

Agreed? Do you have a better solution?