Coveralls logob
Coveralls logo
  • Home
  • Features
  • Pricing
  • Docs
  • Sign In

jquery / jquery-mobile / 2313

5 Feb 2015 - 11:04 coverage increased (+0.009%) to 82.482%
2313

Pull #7953

travis-ci

Acabeff49b5ba95a8e94de9445175f56?size=18&default=identicongabrielschulhof
Textinput: Update comment regarding deprecated style options
Pull Request #7953: Textinput: Implement classes option

3503 of 4247 relevant lines covered (82.48%)

924.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.92
/js/widgets/forms/autogrow.js
1
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2
//>>description: Enhances and consistently styles text inputs.
3
//>>label: Textarea Autosize
4
//>>group: Forms
5
//>>css.structure: ../css/structure/jquery.mobile.forms.textinput.autogrow.css
6
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css
7

8
define( [
9×
9
        "jquery",
10
        "./textinput" ], function( jQuery ) {
11
//>>excludeEnd("jqmBuildExclude");
12
(function( $, undefined ) {
9×
13

14
        $.widget( "mobile.textinput", $.mobile.textinput, {
9×
15
                options: {
16
                        classes: {
17
                                "ui-textinput-autogrow": null,
18
                                "ui-textinput-autogrow-resize": null
19
                        },
20
                        autogrow:true,
21
                        keyupTimeoutBuffer: 100
22
                },
23

24
                _create: function() {
25
                        this._super();
60×
26

27
                        if ( this.options.autogrow && this.isTextarea ) {
60×
28
                                this._autogrow();
27×
29
                        }
30
                },
31

32
                _autogrow: function() {
33
                        this._addClass( this.element, "ui-textinput-autogrow" );
27×
34

35
                        this._on({
27×
36
                                "keyup": "_timeout",
37
                                "change": "_timeout",
38
                                "input": "_timeout",
39
                                "paste": "_timeout"
40
                        });
41

42
                        // Attach to the various you-have-become-visible notifications that the
43
                        // various framework elements emit.
44
                        // TODO: Remove all but the updatelayout handler once #6426 is fixed.
45
                        this._on( true, this.document, {
27×
46

47
                                // TODO: Move to non-deprecated event
48
                                "pageshow": "_handleShow",
49
                                "popupbeforeposition": "_handleShow",
50
                                "updatelayout": "_handleShow",
51
                                "panelopen": "_handleShow"
52
                        });
53
                },
54

55
                // Synchronously fix the widget height if this widget's parents are such
56
                // that they show/hide content at runtime. We still need to check whether
57
                // the widget is actually visible in case it is contained inside multiple
58
                // such containers. For example: panel contains collapsible contains
59
                // autogrow textinput. The panel may emit "panelopen" indicating that its
60
                // content has become visible, but the collapsible is still collapsed, so
61
                // the autogrow textarea is still not visible.
62
                _handleShow: function( event ) {
63
                        if ( $.contains( event.target, this.element[ 0 ] ) &&
66×
64
                                this.element.is( ":visible" ) ) {
65

66
                                if ( event.type !== "popupbeforeposition" ) {
45×
67
                                        this._addClass( this.element, "ui-textinput-autogrow-resize" );
45×
68
                                        this.element
45×
69
                                                .animationComplete(
70
                                                        $.proxy( function() {
71
                                                                this._removeClass( this.element, "ui-textinput-autogrow-resize" );
24×
72
                                                        }, this ),
73
                                                "transition" );
74
                                }
75
                                this._prepareHeightUpdate();
45×
76
                        }
77
                },
78

79
                _unbindAutogrow: function() {
UNCOV
80
                        this._removeClass( this.element, "ui-textinput-autogrow" );
!
UNCOV
81
                        this._off( this.element, "keyup change input paste" );
!
UNCOV
82
                        this._off( this.document,
!
83
                                "pageshow popupbeforeposition updatelayout panelopen" );
84
                },
85

86
                keyupTimeout: null,
87

88
                _prepareHeightUpdate: function( delay ) {
89
                        if ( this.keyupTimeout ) {
48×
UNCOV
90
                                clearTimeout( this.keyupTimeout );
!
91
                        }
92
                        if ( delay === undefined ) {
48×
93
                                this._updateHeight();
45×
94
                        } else {
95
                                this.keyupTimeout = this._delay( "_updateHeight", delay );
3×
96
                        }
97
                },
98

99
                _timeout: function() {
100
                        this._prepareHeightUpdate( this.options.keyupTimeoutBuffer );
3×
101
                },
102

103
                _updateHeight: function() {
104
                        var paddingTop, paddingBottom, paddingHeight, scrollHeight, clientHeight,
48×
105
                                borderTop, borderBottom, borderHeight, height,
106
                                scrollTop = this.window.scrollTop();
107
                        this.keyupTimeout = 0;
48×
108

109
                        // IE8 textareas have the onpage property - others do not
110
                        if ( !( "onpage" in this.element[ 0 ] ) ) {
48×
111
                                this.element.css({
48×
112
                                        "height": 0,
113
                                        "min-height": 0,
114
                                        "max-height": 0
115
                                });
116
                        }
117

118
                        scrollHeight = this.element[ 0 ].scrollHeight;
48×
119
                        clientHeight = this.element[ 0 ].clientHeight;
48×
120
                        borderTop = parseFloat( this.element.css( "border-top-width" ) );
48×
121
                        borderBottom = parseFloat( this.element.css( "border-bottom-width" ) );
48×
122
                        borderHeight = borderTop + borderBottom;
48×
123
                        height = scrollHeight + borderHeight + 15;
48×
124

125
                        // Issue 6179: Padding is not included in scrollHeight and
126
                        // clientHeight by Firefox if no scrollbar is visible. Because
127
                        // textareas use the border-box box-sizing model, padding should be
128
                        // included in the new (assigned) height. Because the height is set
129
                        // to 0, clientHeight == 0 in Firefox. Therefore, we can use this to
130
                        // check if padding must be added.
131
                        if ( clientHeight === 0 ) {
48×
132
                                paddingTop = parseFloat( this.element.css( "padding-top" ) );
!
UNCOV
133
                                paddingBottom = parseFloat( this.element.css( "padding-bottom" ) );
!
UNCOV
134
                                paddingHeight = paddingTop + paddingBottom;
!
135

UNCOV
136
                                height += paddingHeight;
!
137
                        }
138

139
                        this.element.css({
48×
140
                                "height": height,
141
                                "min-height": "",
142
                                "max-height": ""
143
                        });
144

145
                        this.window.scrollTop( scrollTop );
48×
146
                },
147

148
                refresh: function() {
UNCOV
149
                        if ( this.options.autogrow && this.isTextarea ) {
!
UNCOV
150
                                this._updateHeight();
!
151
                        }
152
                },
153

154
                _setOptions: function( options ) {
155

156
                        this._super( options );
6×
157

158
                        if ( options.autogrow !== undefined && this.isTextarea ) {
6×
UNCOV
159
                                if ( options.autogrow ) {
!
UNCOV
160
                                        this._autogrow();
!
161
                                } else {
UNCOV
162
                                        this._unbindAutogrow();
!
163
                                }
164
                        }
165
                }
166

167
        });
168
})( jQuery );
169
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
170
});
171
//>>excludeEnd("jqmBuildExclude");
Troubleshooting · Open an Issue · Sales · Support · ENTERPRISE · CAREERS · STATUS
BLOG · TWITTER · Legal & Privacy · Supported CI Services · What's a CI service? · Automated Testing

© 2022 Coveralls, Inc