How to automatic resize tinyMCE?

后端 未结 12 1484
小蘑菇
小蘑菇 2020-12-01 09:03

I have a TinyMCE that is set over a TextArea, and I want this editor area to ocuppy all the space of its parent div, all times.

I have a JS function that get the cur

12条回答
  •  青春惊慌失措
    2020-12-01 09:47

    This is an old question, but apparently it still drags a lot of attention nowadays (Second half of 2020).

    Sadly, with the release of the TinyMCE v5, most of the workarounds I found simply do not work anymore. I am sure they worked once, but every TinyMCE release seems to bring new "constrainings" that cripple those workarounds...

    Without making it a discussion, I believe it is the cost of evolution. For an old product like the TinyMCE, it is incredible to see it is still around and kicking, staying way above the competition. It is by far one of the most efficient and flexible solutions for all environments, including mobile and for those new languages and frameworks that born since (which seems to be a trend lately, with new ones coming out of the blue every day).

    So, with that in my mind, and after so many (failed) attempts to make most of the proposed solutions work, I decided to dig into the source code (TinyMCE v5.4) to better understand it. What I found was a much superior product overall, and that the solution everyone has been looking for is much simpler to implement than I was anticipating.

    With no further delay, here my solution that simply works. It implements an editor that takes the entire document area (or whatever area you want), which WILL resize with the browser, requiring NO script, NO hack, and NO trick that could cause cross-browsing issues. Here's how:

    1. Give to your and DOM objects the missing properties of size and adjust the spacing accordingly to your needs:
    html, body {
       width    : 100%;
       height   : 100%;
       margin   : 0 !important;
       padding  : 0 !important;
       overflow : hidden;  /* Required if you want to have the editor taking the entire page. */
                           /* Otherwise, set as you need it. */
    }
    
    1. TinyMCE suggests the