Full Code of ro31337/jquery.ns-autogrow for AI

master 1e7000618bcc cached
11 files
16.2 KB
4.5k tokens
1 requests
Download .txt
Repository: ro31337/jquery.ns-autogrow
Branch: master
Commit: 1e7000618bcc
Files: 11
Total size: 16.2 KB

Directory structure:
gitextract_g2lshzrk/

├── .gitignore
├── .npmignore
├── README.md
├── bower.json
├── demo/
│   ├── index.html
│   ├── script.js
│   └── style.css
├── dist/
│   └── jquery.ns-autogrow.js
├── gulpfile.coffee
├── package.json
└── src/
    └── jquery.ns-autogrow.coffee

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
node_modules


================================================
FILE: .npmignore
================================================
bower_components/
bower.json
node_modules/
npm-debug.log
gulpfile.cofee
src/
.github


================================================
FILE: README.md
================================================
### Automatically adjust textarea width/height based on user input.
#### Non-sucking version, still works great and used by a lot of people with no issues! Yes, it is old, but it works!


The only reason I wrote this jQuery plugin is that other plugins suck. They are wide-spread, but outdated and buggy.

Advantages of jquery.ns-autogrow:

* Grows vertically, horizontally or both
* Correctly handles 2 or more spaces
* Copies more css and font styles to shadow div
* Correctly handles long words on one line
* Flickering can be disabled on Enter
* Doesn't add more than one handler to textarea
* Handles textarea scrollbar if any
* Improved support of special characters

## Download
Run one of these commands in your bash according to your needs.

`git clone https://github.com/ro31337/jquery.ns-autogrow.git`

`bower install jquery.ns-autogrow`

`npm install jquery.ns-autogrow`

