~openerp-dev/openerp-web/trunk-jquery1.9-ppa

« back to all changes in this revision

Viewing changes to addons/web/static/lib/jquery.autosize/jquery.autosize.js

  • Committer: Prashant Panchal(OpenERP)
  • Date: 2014-04-16 09:24:51 UTC
  • Revision ID: ppa@tinyerp.com-20140416092451-outv36dahgip1860
[IMP] add jquery-migrate-1.1.1.j & jquery-1.9.1.js & change in web

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Autosize 1.10 - jQuery plugin for textareas
2
 
// (c) 2012 Jack Moore - jacklmoore.com
3
 
// license: www.opensource.org/licenses/mit-license.php
4
 
 
5
 
(function ($) {
6
 
        var
7
 
        hidden = 'hidden',
8
 
        borderBox = 'border-box',
9
 
        lineHeight = 'lineHeight',
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">',
11
 
        // line-height is omitted because IE7/IE8 doesn't return the correct value.
12
 
        copyStyle = [
13
 
                'fontFamily',
14
 
                'fontSize',
15
 
                'fontWeight',
16
 
                'fontStyle',
17
 
                'letterSpacing',
18
 
                'textTransform',
19
 
                'wordSpacing',
20
 
                'textIndent'
21
 
        ],
22
 
        oninput = 'oninput',
23
 
        onpropertychange = 'onpropertychange',
24
 
        test = $(copy)[0];
25
 
 
26
 
        // For testing support in old FireFox
27
 
        test.setAttribute(oninput, "return");
28
 
 
29
 
        if ($.isFunction(test[oninput]) || onpropertychange in test) {
30
 
 
31
 
                // test that line-height can be accurately copied to avoid
32
 
                // incorrect value reporting in old IE and old Opera
33
 
                $(test).css(lineHeight, '99px');
34
 
                if ($(test).css(lineHeight) === '99px') {
35
 
                        copyStyle.push(lineHeight);
36
 
                }
37
 
 
38
 
                $.fn.autosize = function (className) {
39
 
                        return this.each(function () {
40
 
                                var
41
 
                                ta = this,
42
 
                                $ta = $(ta),
43
 
                                mirror,
44
 
                                minHeight = $ta.height(),
45
 
                                maxHeight = parseInt($ta.css('maxHeight'), 10),
46
 
                                active,
47
 
                                i = copyStyle.length,
48
 
                                resize,
49
 
                                boxOffset = 0;
50
 
 
51
 
                                if ($ta.css('box-sizing') === borderBox || $ta.css('-moz-box-sizing') === borderBox || $ta.css('-webkit-box-sizing') === borderBox){
52
 
                                        boxOffset = $ta.outerHeight() - $ta.height();
53
 
                                }
54
 
 
55
 
                                if ($ta.data('mirror') || $ta.data('ismirror')) {
56
 
                                        // if autosize has already been applied, exit.
57
 
                                        // if autosize is being applied to a mirror element, exit.
58
 
                                        return;
59
 
                                } else {
60
 
                                        mirror = $(copy).data('ismirror', true).addClass(className || 'autosizejs')[0];
61
 
 
62
 
                                        // Changed allowed resize only in edit mode by VTA (31/8/2012)
63
 
                                        if ($ta.attr('disabled')) {
64
 
                                                $ta.css('resize', 'none');
65
 
                                        }
66
 
                                        // Changed horizontal to vertical by VTA (31/8/2012)
67
 
                                        resize = $ta.css('resize') === 'none' ? 'none' : 'vertical';
68
 
 
69
 
                                        $ta.data('mirror', $(mirror)).css({
70
 
                                                overflow: hidden,
71
 
                                                overflowY: hidden,
72
 
                                                wordWrap: 'break-word',
73
 
                                                resize: resize
74
 
                                        });
75
 
                                }
76
 
 
77
 
                                // Opera returns '-1px' when max-height is set to 'none'.
78
 
                                maxHeight = maxHeight && maxHeight > 0 ? maxHeight : 9e4;
79
 
 
80
 
                                // Using mainly bare JS in this function because it is going
81
 
                                // to fire very often while typing, and needs to very efficient.
82
 
                                function adjust() {
83
 
                                        var height, overflow;
84
 
                                        // the active flag keeps IE from tripping all over itself.  Otherwise
85
 
                                        // actions in the adjust function will cause IE to call adjust again.
86
 
                                        if (!active) {
87
 
                                                active = true;
88
 
 
89
 
                                                mirror.value = ta.value;
90
 
 
91
 
                                                mirror.style.overflowY = ta.style.overflowY;
92
 
 
93
 
                                                // Update the width in case the original textarea width has changed
94
 
                                                mirror.style.width = $ta.css('width');
95
 
 
96
 
                                                // Needed for IE to reliably return the correct scrollHeight
97
 
                                                mirror.scrollTop = 0;
98
 
 
99
 
                                                // Set a very high value for scrollTop to be sure the
100
 
                                                // mirror is scrolled all the way to the bottom.
101
 
                                                mirror.scrollTop = 9e4;
102
 
 
103
 
                                                height = mirror.scrollTop;
104
 
                                                overflow = hidden;
105
 
                                                if (height > maxHeight) {
106
 
                                                        height = maxHeight;
107
 
                                                        overflow = 'scroll';
108
 
                                                } else if (height < minHeight) {
109
 
                                                        height = minHeight;
110
 
                                                }
111
 
                                                ta.style.overflowY = overflow;
112
 
 
113
 
                                                ta.style.height = height + boxOffset + 'px';
114
 
                                                
115
 
                                                // This small timeout gives IE a chance to draw it's scrollbar
116
 
                                                // before adjust can be run again (prevents an infinite loop).
117
 
                                                setTimeout(function () {
118
 
                                                        active = false;
119
 
                                                }, 1);
120
 
                                        }
121
 
                                }
122
 
 
123
 
                                // mirror is a duplicate textarea located off-screen that
124
 
                                // is automatically updated to contain the same text as the
125
 
                                // original textarea.  mirror always has a height of 0.
126
 
                                // This gives a cross-browser supported way getting the actual
127
 
                                // height of the text, through the scrollTop property.
128
 
                                while (i--) {
129
 
                                        mirror.style[copyStyle[i]] = $ta.css(copyStyle[i]);
130
 
                                }
131
 
 
132
 
                                $('body').append(mirror);
133
 
 
134
 
                                if (onpropertychange in ta) {
135
 
                                        if (oninput in ta) {
136
 
                                                // Detects IE9.  IE9 does not fire onpropertychange or oninput for deletions,
137
 
                                                // so binding to onkeyup to catch most of those occassions.  There is no way that I
138
 
                                                // know of to detect something like 'cut' in IE9.
139
 
                                                ta[oninput] = ta.onkeyup = adjust;
140
 
                                        } else {
141
 
                                                // IE7 / IE8
142
 
                                                ta[onpropertychange] = adjust;
143
 
                                        }
144
 
                                } else {
145
 
                                        // Modern Browsers
146
 
                                        ta[oninput] = adjust;
147
 
                                }
148
 
 
149
 
                                $(window).resize(adjust);
150
 
 
151
 
                                // Allow for manual triggering if needed.
152
 
                                $ta.bind('autosize', adjust);
153
 
 
154
 
                                // Call adjust in case the textarea already contains text.
155
 
                                adjust();
156
 
                        });
157
 
                };
158
 
        } else {
159
 
                // Makes no changes for older browsers (FireFox3- and Safari4-)
160
 
                $.fn.autosize = function () {
161
 
                        return this;
162
 
                };
163
 
        }
164
 
 
165
 
}(jQuery));
 
 
b'\\ No newline at end of file'
 
