jquery.byteLimit: Partial rewrite to fix logic errors
* Previously it was hooking into the keypress event, this meant
that it had to do all sorts of calculation to figure out what
the string length would be *after* the to-be-pressed key
is allowed to be pressed. This sounds trivial, but is quite the
contrary. First of all are control, alt, shift etc. those were
covered.
What wasn't covered and imho can't be realistically covered
without bugs is: copy/paste, drag/drop, text selection and
replacing or removing more at once. Or even a combination of the
above. And then there is custom insert methods such as Narayam,
where the character will not be literally inserted at all.
Therefore I've changed it to instead listen to *after* the insert.
and if necessary undo the last (one or more) characters until the
byteLimit is satisfied. This works much more stable. Still very
fast and not noticeable to the user.
This also fixes the bug where when the limit is reached, you
select all and type something else, you couldn't because it would
prevent the keypress since the limit is reached.
* Updated documentation comments.
* Updated unit tests to simulate onkeyup instead of onkeypress.
- hasLimit option in byteLimitTest() was redundant, using limit
directly, instead of duplicating it twice.
- Added more comments and better test names. Tests themselves
have not changed.
- Removed redundant tests at the bottom that no longer make sense
in the new version (and were broken) since the property is
now always unset instead of just if there is a callback.
The native limit must not interfere.
Change-Id: I9ace3ab79f488d24ad13baace32118c151c06347