Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit 30d42e2

Browse files
author
Gabriel Schulhof
committed
Filterable: Add extension "backcompat" to handle synchronization between widget options and textinput options.
1 parent b8670b7 commit 30d42e2

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

js/index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
'widgets/forms/select.js',
6868
'widgets/forms/select.custom.js',
6969
'widgets/filterable.js',
70+
'widgets/filterable.backcompat.js',
7071
'jquery.mobile.buttonMarkup.js',
7172
'widgets/controlgroup.js',
7273
'jquery.mobile.links.js',

js/jquery.mobile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ define([
2121
"./widgets/navbar",
2222
"./widgets/listview",
2323
"./widgets/filterable",
24+
"./widgets/filterable.backcompat",
2425
"./widgets/listview.autodividers",
2526
"./jquery.mobile.nojs",
2627
"./widgets/forms/checkboxradio",
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2+
//>>description: Links options present in the widget to be filtered to the input
3+
//>>label: Filterable-widgetlink
4+
//>>group: Widgets
5+
6+
define( [
7+
"jquery",
8+
"./filterable" ], function( jQuery ) {
9+
//>>excludeEnd("jqmBuildExclude");
10+
(function( $, undefined ) {
11+
12+
// Create a function that will replace the _setOptions function of a widget,
13+
// and will pass the options on to the input of the filterable.
14+
var replaceSetOptions = function( self, orig ) {
15+
return function( options ) {
16+
orig.call( this, options );
17+
self._syncTextInputOptions( options );
18+
}
19+
}
20+
21+
$.widget( "mobile.filterable", $.mobile.filterable, {
22+
_create: function() {
23+
var idx, widget,
24+
recognizedWidgets = [ "controlgroup", "collapsibleset", "listview", "selectmenu" ];
25+
26+
this._super();
27+
28+
for ( idx in recognizedWidgets ) {
29+
widget = this.element.data( "mobile-" + recognizedWidgets[ idx ] );
30+
if ( widget ) {
31+
32+
// Tap into _setOptions for a recognized widget so we may synchronize
33+
// the widget's style with the textinput style, if the textinput is
34+
// internal
35+
widget._setOptions = replaceSetOptions( this, widget._setOptions );
36+
this._syncTextInputOptions( widget.options );
37+
break;
38+
}
39+
}
40+
},
41+
42+
_syncTextInputOptions: function( options ) {
43+
var idx,
44+
textinputOptions = {};
45+
46+
// We only sync options if the filterable's textinput is of the internally
47+
// generated variety, rather than one specified by the user.
48+
if ( this._isSearchInternal() && $.mobile.textinput ) {
49+
50+
// Apply only the options understood by textinput
51+
for ( idx in $.mobile.textinput.prototype.options ) {
52+
if ( options[ idx ] !== undefined ) {
53+
textinputOptions[ idx ] = options[ idx ];
54+
}
55+
}
56+
this._search.textinput( "option", textinputOptions );
57+
}
58+
}
59+
});
60+
61+
//auto self-init widgets
62+
$.mobile._enhancer.add( "mobile.filterable", {
63+
64+
// We need the widgets to which we can sync the textinput styling to be
65+
// instantiated first, so we may find them during the instantiation of the
66+
// filterable itself.
67+
dependencies: [
68+
"mobile.controlgroup",
69+
"mobile.collapsibleset",
70+
"mobile.listview",
71+
"mobile.selectmenu"
72+
]
73+
});
74+
75+
})( jQuery );
76+
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
77+
});
78+
//>>excludeEnd("jqmBuildExclude");

0 commit comments

Comments
 (0)