zackmdavis / Finetooth

an experimental discussion forum
MIT License
2 stars 0 forks source link

compute vote indices clientside #34

Closed zackmdavis closed 10 years ago

zackmdavis commented 10 years ago

@cookjw

This approach lets us register votes correctly in a way that was impossible under the old strategy (we would just send the text, and have the server try to infer what was actually select, but then if someone voted on a substring that appeared more than once in the votable item, the server would have no way of knowing which occurence was intended). The Selection and Range APIs offered by browsers didn't make this as easy as one might have hoped, but some hours of MDN/Google/StackOverflow/thinking-hard research revealed an acceptable solution (see getVoteSelectionIndices in finetooth.js): Ranges do know the DOM node (HTML tag or text-outside-of-a-tag) that they start and end in, and their position within that node (character offset in the case of a text node), so we can traverse the tags inside of the post's div, counting characters along the way, and taking note of the index where our Range (which we got from the user's selection) starts and ends.

Also, the voting feedback labels use Bootstrap styling now.

Please merge if you find these changes agreeable.