set-caret-position
Advanced tools
Comparing version 1.0.0 to 2.0.0
22
index.js
module.exports = function (inputField, caretPos) { | ||
if (inputField != null) { | ||
if (inputField[0].createTextRange) { | ||
var range = inputField[0].createTextRange(); | ||
range.move('character', caretPos); | ||
range.select(); | ||
if (inputField.createTextRange) { | ||
var range = inputField.createTextRange(); | ||
range.move('character', caretPos); | ||
range.select(); | ||
} else { | ||
if (inputField.selectionStart || $(inputField).selectionStart === | ||
0) { | ||
inputField.focus(); | ||
inputField.setSelectionRange(caretPos, caretPos); | ||
} else { | ||
if (inputField[0].selectionStart || $(inputField)[0].selectionStart === | ||
0) { | ||
inputField[0].focus(); | ||
inputField[0].setSelectionRange(caretPos, caretPos); | ||
} else { | ||
inputField[0].focus(); | ||
} | ||
inputField.focus(); | ||
} | ||
} | ||
}; |
{ | ||
"name": "set-caret-position", | ||
"version": "1.0.0", | ||
"description": "Set caret to position in input area", | ||
"version": "2.0.0", | ||
"description": "Move cursor to beginning of line below", | ||
"main": "index.js", | ||
@@ -22,3 +22,4 @@ "scripts": { | ||
} | ||
], "license": "MIT" | ||
], | ||
"license": "MIT" | ||
} |
#set-caret-position | ||
Selection or full line of text if nothing selected. | ||
Move cursor to beginning of line below. |
13
test.js
var setCaretPosition = require('./index.js'); | ||
setCaretPosition(); | ||
var element = { | ||
range: { | ||
move: function () { | ||
}, | ||
select: function () { | ||
} | ||
}, | ||
createTextRange: function () { | ||
return this.range | ||
} | ||
}; | ||
setCaretPosition(element); | ||
console.log('Done testing. All good'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1336
28