( function ( $ ) {
if ( document.selection && document.selection.createRange ) {
// On IE, patch the focus() method to restore the windows' scroll position
- // (bug 32241)
+ // (T34241)
$.fn.extend( {
focus: ( function ( jqFocus ) {
return function () {
/**
* Helper function to get an IE TextRange object for an element
+ *
+ * @param {HTMLElement} element
+ * @return {TextRange}
*/
- function rangeForElementIE( e ) {
- if ( e.nodeName.toLowerCase() === 'input' ) {
- return e.createTextRange();
+ function rangeForElementIE( element ) {
+ var sel;
+ if ( element.nodeName.toLowerCase() === 'input' ) {
+ return element.createTextRange();
} else {
- var sel = document.body.createTextRange();
- sel.moveToElementText( e );
+ sel = document.body.createTextRange();
+ sel.moveToElementText( element );
return sel;
}
}
* Helper function for IE for activating the textarea. Called only in the
* IE-specific code paths below; makes use of IE-specific non-standard
* function setActive() if possible to avoid screen flicker.
+ *
+ * @param {HTMLElement} element
*/
function activateElementOnIE( element ) {
if ( element.setActive ) {
- element.setActive(); // bug 32241: doesn't scroll
+ element.setActive(); // T34241: doesn't scroll
} else {
$( element ).focus(); // may scroll (but we patched it above)
}
fn = {
/**
* Get the contents of the textarea
+ *
+ * @return {string}
*/
getContents: function () {
return this.val();
},
/**
* Set the contents of the textarea, replacing anything that was there before
+ *
+ * @param {string} content
*/
setContents: function ( content ) {
this.val( content );
/**
* Get the currently selected text in this textarea. Will focus the textarea
* in some browsers (IE/Opera)
+ *
+ * @return {string}
*/
getSelection: function () {
var retval, range,
* Inserts text at the beginning and end of a text selection, optionally
* inserting text at the caret when selection is empty.
*
+ * @param {Object} options Options
* FIXME document the options parameters
+ * @return {jQuery}
*/
encapsulateSelection: function ( options ) {
return this.each( function () {
* Do the splitlines stuff.
*
* Wrap each line of the selected text with pre and post
+ *
+ * @param {string} selText Selected text
+ * @param {string} pre Text before
+ * @param {string} post Text after
+ * @return {string} Wrapped text
*/
function doSplitLines( selText, pre, post ) {
var i,
// IE
// Note that IE9 will trigger the next section unless we check this first.
- // See bug 35201.
+ // See bug T37201.
activateElementOnIE( this );
if ( context ) {
*
* Will focus the textarea in some browsers (IE/Opera)
*
+ * @param {Object} options Options
* FIXME document the options parameters
+ * @return {number} Position
*/
getCaretPosition: function ( options ) {
function getCaret( e ) {
var caretPos = 0,
endPos = 0,
preText, rawPreText, periText,
- rawPeriText, postText, rawPostText,
+ rawPeriText, postText,
// IE Support
preFinished,
periFinished,
// IE doesn't properly report non-selected caret position through
// the selection ranges when textarea isn't focused. This can
// lead to saving a bogus empty selection, which then screws up
- // whatever we do later (bug 31847).
+ // whatever we do later (T33847).
activateElementOnIE( e );
preFinished = false;
// Load the text values we need to compare
preText = rawPreText = preRange.text;
periText = rawPeriText = periRange.text;
- postText = rawPostText = postRange.text;
+ postText = postRange.text;
/*
* Check each range for trimmed newlines by shrinking the range by 1
postFinished = true;
} else {
postRange.moveEnd( 'character', -1 );
- if ( postRange.text === postText ) {
- rawPostText += '\r\n';
- } else {
+ if ( postRange.text !== postText ) {
postFinished = true;
}
}
return getCaret( this.get( 0 ) );
},
/**
+ * @param {Object} options options
* FIXME document the options parameters
+ * @return {jQuery}
*/
setSelection: function ( options ) {
return this.each( function () {
* Scroll a textarea to the current cursor position. You can set the cursor
* position with setSelection()
*
- * @param {boolean} options Whether to force a scroll even if the caret position
- * is already visible. Defaults to false
- *
- * FIXME document the options parameters (function body suggests options.force is a boolean, not options itself)
+ * @param {Object} options options
+ * @cfg {boolean} [force=false] Whether to force a scroll even if the caret position
+ * is already visible.
+ * FIXME document the options parameters
+ * @return {jQuery}
*/
scrollToCaretPosition: function ( options ) {
function getLineLength( e ) {