Skip to content

Instantly share code, notes, and snippets.

@xypaul
Created May 8, 2014 16:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save xypaul/efae27e0d0093d0746c3 to your computer and use it in GitHub Desktop.
Save xypaul/efae27e0d0093d0746c3 to your computer and use it in GitHub Desktop.
Fill container TinyMCE
html,body {
height: 100%;
background: blue;
}
.fill-div {
height: 100%;
width: 100%
}
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="TinyMCE addapts to container" />
<script src="http://code.jquery.com/jquery.min.js"></script>
<link href="http://getbootstrap.com/dist/css/bootstrap.css" rel="stylesheet" type="text/css" />
<script src="http://getbootstrap.com/dist/js/bootstrap.js"></script>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
<script src="//tinymce.cachefly.net/4.0/tinymce.min.js"></script>
</head>
<body>
<div class="fill-div">
</div>
</body>
</html>
// The magic config - http://www.tinymce.com/wiki.php/Configuration
var config = {};
config = $.extend(config, {
statusbar: false,
resize: false,
width: "100%",
height: '100%',
autoresize: true
});
function resize() {
setTimeout(function () {
// Main container
var max = $('.mce-tinymce')
.css('border', 'none')
.parent().outerHeight();
// Menubar
max += -$('.mce-menubar.mce-toolbar').outerHeight();
// Toolbar
max -= $('.mce-toolbar-grp').outerHeight();
// Random fix lawl - why 1px? no one knows
max -= 1;
// Set the new height
$('.mce-edit-area').height(max);
}, 200);
}
$(window).on('resize', function () {
resize();
});
// Setup plugins
config.toolbar = ["undo redo | styleselect | bold italic | alignleft aligncenter alignright | bullist numlist outdent indent "];
// Choose selector
config.selector = ".fill-div";
// Set content once initialized
config.init_instance_callback = function (editor) {
resize();
};
tinyMCE.init(config);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment