Skip to content

Commit

Permalink
Merge pull request #2 from mike-engel/npm-availability
Browse files Browse the repository at this point in the history
Making textarea-autogrow ready for NPM.
  • Loading branch information
codingAspect committed Nov 8, 2015
2 parents 008fd07 + a8a822c commit 0e9dd5d
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 9 deletions.
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 Evyatar Rosner

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.
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,24 @@ A full explanation of the code can be found on my [blog post](http://codingaspec
bower install textarea-autogrow
```

#### npm Installation
```bash
npm install textarea-autogrow
```

######

## Usage:

Just include `textarea-autogrow.js` file in `<head>` tag:
Just include `textarea-autogrow.js` file in `<head>` tag or require it:

```html
<script type="text/javascript" src="textarea-autogrow.js"></script>
```

```javascript
var Autogrow = require('textarea-autogrow');
```

Then initialize the magic:
```javascript
var textarea = document.getElementById('myTextarea');
Expand All @@ -37,10 +45,8 @@ It's also recommended to add those two CSS properties to make things stable:
}
```


######


## More Options:

### Limit Autogrow Lines
Expand All @@ -56,4 +62,4 @@ var growingTextarea = new Autogrow(textarea, 3); // up to 3 lines height
You can set the initial row number using simple HTML attribute `rows`:
```html
<textarea id="myTextarea" rows="1"></textarea>
```
```
24 changes: 24 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "textarea-autogrow",
"version": "1.0.0",
"description": "A pure Javascript solution for auto-grow / expand a textarea element by its content.",
"main": "textarea-autogrow.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/CodingAspect/Textarea-Autogrow.git"
},
"keywords": [
"textarea",
"autogrow",
"expanding"
],
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/CodingAspect/Textarea-Autogrow/issues"
},
"homepage": "https://github.com/CodingAspect/Textarea-Autogrow#readme"
}
14 changes: 11 additions & 3 deletions textarea-autogrow.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
(function(){
this.Autogrow = function(textarea, maxLines){
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define([], factory);
} else if (typeof module === 'object' && module.exports) {
module.exports = factory();
} else {
root.Autogrow = factory();
}
})(this, function(){
return function(textarea, maxLines){
var self = this;

if(maxLines === undefined){
Expand Down Expand Up @@ -50,4 +58,4 @@
// Call autogrowFn() when textarea's value is changed
textarea.addEventListener('input', self.autogrowFn);
};
})();
});
7 changes: 6 additions & 1 deletion textarea-autogrow.min.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
!function(){this.Autogrow=function(t,e){var o=this;void 0===e&&(e=999),o.getOffset=function(t){for(var e=window.getComputedStyle(t,null),o=["paddingTop","paddingBottom"],l=0,i=0;i<o.length;i++)l+=parseInt(e[o[i]]);return l},o.autogrowFn=function(){var e=0,i=!1;return t.scrollHeight-l>o.maxAllowedHeight?(t.style.overflowY="scroll",e=o.maxAllowedHeight):(t.style.overflowY="hidden",t.style.height="auto",e=t.scrollHeight-l,i=!0),t.style.height=e+"px",i};var l=o.getOffset(t);o.rows=t.rows||1,o.lineHeight=t.scrollHeight/o.rows-l/o.rows,o.maxAllowedHeight=o.lineHeight*e-l,t.addEventListener("input",o.autogrowFn)}}();
!function(e,t){"function"==typeof define&&define.amd?define([],t):"object"==typeof module&&module.exports?module.exports=t():e.Autogrow=t()}(this,function(){return function(e,t){var o=this
void 0===t&&(t=999),o.getOffset=function(e){for(var t=window.getComputedStyle(e,null),o=["paddingTop","paddingBottom"],n=0,i=0;i<o.length;i++)n+=parseInt(t[o[i]])
return n},o.autogrowFn=function(){var t=0,i=!1
return e.scrollHeight-n>o.maxAllowedHeight?(e.style.overflowY="scroll",t=o.maxAllowedHeight):(e.style.overflowY="hidden",e.style.height="auto",t=e.scrollHeight-n,i=!0),e.style.height=t+"px",i}
var n=o.getOffset(e)
o.rows=e.rows||1,o.lineHeight=e.scrollHeight/o.rows-n/o.rows,o.maxAllowedHeight=o.lineHeight*t-n,e.addEventListener("input",o.autogrowFn)}})

0 comments on commit 0e9dd5d

Please sign in to comment.