Or download the latest version from the [releases](https://github.com/ro31337/jquery.ns-autogrow/releases) page.

### Options

You can provide multiple options to autogrow like:

```
  $('.example2 textarea').autogrow({vertical: true, horizontal: false});
```

List of options:

Option | Description
-------|------------
vertical | (true/false) - Enable/Disable vertical autogrow (true by default)
horizontal | (true/false) - Enable/Disable horizontal autogrow (true by default)
postGrowCallback | Post grow callback. Executes after dimensions of textarea have been adjusted.
flickering | (true/false) - Enable/Disable flickering. If flickering is disabled, extra line will be added to textarea. Flickering is _enabled_ by default.

There are few more options reserved for debugging purposes. All debugging options start with `debug` prefix:

Option | Description
-------|------------
debugx | X position of shadow element (-10000 by default)
debugy | Y position of shadow element (-10000 by default)
debugcolor | Color of shadow element (yellow by default)


### Demo

[Click here](http://htmlpreview.github.io/?https://raw.githubusercontent.com/ro31337/jquery.ns-autogrow/master/demo/index.html)

### Plans:

* Test and support arabic languages

### :heart: Like it? :heart:

:star: Star it! :star:

### The MIT License (MIT)

The MIT License (MIT)

Copyright (c) 2015 Roman Pushkin

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


================================================
FILE: bower.json
================================================
{
  "name": "jquery.ns-autogrow",
  "description": "Automatically adjust textarea height based on user input. Non-sucking version.",
  "main": "dist/jquery.ns-autogrow.js",
  "keywords": [
    "autogrow",
    "textarea",
    "form",
    "autosize",
    "ui",
    "jquery-plugin",
    "ecosystem:jquery"
  ],
  "author": "Roman Pushkin <roman.pushkin@gmail.com>",
  "homepage": "https://github.com/ro31337/jquery.ns-autogrow",
  "license": "MIT",
  "ignore": [
    "**/.*",
    "bower_components",
    "node_modules",
    "npm-debug.log",
    "gulpfile.coffee",
    "package.json",
    "src"
  ],
  "dependencies": {
    "jquery": "1"
  }
}


================================================
FILE: demo/index.html
================================================
<!DOCTYPE html>
<html>

  <head>
    <script data-require="jquery@2.1.4" data-semver="2.1.4" src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
    <script src="../dist/jquery.ns-autogrow.min.js"></script>
    <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css" />
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
  </head>

  <body>
    <div class="example1">
      <textarea placeholder="horizontal and vertical"></textarea>
    </div>

    <div class="example2">
      <textarea placeholder="vertical only"></textarea>
    </div>

    <div class="example3">
      <textarea placeholder="horizontal only"></textarea>
    </div>

    <div class="example4">
      <textarea placeholder="horizontal and vertical, no flickering"></textarea>
    </div>

  </body>

</html>


================================================
FILE: demo/script.js
================================================
$(function(){
  $('.example1 textarea').autogrow();
  $('.example2 textarea').autogrow({vertical: true, horizontal: false});
  $('.example3 textarea').autogrow({vertical: false, horizontal: true});
  $('.example4 textarea').autogrow({flickering: false});
});


================================================
FILE: demo/style.css
================================================
body { padding: 20px; }
textarea { min-width: 240px; font-size: 18px; }
.example3 textarea { min-height: 50px; }


================================================
FILE: dist/jquery.ns-autogrow.js
================================================
/*!
  Non-Sucking Autogrow 1.1.6
  license: MIT
  author: Roman Pushkin
  https://github.com/ro31337/jquery.ns-autogrow
*/
(function() {
  var getVerticalScrollbarWidth;

  (function($, window) {
    return $.fn.autogrow = function(options) {
      if (options == null) {
        options = {};
      }
      if (options.horizontal == null) {
        options.horizontal = true;
      }
      if (options.vertical == null) {
        options.vertical = true;
      }
      if (options.debugx == null) {
        options.debugx = -10000;
      }
      if (options.debugy == null) {
        options.debugy = -10000;
      }
      if (options.debugcolor == null) {
        options.debugcolor = 'yellow';
      }
      if (options.flickering == null) {
        options.flickering = true;
      }
      if (options.postGrowCallback == null) {
        options.postGrowCallback = function() {};
      }
      if (options.verticalScrollbarWidth == null) {
        options.verticalScrollbarWidth = getVerticalScrollbarWidth();
      }
      if (options.horizontal === false && options.vertical === false) {
        return;
      }
      return this.filter('textarea').each(function() {
        var $e, $shadow, fontSize, heightPadding, minHeight, minWidth, update;
        $e = $(this);
        if ($e.data('autogrow-enabled')) {
          return;
        }
        $e.data('autogrow-enabled');
        minHeight = $e.height();
        minWidth = $e.width();
        heightPadding = $e.css('lineHeight') * 1 || 0;
        $e.hasVerticalScrollBar = function() {
          return $e[0].clientHeight < $e[0].scrollHeight;
        };
        $shadow = $('<div class="autogrow-shadow"></div>').css({
          position: 'absolute',
          display: 'inline-block',
          'background-color': options.debugcolor,
          top: options.debugy,
          left: options.debugx,
          'max-width': $e.css('max-width'),
          'padding': $e.css('padding'),
          fontSize: $e.css('fontSize'),
          fontFamily: $e.css('fontFamily'),
          fontWeight: $e.css('fontWeight'),
          lineHeight: $e.css('lineHeight'),
          resize: 'none',
          'word-wrap': 'break-word'
        }).appendTo(document.body);
        if (options.horizontal === false) {
          $shadow.css({
            'width': $e.width()
          });
        } else {
          fontSize = $e.css('font-size');
          $shadow.css('padding-right', '+=' + fontSize);
          $shadow.normalPaddingRight = $shadow.css('padding-right');
        }
        update = (function(_this) {
          return function(event) {
            var height, val, width;
            val = _this.value.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n /g, '<br/>&nbsp;').replace(/"/g, '&quot;').replace(/'/g, '&#39;').replace(/\n$/, '<br/>&nbsp;').replace(/\n/g, '<br/>').replace(/ {2,}/g, function(space) {
              return Array(space.length - 1).join('&nbsp;') + ' ';
            });
            if (/(\n|\r)/.test(_this.value)) {
              val += '<br />';
              if (options.flickering === false) {
                val += '<br />';
              }
            }
            $shadow.html(val);
            if (options.vertical === true) {
              height = Math.max($shadow.height() + heightPadding, minHeight);
              $e.height(height);
            }
            if (options.horizontal === true) {
              $shadow.css('padding-right', $shadow.normalPaddingRight);
              if (options.vertical === false && $e.hasVerticalScrollBar()) {
                $shadow.css('padding-right', "+=" + options.verticalScrollbarWidth + "px");
              }
              width = Math.max($shadow.outerWidth(), minWidth);
              $e.width(width);
            }
            return options.postGrowCallback($e);
          };
        })(this);
        $e.change(update).keyup(update).keydown(update);
        $(window).resize(update);
        return update();
      });
    };
  })(window.jQuery, window);

  getVerticalScrollbarWidth = function() {
    var inner, outer, w1, w2;
    inner = document.createElement('p');
    inner.style.width = "100%";
    inner.style.height = "200px";
    outer = document.createElement('div');
    outer.style.position = "absolute";
    outer.style.top = "0px";
    outer.style.left = "0px";
    outer.style.visibility = "hidden";
    outer.style.width = "200px";
    outer.style.height = "150px";
    outer.style.overflow = "hidden";
    outer.appendChild(inner);
    document.body.appendChild(outer);
    w1 = inner.offsetWidth;
    outer.style.overflow = 'scroll';
    w2 = inner.offsetWidth;
    if (w1 === w2) {
      w2 = outer.clientWidth;
    }
    document.body.removeChild(outer);
    return w1 - w2;
  };

}).call(this);


