Mercurial > zeropaste
annotate vendor/assets/javascripts/jquery.autosize.js @ 329:430dadffd91e
Fix coding style.
author | edogawaconan <me@myconan.net> |
---|---|
date | Mon, 14 Apr 2014 17:13:22 +0900 |
parents | 56c4cd16d849 |
children |
rev | line source |
---|---|
79
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
1 // Autosize 1.13 - jQuery plugin for textareas |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
2 // (c) 2012 Jack Moore - jacklmoore.com |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
3 // license: www.opensource.org/licenses/mit-license.php |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
4 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
5 (function ($) { |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
6 var |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
7 defaults = { |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
8 className: 'autosizejs', |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
9 append: "", |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
10 callback: false |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
11 }, |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
12 hidden = 'hidden', |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
13 borderBox = 'border-box', |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
14 lineHeight = 'lineHeight', |
97
e8a0e82213cd
Updated autosize from vendor, separated box size hack to its own function.
Edho Arief <edho@myconan.net>
parents:
79
diff
changeset
|
15 copy = '<textarea tabindex="-1" style="position:absolute; top:-9999px; left:-9999px; right:auto; bottom:auto; -moz-box-sizing:content-box; -webkit-box-sizing:content-box; box-sizing:content-box; word-wrap:break-word; height:0 !important; min-height:0 !important; overflow:hidden;"/>', |
79
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
16 // line-height is omitted because IE7/IE8 doesn't return the correct value. |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
17 copyStyle = [ |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
18 'fontFamily', |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
19 'fontSize', |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
20 'fontWeight', |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
21 'fontStyle', |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
22 'letterSpacing', |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
23 'textTransform', |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
24 'wordSpacing', |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
25 'textIndent' |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
26 ], |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
27 oninput = 'oninput', |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
28 onpropertychange = 'onpropertychange', |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
29 test = $(copy)[0]; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
30 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
31 // For testing support in old FireFox |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
32 test.setAttribute(oninput, "return"); |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
33 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
34 if ($.isFunction(test[oninput]) || onpropertychange in test) { |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
35 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
36 // test that line-height can be accurately copied to avoid |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
37 // incorrect value reporting in old IE and old Opera |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
38 $(test).css(lineHeight, '99px'); |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
39 if ($(test).css(lineHeight) === '99px') { |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
40 copyStyle.push(lineHeight); |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
41 } |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
42 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
43 $.fn.autosize = function (options) { |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
44 options = $.extend({}, defaults, options || {}); |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
45 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
46 return this.each(function () { |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
47 var |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
48 ta = this, |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
49 $ta = $(ta), |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
50 mirror, |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
51 minHeight = $ta.height(), |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
52 maxHeight = parseInt($ta.css('maxHeight'), 10), |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
53 active, |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
54 i = copyStyle.length, |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
55 resize, |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
56 boxOffset = 0, |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
57 value = ta.value, |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
58 callback = $.isFunction(options.callback); |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
59 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
60 if ($ta.css('box-sizing') === borderBox || $ta.css('-moz-box-sizing') === borderBox || $ta.css('-webkit-box-sizing') === borderBox){ |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
61 boxOffset = $ta.outerHeight() - $ta.height(); |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
62 } |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
63 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
64 if ($ta.data('mirror') || $ta.data('ismirror')) { |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
65 // if autosize has already been applied, exit. |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
66 // if autosize is being applied to a mirror element, exit. |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
67 return; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
68 } else { |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
69 mirror = $(copy).data('ismirror', true).addClass(options.className)[0]; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
70 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
71 resize = $ta.css('resize') === 'none' ? 'none' : 'horizontal'; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
72 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
73 $ta.data('mirror', $(mirror)).css({ |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
74 overflow: hidden, |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
75 overflowY: hidden, |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
76 wordWrap: 'break-word', |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
77 resize: resize |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
78 }); |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
79 } |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
80 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
81 // Opera returns '-1px' when max-height is set to 'none'. |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
82 maxHeight = maxHeight && maxHeight > 0 ? maxHeight : 9e4; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
83 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
84 // Using mainly bare JS in this function because it is going |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
85 // to fire very often while typing, and needs to very efficient. |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
86 function adjust() { |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
87 var height, overflow, original; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
88 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
89 // the active flag keeps IE from tripping all over itself. Otherwise |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
90 // actions in the adjust function will cause IE to call adjust again. |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
91 if (!active) { |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
92 active = true; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
93 mirror.value = ta.value + options.append; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
94 mirror.style.overflowY = ta.style.overflowY; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
95 original = parseInt(ta.style.height,10); |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
96 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
97 // Update the width in case the original textarea width has changed |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
98 mirror.style.width = $ta.css('width'); |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
99 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
100 // Needed for IE to reliably return the correct scrollHeight |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
101 mirror.scrollTop = 0; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
102 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
103 // Set a very high value for scrollTop to be sure the |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
104 // mirror is scrolled all the way to the bottom. |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
105 mirror.scrollTop = 9e4; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
106 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
107 height = mirror.scrollTop; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
108 overflow = hidden; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
109 if (height > maxHeight) { |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
110 height = maxHeight; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
111 overflow = 'scroll'; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
112 } else if (height < minHeight) { |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
113 height = minHeight; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
114 } |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
115 height += boxOffset; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
116 ta.style.overflowY = overflow; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
117 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
118 if (original !== height) { |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
119 ta.style.height = height + 'px'; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
120 if (callback) { |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
121 options.callback.call(ta); |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
122 } |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
123 } |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
124 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
125 // This small timeout gives IE a chance to draw it's scrollbar |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
126 // before adjust can be run again (prevents an infinite loop). |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
127 setTimeout(function () { |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
128 active = false; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
129 }, 1); |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
130 } |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
131 } |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
132 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
133 // mirror is a duplicate textarea located off-screen that |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
134 // is automatically updated to contain the same text as the |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
135 // original textarea. mirror always has a height of 0. |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
136 // This gives a cross-browser supported way getting the actual |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
137 // height of the text, through the scrollTop property. |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
138 while (i--) { |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
139 mirror.style[copyStyle[i]] = $ta.css(copyStyle[i]); |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
140 } |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
141 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
142 $('body').append(mirror); |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
143 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
144 if (onpropertychange in ta) { |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
145 if (oninput in ta) { |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
146 // Detects IE9. IE9 does not fire onpropertychange or oninput for deletions, |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
147 // so binding to onkeyup to catch most of those occassions. There is no way that I |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
148 // know of to detect something like 'cut' in IE9. |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
149 ta[oninput] = ta.onkeyup = adjust; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
150 } else { |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
151 // IE7 / IE8 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
152 ta[onpropertychange] = adjust; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
153 } |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
154 } else { |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
155 // Modern Browsers |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
156 ta[oninput] = adjust; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
157 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
158 // The textarea overflow is now hidden. But Chrome doesn't reflow the text after the scrollbars are removed. |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
159 // This is a hack to get Chrome to reflow it's text. |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
160 ta.value = ''; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
161 ta.value = value; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
162 } |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
163 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
164 $(window).resize(adjust); |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
165 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
166 // Allow for manual triggering if needed. |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
167 $ta.bind('autosize', adjust); |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
168 |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
169 // Call adjust in case the textarea already contains text. |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
170 adjust(); |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
171 }); |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
172 }; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
173 } else { |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
174 // Makes no changes for older browsers (FireFox3- and Safari4-) |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
175 $.fn.autosize = function (callback) { |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
176 return this; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
177 }; |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
178 } |
50b8738d6428
Use (modified) autosize to automatically resize textarea.
Edho Arief <edho@myconan.net>
parents:
diff
changeset
|
179 |
97
e8a0e82213cd
Updated autosize from vendor, separated box size hack to its own function.
Edho Arief <edho@myconan.net>
parents:
79
diff
changeset
|
180 }(window.jQuery || window.Zepto)); |