motion-kit/motion-kit — pull request #81 by colinta (2014-09-15 17:21:23+00:00)
Title: More selectors: prev, next, and nearest

`prev` and `next` only search siblings, fairly limited. `nearest` is awesome, though. It's roughly based on the **jquery-closest** plugin (https://github.com/fusionbox/jquery-nearest).

It's helpful when you have a bunch of containers that are repeated, so that the `motion_kit_id` of the container view will show up again and again.

```
UIView(id: :row)
- UILabel(id: :name)
- UIImageView(id: :avatar)
UIView(id: :row)
- UILabel(id: :name)
- UIImageView(id: :avatar)
UIView(id: :row)
- UILabel(id: :name)
- UIImageView(id: :avatar)
```

In the context of `:name`, `nearest(:avatar)` will return the expected `UIImageView`. In fact, that same view will be found as long as it is *anywhere inside :row*. e.g.

```
UIView(id: :row)
- UIView
- UILabel(id: :name)
- UIView
- UIImageView(id: :avatar)
```

The "nearest" algorithm searches in this order:

- self
- children
- siblings
- parent view, and it's children
- grandparent, it's children
- etc