================================================
FILE: gulpfile.coffee
================================================
gulp = require 'gulp'
del = require 'del'
coffee = require 'gulp-coffee'
coffeelint = require 'gulp-coffeelint'
header = require 'gulp-header'
uglify = require 'gulp-uglify'
rename = require 'gulp-rename'
pjson = require './package.json'
copyright = """
/*!
  Non-Sucking Autogrow #{pjson.version}
  license: #{pjson.license}
  author: Roman Pushkin
  #{pjson.homepage}
*/

"""

dest = 'dist/'
source = 'src/'
code =
  in: "#{source}*.coffee"
  out: "#{dest}"

gulp.task 'clean', ->
  del [dest + '*']

gulp.task 'build', ->
  gulp
    .src code.in
    .pipe coffeelint()
    .pipe coffeelint.reporter() # Show coffeelint errors
    .pipe coffeelint.reporter('fail') # Make sure it fails in case of error
    .pipe coffee()
    .pipe header copyright
    .pipe gulp.dest(code.out)

  gulp
    .src code.in
    .pipe coffeelint()
    .pipe coffeelint.reporter() # Show coffeelint errors
    .pipe coffeelint.reporter('fail') # Make sure it fails in case of error
    .pipe coffee()
    .pipe uglify()
    .pipe rename({ suffix: '.min' })
    .pipe header copyright
    .pipe gulp.dest(code.out)

gulp.task 'watch', ->
  gulp
    .watch code.in, ['build']

gulp.task 'default', ['clean', 'build', 'watch'], ->
  


