Last active
September 16, 2019 11:16
-
-
Save longlostnick/5633086 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
this.editor = new wysihtml5.Editor("textarea"); | |
this.editor.observe("load", function () { | |
var $iframe = $(this.composer.iframe); | |
var $body = $(this.composer.element); | |
$body | |
.css({ | |
'min-height': 0, | |
'line-height': '20px', | |
'overflow': 'hidden', | |
}) | |
.bind('keypress keyup keydown paste change focus blur', function(e) { | |
var height = Math.min($body[0].scrollHeight, $body.height()); | |
// a little extra height to prevent spazzing out when creating newlines | |
var extra = e.type == "blur" ? 0 : 20 ; | |
$iframe.height(height + extra); | |
}); | |
}); |
awesome piece of code, thanx for sharing.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't forget to set a default
height
on iframe body for it to work otherwise thescrollHeight
is miscalculated.