I implemented a previous answer given here, and now I need to automatically wrap the word around the line instead of always having to manually press the enter key. Any ideas? I'm having quite a bit of trouble with this.
Code:
jQuery('#gift-message-whole-message').on('keypress', function (event) {
var text = jQuery('#gift-message-whole-message').val();
var lines = text.split('\n');
var currentLine = this.value.substr(0, this.selectionStart).split('\n').length;
if (event.keyCode == 13) {
if (lines.length >= jQuery(this).attr('rows')) return false;
} else {
if (lines[currentLine - 1].length >= jQuery(this).attr('cols')) {
return false;
}
}
});