Skip to content

Commit

Permalink
Whitespace cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
Pistos committed Jun 15, 2012
1 parent c4e6dff commit ed30e90
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ A jQuery plugin that auto-expands textareas to fit the contents as a user types.
The expandable plugin has 5 settings:

* `duration` - The speed of the animation when expanding (or shrinking). Default is 'normal'.
* `init` - If true, the textarea will be resized to fit its content on initialization.
* `init` - If true, the textarea will be resized to fit its content on initialization.
* `interval` - The interval at which it checks the textarea. Default is 750.
* `within` - The number of rows left before expanding. Default is 1.
* `by` - The number of rows to expand by. Default is 2.
Expand All @@ -22,4 +22,4 @@ Copyright (c) 2010 [Brandon Aaron](http://brandonaaron.net)

## Contributors

Karl Swedberg
Karl Swedberg
14 changes: 7 additions & 7 deletions jquery.expandable.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $.fn.extend({
by: 2,
init: false
}, givenOptions);

return this.filter('textarea').each(function() {
var $this = $(this).css({ display: 'block', overflow: 'hidden' }),
minHeight = $this.height(),
Expand All @@ -29,12 +29,12 @@ $.fn.extend({
// white-space rules from: http://petesbloggerama.blogspot.com/2007/02/firefox-ie-word-wrap-word-break-tables.html
$mirror = $('<div style="position:absolute;top:-999px;left:-999px;border-color:#000;border-style:solid;overflow-x:hidden;visibility:hidden;z-index:0;white-space: pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word;" />').appendTo('body'),
interval;

// copy styles from textarea to mirror to mirror the textarea as best possible
$.each('borderTopWidth borderRightWidth borderBottomWidth borderLeftWidth paddingTop paddingRight paddingBottom paddingLeft fontSize fontFamily fontWeight fontStyle fontStretch fontVariant wordSpacing lineHeight width'.split(' '), function(i,prop) {
$mirror.css(prop, $this.css(prop));
});

// setup events
$this
.bind('keypress', function(event) { if ( event.keyCode == '13' ) check(); })
Expand All @@ -49,12 +49,12 @@ $.fn.extend({
// encode any html passed in and replace new lines with a <br>
// the &nbsp; is to try and normalize browser behavior
$mirror.html( encodeHTML(text).replace(/\n/g, '&nbsp;<br>') );

height = $this[0].offsetHeight - heightDiff;
usedHeight = $mirror[0].offsetHeight - heightDiff;
usedRows = Math.floor(usedHeight / rowSize);
availableRows = Math.floor((height / rowSize) - usedRows);

// adjust height if needed by either growing or shrinking the text area to within the specified bounds
if ( availableRows <= options.within ) {
newHeight = rowSize * (usedRows + Math.max(availableRows, 0) + options.by);
Expand All @@ -68,7 +68,7 @@ $.fn.extend({
}).end();
}
});

function encodeHTML(text) {
var characters = {
'<' : '&lt;',
Expand All @@ -83,4 +83,4 @@ function encodeHTML(text) {
});
}

})(jQuery);
})(jQuery);

0 comments on commit ed30e90

Please sign in to comment.