I have summernote working on my website, as intended, with:
$('#summernote').summernote({
height: $(document).height() - ($("#Maintable").height() + $("#TblTop").height() + 60),
minHeight: null, // set minimum height of editor
maxHeight: null, // set maximum height of editor
focus: true,
toolbar: [
// [groupName, [list of button]]
['style', ['fontname', 'bold', 'italic', 'underline', 'clear']],
['font', ['strikethrough', 'superscript', 'subscript']],
['fontsize', ['fontsize', 'undo', 'redo']],
['color', ['color']],
['para', ['ul', 'ol', 'paragraph']],
['height', ['height']],
['insert', ['picture', 'video', 'table']],
['search', ['findnreplace', 'changecolor']]
],
buttons: {
changecolor: ChangeColorButton
}
});
However, when I call the following code in a function that gets called on window.onresize
, in order to change the height value, nothing happens. What should I do?
$('#summernote').summernote({
height: 100
});
From the documentation, it seems that summernote does not provide api to set the height after initialization. However, by inspecting the html structure of the created editor, the height, minHeight and maxHeight options are applied to a div with class="note-editable".
Summernote automatically populates the font dropdown with the available fonts that are given on fontNames option. This includes the font set on the current dom element. If you only want to display a specific list of fonts on the dropdown, you can set the addDefaultFonts option to false along with the fontNames option.
Summernote uses the Open Source libraries jQuery and Bootstrap, if you are using the Boostrap 3 or 4 versions of Summernote, or just jQuery if you use the Lite version of Summernote. Include the Following code in the head area of your HTML page. Don’t forget to change the file’s path if you downloaded summernote in a different folders.
You can initialize Summernote with summernote. Then You can use the editor API through the summernote method. This is an example code for inserting ‘hello world’ text. $('#summernote').summernote('editor.insertText', 'hello world')); It calls the editor module’s insertText method with ‘hello world’.
From the documentation, it seems that summernote does not provide api to set the height after initialization.
However, by inspecting the html structure of the created editor, the height
, minHeight
and maxHeight
options are applied to a div
with class="note-editable"
. So we set the height of this div
instead. Following code snippet show how to change the height of the editor after initialize.
$(document).ready(function() {
var t = $('#summernote').summernote(
{
height: 100,
focus: true
}
);
$("#btn").click(function(){
$('div.note-editable').height(150);
});
});
<!-- include libraries(jQuery, bootstrap) -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.js"></script>
<!-- include summernote css/js -->
<link href="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.9/summernote.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.9/summernote.js"></script>
<div id="summernote">Original height is 100. Click the button to change the height to 150</div>
<button id="btn">Change Height</button>
It can be done with JS only, but its a nasty workaround:
let summernoteOptions = {
height: 300
}
$('#summernote').summernote(summernoteOptions);
$(document).on('click', '#change', function(){
summernoteOptions.height = 100;
let content = $('#summernote').summernote('code');
$('#summernote').summernote('destroy');
$('#summernote').summernote(summernoteOptions);
$('#summernote').summernote('code', content);
});
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet">
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.js"></script>
<link href="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.9/summernote.css" rel="stylesheet">
<script src="http://cdnjs.cloudflare.com/ajax/libs/summernote/0.8.9/summernote.js"></script>
<div id="summernote">Some text...</div>
<button id="change">Change Height Button</button>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With