Refactor logic from link function into controller.

This is a preliminary attempt to refactor the logic of the directive into a controller.  Aside from also cleaning up some jsHint warnings, this does not change any functionality of the directive (at least not intentionally).  **This change is barely tested and I do not expect it to be merged.** I'm just looking for some other opinions.  See #54 for an explanation of why this change might be a good idea.