
Extends the Element Type to include methods useful in managing inputs.
Uses String:tidy to clean up common special characters with their ASCII counterparts (smart quotes, elipse characters, stuff from MS Word, etc.).
$('myInput').tidy();
Returns the text of an input within a range.
$('myInput').getTextInRange(start, end);
Get the text selected in an input, returns a range (see Element:getTextInRange).
$('myInput').getSelectedText();
Returns the index of start of the selected text.
$('myInput').getSelectionStart();
Returns the index of end of the selected text.
$('myInput').getSelectionEnd();
Returns the range of what is selected within the element.
$('myInput').getSelectedRange();
{start: 2, end: 12}
Sets the caret at the given position.
$('myInput').setCaretPosition(pos);
$('myInput').setCaretPosition(3); $('myInput').setCaretPosition("end");
Returns the caret position.
$('myInput').getCaretPosition();
Selects text within a given range.
$('myInput').selectRange(start, end);
$('myInput').selectRange(2, 4); <input id="test" value="012345" /> $('test').selectRange(2, 4); //selects "23"
Inserts a value at the cursor location; if text is selected, it replaces this text.
$('myInput').insertAtCursor(value[, selectText]);
$('myInput').insertAtCursor("<br />"); $('myInput').insertAtCursor("type something here", true);
Inserts two strings around the selected text.
$('myInput').insertAroundCursor(options);
<input id="test" value="ninjas are the most dangerous thing in the world" /> //let's assume that the user selects the word "ninjas" $('test').insertAroundCursor({before: "<", after: ">", defaultMiddle: "tag-name"}); //value is now: //<ninjas> are the most dangerous thing in the world
© Linux.ria.ua, 2008-2024 |