summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/behaviors/autosize.js
blob: c62a4c5a45658c17dab95ef88124de98635f8674 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* eslint-disable func-names, space-before-function-paren, prefer-arrow-callback, no-var, consistent-return, padded-blocks, max-len */
/* global autosize */

/*= require jquery.ba-resize */
/*= require autosize */

(function() {
  $(function() {
    var $fields;
    $fields = $('.js-autosize');
    $fields.on('autosize:resized', function() {
      var $field;
      $field = $(this);
      return $field.data('height', $field.outerHeight());
    });
    $fields.on('resize.autosize', function() {
      var $field;
      $field = $(this);
      if ($field.data('height') !== $field.outerHeight()) {
        $field.data('height', $field.outerHeight());
        autosize.destroy($field);
        return $field.css('max-height', window.outerHeight);
      }
    });
    autosize($fields);
    autosize.update($fields);
    return $fields.css('resize', 'vertical');
  });

}).call(this);