Skip to content

Commit de43d3f

Browse files
author
Gabriel Schulhof
committed
Loader: Attach to body when no $.mobile.pageContainer found
Closes jquery-archivegh-7761 Fixes jquery-archivegh-7760
1 parent 4ef44a6 commit de43d3f

File tree

3 files changed

+58
-5
lines changed

3 files changed

+58
-5
lines changed

js/widgets/loader.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
//>>label: Loading Message
44
//>>group: Widgets
55

6-
define( [ "jquery", "../core", "../widget" ], function( jQuery ) {
6+
define( [
7+
"jquery",
8+
"../helpers",
9+
"../defaults",
10+
"../widget" ], function( jQuery ) {
711
//>>excludeEnd("jqmBuildExclude");
812

913
(function( $ ) {
@@ -114,8 +118,11 @@ define( [ "jquery", "../core", "../widget" ], function( jQuery ) {
114118
this.element.find( "h1" ).text( message );
115119
}
116120

117-
// attach the loader to the DOM
118-
this.element.appendTo( $.mobile.pageContainer );
121+
// If the pagecontainer widget has been defined we may use the :mobile-pagecontainer
122+
// and attach to the element on which the pagecontainer widget has been defined. If not,
123+
// we attach to the body.
124+
this.element.appendTo( $.mobile.pagecontainer ?
125+
$( ":mobile-pagecontainer" ) : $( "body" ) );
119126

120127
// check that the loader is visible
121128
this.checkLoaderPosition();
@@ -131,8 +138,8 @@ define( [ "jquery", "../core", "../widget" ], function( jQuery ) {
131138
this.element.removeClass( "ui-loader-fakefix" );
132139
}
133140

134-
$.mobile.window.unbind( "scroll", this.fakeFixLoader );
135-
$.mobile.window.unbind( "scroll", this.checkLoaderPosition );
141+
this.window.unbind( "scroll", this.fakeFixLoader );
142+
this.window.unbind( "scroll", this.checkLoaderPosition );
136143
}
137144
});
138145

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1">
6+
<title>jQuery Mobile Loader Test Suite</title>
7+
8+
<script src="../../../external/requirejs/require.js"></script>
9+
<script src="../../../js/requirejs.config.js"></script>
10+
<script src="../../../js/jquery.tag.inserter.js"></script>
11+
<script src="../../../tests/jquery.testHelper.js"></script>
12+
13+
<link rel="stylesheet" href="../../../css/themes/default/jquery.mobile.css"/>
14+
<link rel="stylesheet" href="../../../external/qunit/qunit.css"/>
15+
<link rel="stylesheet" href="../../jqm-tests.css"/>
16+
<script src="../../../external/qunit/qunit.js"></script>
17+
<script>
18+
$.testHelper.asyncLoad([
19+
[
20+
"widgets/loader"
21+
],
22+
[
23+
"../../jquery.setNameSpace.immediately.js"
24+
],
25+
[
26+
"loader_core.js"
27+
]
28+
]);
29+
</script>
30+
31+
<script src="../../swarminject.js"></script>
32+
</head>
33+
<body>
34+
<div id="qunit"></div>
35+
</body>
36+
</html>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
test( "Loader attaches to DOM when running individually", function() {
2+
var loader = $.mobile.loading( "show" );
3+
4+
deepEqual( $.contains( document, loader[ 0 ] ), true,
5+
"Document contains the loader after it is shown" );
6+
7+
deepEqual( loader.is( ":visible" ), true, "Loader is visible when shown" );
8+
9+
$.mobile.loading( "hide" );
10+
});

0 commit comments

Comments
 (0)