Adding selection support

The multiple commits are caused by me uploading code via Github. I will rebase it all before I merge. 
Two small nits: Please order the variables alphabetically and write the variable names in [camelCase](https://en.wikipedia.org/wiki/Naming_convention_(programming)#JavaScript).