jquery-notebook
jquery-notebook copied to clipboard
Method to check if notebook is empty
I want to request some new feature.
Currently I can't find a way to check if notebook is empty.
if (/^\s*$/.test($(this).text())) {
} else {
}
You are using this to set placeholder, but this is not enough for checking content because It can return Your text here...
this is how I'm checking inside my function. note whitespaces
if (/^\s*$/.test(form.find('.jquery-notebook').text()) || form.find('.jquery-notebook').text() == ' Your text here... ') {
alert(1)
} else {
alert(2)
}
probably this is better to be done with test
but I don't know anything about regEx
also I'm writing too much issues here, So I'll merge another feature request here and you decide if this needs to be implemented. What about disabling notebook. You know, sometimes it takes time for ajax to complete request (especially when uploading images parallely) so usually one would disable textarea and upon complete reenable it.
The trick here is to check if either the .placeholder
element exists or if the editor itself is empty.
Consider this code:
$.fn.isEmpty = function() {
if (($(this).find('.placeholder').length > 0) || (/^\s*$/.test($(this).text())) ) {
return true;
} else {
return false;
};
};
Simple use of the function:
Add to HTML:
<a id="test" href="#">Test if empty</a>
Add to $(document).ready
$('#test').click( function() {
if($('.editor').isEmpty()) {
console.log("Empty");
} else {
console.log("Not empty");
};
});
Thanks, this makes sense
@krilor, are you planning to issue a pull request for the changes you made, or are you keeping them local to your repository?