================================================
FILE: package.json
================================================
{
  "name": "jquery.ns-autogrow",
  "version": "1.1.6",
  "description": "Automatically adjust textarea height based on user input. Non-sucking version.",
  "main": "dist/jquery.ns-autogrow.js",
  "keywords": [
    "autogrow",
    "textarea",
    "form",
    "autosize",
    "ui",
    "jquery-plugin",
    "ecosystem:jquery"
  ],
  "author": "Roman Pushkin <roman.pushkin@gmail.com>",
  "homepage": "https://github.com/ro31337/jquery.ns-autogrow",
  "license": "MIT",
  "repository": {
    "type": "git",
    "url": "https://github.com/ro31337/jquery.ns-autogrow.git"
  },
  "files": [
    "demo",
    "dist"
  ],
  "directories": {
    "example": "demo"
  },
  "bugs": {
    "url": "https://github.com/ro31337/jquery.ns-autogrow/issues"
  },
  "dependencies": {
    "jquery": "^1.12.4"
  },
  "devDependencies": {
    "coffee-script": "^1.10.0",
    "del": "^2.0.2",
    "gulp": "^3.9.0",
    "gulp-coffee": "^2.3.1",
    "gulp-coffeelint": "^0.5.0",
    "gulp-header": "^1.7.1",
    "gulp-rename": "^1.2.2",
    "gulp-uglify": "^1.4.1"
  }
}


================================================
FILE: src/jquery.ns-autogrow.coffee
================================================
(($, window) ->

  $.fn.autogrow = (options) ->
    options            ?= {}
    options.horizontal ?= true
    options.vertical   ?= true
    options.debugx     ?= -10000
    options.debugy     ?= -10000
    options.debugcolor ?= 'yellow'
    options.flickering ?= true
    options.postGrowCallback ?= ->
    options.verticalScrollbarWidth ?= getVerticalScrollbarWidth()

    if options.horizontal is false and options.vertical is false
      return

    @.filter('textarea').each ->

      $e = $(@)

      return if $e.data 'autogrow-enabled'
      $e.data 'autogrow-enabled'

      minHeight     = $e.height()
      minWidth      = $e.width()
      heightPadding = $e.css('lineHeight') * 1 || 0
      $e.hasVerticalScrollBar = ->
        $e[0].clientHeight < $e[0].scrollHeight

      $shadow = $('<div class="autogrow-shadow"></div>')
        .css (
          position:           'absolute'
          display:            'inline-block'
          'background-color': options.debugcolor
          top:                options.debugy
          left:               options.debugx
          'max-width':        $e.css 'max-width'
          'padding':          $e.css 'padding'
          fontSize:           $e.css 'fontSize'
          fontFamily:         $e.css 'fontFamily'
          fontWeight:         $e.css 'fontWeight'
          lineHeight:         $e.css 'lineHeight'
          resize:             'none'
          'word-wrap':        'break-word' )
        .appendTo document.body

      if options.horizontal is false
        # fix width of shadow div, so it will remain unchanged
        $shadow.css({'width': $e.width()})
      else
        # make sure we have right padding to avoid flickering
        fontSize = $e.css 'font-size' # => 20px
        $shadow.css('padding-right', '+=' + fontSize)
        $shadow.normalPaddingRight = $shadow.css 'padding-right'

      update = (event) =>
        val = @
          .value
          .replace /&/g,   '&amp;'
          .replace /</g,   '&lt;'
          .replace />/g,   '&gt;'
          .replace /\n /g, '<br/>&nbsp;'
          .replace /"/g,   '&quot;'
          .replace /'/g,   '&#39;'
          .replace /\n$/,  '<br/>&nbsp;'
          .replace /\n/g,  '<br/>'
          .replace(
            / {2,}/g
            (space) -> Array(space.length - 1).join('&nbsp;') + ' '
          )

        if /(\n|\r)/.test @.value
          val += '<br />'

          # no flickering, but one extra line will be added
          if options.flickering is false
            val += '<br />'

        $shadow.html val

        if options.vertical is true
          height = Math.max($shadow.height() + heightPadding, minHeight)
          $e.height height

        if options.horizontal is true
          $shadow.css 'padding-right', $shadow.normalPaddingRight

          # if it should not grow vertically and if we have scrollbar,
          # add additional padding to shadow div to emulate the scrollbar
          if options.vertical is false and $e.hasVerticalScrollBar()
            $shadow.css 'padding-right', "+=#{options.verticalScrollbarWidth}px"

          # outerWidth is width with padding
          width = Math.max $shadow.outerWidth(), minWidth
          $e.width width

        options.postGrowCallback $e

      $e.change  update
        .keyup   update
        .keydown update

      $(window).resize update
      update()

) window.jQuery, window

