├── .gitignore ├── .gitattributes ├── example ├── amd-js │ └── app.js ├── as-an-amd-module.html ├── as-a-native-plugin.html ├── basic.html ├── options.html └── reset.html ├── bower.json ├── .jshintrc ├── Gruntfile.js ├── package.json ├── LICENSE ├── assets ├── style.css └── require.min.js ├── dist └── autoresize-textarea.js ├── README.md ├── index.html └── src └── autoresize-textarea.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .DS_Store 3 | *.log 4 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | index.html linguist-documentation 2 | example/* linguist-documentation 3 | assets/* linguist-documentation 4 | -------------------------------------------------------------------------------- /example/amd-js/app.js: -------------------------------------------------------------------------------- 1 | requirejs.config({ 2 | 'baseUrl': 'amd-js', 3 | 'paths': { 4 | 'jquery': 'http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.2.min', 5 | 'autoresize-textarea': '../../src/autoresize-textarea' 6 | } 7 | }); 8 | 9 | requirejs(['jquery', 'autoresize-textarea'], function($) { 10 | $('#desc').autoResize(); 11 | }); 12 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "autoresize-textarea", 3 | "version": "1.1.3", 4 | "description": "A [jQuery] plugin can automatically resize textarea's height", 5 | "main": "src/autoresize-textarea.js", 6 | "keywords": [ 7 | "auto resize", 8 | "auto height", 9 | "textarea" 10 | ], 11 | "ignore": [ 12 | "node_modules", 13 | "bower_components" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "camelcase": true, 3 | "eqeqeq": true, 4 | "immed": true, 5 | "latedef": true, 6 | "newcap": true, 7 | "noarg": true, 8 | "quotmark": "single", 9 | "undef": true, 10 | "unused": true, 11 | "trailing": true, 12 | 13 | "boss": true, 14 | "eqnull": true, 15 | "expr": true, 16 | 17 | "node": true, 18 | "browser": true, 19 | "globals": { 20 | "define": true 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | /** 2 | * autoresize-textarea 3 | * https://github.com/Alex1990/autoresize-textarea 4 | * 5 | * Copyright (c) 2015 Alex Chao 6 | * Under the MIT license 7 | */ 8 | 9 | 'use strict'; 10 | 11 | module.exports = function(grunt) { 12 | 13 | // Load all grunt tasks 14 | require('load-grunt-tasks')(grunt); 15 | 16 | // Project configuration 17 | grunt.initConfig({ 18 | jshint: { 19 | all: [ 20 | 'Gruntfile.js', 21 | 'src/*.js' 22 | ], 23 | options: { 24 | jshintrc: '.jshintrc' 25 | } 26 | }, 27 | uglify: { 28 | build: { 29 | files: [ 30 | { 31 | expand: true, 32 | cwd: 'src', 33 | src: '**/*.js', 34 | dest: 'dist' 35 | } 36 | ] 37 | } 38 | } 39 | }); 40 | 41 | grunt.registerTask('default', ['jshint', 'uglify']); 42 | 43 | }; 44 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "autoresize-textarea", 3 | "version": "1.1.3", 4 | "description": "A [jQuery] plugin can automatically resize textarea's height", 5 | "main": "src/autoresize-textarea.js", 6 | "author": { 7 | "name": "Alex Chao", 8 | "email": "alexchao1990@gmail.com" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git://github.com/Alex1990/autoresize-textarea.git" 13 | }, 14 | "bugs": { 15 | "url": "https://github.com/Alex1990/autoresize-textarea/issues" 16 | }, 17 | "licenses": [ 18 | { 19 | "type": "MIT", 20 | "url": "https://github.com/Alex1990/autoresize-textarea/blob/master/LICENSE" 21 | } 22 | ], 23 | "dependencies": {}, 24 | "devDependencies": { 25 | "grunt": "~0.4.5", 26 | "grunt-cli": "~0.1.13", 27 | "grunt-contrib-jshint": "~0.11.0", 28 | "grunt-contrib-uglify": "~0.8.0", 29 | "load-grunt-tasks": "~3.1.0" 30 | }, 31 | "keywords": [ 32 | "auto resize", 33 | "auto height", 34 | "textarea" 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /example/as-an-amd-module.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | As an AMD module 6 | 7 | 8 | 9 |

Try to input/delete some characters.

10 | 14 |
15 |
16 |

Auto resize textarea

17 | 18 |
19 |
20 |

Default textarea

21 | 22 |
23 |
24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /example/as-a-native-plugin.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | As a native plugin 6 | 7 | 8 | 9 |

Try to input/delete some characters.

10 | 14 |
15 |
16 |

Auto resize textarea

17 | 18 |
19 |
20 |

Default textarea

21 | 22 |
23 |
24 | 25 | 28 | 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Alex Chao 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /example/basic.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Basic 6 | 7 | 8 | 9 |

Try to input or delete some characters.

10 | 14 |
15 |
16 |

Auto resize textarea

17 | 18 |
19 |
20 |

Default textarea

21 | 22 |
23 |
24 | 25 | 26 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /example/options.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Options 6 | 7 | 8 | 9 |

Try to input or delete some characters.

10 | 14 |
15 |
16 |

Auto resize textarea

17 | 18 |
19 |
20 |

Default textarea

21 | 22 |
23 |
24 | 25 | 26 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /assets/style.css: -------------------------------------------------------------------------------- 1 | ::selection { 2 | background-color: #f0f4f8; 3 | } 4 | 5 | ::-moz-selection { 6 | background-color: #f0f4f8; 7 | } 8 | 9 | body { 10 | margin: 0; 11 | padding: 10px; 12 | } 13 | 14 | body, 15 | textarea { 16 | font:400 1em/1.8 Helvetica, Arial, Microsoft Yahei, Hiragino Sans GB, WenQuanYi Micro Hei, sans-serif; 17 | } 18 | 19 | .btn { 20 | display: inline-block; 21 | *display: inline; 22 | padding: 5px 10px; 23 | font:400 1.125em/1 Helvetica, Arial, Microsoft Yahei, Hiragino Sans GB, WenQuanYi Micro Hei, sans-serif; 24 | background: #eee; 25 | color: #333; 26 | border: 1px solid #ddd; 27 | outline: 0; 28 | box-shadow: 0 1px 3px #ddd; 29 | transition: .25s; 30 | cursor: pointer; 31 | } 32 | 33 | .btn:hover { 34 | background: #f8f8f8; 35 | color: #000; 36 | border-color: #d0d0d0; 37 | } 38 | 39 | .fl { 40 | float: left; 41 | } 42 | 43 | .fr { 44 | float: right; 45 | } 46 | 47 | .clearfix:before, 48 | .clearfix:after { 49 | content: ' '; 50 | display: table; 51 | } 52 | 53 | .clearfix:after { 54 | clear: both; 55 | } 56 | 57 | .clearfix { 58 | *zoom: 1; 59 | } 60 | 61 | .title { 62 | color: #630; 63 | } 64 | 65 | .intro { 66 | color: #444; 67 | } 68 | 69 | .test-section h2 { 70 | color: #ddd; 71 | } 72 | 73 | .col { 74 | margin-right: 30px; 75 | } 76 | 77 | .desc { 78 | margin: 0; 79 | padding: 5px; 80 | width: 300px; 81 | height: 20px; 82 | font-size: 14px; 83 | line-height: 20px; 84 | border: 1px solid #aaa; 85 | outline: 0; 86 | overflow: hidden; 87 | resize: none; 88 | } 89 | 90 | .desc:focus { 91 | border-color: #555; 92 | } -------------------------------------------------------------------------------- /example/reset.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Reset 6 | 7 | 8 | 9 |

Try to input or delete some characters.

10 | 14 |
15 |
16 |

- Make it automatically resize the height.

17 |

- Reset it to a normal textarea.

18 |
19 |
20 |

Auto resize textarea

21 | 22 |
23 |
24 |

Default textarea

25 | 26 |
27 |
28 | 29 | 30 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /dist/autoresize-textarea.js: -------------------------------------------------------------------------------- 1 | !function(a,b){"function"==typeof define&&define.amd?define(["jquery"],b):"object"==typeof exports?module.exports=b(require("jquery")):b(a.jQuery,a)}(this,function(a,b){"use strict";var c,d,e=window,f=document,g=navigator.userAgent;/msie|trident/i.test(g)&&(d=g.match(/(?:msie |rv:)(\d+(\.\d+)?)/i),c=d&&d.length>1&&d[1]||"");var h=function(a,b,c){a[b+c]=function(b){c.call(a,b)},a.attachEvent("on"+b,a[b+c])},i=function(a,b,c){a.detachEvent("on"+b,a[b+c])},j=function(a,b){return e.getComputedStyle?e.getComputedStyle(a)[b]:a.currentStyle?a.currentStyle[b]:void 0},k=function(b,d){null==d?d={}:"function"==typeof d&&(d={onresizeheight:d});var e=b.value;b.value="";var g=parseFloat(j(b,"paddingTop"))+parseFloat(j(b,"paddingBottom")),k=b.scrollHeight-(b.clientHeight-g);b.value=e;var l,m;9>c&&(l=function(){b.scrollTop=0},h(b,"scroll",l),m=b.value,b.value="aa",b.value=m,f.execCommand("Undo"),f.execCommand("Undo"),f.execCommand("Undo"),f.execCommand("Undo"));var n,o=!0,p=function(){if(b.value!==e||o){e=b.value;var f=b.style.height;b.style.height="";var g=function(){var c=b.scrollHeight-k;d.maxHeight&&c>d.maxHeight?(b.style.height=d.maxHeight+"px",b.style.overflowY="auto",b.detachEvent&&i(b,"scroll",l)):b.style.height=c+"px";var e=parseFloat(b.style.height);n!==e&&(n=e,a&&a.fn&&a(b).trigger("autoresize:height",e),d.onresizeheight&&d.onresizeheight.call(b,e))};9>c?(setTimeout(g,0),b.style.height=f):g()}};if(b.addEventListener&&(!c||c>9))b.addEventListener("input",p,!1);else{var q=function(a){"value"===a.propertyName&&p()};h(b,"propertychange",q);var r=function(a){"focus"===a.type?h(f,"selectionchange",p):i(f,"selectionchange",p)};h(b,"focus",r),h(b,"blur",r),h(b,"keyup",p)}return p(),o=!1,{reset:function(){b.style.height="",b.removeEventListener&&(!c||c>9)?b.removeEventListener("input",p,!1):(b.style.overflowY="",i(b,"propertychange",q),i(f,"selectionchange",p),i(b,"focus",r),i(b,"blur",r),i(b,"keyup",p),i(b,"scroll",l))}}};return a&&a.fn?a.fn.autoResize=function(b){var c=[];return this.each(function(a,d){c.push(k(d,b))}),{reset:function(){a.each(c,function(a,b){b.reset()})}}}:b&&(b.autoResize=k),k}); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # autoresize-textarea 2 | 3 | A jQuery (optional) plugin can automatically resize the textarea's height. 4 | 5 | **Note: You can use Lea Verou's [stretchy](https://github.com/LeaVerou/stretchy) if you don't intend to support IE6-8.** 6 | 7 | ## Usage 8 | 9 | HTML: 10 | 11 | ```html 12 | 13 | ``` 14 | 15 | CSS: 16 | 17 | ```css 18 | #description { 19 | padding: 3px; 20 | height: 24px; 21 | font-size: 16px; 22 | line-height: 24px; 23 | overflow: hidden; 24 | resize: none; 25 | } 26 | ``` 27 | 28 | **Note:** Do not set transition property for the textarea. 29 | 30 | In most cases, it will be as a jQuery plugin. 31 | 32 | ```js 33 | $('#description').autoResize(); 34 | ``` 35 | 36 | It returns an object which contains a `reset` method to detach the bound events on textarea. So, the textarea will be changed to a normal textarea. 37 | 38 | ```js 39 | var autoresizeObj = $('#description').autoResize(); 40 | autoresizeObj.reset(); 41 | ``` 42 | 43 | If there isn't the jQuery object on global object, it will expose an `autoResize()` method to global object. 44 | 45 | ```js 46 | autoResize( document.getElementById('description') ); 47 | ``` 48 | 49 | And, this plugin can be used as a CommonJS/AMD module. You can see the demos in `example` folder for more details. 50 | 51 | ## Package 52 | 53 | You can use [npm](https://docs.npmjs.com) or [bower](http://bower.io) to install it. 54 | 55 | **NPM:** 56 | 57 | ```bash 58 | npm install autoresize-textarea 59 | ``` 60 | 61 | **Bower:** 62 | 63 | ```bash 64 | bower install autoresize-textarea 65 | ``` 66 | 67 | ## Options 68 | 69 | You can pass an configurable object as the first parameter. If you passed a function as the first parameter, it will be treated as `onresizeheight` option. 70 | 71 | - **maxHeight** 72 | 73 | Type: `Number` Default: `undefined` 74 | 75 | When the height of textarea is greater than `maxHeight`, the `maxHeight` will be as the height, and the `overflow-y` will be set to `auto`. 76 | 77 | - **onresizeheight** 78 | 79 | Type: `Function` Default: `undefined` 80 | 81 | When the textarea's height is changed, this callback will be called. In `onresizeheight` callback, `this` refer to the textarea element and the first argument is the current numeric height of the textarea. 82 | 83 | ## Events 84 | 85 | **(Only for as a jQuery plugin)** 86 | 87 | When the textarea's height is changed, a named `autoresize:height` event will be triggered on textarea element and the current height of textarea will be passed as the second parameter of the event listener. 88 | 89 | ## Compatibility 90 | 91 | Tested in IE6+ (including compatibility mode) and other modern browsers. 92 | 93 | **IE drawbacks:** 94 | 95 | - In IE7 (simulated by IE9), IE10 (simulated by IE11), IE11, the content will jump up and down when a newline is seen. For example, press the "Enter" key. 96 | - In IE7/8 (simulated by IE11), the `scrollHeight` will increase a few pixels after typing a character in a blank line (without any character). 97 | - In IE9 and IE7/8 (simulated by IE9), for `example/basic.html` example, when the value of `padding` is less than 5 pixels, the textarea will move up about 1 pixel after first newline. 98 | 99 | ## Thanks to 100 | 101 | - The [dottoro](http://help.dottoro.com) reference helps me get some key details about `scrollHeight` and `oninput`/`onpropertychange`/`onpaste` events. 102 | 103 | - A Ben Alpert's article - [A near-perfect oninput shim for IE 8 and 9](http://benalpert.com/2013/06/18/a-near-perfect-oninput-shim-for-ie-8-and-9.html), makes me understand how to use the `onselectionchange` event. 104 | 105 | - The [AutoResize](https://github.com/azoff/AutoResize) plugin commited in 2011 provides another solution. I refer to the part of it. 106 | 107 | ## License 108 | 109 | Under the MIT license. 110 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | autoresize-textarea - A jQuery (optional) plugin can automatically resize the textarea's height 6 | 87 | 88 | 89 |
90 |
91 |

autoresize-textarea

92 |

A jQuery (optional) plugin can automatically resize the textarea's height.

93 |
94 |
95 |
96 |
97 |
98 |

Demo

99 |

Try to input or delete some characters.

100 |
    101 |
  • Input interactions: Type, Paste (Ctrl+X or Context Menu), Drag and Drop, Undo (Ctrl+Z or Context Menu).
  • 102 |
  • Delete interactions: Backspace key, Delete key, Cut (Ctrl+X or Context Menu), Drag and Drop, Undo (Ctrl+Z or Context menu).
  • 103 |
104 |
105 | 106 |
107 |
108 |
109 |

Examples

110 | 117 |
118 |
119 |

Usage

120 |

Download and learn how to use see it on github

121 |
122 |
123 |

License

124 |

Under the MIT license.

125 |
126 |
127 |
128 | 133 | 134 | 135 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /src/autoresize-textarea.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * autoresize-textarea.js - automatically resize the textarea's height 3 | * https://github.com/Alex1990/autoresize-textarea 4 | * Under the MIT License | (c) 2015 Alex Chao 5 | */ 6 | 7 | !(function(global, factory) { 8 | 9 | // Uses CommonJS, AMD or browser global to create a jQuery plugin. 10 | // See: https://github.com/umdjs/umd 11 | if (typeof define === 'function' && define.amd) { 12 | // Expose this plugin as an AMD module. Register an anonymous module. 13 | define(['jquery'], factory); 14 | } else if (typeof exports === 'object') { 15 | // Node/CommonJS module 16 | module.exports = factory(require('jquery')); 17 | } else { 18 | // Browser globals 19 | factory(global.jQuery, global); 20 | } 21 | 22 | }(this, function($, global) { 23 | 24 | 'use strict'; 25 | 26 | // Shortand. 27 | var win = window; 28 | var doc = document; 29 | var ua = navigator.userAgent; 30 | 31 | var ie; 32 | var match; 33 | 34 | // Detect the IE version. 35 | if (/msie|trident/i.test(ua)) { 36 | match = ua.match(/(?:msie |rv:)(\d+(\.\d+)?)/i); 37 | ie = (match && match.length > 1 && match[1]) || ''; 38 | } 39 | 40 | // An attachEvent/detachEvent wrapper to save bytes. 41 | var addEvent = function(elem, event, listener) { 42 | elem[event + listener] = function(e) { 43 | listener.call(elem, e); 44 | }; 45 | elem.attachEvent('on' + event, elem[event + listener]); 46 | }; 47 | var removeEvent = function(elem, event, listener) { 48 | elem.detachEvent('on' + event, elem[event + listener]); 49 | }; 50 | 51 | // Get the computed style. 52 | // In IE9+ and other modern browsers, use window.getComputedStyle method. 53 | // In IE6-8, use Element.currentStyle object. 54 | var curCSS = function(elem, prop) { 55 | if (win.getComputedStyle) { 56 | return win.getComputedStyle(elem)[prop]; 57 | } else if (elem.currentStyle) { 58 | return elem.currentStyle[prop]; 59 | } 60 | }; 61 | 62 | // Main function. 63 | var autoResize = function(elem, opts) { 64 | 65 | // Handle the different type parameters. 66 | if (opts == null) { 67 | opts = {}; 68 | } else if (typeof opts === 'function') { 69 | opts = { 70 | onresizeheight: opts 71 | }; 72 | } 73 | 74 | var lastValue = elem.value; 75 | elem.value = ''; 76 | 77 | // In default, the textarea's height is integeral multiple of 78 | // the line-height, and the offset between scrollHeight and height is 79 | // the sum of top padding and bottom padding. But, in older IE, the height 80 | // is less than the scrollHeight because the line-height cannot expand 81 | // the height. So you'd better always set the textarea's height explicitly. 82 | var vPadding = parseFloat(curCSS(elem, 'paddingTop')) + 83 | parseFloat(curCSS(elem, 'paddingBottom')); 84 | 85 | var offset = elem.scrollHeight - (elem.clientHeight - vPadding); 86 | elem.value = lastValue; 87 | 88 | var scrollListener; 89 | var tmpValue; 90 | 91 | if (ie < 9) { 92 | // For IE6-8, prevent the content jump when press enter key quickly. 93 | scrollListener = function() { 94 | elem.scrollTop = 0; 95 | }; 96 | addEvent(elem, 'scroll', scrollListener); 97 | 98 | // In IE6-8, the first Drop interaction may not trigger keyup/keydown/ 99 | // propertychange/selectionchange event. The below code works for all 100 | // examples except example/as-a-native-plugin.html(IE8). In fact, I don't know why 101 | // it works. 102 | tmpValue = elem.value; 103 | elem.value = 'aa'; 104 | elem.value = tmpValue; 105 | 106 | // Restore the Undo command in context menu. 107 | doc.execCommand('Undo'); 108 | doc.execCommand('Undo'); 109 | doc.execCommand('Undo'); 110 | doc.execCommand('Undo'); 111 | } 112 | 113 | var isInit = true; 114 | var lastHeight; 115 | 116 | // When the input event is fired and the content of textarea is changed, 117 | // remove the inline style height, and then set the inline style height 118 | // to scrollHeight excerpt for the top padding and bottom padding. 119 | var inputListener = function() { 120 | if (elem.value !== lastValue || isInit) { 121 | lastValue = elem.value; 122 | 123 | var tmpHeight = elem.style.height; 124 | elem.style.height = ''; 125 | 126 | var setHeight = function() { 127 | var height = elem.scrollHeight - offset; 128 | 129 | // When opts.maxHeight is provided and the height of textarea is 130 | // great than opts.maxHeight, the opts.maxHeight will be as the 131 | // height, and the overflow-y will be set to auto. 132 | if (opts.maxHeight && height > opts.maxHeight) { 133 | elem.style.height = opts.maxHeight + 'px'; 134 | elem.style.overflowY = 'auto'; 135 | 136 | elem.detachEvent && removeEvent(elem, 'scroll', scrollListener); 137 | } else { 138 | elem.style.height = height + 'px'; 139 | } 140 | 141 | var currentHeight = parseFloat(elem.style.height); 142 | 143 | if (lastHeight !== currentHeight) { 144 | lastHeight = currentHeight; 145 | if ($ && $.fn) { 146 | $(elem).trigger('autoresize:height', currentHeight); 147 | } 148 | opts.onresizeheight && opts.onresizeheight.call(elem, currentHeight); 149 | } 150 | }; 151 | 152 | // In IE6-8, the immediate scrollHeight isn't expected after 153 | // an undo operation. 154 | if (ie < 9) { 155 | setTimeout(setHeight, 0); 156 | // Prevent the height jump. 157 | elem.style.height = tmpHeight; 158 | } else { 159 | setHeight(); 160 | } 161 | } 162 | }; 163 | 164 | // For modern browsers, the input is enough. 165 | if (elem.addEventListener && (!ie || ie > 9)) { 166 | elem.addEventListener('input', inputListener, false); 167 | } else { 168 | 169 | // For IE6-9, we can use onpropertychange (combine with propertyName) 170 | // to simulate the input event, but they are not identical. For more 171 | // details about how to simulate the input event perfectly, you can 172 | // see http://benalpert.com/2013/06/18/a-near-perfect-oninput-shim-for-ie-8-and-9.html 173 | var propertychangeListener = function(e) { 174 | if (e.propertyName === 'value') { 175 | inputListener(); 176 | } 177 | }; 178 | addEvent(elem, 'propertychange', propertychangeListener); 179 | 180 | // In IE 9, input/propertychange event fires for most input operation but is buggy 181 | // and doesn't fire when text is deleted, but conveniently, 182 | // selectionchange appears to fire in all of the remaining cases. 183 | // 184 | // The selectionchange is fired frequently, so we just listen it when 185 | // the textarea gets cursor. 186 | var focusListener = function(e) { 187 | if (e.type === 'focus') { 188 | addEvent(doc, 'selectionchange', inputListener); 189 | } else { 190 | removeEvent(doc, 'selectionchange', inputListener); 191 | } 192 | }; 193 | addEvent(elem, 'focus', focusListener); 194 | addEvent(elem, 'blur', focusListener); 195 | 196 | // In IE6-8, the first interaction (type/paste) maybe not trigger 197 | // the propertychange, but trigger keyup. 198 | addEvent(elem, 'keyup', inputListener); 199 | } 200 | 201 | // Initialize 202 | inputListener(); 203 | isInit = false; 204 | 205 | // Return an object which contains a `reset` method to detach the bound 206 | // events on textarea. 207 | return { 208 | reset: function() { 209 | elem.style.height = ''; 210 | if (elem.removeEventListener && (!ie || ie > 9)) { 211 | elem.removeEventListener('input', inputListener, false); 212 | } else { 213 | elem.style.overflowY = ''; 214 | removeEvent(elem, 'propertychange', propertychangeListener); 215 | removeEvent(doc, 'selectionchange', inputListener); 216 | removeEvent(elem, 'focus', focusListener); 217 | removeEvent(elem, 'blur', focusListener); 218 | removeEvent(elem, 'keyup', inputListener); 219 | removeEvent(elem, 'scroll', scrollListener); 220 | } 221 | } 222 | }; 223 | }; 224 | 225 | // Expose it as a jQuery plugin. 226 | if ($ && $.fn) { 227 | $.fn.autoResize = function(opts) { 228 | var arr = []; 229 | 230 | this.each(function(i, elem) { 231 | arr.push(autoResize(elem, opts)); 232 | }); 233 | 234 | return { 235 | reset: function() { 236 | $.each(arr, function(i, item) { 237 | item.reset(); 238 | }); 239 | } 240 | }; 241 | }; 242 | } else if (global) { 243 | // Expose it as a method on global object. 244 | global.autoResize = autoResize; 245 | } 246 | 247 | return autoResize; 248 | })); 249 | -------------------------------------------------------------------------------- /assets/require.min.js: -------------------------------------------------------------------------------- 1 | var requirejs,require,define;(function(global){var req,s,head,baseElement,dataMain,src,interactiveScript,currentlyAddingScript,mainScript,subPath,version="2.1.17",commentRegExp=/(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,cjsRequireRegExp=/[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,jsSuffixRegExp=/\.js$/,currDirRegExp=/^\.\//,op=Object.prototype,ostring=op.toString,hasOwn=op.hasOwnProperty,ap=Array.prototype,apsp=ap.splice,isBrowser=!!(typeof window!=="undefined"&&typeof navigator!=="undefined"&&window.document),isWebWorker=!isBrowser&&typeof importScripts!=="undefined",readyRegExp=isBrowser&&navigator.platform==="PLAYSTATION 3"?/^complete$/:/^(complete|loaded)$/,defContextName="_",isOpera=typeof opera!=="undefined"&&opera.toString()==="[object Opera]",contexts={},cfg={},globalDefQueue=[],useInteractive=false;function isFunction(it){return ostring.call(it)==="[object Function]"}function isArray(it){return ostring.call(it)==="[object Array]"}function each(ary,func){if(ary){var i;for(i=0;i-1;i-=1){if(ary[i]&&func(ary[i],i,ary)){break}}}}function hasProp(obj,prop){return hasOwn.call(obj,prop)}function getOwn(obj,prop){return hasProp(obj,prop)&&obj[prop]}function eachProp(obj,func){var prop;for(prop in obj){if(hasProp(obj,prop)){if(func(obj[prop],prop)){break}}}}function mixin(target,source,force,deepStringMixin){if(source){eachProp(source,function(value,prop){if(force||!hasProp(target,prop)){if(deepStringMixin&&typeof value==="object"&&value&&!isArray(value)&&!isFunction(value)&&!(value instanceof RegExp)){if(!target[prop]){target[prop]={}}mixin(target[prop],value,force,deepStringMixin)}else{target[prop]=value}}})}return target}function bind(obj,fn){return function(){return fn.apply(obj,arguments)}}function scripts(){return document.getElementsByTagName("script")}function defaultOnError(err){throw err}function getGlobal(value){if(!value){return value}var g=global;each(value.split("."),function(part){g=g[part]});return g}function makeError(id,msg,err,requireModules){var e=new Error(msg+"\nhttp://requirejs.org/docs/errors.html#"+id);e.requireType=id;e.requireModules=requireModules;if(err){e.originalError=err}return e}if(typeof define!=="undefined"){return}if(typeof requirejs!=="undefined"){if(isFunction(requirejs)){return}cfg=requirejs;requirejs=undefined}if(typeof require!=="undefined"&&!isFunction(require)){cfg=require;require=undefined}function newContext(contextName){var inCheckLoaded,Module,context,handlers,checkLoadedTimeoutId,config={waitSeconds:7,baseUrl:"./",paths:{},bundles:{},pkgs:{},shim:{},config:{}},registry={},enabledRegistry={},undefEvents={},defQueue=[],defined={},urlFetched={},bundlesMap={},requireCounter=1,unnormalizedCounter=1;function trimDots(ary){var i,part;for(i=0;i0){ary.splice(i-1,2);i-=2}}}}}}function normalize(name,baseName,applyMap){var pkgMain,mapValue,nameParts,i,j,nameSegment,lastIndex,foundMap,foundI,foundStarMap,starI,normalizedBaseParts,baseParts=(baseName&&baseName.split("/")),map=config.map,starMap=map&&map["*"];if(name){name=name.split("/");lastIndex=name.length-1;if(config.nodeIdCompat&&jsSuffixRegExp.test(name[lastIndex])){name[lastIndex]=name[lastIndex].replace(jsSuffixRegExp,"")}if(name[0].charAt(0)==="."&&baseParts){normalizedBaseParts=baseParts.slice(0,baseParts.length-1);name=normalizedBaseParts.concat(name)}trimDots(name);name=name.join("/")}if(applyMap&&map&&(baseParts||starMap)){nameParts=name.split("/");outerLoop:for(i=nameParts.length;i>0;i-=1){nameSegment=nameParts.slice(0,i).join("/");if(baseParts){for(j=baseParts.length;j>0;j-=1){mapValue=getOwn(map,baseParts.slice(0,j).join("/"));if(mapValue){mapValue=getOwn(mapValue,nameSegment);if(mapValue){foundMap=mapValue;foundI=i;break outerLoop}}}}if(!foundStarMap&&starMap&&getOwn(starMap,nameSegment)){foundStarMap=getOwn(starMap,nameSegment);starI=i}}if(!foundMap&&foundStarMap){foundMap=foundStarMap;foundI=starI}if(foundMap){nameParts.splice(0,foundI,foundMap);name=nameParts.join("/")}}pkgMain=getOwn(config.pkgs,name);return pkgMain?pkgMain:name}function removeScript(name){if(isBrowser){each(scripts(),function(scriptNode){if(scriptNode.getAttribute("data-requiremodule")===name&&scriptNode.getAttribute("data-requirecontext")===context.contextName){scriptNode.parentNode.removeChild(scriptNode);return true}})}}function hasPathFallback(id){var pathConfig=getOwn(config.paths,id);if(pathConfig&&isArray(pathConfig)&&pathConfig.length>1){pathConfig.shift();context.require.undef(id);context.makeRequire(null,{skipMap:true})([id]);return true}}function splitPrefix(name){var prefix,index=name?name.indexOf("!"):-1;if(index>-1){prefix=name.substring(0,index);name=name.substring(index+1,name.length)}return[prefix,name]}function makeModuleMap(name,parentModuleMap,isNormalized,applyMap){var url,pluginModule,suffix,nameParts,prefix=null,parentName=parentModuleMap?parentModuleMap.name:null,originalName=name,isDefine=true,normalizedName="";if(!name){isDefine=false;name="_@r"+(requireCounter+=1)}nameParts=splitPrefix(name);prefix=nameParts[0];name=nameParts[1];if(prefix){prefix=normalize(prefix,parentName,applyMap);pluginModule=getOwn(defined,prefix)}if(name){if(prefix){if(pluginModule&&pluginModule.normalize){normalizedName=pluginModule.normalize(name,function(name){return normalize(name,parentName,applyMap)})}else{normalizedName=name.indexOf("!")===-1?normalize(name,parentName,applyMap):name}}else{normalizedName=normalize(name,parentName,applyMap);nameParts=splitPrefix(normalizedName);prefix=nameParts[0];normalizedName=nameParts[1];isNormalized=true;url=context.nameToUrl(normalizedName)}}suffix=prefix&&!pluginModule&&!isNormalized?"_unnormalized"+(unnormalizedCounter+=1):"";return{prefix:prefix,name:normalizedName,parentMap:parentModuleMap,unnormalized:!!suffix,url:url,originalName:originalName,isDefine:isDefine,id:(prefix?prefix+"!"+normalizedName:normalizedName)+suffix}}function getModule(depMap){var id=depMap.id,mod=getOwn(registry,id);if(!mod){mod=registry[id]=new context.Module(depMap)}return mod}function on(depMap,name,fn){var id=depMap.id,mod=getOwn(registry,id);if(hasProp(defined,id)&&(!mod||mod.defineEmitComplete)){if(name==="defined"){fn(defined[id])}}else{mod=getModule(depMap);if(mod.error&&name==="error"){fn(mod.error)}else{mod.on(name,fn)}}}function onError(err,errback){var ids=err.requireModules,notified=false;if(errback){errback(err)}else{each(ids,function(id){var mod=getOwn(registry,id);if(mod){mod.error=err;if(mod.events.error){notified=true;mod.emit("error",err)}}});if(!notified){req.onError(err)}}}function takeGlobalQueue(){if(globalDefQueue.length){apsp.apply(defQueue,[defQueue.length,0].concat(globalDefQueue));globalDefQueue=[]}}handlers={require:function(mod){if(mod.require){return mod.require}else{return(mod.require=context.makeRequire(mod.map))}},exports:function(mod){mod.usingExports=true;if(mod.map.isDefine){if(mod.exports){return(defined[mod.map.id]=mod.exports)}else{return(mod.exports=defined[mod.map.id]={})}}},module:function(mod){if(mod.module){return mod.module}else{return(mod.module={id:mod.map.id,uri:mod.map.url,config:function(){return getOwn(config.config,mod.map.id)||{}},exports:mod.exports||(mod.exports={})})}}};function cleanRegistry(id){delete registry[id];delete enabledRegistry[id]}function breakCycle(mod,traced,processed){var id=mod.map.id;if(mod.error){mod.emit("error",mod.error)}else{traced[id]=true;each(mod.depMaps,function(depMap,i){var depId=depMap.id,dep=getOwn(registry,depId);if(dep&&!mod.depMatched[i]&&!processed[depId]){if(getOwn(traced,depId)){mod.defineDep(i,defined[depId]);mod.check()}else{breakCycle(dep,traced,processed)}}});processed[id]=true}}function checkLoaded(){var err,usingPathFallback,waitInterval=config.waitSeconds*1000,expired=waitInterval&&(context.startTime+waitInterval)1)){ext=moduleNamePlusExt.substring(index,moduleNamePlusExt.length);moduleNamePlusExt=moduleNamePlusExt.substring(0,index)}return context.nameToUrl(normalize(moduleNamePlusExt,relMap&&relMap.id,true),ext,true)},defined:function(id){return hasProp(defined,makeModuleMap(id,relMap,false,true).id)},specified:function(id){id=makeModuleMap(id,relMap,false,true).id;return hasProp(defined,id)||hasProp(registry,id)}});if(!relMap){localRequire.undef=function(id){takeGlobalQueue();var map=makeModuleMap(id,relMap,true),mod=getOwn(registry,id);removeScript(id);delete defined[id];delete urlFetched[map.url];delete undefEvents[id];eachReverse(defQueue,function(args,i){if(args[0]===id){defQueue.splice(i,1)}});if(mod){if(mod.events.defined){undefEvents[id]=mod.events}cleanRegistry(id)}}}return localRequire},enable:function(depMap){var mod=getOwn(registry,depMap.id);if(mod){getModule(depMap).enable()}},completeLoad:function(moduleName){var found,args,mod,shim=getOwn(config.shim,moduleName)||{},shExports=shim.exports;takeGlobalQueue();while(defQueue.length){args=defQueue.shift();if(args[0]===null){args[0]=moduleName;if(found){break}found=true}else{if(args[0]===moduleName){found=true}}callGetModule(args)}mod=getOwn(registry,moduleName);if(!found&&!hasProp(defined,moduleName)&&mod&&!mod.inited){if(config.enforceDefine&&(!shExports||!getGlobal(shExports))){if(hasPathFallback(moduleName)){return}else{return onError(makeError("nodefine","No define call for "+moduleName,null,[moduleName]))}}else{callGetModule([moduleName,(shim.deps||[]),shim.exportsFn])}}checkLoaded()},nameToUrl:function(moduleName,ext,skipExt){var paths,syms,i,parentModule,url,parentPath,bundleId,pkgMain=getOwn(config.pkgs,moduleName);if(pkgMain){moduleName=pkgMain}bundleId=getOwn(bundlesMap,moduleName);if(bundleId){return context.nameToUrl(bundleId,ext,skipExt)}if(req.jsExtRegExp.test(moduleName)){url=moduleName+(ext||"")}else{paths=config.paths;syms=moduleName.split("/");for(i=syms.length;i>0;i-=1){parentModule=syms.slice(0,i).join("/");parentPath=getOwn(paths,parentModule);if(parentPath){if(isArray(parentPath)){parentPath=parentPath[0]}syms.splice(0,i,parentPath);break}}url=syms.join("/");url+=(ext||(/^data\:|\?/.test(url)||skipExt?"":".js"));url=(url.charAt(0)==="/"||url.match(/^[\w\+\.\-]+:/)?"":config.baseUrl)+url}return config.urlArgs?url+((url.indexOf("?")===-1?"?":"&")+config.urlArgs):url},load:function(id,url){req.load(context,id,url)},execCb:function(name,callback,args,exports){return callback.apply(exports,args)},onScriptLoad:function(evt){if(evt.type==="load"||(readyRegExp.test((evt.currentTarget||evt.srcElement).readyState))){interactiveScript=null;var data=getScriptData(evt);context.completeLoad(data.id)}},onScriptError:function(evt){var data=getScriptData(evt);if(!hasPathFallback(data.id)){return onError(makeError("scripterror","Script error for: "+data.id,evt,[data.id]))}}};context.require=context.makeRequire();return context}req=requirejs=function(deps,callback,errback,optional){var context,config,contextName=defContextName;if(!isArray(deps)&&typeof deps!=="string"){config=deps;if(isArray(callback)){deps=callback;callback=errback;errback=optional}else{deps=[]}}if(config&&config.context){contextName=config.context}context=getOwn(contexts,contextName);if(!context){context=contexts[contextName]=req.s.newContext(contextName)}if(config){context.configure(config)}return context.require(deps,callback,errback)};req.config=function(config){return req(config)};req.nextTick=typeof setTimeout!=="undefined"?function(fn){setTimeout(fn,4)}:function(fn){fn()};if(!require){require=req}req.version=version;req.jsExtRegExp=/^\/|:|\?|\.js$/;req.isBrowser=isBrowser;s=req.s={contexts:contexts,newContext:newContext};req({});each(["toUrl","undef","defined","specified"],function(prop){req[prop]=function(){var ctx=contexts[defContextName];return ctx.require[prop].apply(ctx,arguments)}});if(isBrowser){head=s.head=document.getElementsByTagName("head")[0];baseElement=document.getElementsByTagName("base")[0];if(baseElement){head=s.head=baseElement.parentNode}}req.onError=defaultOnError;req.createNode=function(config,moduleName,url){var node=config.xhtml?document.createElementNS("http://www.w3.org/1999/xhtml","html:script"):document.createElement("script");node.type=config.scriptType||"text/javascript";node.charset="utf-8";node.async=true;return node};req.load=function(context,moduleName,url){var config=(context&&context.config)||{},node;if(isBrowser){node=req.createNode(config,moduleName,url);node.setAttribute("data-requirecontext",context.contextName);node.setAttribute("data-requiremodule",moduleName);if(node.attachEvent&&!(node.attachEvent.toString&&node.attachEvent.toString().indexOf("[native code")<0)&&!isOpera){useInteractive=true;node.attachEvent("onreadystatechange",context.onScriptLoad)}else{node.addEventListener("load",context.onScriptLoad,false);node.addEventListener("error",context.onScriptError,false)}node.src=url;currentlyAddingScript=node;if(baseElement){head.insertBefore(node,baseElement)}else{head.appendChild(node)}currentlyAddingScript=null;return node}else{if(isWebWorker){try{importScripts(url);context.completeLoad(moduleName)}catch(e){context.onError(makeError("importscripts","importScripts failed for "+moduleName+" at "+url,e,[moduleName]))}}}};function getInteractiveScript(){if(interactiveScript&&interactiveScript.readyState==="interactive"){return interactiveScript}eachReverse(scripts(),function(script){if(script.readyState==="interactive"){return(interactiveScript=script)}});return interactiveScript}if(isBrowser&&!cfg.skipDataMain){eachReverse(scripts(),function(script){if(!head){head=script.parentNode}dataMain=script.getAttribute("data-main");if(dataMain){mainScript=dataMain;if(!cfg.baseUrl){src=mainScript.split("/");mainScript=src.pop();subPath=src.length?src.join("/")+"/":"./";cfg.baseUrl=subPath}mainScript=mainScript.replace(jsSuffixRegExp,"");if(req.jsExtRegExp.test(mainScript)){mainScript=dataMain}cfg.deps=cfg.deps?cfg.deps.concat(mainScript):[mainScript];return true}})}define=function(name,deps,callback){var node,context;if(typeof name!=="string"){callback=deps;deps=name;name=null}if(!isArray(deps)){callback=deps;deps=null}if(!deps&&isFunction(callback)){deps=[];if(callback.length){callback.toString().replace(commentRegExp,"").replace(cjsRequireRegExp,function(match,dep){deps.push(dep)});deps=(callback.length===1?["require"]:["require","exports","module"]).concat(deps)}}if(useInteractive){node=currentlyAddingScript||getInteractiveScript();if(node){if(!name){name=node.getAttribute("data-requiremodule")}context=contexts[node.getAttribute("data-requirecontext")]}}(context?context.defQueue:globalDefQueue).push([name,deps,callback])};define.amd={jQuery:true};req.exec=function(text){return eval(text)};req(cfg)}(this)); --------------------------------------------------------------------------------