Skip to content

Instantly share code, notes, and snippets.

@OneHoopyFrood
Created April 21, 2016 22:58
Show Gist options
  • Save OneHoopyFrood/36452897659016176738adda1fd4f4e2 to your computer and use it in GitHub Desktop.
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/
(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();
@OneHoopyFrood
Copy link
Author

Oops, can be buggy. Type quickly and hit enter a bunch and it has a tendency to forget the newline...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment