https://github.com/canop/taliner.js
Is the caret on the first line of the textarea ? On the last line ?
https://github.com/canop/taliner.js
Last synced: 5 months ago
JSON representation
Is the caret on the first line of the textarea ? On the last line ?
- Host: GitHub
- URL: https://github.com/canop/taliner.js
- Owner: Canop
- Created: 2014-07-07T15:06:00.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2019-09-19T11:40:20.000Z (almost 7 years ago)
- Last Synced: 2025-01-19T11:19:23.502Z (over 1 year ago)
- Language: HTML
- Size: 1.95 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# Why ?
Find if the caret is on the first line or on the last line of a textarea isn't easy. More details on why it's hard in [this StackOverflow question](http://stackoverflow.com/q/24605280/263525).
If you need this precise information, then this plugin might be handy.
**[Demonstration](http://dystroy.org/demos/taliner/demo.html)**
# How to use it ?
`$('#yourTextarea').taliner()` returns an object with three properties :
- caretOnFirstLine : a boolean telling if the caret is on the first line of the textarea.
- caretOnLastLine : a boolean too. Guess what it is.
- linesNumber : the total number of lines of text of the textarea.
# Does it really always work ?
Almost.
If a line ends with a space because of word wrapping and you click right to that line, you'll end to a position undistinguishable from the start of the following line.
I don't see any fix for that right now. if you have one, please contribute.
# Alternatives
There's a specification for a [CaretPosition](https://developer.mozilla.org/en-US/docs/Web/API/CaretPosition) in the browser.
But it's only available on Firefox.
# License
Public Domain. Use as you wish and at your own risk.