77define ( [ "jquery" , "./forms/textinput" ] , function ( jQuery ) {
88//>>excludeEnd("jqmBuildExclude");
99( function ( $ , undefined ) {
10- "use strict" ;
1110
1211 // TODO rename filterCallback/deprecate and default to the item itself as the first argument
1312 var defaultfilterCallback = function ( text , searchValue /*, item */ ) {
@@ -31,9 +30,8 @@ define( [ "jquery", "./forms/textinput" ], function( jQuery ) {
3130 } ,
3231
3332 _onKeyUp : function ( ) {
34- var self = this ,
35- search = self . _search [ 0 ] ,
36- o = self . options ,
33+ var search = this . _search [ 0 ] ,
34+ o = this . options ,
3735 getAttrFixed = $ . mobile . getAttribute ,
3836 val = search . value . toLowerCase ( ) ,
3937 lastval = getAttrFixed ( search , "lastval" , true ) + "" ;
@@ -47,21 +45,19 @@ define( [ "jquery", "./forms/textinput" ], function( jQuery ) {
4745 window . clearTimeout ( o . timer ) ;
4846 }
4947
50- o . timer = window . setTimeout ( function ( ) {
48+ o . timer = this . _delay ( function ( ) {
49+ this . _trigger ( "beforefilter" , "beforefilter" , { input : search } ) ;
5150
52- self . _trigger ( "beforefilter" , "beforefilter" , { input : search } ) ;
53-
5451 // Change val as lastval for next execution
5552 search . setAttribute ( "data-" + $ . mobile . ns + "lastval" , val ) ;
56-
57- self . _filterItems ( search , val , lastval ) ;
58- } , 250 ) ;
53+
54+ this . _filterItems ( search , val , lastval ) ;
55+ } , 250 )
5956 } ,
6057
6158 _getFilterableItems : function ( ) {
62- var self = this ,
63- el = self . element ,
64- o = self . options ,
59+ var el = this . element ,
60+ o = this . options ,
6561 items = [ ] ;
6662
6763 if ( typeof o . selector === "string" ) {
@@ -73,11 +69,10 @@ define( [ "jquery", "./forms/textinput" ], function( jQuery ) {
7369 } ,
7470
7571 _setFilterableItems : function ( val , lastval ) {
76- var self = this ,
77- o = self . options ,
72+ var o = this . options ,
7873 filterItems = [ ] ,
7974 isCustomfilterCallback = o . filterCallback !== defaultfilterCallback ,
80- _getFilterableItems = self . _getFilterableItems ( ) ;
75+ _getFilterableItems = this . _getFilterableItems ( ) ;
8176
8277 if ( isCustomfilterCallback || val . length < lastval . length || val . indexOf ( lastval ) !== 0 ) {
8378
@@ -96,18 +91,17 @@ define( [ "jquery", "./forms/textinput" ], function( jQuery ) {
9691 } ,
9792
9893 _filterItems : function ( search , val , lastval ) {
99- var self = this ,
100- o = self . options ,
94+ var o = this . options ,
10195 getAttrFixed = $ . mobile . getAttribute ,
102- filterItems = self . _setFilterableItems ( val , lastval ) ,
103- _getFilterableItems = self . _getFilterableItems ( ) ,
96+ filterItems = this . _setFilterableItems ( val , lastval ) ,
97+ _getFilterableItems = this . _getFilterableItems ( ) ,
10498 childItems = false ,
10599 itemtext = "" ,
106100 item ,
107- select = self . element . parents ( ".ui-select" ) ,
101+ select = this . element . parents ( ".ui-select" ) ,
108102 i ;
109103
110- self . _setOption ( "timer" , undefined ) ;
104+ this . _setOption ( "timer" , undefined ) ;
111105
112106 if ( val ) {
113107
@@ -137,12 +131,12 @@ define( [ "jquery", "./forms/textinput" ], function( jQuery ) {
137131 }
138132 }
139133
140- self . _toggleFilterableItems ( filterItems , select , o . filterReveal , true ) ;
134+ this . _toggleFilterableItems ( filterItems , select , o . filterReveal , true ) ;
141135 } else {
142- self . _toggleFilterableItems ( filterItems , select , o . filterReveal ) ;
136+ this . _toggleFilterableItems ( filterItems , select , o . filterReveal ) ;
143137 }
144138
145- self . _addFirstLastClasses ( _getFilterableItems , self . _getVisibles ( _getFilterableItems , false ) , false ) ;
139+ this . _addFirstLastClasses ( _getFilterableItems , this . _getVisibles ( _getFilterableItems , false ) , false ) ;
146140 } ,
147141
148142 _toggleFilterableItems : function ( filterItems , select , reveal , isVal ) {
@@ -176,13 +170,12 @@ define( [ "jquery", "./forms/textinput" ], function( jQuery ) {
176170 } ,
177171
178172 _enhance : function ( ) {
179- var self = this ,
180- el = this . element ,
181- o = self . options ,
173+ var el = this . element ,
174+ o = this . options ,
182175 wrapper = $ ( "<div>" , {
183176 "class" : o . classes + " ui-filter " ,
184177 "role" : "search" ,
185- "id" : o . id || "ui-filter-" + self . uuid
178+ "id" : o . id || "ui-filter-" + this . uuid
186179 } ) ,
187180 search = $ ( "<input>" , {
188181 placeholder : o . filterPlaceholder
@@ -208,19 +201,18 @@ define( [ "jquery", "./forms/textinput" ], function( jQuery ) {
208201 } ,
209202
210203 _create : function ( ) {
211- var self = this ,
212- o = self . options ,
204+ var o = this . options ,
213205 search ,
214- items = self . _getFilterableItems ( ) ;
206+ items = this . _getFilterableItems ( ) ;
215207
216208 if ( o . filterReveal ) {
217209 items . addClass ( "ui-screen-hidden" ) ;
218210 }
219211
220- self . _setOption ( "timer" , undefined ) ;
212+ this . _setOption ( "timer" , undefined ) ;
221213
222214 if ( o . enhance ) {
223- search = self . _enhance ( ) ;
215+ search = this . _enhance ( ) ;
224216 } else {
225217 // NOTE: DIY requires data-id, otherwise how do we find the search
226218 // input. We could always wrap the filterable element (e.g. ul) in
@@ -229,9 +221,9 @@ define( [ "jquery", "./forms/textinput" ], function( jQuery ) {
229221 search = $ ( "#" + o . id ) . find ( "input" ) ;
230222 }
231223
232- self . _on ( search , { keyup : "_onKeyUp" , change : "_onKeyUp" , input : "_onKeyUp" } ) ;
224+ this . _on ( search , { keyup : "_onKeyUp" , change : "_onKeyUp" , input : "_onKeyUp" } ) ;
233225
234- $ . extend ( self , {
226+ $ . extend ( this , {
235227 _search : search
236228 } ) ;
237229
@@ -244,38 +236,36 @@ define( [ "jquery", "./forms/textinput" ], function( jQuery ) {
244236 // "_super()-widget" calling it. So 2x input on the filter should trigger
245237 // 2x addFirstLastClasses vs. currently 3x because of including the call
246238 // when setting up the parent listview.
247- self . _addFirstLastClasses ( items , self . _getVisibles ( items , true ) , true ) ;
239+ this . _addFirstLastClasses ( items , this . _getVisibles ( items , true ) , true ) ;
248240 } ,
249241
250242 _setOptions : function ( options ) {
251- var self = this ,
252- key ;
243+ var key ;
253244
254245 for ( key in options ) {
255246 if ( options . hasOwnProperty ( key ) ) {
256- self . _setOption ( key , options [ key ] ) ;
247+ this . _setOption ( key , options [ key ] ) ;
257248 }
258249 }
259250
260- return self ;
251+ return this ;
261252 } ,
262253
263254 _setOption : function ( key , value ) {
264- var self = this ,
265- o = self . options ,
266- wrapper = document . getElementById ( o . id || "ui-filter-" + self . uuid ) ,
255+ var o = this . options ,
256+ wrapper = document . getElementById ( o . id || "ui-filter-" + this . uuid ) ,
267257 $input = $ ( wrapper ) . find ( "input" ) ;
268258
269259 // always update
270260 o [ key ] = value ;
271261
272262 if ( key === "disabled" ) {
273263 $input
274- . toggleClass ( self . widgetFullName + "-disabled ui-state-disabled" , ! ! value )
264+ . toggleClass ( this . widgetFullName + "-disabled ui-state-disabled" , ! ! value )
275265 . attr ( "aria-disabled" , value )
276266 . textinput ( value ? "disable" : "enable" ) ;
277267 }
278- return self ;
268+ return this ;
279269 } ,
280270
281271 widget : function ( ) {
@@ -291,15 +281,14 @@ define( [ "jquery", "./forms/textinput" ], function( jQuery ) {
291281 } ,
292282
293283 destroy : function ( ) {
294- var self = this ,
295- o = self . options ,
296- wrapper = document . getElementById ( o . id || "ui-filter-" + self . uuid ) ;
284+ var o = this . options ,
285+ wrapper = document . getElementById ( o . id || "ui-filter-" + this . uuid ) ;
297286
298287 if ( o . enhance ) {
299288 wrapper . parentNode . removeChild ( wrapper ) ;
300289 }
301- self . _toggleFilterableItems ( self . _getFilterableItems ( ) , false , false ) ;
302- self . _destroy ( ) ;
290+ this . _toggleFilterableItems ( this . _getFilterableItems ( ) , false , false ) ;
291+ this . _destroy ( ) ;
303292 }
304293
305294 } , $ . mobile . behaviors . addFirstLastClasses ) ) ;
0 commit comments