Skip to content

Commit

Permalink
code mirror size by textarea's rows and cols
Browse files Browse the repository at this point in the history
  • Loading branch information
sudosu committed Jun 21, 2014
1 parent 4ca4361 commit 93219c5
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion app/views/rails_admin/main/_form_code_mirrorml.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,41 @@
:locations => field.assets
}

= render 'form', form: form, field: field, field_type: :text_area, html_attributes: field.html_attributes.reverse_merge(:data => { :richtext => 'codemirror', :options => js_data.to_json })
editor_size = {
width: 'auto',
heigth: '300px',
}

if field.html_attributes[:cols]
if field.html_attributes[:cols].to_s.match('%')
editor_size[:heigth] = field.html_attributes[:cols]
else
editor_size[:heigth] = "#{field.html_attributes[:cols].to_i * 8}px"
end
end

if field.html_attributes[:rows]
if field.html_attributes[:rows].to_s.match('%')
editor_size[:heigth] = field.html_attributes[:rows]
else
editor_size[:heigth] = "#{field.html_attributes[:rows].to_i * 20}px"
end
end

- uniqid = "code_mirror_#{SecureRandom.hex(10)}"

:css
##{uniqid} .CodeMirror {
width: #{editor_size[:width]};
height: #{editor_size[:heigth]};
}

:javascript
$(document).on('click', '##{uniqid} .nav.nav-tabs li a', function(e){
$('#static_page_html_field .tab-content '+ $(this).attr('href') + ' .CodeMirror').each(function(i, el){
el.CodeMirror.refresh();
});
});

%div{id: uniqid}
= render 'form', form: form, field: field, field_type: :text_area, html_attributes: field.html_attributes.reverse_merge(:data => { :richtext => 'codemirror', :options => js_data.to_json })

0 comments on commit 93219c5

Please sign in to comment.