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

Commit 7273a5e

Browse files
author
Gabriel Schulhof
committed
[select] Implement _destroy() -- Fixes #4661
1 parent b88b6f3 commit 7273a5e

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" ),
@@ -97,6 +98,17 @@ define( [
9798
// Create list from select, update state
9899
self.refresh();
99100

101+
if ( self._origTabIndex === undefined ) {
102+
self._origTabIndex = self.select.attr( "tabindex" );
103+
// Map undefined to false, because self._origTabIndex === undefined
104+
// indicates that we have not yet checked whether the select has
105+
// originally had a tabindex attribute, whereas false indicates that
106+
// we have checked the select for such an attribute, and have found
107+
// none present.
108+
if ( self._origTabIndex === undefined ) {
109+
self._origTabIndex = false;
110+
}
111+
}
100112
self.select.attr( "tabindex", "-1" ).focus(function() {
101113
$( this ).blur();
102114
self.button.focus();
@@ -461,7 +473,12 @@ define( [
461473
needPlaceholder = false;
462474
isPlaceholderItem = true;
463475

464-
// If we have identified a placeholder, mark it retroactively in the select as well
476+
// If we have identified a placeholder, record the fact that it was
477+
// us who have added the placeholder to the option and mark it
478+
// retroactively in the select as well
479+
if ( !option.hasAttribute( dataPlaceholderAttr ) ) {
480+
this._removePlaceholderAttr = true;
481+
}
465482
option.setAttribute( dataPlaceholderAttr, true );
466483
if ( o.hidePlaceholderMenuItems ) {
467484
classes.push( "ui-selectmenu-placeholder" );
@@ -512,6 +529,30 @@ define( [
512529
// TODO value is undefined at creation
513530
"aria-owns": this.menuId
514531
});
532+
},
533+
534+
_destroy: function() {
535+
this.close();
536+
537+
// Restore the tabindex attribute to its original value
538+
if ( this._origTabIndex !== undefined ) {
539+
if ( this._origTabIndex !== false ) {
540+
this.select.attr( "tabindex", this._origTabIndex );
541+
} else {
542+
this.select.removeAttr( "tabindex" );
543+
}
544+
}
545+
546+
// Remove the placeholder attribute if we were the ones to add it
547+
if ( this._removePlaceholderAttr ) {
548+
this._selectOptions().removeAttr( "data-" + $.mobile.ns + "placeholder" );
549+
}
550+
551+
// Remove the popup
552+
this.listbox.remove();
553+
554+
// Chain up
555+
origDestroy.apply( this, arguments );
515556
}
516557
});
517558
};

js/widgets/forms/select.js

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

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

0 commit comments

Comments
 (0)