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

Commit 56987c3

Browse files
author
Gabriel Schulhof
committed
[select] Implement _destroy() -- Fixes #4661
(cherry picked from commit 7273a5e)
1 parent c824fa9 commit 56987c3

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

js/widgets/forms/select.custom.js

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ define( [
2525
var extendSelect = function( widget ) {
2626

2727
var select = widget.select,
28+
origDestroy = widget._destroy,
2829
selectID = widget.selectID,
2930
label = widget.label,
3031
thisPage = widget.select.closest( ".ui-page" ),
@@ -94,6 +95,17 @@ define( [
9495
// Create list from select, update state
9596
self.refresh();
9697

98+
if ( self._origTabIndex === undefined ) {
99+
self._origTabIndex = self.select.attr( "tabindex" );
100+
// Map undefined to false, because self._origTabIndex === undefined
101+
// indicates that we have not yet checked whether the select has
102+
// originally had a tabindex attribute, whereas false indicates that
103+
// we have checked the select for such an attribute, and have found
104+
// none present.
105+
if ( self._origTabIndex === undefined ) {
106+
self._origTabIndex = false;
107+
}
108+
}
97109
self.select.attr( "tabindex", "-1" ).focus(function() {
98110
$( this ).blur();
99111
self.button.focus();
@@ -458,7 +470,12 @@ define( [
458470
needPlaceholder = false;
459471
isPlaceholderItem = true;
460472

461-
// If we have identified a placeholder, mark it retroactively in the select as well
473+
// If we have identified a placeholder, record the fact that it was
474+
// us who have added the placeholder to the option and mark it
475+
// retroactively in the select as well
476+
if ( !option.hasAttribute( dataPlaceholderAttr ) ) {
477+
this._removePlaceholderAttr = true;
478+
}
462479
option.setAttribute( dataPlaceholderAttr, true );
463480
if ( o.hidePlaceholderMenuItems ) {
464481
classes.push( "ui-selectmenu-placeholder" );
@@ -509,6 +526,30 @@ define( [
509526
// TODO value is undefined at creation
510527
"aria-owns": this.menuId
511528
});
529+
},
530+
531+
_destroy: function() {
532+
this.close();
533+
534+
// Restore the tabindex attribute to its original value
535+
if ( this._origTabIndex !== undefined ) {
536+
if ( this._origTabIndex !== false ) {
537+
this.select.attr( "tabindex", this._origTabIndex );
538+
} else {
539+
this.select.removeAttr( "tabindex" );
540+
}
541+
}
542+
543+
// Remove the placeholder attribute if we were the ones to add it
544+
if ( this._removePlaceholderAttr ) {
545+
this._selectOptions().removeAttr( "data-" + $.mobile.ns + "placeholder" );
546+
}
547+
548+
// Remove the popup
549+
this.listbox.remove();
550+
551+
// Chain up
552+
origDestroy.apply( this, arguments );
512553
}
513554
});
514555
};

js/widgets/forms/select.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
7575
}
7676
},
7777

78+
_destroy: function() {
79+
var wrapper = this.element.parents( ".ui-select" );
80+
if ( wrapper.length > 0 ) {
81+
this.element.insertAfter( wrapper );
82+
wrapper.remove();
83+
}
84+
},
85+
7886
_create: function() {
7987
this._preExtension();
8088

0 commit comments

Comments
 (0)