Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var lastSpaceIndex = null;
- var lastLineBreak = 0;
- function checkLineLength (str) {
- var strLength = str.length;
- if(str.length === 0) {
- lastSpaceindex = 0;
- lastLineBreak = 0;
- }
- if (strLength % 30 === 0) {
- lastlineBreak = strLength;
- insertLineBreak(str, lastLineBreak);
- }
- console.log((strLength - lastLineBreak));
- if (((strLength - lastLineBreak) > 30)) {
- lastLineBreak = lastSpaceIndex;
- insertLineBreak(str, lastLineBreak - 1);
- }
- lastSpaceIndex = strLength;
- }
- function insertLineBreak (str, index) {
- var newStr = str.split("");
- newStr[index] = '\n';
- console.log(newStr.join(''))
- }
- document.addEventListener('keyup', function (evt) {
- if(evt.target.id === 'ta' && evt.keyCode === 13){
- lastLineBreak = evt.target.value.length;
- }
- if(evt.target.id === 'ta' && evt.keyCode === 32){
- checkLineLength(evt.target.value)
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement