[CLEAN] qweb, kanban: removed forgotten console.log + unnecessary void line
[odoo/odoo.git] / addons / web / static / lib / jquery.autosize / jquery.autosize.js
1 // Autosize 1.10 - jQuery plugin for textareas\r
2 // (c) 2012 Jack Moore - jacklmoore.com\r
3 // license: www.opensource.org/licenses/mit-license.php\r
4 \r
5 (function ($) {\r
6         var\r
7         hidden = 'hidden',\r
8         borderBox = 'border-box',\r
9         lineHeight = 'lineHeight',\r
10         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">',\r
11         // line-height is omitted because IE7/IE8 doesn't return the correct value.\r
12         copyStyle = [\r
13                 'fontFamily',\r
14                 'fontSize',\r
15                 'fontWeight',\r
16                 'fontStyle',\r
17                 'letterSpacing',\r
18                 'textTransform',\r
19                 'wordSpacing',\r
20                 'textIndent'\r
21         ],\r
22         oninput = 'oninput',\r
23         onpropertychange = 'onpropertychange',\r
24         test = $(copy)[0];\r
25 \r
26         // For testing support in old FireFox\r
27         test.setAttribute(oninput, "return");\r
28 \r
29         if ($.isFunction(test[oninput]) || onpropertychange in test) {\r
30 \r
31                 // test that line-height can be accurately copied to avoid\r
32                 // incorrect value reporting in old IE and old Opera\r
33                 $(test).css(lineHeight, '99px');\r
34                 if ($(test).css(lineHeight) === '99px') {\r
35                         copyStyle.push(lineHeight);\r
36                 }\r
37 \r
38                 $.fn.autosize = function (className) {\r
39                         return this.each(function () {\r
40                                 var\r
41                                 ta = this,\r
42                                 $ta = $(ta),\r
43                                 mirror,\r
44                                 minHeight = $ta.height(),\r
45                                 maxHeight = parseInt($ta.css('maxHeight'), 10),\r
46                                 active,\r
47                                 i = copyStyle.length,\r
48                                 resize,\r
49                                 boxOffset = 0;\r
50 \r
51                                 if ($ta.css('box-sizing') === borderBox || $ta.css('-moz-box-sizing') === borderBox || $ta.css('-webkit-box-sizing') === borderBox){\r
52                                         boxOffset = $ta.outerHeight() - $ta.height();\r
53                                 }\r
54 \r
55                                 if ($ta.data('mirror') || $ta.data('ismirror')) {\r
56                                         // if autosize has already been applied, exit.\r
57                                         // if autosize is being applied to a mirror element, exit.\r
58                                         return;\r
59                                 } else {\r
60                                         mirror = $(copy).data('ismirror', true).addClass(className || 'autosizejs')[0];\r
61 \r
62                                         // Changed allowed resize only in edit mode by VTA (31/8/2012)\r
63                                         if ($ta.attr('disabled')) {\r
64                                                 $ta.css('resize', 'none');\r
65                                         }\r
66                                         // Changed horizontal to vertical by VTA (31/8/2012)\r
67                                         resize = $ta.css('resize') === 'none' ? 'none' : 'vertical';\r
68 \r
69                                         $ta.data('mirror', $(mirror)).css({\r
70                                                 overflow: hidden,\r
71                                                 overflowY: hidden,\r
72                                                 wordWrap: 'break-word',\r
73                                                 resize: resize\r
74                                         });\r
75                                 }\r
76 \r
77                                 // Opera returns '-1px' when max-height is set to 'none'.\r
78                                 maxHeight = maxHeight && maxHeight > 0 ? maxHeight : 9e4;\r
79 \r
80                                 // Using mainly bare JS in this function because it is going\r
81                                 // to fire very often while typing, and needs to very efficient.\r
82                                 function adjust() {\r
83                                         var height, overflow;\r
84                                         // the active flag keeps IE from tripping all over itself.  Otherwise\r
85                                         // actions in the adjust function will cause IE to call adjust again.\r
86                                         if (!active) {\r
87                                                 active = true;\r
88 \r
89                                                 mirror.value = ta.value;\r
90 \r
91                                                 mirror.style.overflowY = ta.style.overflowY;\r
92 \r
93                                                 // Update the width in case the original textarea width has changed\r
94                                                 mirror.style.width = $ta.css('width');\r
95 \r
96                                                 // Needed for IE to reliably return the correct scrollHeight\r
97                                                 mirror.scrollTop = 0;\r
98 \r
99                                                 // Set a very high value for scrollTop to be sure the\r
100                                                 // mirror is scrolled all the way to the bottom.\r
101                                                 mirror.scrollTop = 9e4;\r
102 \r
103                                                 height = mirror.scrollTop;\r
104                                                 overflow = hidden;\r
105                                                 if (height > maxHeight) {\r
106                                                         height = maxHeight;\r
107                                                         overflow = 'scroll';\r
108                                                 } else if (height < minHeight) {\r
109                                                         height = minHeight;\r
110                                                 }\r
111                                                 ta.style.overflowY = overflow;\r
112 \r
113                                                 ta.style.height = height + boxOffset + 'px';\r
114                                                 \r
115                                                 // This small timeout gives IE a chance to draw it's scrollbar\r
116                                                 // before adjust can be run again (prevents an infinite loop).\r
117                                                 setTimeout(function () {\r
118                                                         active = false;\r
119                                                 }, 1);\r
120                                         }\r
121                                 }\r
122 \r
123                                 // mirror is a duplicate textarea located off-screen that\r
124                                 // is automatically updated to contain the same text as the\r
125                                 // original textarea.  mirror always has a height of 0.\r
126                                 // This gives a cross-browser supported way getting the actual\r
127                                 // height of the text, through the scrollTop property.\r
128                                 while (i--) {\r
129                                         mirror.style[copyStyle[i]] = $ta.css(copyStyle[i]);\r
130                                 }\r
131 \r
132                                 $('body').append(mirror);\r
133 \r
134                                 if (onpropertychange in ta) {\r
135                                         if (oninput in ta) {\r
136                                                 // Detects IE9.  IE9 does not fire onpropertychange or oninput for deletions,\r
137                                                 // so binding to onkeyup to catch most of those occassions.  There is no way that I\r
138                                                 // know of to detect something like 'cut' in IE9.\r
139                                                 ta[oninput] = ta.onkeyup = adjust;\r
140                                         } else {\r
141                                                 // IE7 / IE8\r
142                                                 ta[onpropertychange] = adjust;\r
143                                         }\r
144                                 } else {\r
145                                         // Modern Browsers\r
146                                         ta[oninput] = adjust;\r
147                                 }\r
148 \r
149                                 $(window).resize(adjust);\r
150 \r
151                                 // Allow for manual triggering if needed.\r
152                                 $ta.bind('autosize', adjust);\r
153 \r
154                                 // Call adjust in case the textarea already contains text.\r
155                                 adjust();\r
156                         });\r
157                 };\r
158         } else {\r
159                 // Makes no changes for older browsers (FireFox3- and Safari4-)\r
160                 $.fn.autosize = function () {\r
161                         return this;\r
162                 };\r
163         }\r
164 \r
165 }(jQuery));