From a8a822cbe5197a990c09861abf95ebe19deea80a Mon Sep 17 00:00:00 2001 From: Mike Engel Date: Wed, 29 Jul 2015 11:52:13 -0600 Subject: [PATCH] Making textarea-autogrow ready for NPM. Also adding the MIT license. --- LICENSE.md | 21 +++++++++++++++++++++ README.md | 16 +++++++++++----- package.json | 24 ++++++++++++++++++++++++ textarea-autogrow.js | 14 +++++++++++--- textarea-autogrow.min.js | 7 ++++++- 5 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 LICENSE.md create mode 100644 package.json diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..77f60eb --- /dev/null +++ b/LICENSE.md @@ -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. diff --git a/README.md b/README.md index 4378bc2..ea6fadb 100644 --- a/README.md +++ b/README.md @@ -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 `` tag: +Just include `textarea-autogrow.js` file in `` tag or require it: ```html ``` +```javascript +var Autogrow = require('textarea-autogrow'); +``` + Then initialize the magic: ```javascript var textarea = document.getElementById('myTextarea'); @@ -37,10 +45,8 @@ It's also recommended to add those two CSS properties to make things stable: } ``` - ###### - ## More Options: ### Limit Autogrow Lines @@ -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 -``` \ No newline at end of file +``` diff --git a/package.json b/package.json new file mode 100644 index 0000000..d520827 --- /dev/null +++ b/package.json @@ -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" +} diff --git a/textarea-autogrow.js b/textarea-autogrow.js index 91caf5e..528d948 100644 --- a/textarea-autogrow.js +++ b/textarea-autogrow.js @@ -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){ @@ -50,4 +58,4 @@ // Call autogrowFn() when textarea's value is changed textarea.addEventListener('input', self.autogrowFn); }; -})(); \ No newline at end of file +}); diff --git a/textarea-autogrow.min.js b/textarea-autogrow.min.js index 12b69b1..f0069f7 100644 --- a/textarea-autogrow.min.js +++ b/textarea-autogrow.min.js @@ -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;io.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)}}(); \ No newline at end of file +!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;io.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)}})