This function works:
function refreshCodeMirror(){
$("textarea").each(function(){
var codeMirror = $(this).data('codeMirror');
setTimeout(function(codeMirror){
return function () {
codeMirror.refresh();
}
}(codeMirror), 10)
});
}
But when I tried to simplify it to this:
function refreshCodeMirror(){
$("textarea").each(function(){
var codeMirror = $(this).data('codeMirror');
setTimeout(codeMirror.refresh, 10)
});
}
The simplification does not work.
Some (possibly irrelevant) context:
The refreshCodeMirror function is being called in the onclick for a bootstrap tab-header within a django template:
<div class="row">
<div class="col-md-12">
<ul class="nav nav-tabs" role="tablist">
{% for field in form_tab_fields %}
<li role="presentation"{% if forloop.first %} class="active"{% endif %}>
<a class="tab-header" href="#{{ field.id_for_label }}_tab" data-toggle="tab" onclick="refreshCodeMirror()">{{ field.label_tag }}</a>
</li>
{% endfor %}
</ul>
<div class="tab-content">
{% for field in form_tab_fields %}
<div role="tabpanel"
class="form-group tab-pane{% if forloop.first %} active{% endif %}"
id="{{ field.id_for_label }}_tab">
{{ field }}
{{ field.errors }}
</div>
{% endfor %}
</div>
</div>
</div>
Everything works fine with the first function above and, while I would like to remove all the redundant refresh calls, they don't seem to matter and when I use a single text area (by passing the element id), the working function above stops working.