NicEdit in Hidden Div is resized small
Asked Answered
R

8

7

I am trying to use the NicEdit editor for a textarea hidden in a div. When the user clicks a button, the targeted textarea's parent div is revealed. The width of the textarea is set to 100% of the parent div. The problem is that the parent div is hidden so the textrea has no width before the parent div is revealed. If I try to attach the NicEdit editor at the same time as revealing it's parent div, the editor appears tiny.

<script type="text/javascript">

function add_task_editor() {
        new nicEditor({buttonList : ['fontSize','bold','italic','underline','strikeThrough','subscript','superscript','ul','link']}).panelInstance('task_description');
    };

$('#trigger_it').click(function (e) {
 $('#parent_div').show();
 add_task_editor();

});
</script>
<div id="parent_div" style="display: none;">
<textarea id="task_description"></textarea>
</div>

Is there a way to fix this so that the editor's width is set to 100% of the parent div after it is loaded?

Russianize answered 28/7, 2012 at 21:25 Comment(0)
A
1

Of course, basically after the editor is created, inspect it to find it's ID or a class it has, and set it's width $('#editorsID').width('100%'); for example.

Or maybe find it's parent div's width in pixels and set it to that.

Anthodium answered 28/7, 2012 at 22:1 Comment(0)
P
13

In my case this worked with jquery:

new nicEditor().panelInstance('myArea');

$('.nicEdit-panelContain').parent().width('100%');
$('.nicEdit-panelContain').parent().next().width('100%');

Or to absolute witdh:

$('.nicEdit-panelContain').parent().width('400px');
$('.nicEdit-panelContain').parent().next().width('400px');
Pubes answered 17/8, 2012 at 6:59 Comment(0)
P
2

The answer by @Hans worked with me ... But I needed to add this as well to resize the div containing the text being edited (only the container around that div was being resized when not using the line below):

$('.nicEdit-main').width('100%');
Prelatism answered 4/10, 2013 at 1:43 Comment(0)
A
2
$('.nicEdit-panelContain').parent().width('100%');
$('.nicEdit-panelContain').parent().next()
    .width($('.nicEdit-panelContain').parent().width()-2);

Add "-2" to "width" if parent of textarea has prop "padding-left" or "padding-right".

Agentive answered 27/7, 2016 at 21:3 Comment(0)
S
2

This worked best for me:

new nicEditor().panelInstance('nic-me');
$('.nicEdit-panelContain').parent().width('100%');
$('.nicEdit-panelContain').parent().next().width('98%');
$('.nicEdit-main').width('100%');
Sharynshashlik answered 13/4, 2018 at 15:13 Comment(0)
A
1

Of course, basically after the editor is created, inspect it to find it's ID or a class it has, and set it's width $('#editorsID').width('100%'); for example.

Or maybe find it's parent div's width in pixels and set it to that.

Anthodium answered 28/7, 2012 at 22:1 Comment(0)
W
0

This solve my case! Thanks

$(document).ready(function(){
        bkLib.onDomLoaded(function() {
        new nicEditor({fullPanel : true, maxHeight:100}).panelInstance('myArea');
        $('.nicEdit-panelContain').parent().width('100%');
        $('.nicEdit-panelContain').parent().next().width('98%');
        $('.nicEdit-main').width('100%');
        });
    });
Willowwillowy answered 14/1, 2019 at 16:57 Comment(0)
M
0

for those who have the same problem, I optimized that and it looks completely normal:

$(document).ready(function(){
    bkLib.onDomLoaded(function() {
        new nicEditor({fullPanel : true}).panelInstance('myArea');
        $('.nicEdit-panelContain').parent().css({width:'100%', padding:"0"});
        $('.nicEdit-panelContain').parent().next().css({width:'100%', padding:"5px"});
        $('.nicEdit-main').css({width:'100%', padding:"0", minHeight:"80px"});
    });
});
Mutualize answered 6/6, 2019 at 7:27 Comment(0)
S
0

After trying multiple stuff on the panel resize.. this worked for me..

bkLib.onDomLoaded(function() {
    new nicEditor().panelInstance('textarea_id');
    document.querySelector('div[unselectable="on"]').setAttribute('style', '');
});

basically just removing the default width being set by nicEdit script on load and it should automatically adjust the panel width..

Sob answered 11/12, 2020 at 23:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.