diff options
author | Robert Speicher <rspeicher@gmail.com> | 2016-02-02 00:55:00 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2016-02-02 01:00:03 +0300 |
commit | 933834c4a60610710fc949daa2e15531c2c45780 (patch) | |
tree | 7b312b52c0cca80a881241866c3e43119ca235f9 /app/assets/javascripts/behaviors | |
parent | ea11f0218a0cb8c23091965989a5b0875fd1daae (diff) |
Allow manual resize of js-autosize textareas
First, the autosize library was being too controlling and removed the
`resize` property from any elements to which it was attached, removing
the drag handle.
Second, we detect when the user manually resizes an autosize textarea,
and then remove the autosize behavior from it and increase its
max-height.
This should allow for the best of both worlds.
Closes #12832
Diffstat (limited to 'app/assets/javascripts/behaviors')
-rw-r--r-- | app/assets/javascripts/behaviors/autosize.js.coffee | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/app/assets/javascripts/behaviors/autosize.js.coffee b/app/assets/javascripts/behaviors/autosize.js.coffee index b32072e61ee..a072fe48a98 100644 --- a/app/assets/javascripts/behaviors/autosize.js.coffee +++ b/app/assets/javascripts/behaviors/autosize.js.coffee @@ -1,4 +1,22 @@ +#= require jquery.ba-resize #= require autosize $ -> - autosize($('.js-autosize')) + $fields = $('.js-autosize') + + $fields.on 'autosize:resized', -> + $field = $(@) + $field.data('height', $field.outerHeight()) + + $fields.on 'resize.autosize', -> + $field = $(@) + + if $field.data('height') != $field.outerHeight() + $field.data('height', $field.outerHeight()) + autosize.destroy($field) + $field.css('max-height', window.outerHeight) + + autosize($fields) + autosize.update($fields) + + $fields.css('resize', 'vertical') |