Created
April 21, 2016 22:58
-
-
Save OneHoopyFrood/36452897659016176738adda1fd4f4e2 to your computer and use it in GitHub Desktop.
Quick little script to cause a text area to contain bullets on each newline. Adapted from: http://jsfiddle.net/abhiagrawal87/m39xt/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
$.fn.bulletedTextArea = function() { | |
var ele = $(this); | |
var correctBlank = function() { | |
if (ele.val() === '' || ele.val() === '•') { | |
ele.val('• '); | |
} | |
} | |
this.focus(function() { | |
correctBlank(); | |
}); | |
this.keyup(function(event) { | |
var keycode = (event.keyCode ? event.keyCode : event.which); | |
if (keycode == '13') { | |
this.value += '• '; | |
} | |
var txtval = this.value; | |
for (i = 1; i <= 2; i++) { | |
if (txtval.substr(txtval.length - i) == '\n•'.substring(0, i)) { | |
this.value = txtval.substring(0, txtval.length - i); | |
} | |
} | |
correctBlank(); | |
}); | |
return this; | |
}; | |
})(jQuery); | |
$('#listtest').bulletedTextArea(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Oops, can be buggy. Type quickly and hit enter a bunch and it has a tendency to forget the newline...