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

Commit 7850a2f

Browse files
author
Gabriel Schulhof
committed
Panel: Do not store ID inside the widget
Fixes gh-6769
1 parent d0fed72 commit 7850a2f

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

js/widgets/panel.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ $.widget( "mobile.panel", {
3434
positionFixed: false
3535
},
3636

37-
_panelID: null,
3837
_closeLink: null,
3938
_parentPage: null,
4039
_page: null,
@@ -49,7 +48,6 @@ $.widget( "mobile.panel", {
4948

5049
// expose some private props to other methods
5150
$.extend( this, {
52-
_panelID: el.attr( "id" ),
5351
_closeLink: el.find( ":jqmData(rel='close')" ),
5452
_parentPage: ( parentPage.length > 0 ) ? parentPage : false,
5553
_page: this._getPage,
@@ -91,7 +89,7 @@ $.widget( "mobile.panel", {
9189
var self = this,
9290
target = self._parentPage ? self._parentPage.parent() : self.element.parent();
9391

94-
self._modal = $( "<div class='" + self.options.classes.modal + "' data-panelid='" + self._panelID + "'></div>" )
92+
self._modal = $( "<div class='" + self.options.classes.modal + "'></div>" )
9593
.on( "mousedown", function() {
9694
self.close();
9795
})
@@ -223,9 +221,13 @@ $.widget( "mobile.panel", {
223221
},
224222

225223
_handleClick: function( e ) {
226-
if ( e.currentTarget.href.split( "#" )[ 1 ] === this._panelID && this._panelID !== undefined ) {
224+
var link,
225+
panelId = this.element.attr( "id" );
226+
227+
if ( e.currentTarget.href.split( "#" )[ 1 ] === panelId && panelId !== undefined ) {
228+
227229
e.preventDefault();
228-
var link = $( e.target );
230+
link = $( e.target );
229231
if ( link.hasClass( "ui-btn" ) ) {
230232
link.addClass( $.mobile.activeBtnClass );
231233
this.element.one( "panelopen panelclose", function() {

tests/unit/panel/index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@
7070
<div data-nstest-role="panel" id="panel-test-ignore-unrelated-link">
7171
<a href="#" id="unrelated-link" data-nstest-ajax="false">Unrelated link</a>
7272
</div>
73+
<div data-nstest-role="panel" id="panel-test-id-change">
74+
<p>Contents of a panel.</p>
75+
</div>
7376
<div data-nstest-role="header">
7477
<h1>Panel Test</h1>
7578
</div>
@@ -85,6 +88,7 @@ <h1 id="demo-links">Panels</h1>
8588
<a href="#panel-test-destroy">Open Panel</a>
8689
<a href="#panel-test-non-default-theme">Open Panel</a>
8790
<a href="#panel-test-with-close">Open Panel</a>
91+
<a href="#panel-test-id-change">Open Panel</a>
8892
</div>
8993
</div>
9094

tests/unit/panel/panel_core.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,4 +326,32 @@
326326
]);
327327
});
328328

329+
asyncTest( "Panel still opens after changing its ID", function() {
330+
var eventNs = ".panelStillOpensAfterChangingItsId",
331+
idTestPanel = $( "#panel-test-id-change" ),
332+
idTestLink = $( "a[href='#panel-test-id-change']" );
333+
334+
expect( 1 );
335+
336+
idTestPanel.attr( "id", "something-else" );
337+
idTestLink.attr( "href", "#something-else" );
338+
339+
$.testHelper.detailedEventCascade([
340+
function() {
341+
idTestLink.click();
342+
},
343+
{
344+
panelopen: { src: idTestPanel, event: "panelopen" + eventNs + "1" }
345+
},
346+
function( result ) {
347+
deepEqual( result.panelopen.timedOut, false, "Renamed panel has opened" );
348+
idTestPanel.panel( "close" );
349+
},
350+
{
351+
panelclose: { src: idTestPanel, event: "panelclose" + eventNs + "2" }
352+
},
353+
start
354+
]);
355+
});
356+
329357
}( jQuery ));

0 commit comments

Comments
 (0)