1
/*!
 
2
        Autosize v1.18.6 - 2014-03-13
 
3
        Automatically adjust textarea height based on user input.
 
4
        (c) 2014 Jack Moore - http://www.jacklmoore.com/autosize
 
5
        license: http://www.opensource.org/licenses/mit-license.php
 
6
*/
 
7
(function ($) {
 
8
        var
 
9
        defaults = {
 
10
                className: 'autosizejs',
 
11
                id: 'autosizejs',
 
12
                append: '',
 
13
                callback: false,
 
14
                resizeDelay: 10,
 
15
                placeholder: true
 
16
        },
 
17
 
 
18
        // border:0 is unnecessary, but avoids a bug in Firefox on OSX
 
19
        copy = '<textarea tabindex="-1" style="position:absolute; top:-999px; left:0; right:auto; bottom:auto; border:0; padding: 0; -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; transition:none; -webkit-transition:none; -moz-transition:none;"/>',
 
20
 
 
21
        // line-height is conditionally included because IE7/IE8/old Opera do not return the correct value.
 
22
        typographyStyles = [
 
23
                'fontFamily',
 
24
                'fontSize',
 
25
                'fontWeight',
 
26
                'fontStyle',
 
27
                'letterSpacing',
 
28
                'textTransform',
 
29
                'wordSpacing',
 
30
                'textIndent'
 
31
        ],
 
32
 
 
33
        // to keep track which textarea is being mirrored when adjust() is called.
 
34
        mirrored,
 
35
 
 
36
        // the mirror element, which is used to calculate what size the mirrored element should be.
 
37
        mirror = $(copy).data('autosize', true)[0];
 
38
 
 
39
        // test that line-height can be accurately copied.
 
40
        mirror.style.lineHeight = '99px';
 
41
        if ($(mirror).css('lineHeight') === '99px') {
 
42
                typographyStyles.push('lineHeight');
 
43
        }
 
44
        mirror.style.lineHeight = '';
 
45
 
 
46
        $.fn.autosize = function (options) {
 
47
                if (!this.length) {
 
48
                        return this;
 
49
                }
 
50
 
 
51
                options = $.extend({}, defaults, options || {});
 
52
 
 
53
                if (mirror.parentNode !== document.body) {
 
54
                        $(document.body).append(mirror);
 
55
                }
 
56
 
 
57
                return this.each(function () {
 
58
                        var
 
59
                        ta = this,
 
60
                        $ta = $(ta),
 
61
                        maxHeight,
 
62
                        minHeight,
 
63
                        boxOffset = 0,
 
64
                        callback = $.isFunction(options.callback),
 
65
                        originalStyles = {
 
66
                                height: ta.style.height,
 
67
                                overflow: ta.style.overflow,
 
68
                                overflowY: ta.style.overflowY,
 
69
                                wordWrap: ta.style.wordWrap,
 
70
                                resize: ta.style.resize
 
71
                        },
 
72
                        timeout,
 
73
                        width = $ta.width();
 
74
 
 
75
                        if ($ta.data('autosize')) {
 
76
                                // exit if autosize has already been applied, or if the textarea is the mirror element.
 
77
                                return;
 
78
                        }
 
79
                        $ta.data('autosize', true);
 
80
 
 
81
                        if ($ta.css('box-sizing') === 'border-box' || $ta.css('-moz-box-sizing') === 'border-box' || $ta.css('-webkit-box-sizing') === 'border-box'){
 
82
                                boxOffset = $ta.outerHeight() - $ta.height();
 
83
                        }
 
84
 
 
85
                        // IE8 and lower return 'auto', which parses to NaN, if no min-height is set.
 
86
                        minHeight = Math.max(parseInt($ta.css('minHeight'), 10) - boxOffset || 0, $ta.height());
 
87
 
 
88
                        $ta.css({
 
89
                                overflow: 'hidden',
 
90
                                overflowY: 'hidden',
 
91
                                wordWrap: 'break-word', // horizontal overflow is hidden, so break-word is necessary for handling words longer than the textarea width
 
92
                                resize: ($ta.css('resize') === 'none' || $ta.css('resize') === 'vertical') ? 'none' : 'horizontal'
 
93
                        });
 
94
 
 
95
                        // The mirror width must exactly match the textarea width, so using getBoundingClientRect because it doesn't round the sub-pixel value.
 
96
                        // window.getComputedStyle, getBoundingClientRect returning a width are unsupported, but also unneeded in IE8 and lower.
 
97
                        function setWidth() {
 
98
                                var width;
 
99
                                var style = window.getComputedStyle ? window.getComputedStyle(ta, null) : false;
 
100
                                
 
101
                                if (style) {
 
102
 
 
103
                                        width = ta.getBoundingClientRect().width;
 
104
 
 
105
                                        if (width === 0) {
 
106
                                                width = parseInt(style.width,10);
 
107
                                        }
 
108
 
 
109
                                        $.each(['paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth'], function(i,val){
 
110
                                                width -= parseInt(style[val],10);
 
111
                                        });
 
112
                                } else {
 
113
                                        width = Math.max($ta.width(), 0);
 
114
                                }
 
115
 
 
116
                                mirror.style.width = width + 'px';
 
117
                        }
 
118
 
 
119
                        function initMirror() {
 
120
                                var styles = {};
 
121
 
 
122
                                mirrored = ta;
 
123
                                mirror.className = options.className;
 
124
                                mirror.id = options.id;
 
125
                                maxHeight = parseInt($ta.css('maxHeight'), 10);
 
126
 
 
127
                                // mirror is a duplicate textarea located off-screen that
 
128
                                // is automatically updated to contain the same text as the
 
129
                                // original textarea.  mirror always has a height of 0.
 
130
                                // This gives a cross-browser supported way getting the actual
 
131
                                // height of the text, through the scrollTop property.
 
132
                                $.each(typographyStyles, function(i,val){
 
133
                                        styles[val] = $ta.css(val);
 
134
                                });
 
135
                                
 
136
                                $(mirror).css(styles).attr('wrap', $ta.attr('wrap'));
 
137
 
 
138
                                setWidth();
 
139
 
 
140
                                // Chrome-specific fix:
 
141
                                // When the textarea y-overflow is hidden, Chrome doesn't reflow the text to account for the space
 
142
                                // made available by removing the scrollbar. This workaround triggers the reflow for Chrome.
 
143
                                if (window.chrome) {
 
144
                                        var width = ta.style.width;
 
145
                                        ta.style.width = '0px';
 
146
                                        var ignore = ta.offsetWidth;
 
147
                                        ta.style.width = width;
 
148
                                }
 
149
                        }
 
150
 
 
151
                        // Using mainly bare JS in this function because it is going
 
152
                        // to fire very often while typing, and needs to very efficient.
 
153
                        function adjust() {
 
154
                                var height, original;
 
155
 
 
156
                                if (mirrored !== ta) {
 
157
                                        initMirror();
 
158
                                } else {
 
159
                                        setWidth();
 
160
                                }
 
161
 
 
162
                                if (!ta.value && options.placeholder) {
 
163
                                        // If the textarea is empty, copy the placeholder text into 
 
164
                                        // the mirror control and use that for sizing so that we 
 
165
                                        // don't end up with placeholder getting trimmed.
 
166
                                        mirror.value = ($ta.attr("placeholder") || '') + options.append;
 
167
                                } else {
 
168
                                        mirror.value = ta.value + options.append;
 
169
                                }
 
170
 
 
171
                                mirror.style.overflowY = ta.style.overflowY;
 
172
                                original = parseInt(ta.style.height,10);
 
173
 
 
174
                                // Setting scrollTop to zero is needed in IE8 and lower for the next step to be accurately applied
 
175
                                mirror.scrollTop = 0;
 
176
 
 
177
                                mirror.scrollTop = 9e4;
 
178
 
 
179
                                // Using scrollTop rather than scrollHeight because scrollHeight is non-standard and includes padding.
 
180
                                height = mirror.scrollTop;
 
181
 
 
182
                                if (maxHeight && height > maxHeight) {
 
183
                                        ta.style.overflowY = 'scroll';
 
184
                                        height = maxHeight;
 
185
                                } else {
 
186
                                        ta.style.overflowY = 'hidden';
 
187
                                        if (height < minHeight) {
 
188
                                                height = minHeight;
 
189
                                        }
 
190
                                }
 
191
 
 
192
                                height += boxOffset;
 
193
 
 
194
                                if (original !== height) {
 
195
                                        ta.style.height = height + 'px';
 
196
                                        if (callback) {
 
197
                                                options.callback.call(ta,ta);
 
198
                                        }
 
199
                                }
 
200
                        }
 
201
 
 
202
                        function resize () {
 
203
                                clearTimeout(timeout);
 
204
                                timeout = setTimeout(function(){
 
205
                                        var newWidth = $ta.width();
 
206
 
 
207
                                        if (newWidth !== width) {
 
208
                                                width = newWidth;
 
209
                                                adjust();
 
210
                                        }
 
211
                                }, parseInt(options.resizeDelay,10));
 
212
                        }
 
213
 
 
214
                        if ('onpropertychange' in ta) {
 
215
                                if ('oninput' in ta) {
 
216
                                        // Detects IE9.  IE9 does not fire onpropertychange or oninput for deletions,
 
217
                                        // so binding to onkeyup to catch most of those occasions.  There is no way that I
 
218
                                        // know of to detect something like 'cut' in IE9.
 
219
                                        $ta.on('input.autosize keyup.autosize', adjust);
 
220
                                } else {
 
221
                                        // IE7 / IE8
 
222
                                        $ta.on('propertychange.autosize', function(){
 
223
                                                if(event.propertyName === 'value'){
 
224
                                                        adjust();
 
225
                                                }
 
226
                                        });
 
227
                                }
 
228
                        } else {
 
229
                                // Modern Browsers
 
230
                                $ta.on('input.autosize', adjust);
 
231
                        }
 
232
 
 
233
                        // Set options.resizeDelay to false if using fixed-width textarea elements.
 
234
                        // Uses a timeout and width check to reduce the amount of times adjust needs to be called after window resize.
 
235
 
 
236
                        if (options.resizeDelay !== false) {
 
237
                                $(window).on('resize.autosize', resize);
 
238
                        }
 
239
 
 
240
                        // Event for manual triggering if needed.
 
241
                        // Should only be needed when the value of the textarea is changed through JavaScript rather than user input.
 
242
                        $ta.on('autosize.resize', adjust);
 
243
 
 
244
                        // Event for manual triggering that also forces the styles to update as well.
 
245
                        // Should only be needed if one of typography styles of the textarea change, and the textarea is already the target of the adjust method.
 
246
                        $ta.on('autosize.resizeIncludeStyle', function() {
 
247
                                mirrored = null;
 
248
                                adjust();
 
249
                        });
 
250
 
 
251
                        $ta.on('autosize.destroy', function(){
 
252
                                mirrored = null;
 
253
                                clearTimeout(timeout);
 
254
                                $(window).off('resize', resize);
 
255
                                $ta
 
256
                                        .off('autosize')
 
257
                                        .off('.autosize')
 
258
                                        .css(originalStyles)
 
259
                                        .removeData('autosize');
 
260
                        });
 
261
 
 
262
                        // Call adjust in case the textarea already contains text.
 
263
                        adjust();
 
264
                });
 
265
        };
 
266
}(window.jQuery || window.$)); // jQuery or jQuery-like library, such as Zepto