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

Commit 7eade19

Browse files
committed
Select: Implement native fallback to replace dialog
1 parent 6e9db49 commit 7eade19

File tree

2 files changed

+50
-34
lines changed

2 files changed

+50
-34
lines changed

demos/selectmenu-custom/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@
204204
<div data-demo-html="true">
205205
<div class="ui-field-contain">
206206
<label for="select-custom-24">Multiple, icon left, long list:</label>
207-
<select name="select-custom-24" id="select-custom-24" data-native-menu="false" multiple="multiple" data-iconpos="left">
207+
<select name="select-custom-24" size="5" id="select-custom-24" data-native-menu="false" multiple="multiple" data-iconpos="left">
208208
<option>Choose options</option>
209209
<option value="AL">Alabama</option>
210210
<option value="AK">Alaska</option>

js/widgets/forms/select.custom.js

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ $.widget( "mobile.selectmenu", $.mobile.selectmenu, {
4949
},
5050

5151
_handleSelectFocus: function() {
52-
this.element.blur();
53-
this.button.focus();
52+
//this.element.blur();
53+
//this.button.focus();
5454
},
5555

5656
_handleKeydown: function( event ) {
@@ -64,15 +64,54 @@ $.widget( "mobile.selectmenu", $.mobile.selectmenu, {
6464
}
6565

6666
if (event.type === "vclick" ||
67-
event.keyCode && (event.keyCode === $.mobile.keyCode.ENTER || event.keyCode === $.mobile.keyCode.SPACE)) {
67+
event.keyCode && (event.keyCode === $.mobile.keyCode.ENTER ||
68+
event.keyCode === $.mobile.keyCode.SPACE)) {
6869

6970
this._decideFormat();
7071
if ( this.menuType === "overlay" ) {
7172
this.button.attr( "href", "#" + this.popupId ).attr( "data-" + ( $.mobile.ns || "" ) + "rel", "popup" );
73+
this.isOpen = true;
74+
} else if( this.element[0].multiple ){
75+
this.element.css( {
76+
"height": "auto",
77+
"max-height": "10000px",
78+
"min-height": "0"
79+
})
80+
var isSoft = ( this.element.height() < 40 );
81+
if( !isSoft ){
82+
this.element.css({
83+
"opacity": "1",
84+
});
85+
//this.element.attr( "size", "5" );
86+
this.element.appendTo( this.button );
87+
this.button.innerHeight( this.element.height() );
88+
this.element.focus();
89+
this._on( this.document, {
90+
"click": function(event){
91+
if( event.target.nodeName !== "OPTION" ){
92+
this.element.css({
93+
"opacity":"0",
94+
"height":"auto",
95+
"max-height": "100%"
96+
})
97+
this.button.height( "auto" );
98+
this._off( this.document, "click" );
99+
}
100+
}
101+
})
102+
103+
} else {
104+
this._destroy();
105+
this.options.nativeMenu = true;
106+
this._create();
107+
}
72108
} else {
73-
this.button.attr( "href", "#" + this.dialogId ).attr( "data-" + ( $.mobile.ns || "" ) + "rel", "dialog" );
109+
this._destroy();
110+
this.options.nativeMenu = true;
111+
this._create();
112+
//return false;
113+
//this.button.attr( "href", "#" + this.dialogId ).attr( "data-" + ( $.mobile.ns || "" ) + "rel", "dialog" );
74114
}
75-
this.isOpen = true;
76115
// Do not prevent default, so the navigation may have a chance to actually open the chosen format
77116
}
78117
},
@@ -364,40 +403,15 @@ $.widget( "mobile.selectmenu", $.mobile.selectmenu, {
364403
},
365404

366405
_decideFormat: function() {
367-
var self = this,
406+
var self = this, options, iconpos,
368407
$window = this.window,
369408
selfListParent = self.list.parent(),
370409
menuHeight = selfListParent.outerHeight(),
371-
scrollTop = $window.scrollTop(),
372-
btnOffset = self.button.offset().top,
373410
screenHeight = $window.height();
374411

375412
if ( menuHeight > screenHeight - 80 || !$.support.scrollTop ) {
376-
377-
self.menuPage.appendTo( $.mobile.pageContainer ).page();
378-
self.menuPageContent = self.menuPage.find( ".ui-content" );
379-
self.menuPageClose = self.menuPage.find( ".ui-header a" );
380-
381-
// prevent the parent page from being removed from the DOM,
382-
// otherwise the results of selecting a list item in the dialog
383-
// fall into a black hole
384-
self.thisPage.unbind( "pagehide.remove" );
385-
386-
//for WebOS/Opera Mini (set lastscroll using button offset)
387-
if ( scrollTop === 0 && btnOffset > screenHeight ) {
388-
self.thisPage.one( "pagehide", function() {
389-
$( this ).jqmData( "lastScroll", btnOffset );
390-
});
391-
}
392-
393-
self.menuPage.one( {
394-
pageshow: $.proxy( this, "_focusMenuItem" ),
395-
pagehide: $.proxy( this, "close" )
396-
});
397-
398-
self.menuType = "page";
399-
self.menuPageContent.append( self.list );
400-
self.menuPage.find( "div .ui-title" ).text( self.label.text() );
413+
this.menuType = "native";
414+
this.options.nativeMenu = true;
401415
} else {
402416
self.menuType = "overlay";
403417

@@ -531,6 +545,8 @@ $.widget( "mobile.selectmenu", $.mobile.selectmenu, {
531545
_destroy: function() {
532546

533547
if ( !this.options.nativeMenu ) {
548+
this._off( this.button, "vclick" );
549+
this._off( this.select, "focus" );
534550
this.close();
535551

536552
// Restore the tabindex attribute to its original value

0 commit comments

Comments
 (0)