(function ($) {
$.fn.fakeTextbox = function () {
return this.each(function () {
var $me = $(this),
cursorTimer,
$tb = $('');
if ($me.data('ftbftw')) {
console.log('already initialized');
return;
}
$me.data('ftbftw', 1);
$tb.insertAfter($me);
function appendCaret(toHere, position, selStart, selEnd) {
if (position === selStart) {
toHere += "
";
}
if (position === selEnd) {
toHere += "
";
}
return toHere;
}
function syncTextbox() {
var tbVal = $tb.val().replace('<', '<');
var tbLen = tbVal.length;
var selStart = $tb.get(0).selectionStart;
var selEnd = $tb.get(0).selectionEnd;
var newOut = '
';
for (var i = 0; i < tbLen; i++) {
newOut = appendCaret(newOut, i, selStart, selEnd);
newOut += tbVal[i];
}
$me.html(colorize(appendCaret(newOut, i, selStart, selEnd) + '