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

Commit 445ff20

Browse files
author
Gabriel Schulhof
committed
Pagecontainer: Correctly identify the current page as a dialog
(cherry picked from commit ba428b0) Closes gh-7541 Fixes gh-7538
1 parent 8ba83c0 commit 445ff20

File tree

7 files changed

+110
-4
lines changed

7 files changed

+110
-4
lines changed

js/widgets/pagecontainer.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,10 @@ define( [
256256

257257
// If current active page is not a dialog skip the dialog and continue
258258
// in the same direction
259-
if ( activeContent && !activeContent.hasClass( "ui-dialog" ) ) {
259+
// Note: The dialog widget is deprecated as of 1.4.0 and will be removed in 1.5.0.
260+
// Thus, as of 1.5.0 activeContent.data( "mobile-dialog" ) will always evaluate to
261+
// falsy, so the second condition in the if-statement below can be removed altogether.
262+
if ( activeContent && !activeContent.data( "mobile-dialog" ) ) {
260263
// determine if we're heading forward or backward and continue
261264
// accordingly past the current dialog
262265
if ( data.direction === "back" ) {

tests/integration/navigation/sequence/another-page.html

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
</head>
66
<body>
77

8-
<div data-nstest-role="page" id="anotherPage"></div>
8+
<div data-nstest-role="page" id="anotherPage">
9+
<a href="#popupOnAnotherPage" id="openPopupOnAnotherPage" data-nstest-rel="popup">Open popup</a>
10+
<div id="popupOnAnotherPage" data-nstest-role="popup">
11+
<a href="page-styled-as-dialog.html" id="openPageStyledAsDialog">Page styled as dialog</a>
12+
</div>
13+
</div>
914

1015
</body>
1116
</html>

tests/integration/navigation/sequence/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
$.testHelper.asyncLoad([
2222
[
2323
"widgets/dialog",
24-
"widgets/page",
24+
"widgets/page.dialog",
2525
"widgets/popup"
2626
],
2727
[ "jquery.mobile.init" ],
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<html>
2+
<head>
3+
<title>Page styled as a dialog</title>
4+
</head>
5+
<body>
6+
<div id="pageStyledAsDialog" data-nstest-role="page" data-nstest-dialog="true">
7+
<div data-nstest-role="header">
8+
<h2>Page styled as a dialog</h2>
9+
</div>
10+
<div class="ui-content">
11+
<p>Content</p>
12+
</div>
13+
</div>
14+
</body>
15+
</html>

tests/integration/navigation/sequence/sequence_core.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,4 +545,65 @@
545545
], eventNs );
546546
});
547547

548+
asyncTest( "Sequence page1 -> page2 -> popup -> page-styled-as-dialog <- back", function() {
549+
var eventNs = ".page1Page2PopupDialogPageBack";
550+
551+
expect();
552+
553+
maybeWaitForStartPage([
554+
function() {
555+
$( "#openAnotherPage" ).click();
556+
},
557+
{
558+
pagecontainerchange: {
559+
src: $.mobile.pageContainer,
560+
event: "pagecontainerchange" + eventNs + "1"
561+
}
562+
},
563+
function() {
564+
deepEqual( $.mobile.activePage.attr( "id" ), "anotherPage",
565+
"Landed on another page" );
566+
$( "#openPopupOnAnotherPage" ).click();
567+
},
568+
{
569+
popupafteropen: {
570+
src: function() { return $( "#popupOnAnotherPage" ); },
571+
event: "popupafteropen" + eventNs + "2"
572+
}
573+
},
574+
function() {
575+
$( "#openPageStyledAsDialog" ).click();
576+
},
577+
{
578+
pagecontainerchange: {
579+
src: $.mobile.pageContainer,
580+
event: "pagecontainerchange" + eventNs + "3"
581+
}
582+
},
583+
function() {
584+
deepEqual( $.mobile.activePage.attr( "id" ), "pageStyledAsDialog",
585+
"Landed on page styled as dialog" );
586+
$.mobile.back();
587+
},
588+
{
589+
pagecontainerchange: {
590+
src: $.mobile.pageContainer,
591+
event: "pagecontainerchange" + eventNs + "4"
592+
}
593+
},
594+
function() {
595+
deepEqual( $.mobile.activePage.attr( "id" ), "anotherPage",
596+
"Navigating back() from the page styled as a dialog reaches another page" );
597+
$.mobile.back();
598+
},
599+
{
600+
pagecontainerchange: {
601+
src: $.mobile.pageContainer,
602+
event: "pagecontainerchange" + eventNs + "4"
603+
}
604+
},
605+
start
606+
], eventNs );
607+
});
608+
548609
})( jQuery );

tests/unit/content/content_core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@
120120
var result, opts = {};
121121

122122
proto.getActivePage = function() {
123-
return $( "<div>", {"class": "ui-dialog"} );
123+
return $( "<div>" ).data( "mobile-dialog", true );
124124
};
125125

126126
proto._getHistory = function() {

tests/unit/pagecontainer/pagecontainer_core.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,26 @@ test( "load does not trigger an error when called withput a second param", funct
2626
ok( "no error triggered when load method called without options" );
2727
});
2828

29+
module( "_handleDialog()" );
30+
31+
test( "A dialog is recognized via presence of the data key, not the ui-dialog class", function() {
32+
var getActiveHistoryCalled = false;
33+
34+
deepEqual( $.mobile.pagecontainer.prototype._handleDialog.call({
35+
getActivePage: function() {
36+
return $( "<div class='ui-dialog'></div>" );
37+
},
38+
_getActiveHistory: function() {
39+
getActiveHistoryCalled = true;
40+
return {};
41+
},
42+
back: $.noop,
43+
forward: $.noop,
44+
}, {}, {
45+
pageUrl: "xyzzy.html"
46+
}), false, "page is recognized as page even when the ui-dialog class is present" );
47+
48+
deepEqual( getActiveHistoryCalled, false, "_getActiveHistory() should not have been called" );
49+
});
50+
2951
})();

0 commit comments

Comments
 (0)