loopj/jquery-tokeninput — pull request #323 by dmagliola (2012-05-31 10:49:39+00:00)
Title: Adding a "context" setting, to use tokenInput inside floating dialogs.

When you use a tokenInput control inside a jQuery UI dialog (or something that behaves similarly), there are a few issues with the "dropdown". If you move the dialog around while displaying the dropdown, the dropdown remains in place. Also, it's fairly easy to get to the point where you dismiss the dialog but the dropdown remains visible in the page forever.

To solve this, I added the concept of a "context" element. When it's null, the context is the body. But if it's not null, then the dropdown gets added to that context element, instead of the body, and when showing it, the absolute offsets are calculated against this context, instead of against the page. That way, the dropdown is positioned correctly, follows the context around, and if the context is killed, the dropdown is killed.

A small side effect of that is that your context needs to be positioned (relative/absolute), but that normally happens naturally anyway.

Admittedly, "context" is probably not the clearest name for it, but I believe the concept is solid, and it solved these two problems for me, while being unobtrusive if you don't need it.