Permalink
Browse files

Filterable: Add extension "backcompat" to handle synchronization betw…

…een widget options and textinput options.
  • Loading branch information...
gabrielschulhof committed Jul 21, 2013
1 parent b8670b7 commit 30d42e2eda189443d1d56438c6eb278a8821a151
Showing with 80 additions and 0 deletions.
  1. +1 −0 js/index.php
  2. +1 −0 js/jquery.mobile.js
  3. +78 −0 js/widgets/filterable.backcompat.js
View
@@ -67,6 +67,7 @@
'widgets/forms/select.js',
'widgets/forms/select.custom.js',
'widgets/filterable.js',
+ 'widgets/filterable.backcompat.js',
'jquery.mobile.buttonMarkup.js',
'widgets/controlgroup.js',
'jquery.mobile.links.js',
View
@@ -21,6 +21,7 @@ define([
"./widgets/navbar",
"./widgets/listview",
"./widgets/filterable",
+ "./widgets/filterable.backcompat",
"./widgets/listview.autodividers",
"./jquery.mobile.nojs",
"./widgets/forms/checkboxradio",
@@ -0,0 +1,78 @@
+//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
+//>>description: Links options present in the widget to be filtered to the input
+//>>label: Filterable-widgetlink
+//>>group: Widgets
+
+define( [
+ "jquery",
+ "./filterable" ], function( jQuery ) {
+//>>excludeEnd("jqmBuildExclude");
+(function( $, undefined ) {
+
+// Create a function that will replace the _setOptions function of a widget,
+// and will pass the options on to the input of the filterable.
+var replaceSetOptions = function( self, orig ) {
+ return function( options ) {
+ orig.call( this, options );
+ self._syncTextInputOptions( options );
+ }
+}
+
+$.widget( "mobile.filterable", $.mobile.filterable, {
+ _create: function() {
+ var idx, widget,
+ recognizedWidgets = [ "controlgroup", "collapsibleset", "listview", "selectmenu" ];
+
+ this._super();
+
+ for ( idx in recognizedWidgets ) {
+ widget = this.element.data( "mobile-" + recognizedWidgets[ idx ] );
+ if ( widget ) {
+
+ // Tap into _setOptions for a recognized widget so we may synchronize
+ // the widget's style with the textinput style, if the textinput is
+ // internal
+ widget._setOptions = replaceSetOptions( this, widget._setOptions );
+ this._syncTextInputOptions( widget.options );
+ break;
+ }
+ }
+ },
+
+ _syncTextInputOptions: function( options ) {
+ var idx,
+ textinputOptions = {};
+
+ // We only sync options if the filterable's textinput is of the internally
+ // generated variety, rather than one specified by the user.
+ if ( this._isSearchInternal() && $.mobile.textinput ) {
+
+ // Apply only the options understood by textinput
+ for ( idx in $.mobile.textinput.prototype.options ) {
+ if ( options[ idx ] !== undefined ) {
+ textinputOptions[ idx ] = options[ idx ];
+ }
+ }
+ this._search.textinput( "option", textinputOptions );
+ }
+ }
+});
+
+ //auto self-init widgets
+ $.mobile._enhancer.add( "mobile.filterable", {
+
+ // We need the widgets to which we can sync the textinput styling to be
+ // instantiated first, so we may find them during the instantiation of the
+ // filterable itself.
+ dependencies: [
+ "mobile.controlgroup",
+ "mobile.collapsibleset",
+ "mobile.listview",
+ "mobile.selectmenu"
+ ]
+ });
+
+})( jQuery );
+//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
+});
+//>>excludeEnd("jqmBuildExclude");

0 comments on commit 30d42e2

Please sign in to comment.