|
| 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