|
6 | 6 |
|
7 | 7 | define( [ |
8 | 8 | "jquery", |
9 | | - "./listview", |
| 9 | + "./listview.hidedividers", |
10 | 10 | "./filterable" ], function( jQuery ) { |
11 | 11 | //>>excludeEnd("jqmBuildExclude"); |
12 | 12 | (function( $, undefined ) { |
@@ -160,6 +160,24 @@ $.widget( "mobile.filterable", $.mobile.filterable, { |
160 | 160 | return ret; |
161 | 161 | }, |
162 | 162 |
|
| 163 | + // The listview implementation accompanying this filterable backcompat layer will call |
| 164 | + // filterable.refresh() after it's done refreshing the listview to make sure the filterable |
| 165 | + // filters out any new items added. However, when the listview refresh has been initiated by |
| 166 | + // the filterable itself, then such filtering has already taken place, and calling the |
| 167 | + // filterable's refresh() method will cause an infinite recursion. We stop this by setting a |
| 168 | + // flag that will cause the filterable's refresh() method to short-circuit. |
| 169 | + _refreshChildWidget: function() { |
| 170 | + this._refreshingChildWidget = true; |
| 171 | + this._superApply( arguments ); |
| 172 | + this._refreshingChildWidget = false; |
| 173 | + }, |
| 174 | + |
| 175 | + refresh: function() { |
| 176 | + if ( !this._refreshingChildWidget ) { |
| 177 | + this._superApply( arguments ); |
| 178 | + } |
| 179 | + }, |
| 180 | + |
163 | 181 | _destroy: function() { |
164 | 182 | if ( this._isSearchInternal() ) { |
165 | 183 | this._search.remove(); |
@@ -207,29 +225,18 @@ $.widget( "mobile.listview", $.mobile.listview, { |
207 | 225 | return this._super(); |
208 | 226 | }, |
209 | 227 |
|
210 | | - _afterListviewRefresh: function() { |
211 | | - var filterable = this.element.data( "mobile-filterable" ); |
212 | | - |
213 | | - if ( this.options.filter === true && filterable ) { |
214 | | - this._preventRefreshLoop = true; |
215 | | - filterable.refresh(); |
216 | | - } |
217 | | - }, |
218 | | - |
219 | | - // Eliminate infinite recursion caused by the fact that we call filterable.refresh() from |
220 | | - // _afterListviewRefresh() above, which, in turn, calls _refreshChildWidget(), which, in |
221 | | - // turn, calls listview refresh(), which would, in turn, calls _afterListviewRefresh() |
222 | | - // above, if we wouldn't prevent that right here. |
223 | 228 | refresh: function() { |
224 | | - var returnValue; |
| 229 | + var filterable; |
225 | 230 |
|
226 | | - if ( !this._preventRefreshLoop ) { |
227 | | - returnValue = this._superApply( arguments ); |
228 | | - } |
| 231 | + this._superApply( arguments ); |
229 | 232 |
|
230 | | - this._preventRefreshLoop = false; |
| 233 | + if ( this.options.filter === true ) { |
| 234 | + filterable = this.element.data( "mobile-filterable" ); |
231 | 235 |
|
232 | | - return returnValue; |
| 236 | + if ( filterable ) { |
| 237 | + filterable.refresh(); |
| 238 | + } |
| 239 | + } |
233 | 240 | } |
234 | 241 | }); |
235 | 242 |
|
|
0 commit comments