|
12 | 12 | <script src="../_assets/js/"></script>
|
13 | 13 | <script src="../../js/"></script>
|
14 | 14 | <script>
|
15 |
| - $.mobile.document |
16 |
| - |
17 |
| - // "filter-menu-menu" is the ID generated for the listview when it is created |
18 |
| - // by the custom selectmenu plugin. Upon creation of the listview widget we |
19 |
| - // want to prepend an input field to the list to be used for a filter. |
20 |
| - .on( "listviewcreate", "#filter-menu-menu", function( e ) { |
21 |
| - var input, |
22 |
| - listbox = $( "#filter-menu-listbox" ), |
23 |
| - form = listbox.jqmData( "filter-form" ), |
24 |
| - listview = $( e.target ); |
25 |
| - |
26 |
| - // We store the generated form in a variable attached to the popup so we |
27 |
| - // avoid creating a second form/input field when the listview is |
28 |
| - // destroyed/rebuilt during a refresh. |
29 |
| - if ( !form ) { |
30 |
| - input = $( "<input data-type='search'></input>" ); |
31 |
| - form = $( "<form></form>" ).append( input ); |
32 |
| - |
33 |
| - input.textinput(); |
34 |
| - |
35 |
| - $( "#filter-menu-listbox" ) |
36 |
| - .prepend( form ) |
37 |
| - .jqmData( "filter-form", form ); |
38 |
| - } |
39 |
| - |
40 |
| - // Instantiate a filterable widget on the newly created listview and |
41 |
| - // indicate that the generated input is to be used for the filtering. |
42 |
| - listview.filterable({ input: input }); |
43 |
| - }) |
44 |
| - |
45 |
| - // The custom select list may show up as either a popup or a dialog, |
46 |
| - // depending how much vertical room there is on the screen. If it shows up |
47 |
| - // as a dialog, then the form containing the filter input field must be |
48 |
| - // transferred to the dialog so that the user can continue to use it for |
49 |
| - // filtering list items. |
50 |
| - // |
51 |
| - // After the dialog is closed, the form containing the filter input is |
52 |
| - // transferred back into the popup. |
53 |
| - .on( "pagebeforeshow pagehide", "#filter-menu-dialog", function( e ) { |
54 |
| - var form = $( "#filter-menu-listbox" ).jqmData( "filter-form" ), |
55 |
| - placeInDialog = ( e.type === "pagebeforeshow" ), |
56 |
| - destination = placeInDialog ? $( e.target ).find( ".ui-content" ) : $( "#filter-menu-listbox" ); |
57 |
| - |
58 |
| - form |
59 |
| - .find( "input" ) |
60 |
| - |
61 |
| - // Turn off the "inset" option when the filter input is inside a dialog |
62 |
| - // and turn it back on when it is placed back inside the popup, because |
63 |
| - // it looks better that way. |
64 |
| - .textinput( "option", "inset", !placeInDialog ) |
65 |
| - .end() |
66 |
| - .prependTo( destination ); |
| 15 | +$.mobile.document |
| 16 | + |
| 17 | + // The custom selectmenu plugin generates an ID for the listview by suffixing the ID of the |
| 18 | + // native widget with "-menu". Upon creation of the listview widget we want to place an |
| 19 | + // input field before the list to be used for a filter. |
| 20 | + .on( "listviewcreate", "#filter-menu-menu,#title-filter-menu-menu", function( event ) { |
| 21 | + var input, |
| 22 | + list = $( event.target ) |
| 23 | + form = list.jqmData( "filter-form" ); |
| 24 | + |
| 25 | + // We store the generated form in a variable attached to the popup so we avoid creating a |
| 26 | + // second form/input field when the listview is destroyed/rebuilt during a refresh. |
| 27 | + if ( !form ) { |
| 28 | + input = $( "<input data-type='search'></input>" ); |
| 29 | + form = $( "<form></form>" ).append( input ); |
| 30 | + |
| 31 | + input.textinput(); |
| 32 | + |
| 33 | + list |
| 34 | + .before( form ) |
| 35 | + .jqmData( "filter-form", form ) ; |
| 36 | + form.jqmData( "listview", list ); |
| 37 | + } |
| 38 | + |
| 39 | + // Instantiate a filterable widget on the newly created listview and indicate that the |
| 40 | + // generated input is to be used for the filtering. |
| 41 | + list.filterable({ |
| 42 | + input: input, |
| 43 | + children: "> li:not(:jqmData(placeholder='true'))" |
67 | 44 | });
|
| 45 | + }) |
| 46 | + |
| 47 | + // The custom select list may show up as either a popup or a dialog, depending how much |
| 48 | + // vertical room there is on the screen. If it shows up as a dialog, then the form containing |
| 49 | + // the filter input field must be transferred to the dialog so that the user can continue to |
| 50 | + // use it for filtering list items. |
| 51 | + .on( "pagebeforeshow", "#filter-menu-dialog,#title-filter-menu-dialog", function( event ) { |
| 52 | + var dialog = $( event.target ) |
| 53 | + listview = dialog.find( "ul" ), |
| 54 | + form = listview.jqmData( "filter-form" ); |
| 55 | + |
| 56 | + // Attach a reference to the listview as a data item to the dialog, because during the |
| 57 | + // pagehide handler below the selectmenu widget will already have returned the listview |
| 58 | + // to the popup, so we won't be able to find it inside the dialog with a selector. |
| 59 | + dialog.jqmData( "listview", listview ); |
| 60 | + |
| 61 | + // Place the form before the listview in the dialog. |
| 62 | + listview.before( form ); |
| 63 | + }) |
| 64 | + |
| 65 | + // After the dialog is closed, the form containing the filter input is returned to the popup. |
| 66 | + .on( "pagehide", "#filter-menu-dialog,#title-filter-menu-dialog", function( event ) { |
| 67 | + var listview = $( event.target ).jqmData( "listview" ), |
| 68 | + form = listview.jqmData( "filter-form" ); |
| 69 | + |
| 70 | + // Put the form back in the popup. It goes ahead of the listview. |
| 71 | + listview.before( form ); |
| 72 | + }); |
68 | 73 | </script>
|
69 | 74 | <style>
|
70 | 75 | .ui-selectmenu.ui-popup .ui-input-search {
|
|
118 | 123 | </form>
|
119 | 124 | </div>
|
120 | 125 |
|
| 126 | + <p>You can also handle custom menus with placeholder items:</p> |
| 127 | + |
| 128 | + <div data-demo-html="true" data-demo-js="true" data-demo-css="true"> |
| 129 | + <form> |
| 130 | + <select id="title-filter-menu" data-native-menu="false"> |
| 131 | + <option>Select fruit...</option> |
| 132 | + <option value="orange">Orange</option> |
| 133 | + <option value="apple">Apple</option> |
| 134 | + <option value="peach">Peach</option> |
| 135 | + <option value="lemon">Lemon</option> |
| 136 | + </select> |
| 137 | + </form> |
| 138 | + </div> |
| 139 | + |
121 | 140 | </div><!-- /content -->
|
122 | 141 |
|
123 | 142 | <?php include( '../jqm-navmenu.php' ); ?>
|
|
0 commit comments