This repository was archived by the owner on Oct 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathtextinput.js
197 lines (161 loc) · 4.87 KB
/
textinput.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*!
* jQuery Mobile Textinput @VERSION
* http://jquerymobile.com
*
* Copyright jQuery Foundation and other contributors
* Released under the MIT license.
* http://jquery.org/license
*/
//>>label: Text Inputs & Textareas
//>>group: Forms
//>>description: Enhances and consistently styles text inputs.
//>>docs: http://api.jquerymobile.com/textinput/
//>>demos: http://demos.jquerymobile.com/@VERSION/textinput/
//>>css.structure: ../css/structure/jquery.mobile.forms.textinput.css
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css
( function( factory ) {
if ( typeof define === "function" && define.amd ) {
// AMD. Register as an anonymous module.
define( [
"jquery",
"../../core",
"../../widget",
"../../degradeInputs",
"../widget.theme",
"../../zoom" ], factory );
} else {
// Browser globals
factory( jQuery );
}
} )( function( $ ) {
$.widget( "mobile.textinput", {
version: "@VERSION",
options: {
classes: {
"ui-textinput": "ui-corner-all ui-shadow-inset",
"ui-textinput-search-icon": "ui-icon ui-alt-icon ui-icon-search"
},
theme: "inherit",
// This option defaults to true on iOS devices.
preventFocusZoom: /iPhone|iPad|iPod/.test( navigator.platform ) && navigator.userAgent.indexOf( "AppleWebKit" ) > -1,
enhanced: false
},
_create: function() {
var options = this.options,
isSearch = this.element.is( "[type='search'], :jqmData(type='search')" ),
isTextarea = this.element[ 0 ].nodeName.toLowerCase() === "textarea";
if ( this.element.prop( "disabled" ) ) {
options.disabled = true;
}
$.extend( this, {
isSearch: isSearch,
isTextarea: isTextarea
} );
this._autoCorrect();
if ( !options.enhanced ) {
this._enhance();
} else {
this._outer = ( isTextarea ? this.element : this.element.parent() );
if ( isSearch ) {
this._searchIcon = this._outer.children( ".ui-textinput-search-icon" );
}
}
this._addClass( this._outer,
"ui-textinput ui-textinput-" + ( this.isSearch ? "search" : "text" ) );
if ( this._searchIcon ) {
this._addClass( this._searchIcon, "ui-textinput-search-icon" );
}
this._on( {
"focus": "_handleFocus",
"blur": "_handleBlur"
} );
if ( options.disabled !== undefined ) {
this.element.prop( "disabled", !!options.disabled );
this._toggleClass( this._outer, null, "ui-state-disabled", !!options.disabled );
}
},
refresh: function() {
this._setOptions( {
"disabled": this.element.is( ":disabled" )
} );
},
_themeElements: function() {
return [
{
element: this._outer,
prefix: "ui-body-"
}
];
},
_enhance: function() {
var outer;
if ( !this.isTextarea ) {
outer = $( "<div>" );
if ( this.isSearch ) {
this._searchIcon = $( "<span>" ).prependTo( outer );
}
} else {
outer = this.element;
}
this._outer = outer;
// Now that we're done building up the wrapper, wrap the input in it
if ( !this.isTextarea ) {
outer.insertBefore( this.element ).append( this.element );
}
},
widget: function() {
return this._outer;
},
_autoCorrect: function() {
// XXX: Temporary workaround for issue 785 (Apple bug 8910589).
// Turn off autocorrect and autocomplete on non-iOS 5 devices
// since the popup they use can't be dismissed by the user. Note
// that we test for the presence of the feature by looking for
// the autocorrect property on the input element. We currently
// have no test for iOS 5 or newer so we're temporarily using
// the touchOverflow support flag for jQM 1.0. Yes, I feel dirty.
// - jblas
if ( typeof this.element[ 0 ].autocorrect !== "undefined" &&
!$.support.touchOverflow ) {
// Set the attribute instead of the property just in case there
// is code that attempts to make modifications via HTML.
this.element[ 0 ].setAttribute( "autocorrect", "off" );
this.element[ 0 ].setAttribute( "autocomplete", "off" );
}
},
_handleBlur: function() {
this._removeClass( this._outer, null, "ui-focus" );
if ( this.options.preventFocusZoom ) {
$.mobile.zoom.enable( true );
}
},
_handleFocus: function() {
// In many situations, iOS will zoom into the input upon tap, this
// prevents that from happening
if ( this.options.preventFocusZoom ) {
$.mobile.zoom.disable( true );
}
this._addClass( this._outer, null, "ui-focus" );
},
_setOptions: function( options ) {
if ( options.disabled !== undefined ) {
this.element.prop( "disabled", !!options.disabled );
this._toggleClass( this._outer, null, "ui-state-disabled", !!options.disabled );
}
return this._superApply( arguments );
},
_destroy: function() {
if ( this.options.enhanced ) {
this.classesElementLookup = {};
return;
}
if ( this._searchIcon ) {
this._searchIcon.remove();
}
if ( !this.isTextarea ) {
this.element.unwrap();
}
}
} );
return $.widget( "mobile.textinput", $.mobile.textinput, $.mobile.widget.theme );
} );