getVerticalScrollbarWidth = ->
  inner = document.createElement('p')
  inner.style.width = "100%"
  inner.style.height = "200px"

  outer = document.createElement('div')
  outer.style.position = "absolute"
  outer.style.top = "0px"
  outer.style.left = "0px"
  outer.style.visibility = "hidden"
  outer.style.width = "200px"
  outer.style.height = "150px"
  outer.style.overflow = "hidden"
  outer.appendChild (inner)

  document.body.appendChild (outer)
  w1 = inner.offsetWidth
  outer.style.overflow = 'scroll'
  w2 = inner.offsetWidth
  if w1 is w2
    w2 = outer.clientWidth

  document.body.removeChild (outer)
  w1 - w2
Download .txt
gitextract_g2lshzrk/

├── .gitignore
├── .npmignore
├── README.md
├── bower.json
├── demo/
│   ├── index.html
│   ├── script.js
│   └── style.css
├── dist/
│   └── jquery.ns-autogrow.js
├── gulpfile.coffee
├── package.json
└── src/
    └── jquery.ns-autogrow.coffee
Condensed preview — 11 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (18K chars).
[
  {
    "path": ".gitignore",
    "chars": 14,
    "preview": "node_modules\r\n"
  },
  {
    "path": ".npmignore",
    "chars": 85,
    "preview": "bower_components/\nbower.json\nnode_modules/\nnpm-debug.log\ngulpfile.cofee\nsrc/\n.github\n"
  },
  {
    "path": "README.md",
    "chars": 3382,
    "preview": "### Automatically adjust textarea width/height based on user input.\r\n#### Non-sucking version, still works great and use"
  },
  {
    "path": "bower.json",
    "chars": 640,
    "preview": "{\n  \"name\": \"jquery.ns-autogrow\",\n  \"description\": \"Automatically adjust textarea height based on user input. Non-suckin"
  },
  {
    "path": "demo/index.html",
    "chars": 860,
    "preview": "<!DOCTYPE html>\n<html>\n\n  <head>\n    <script data-require=\"jquery@2.1.4\" data-semver=\"2.1.4\" src=\"http://code.jquery.com"
  },
  {
    "path": "demo/script.js",
    "chars": 259,
    "preview": "$(function(){\n  $('.example1 textarea').autogrow();\n  $('.example2 textarea').autogrow({vertical: true, horizontal: fals"
  },
  {
    "path": "demo/style.css",
    "chars": 113,
    "preview": "body { padding: 20px; }\ntextarea { min-width: 240px; font-size: 18px; }\n.example3 textarea { min-height: 50px; }\n"
  },
  {
    "path": "dist/jquery.ns-autogrow.js",
    "chars": 4789,
    "preview": "/*!\n  Non-Sucking Autogrow 1.1.6\n  license: MIT\n  author: Roman Pushkin\n  https://github.com/ro31337/jquery.ns-autogrow\n"
  },
  {
    "path": "gulpfile.coffee",
    "chars": 1265,
    "preview": "gulp = require 'gulp'\r\ndel = require 'del'\r\ncoffee = require 'gulp-coffee'\r\ncoffeelint = require 'gulp-coffeelint'\r\nhead"
  },
  {
    "path": "package.json",
    "chars": 1044,
    "preview": "{\n  \"name\": \"jquery.ns-autogrow\",\n  \"version\": \"1.1.6\",\n  \"description\": \"Automatically adjust textarea height based on "
  },
  {
    "path": "src/jquery.ns-autogrow.coffee",
    "chars": 4168,
    "preview": "(($, window) ->\r\n\r\n  $.fn.autogrow = (options) ->\r\n    options            ?= {}\r\n    options.horizontal ?= true\r\n    opt"
  }
]

About this extraction

This page contains the full source code of the ro31337/jquery.ns-autogrow GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 11 files (16.2 KB), approximately 4.5k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!