JSFiddle - React, Tailwind, and code Playground
HTML
<form>
<input id="textbox" type="text">
</form>
JavaScript
/**
* jQuery auto-correct plugin
*
* Version 2.0
*
* Copyright (c) 2012 Amit Badkas <[email protected]>
*
* Dual licensed under the MIT (MIT-LICENSE.txt) and GPL (GPL-LICENSE.txt) licenses
*
* @URL http://www.sanisoft.com/blog/2009/06/22/jquery-auto-correct-plugin/
*
* @Example example.html
*/
jQuery.fn.autocorrect = function(options)
{
// If plugin attached to text/textarea field then don't need to proceed further
if ("text" != jQuery(this).attr("type") && !jQuery(this).is("textarea"))
{
return;
}
// Default parameters for plugin with some default corrections
var defaults = {
corrections: {
teh: "the",
gr8: "great",
taht: "that",
ur : "you are",
arent: "are not"
}
};
// Merge corrections passed at run-time
if (options && options.corrections)
{
options.corrections = jQuery.extend(defaults.corrections, options.corrections);
}
// Merge options passed at run-time
var opts = jQuery.extend(defaults, options);
// Function used to get caret's position
getCaretPosition = function(oField)
{
// Initialize
var iCaretPos = 0;
// IE Support
if (document.selection)
{
// To get cursor position, get empty selection range
var oSel = document.selection.createRange();
// Move selection start to 0th position
oSel.moveStart("character", 0 - oField.value.length);
// The caret position is selection length
iCaretPos = oSel.text.length;
}
// Firefox support
else if (oField.selectionStart || oField.selectionStart == "0")
{
iCaretPos = oField.selectionStart;
}
// Return results
return (iCaretPos);
}
// Function used to set caret's position
function setCaretPosition (oField, iCaretPos)
{
// IE...