davidfowl/JabbR — pull request #556 by dpatti (2012-07-29 20:50:51+00:00)
Title: Improve the automatic scrolling for rich content

Three notable instances were corrected here:

* When someone enters an image link, once that image loads the window may scroll
up past the bottom edge of the screen.
* When you join a room with images, as they load they will push the scroll up.
* When you paste content, it is later replaced with the full version from the
server, which causes chat to be scrolled up.

The latter of the three was the most simple case, and it involved simply placing
the ui.replaceMessage() function into the scrollIfNecessary wrapper.

In the case of the images, there was already a system in place to force scroll
after 850ms in the case of a new message; however, this was not working since it
required you to already be at the end of the chat scroll. A new method was added
that can be called to attach load event handlers to elements within those
messages which will correct the scroll position only if the user himself has not
touched it in the meantime.

Deciding which elements to attach the load event handler to is done in the
utility function expandableContent(), which uses a hard-coded list of selectors
to search for within the messages provided. Most rich content in JabbR has
hard-coded dimensions, but the one exception that I found in my testing was
images for obvious reasons. If there are more, they can be easily added to the
array. At the very least, the functionality will not regress as it was never
working in the first place.