Permalink
Browse files

Loader: Attach to body when no $.mobile.pageContainer found

(cherry picked from commit de43d3f)

Closes gh-7761
Fixes gh-7760
1 parent 2cca0f0 commit 005206f6e196813f2517e0aedbe071bc4445d06d @gabrielschulhof gabrielschulhof committed Oct 9, 2014
View
@@ -3,7 +3,11 @@
//>>label: Loading Message
//>>group: Widgets
-define( [ "jquery", "../jquery.mobile.core", "../jquery.mobile.widget" ], function( jQuery ) {
+define( [
+ "jquery",
+ "../jquery.mobile.helpers",
+ "../jquery.mobile.defaults",
+ "../jquery.mobile.widget" ], function( jQuery ) {
//>>excludeEnd("jqmBuildExclude");
(function( $ ) {
@@ -114,8 +118,11 @@ define( [ "jquery", "../jquery.mobile.core", "../jquery.mobile.widget" ], functi
this.element.find( "h1" ).text( message );
}
- // attach the loader to the DOM
- this.element.appendTo( $.mobile.pageContainer );
+ // If the pagecontainer widget has been defined we may use the :mobile-pagecontainer
+ // and attach to the element on which the pagecontainer widget has been defined. If not,
+ // we attach to the body.
+ this.element.appendTo( $.mobile.pagecontainer ?
+ $( ":mobile-pagecontainer" ) : $( "body" ) );
// check that the loader is visible
this.checkLoaderPosition();
@@ -131,8 +138,8 @@ define( [ "jquery", "../jquery.mobile.core", "../jquery.mobile.widget" ], functi
this.element.removeClass( "ui-loader-fakefix" );
}
- $.mobile.window.unbind( "scroll", this.fakeFixLoader );
- $.mobile.window.unbind( "scroll", this.checkLoaderPosition );
+ this.window.unbind( "scroll", this.fakeFixLoader );
+ this.window.unbind( "scroll", this.checkLoaderPosition );
}
});
@@ -0,0 +1,36 @@
+<!doctype html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1">
+ <title>jQuery Mobile Loader Test Suite</title>
+
+ <script src="../../../external/requirejs/require.js"></script>
+ <script src="../../../js/requirejs.config.js"></script>
+ <script src="../../../js/jquery.tag.inserter.js"></script>
+ <script src="../../../tests/jquery.testHelper.js"></script>
+
+ <link rel="stylesheet" href="../../../css/themes/default/jquery.mobile.css"/>
+ <link rel="stylesheet" href="../../../external/qunit/qunit.css"/>
+ <link rel="stylesheet" href="../../jqm-tests.css"/>
+ <script src="../../../external/qunit/qunit.js"></script>
+ <script>
+ $.testHelper.asyncLoad([
+ [
+ "widgets/loader"
+ ],
+ [
+ "../../jquery.setNameSpace.immediately.js"
+ ],
+ [
+ "loader_core.js"
+ ]
+ ]);
+ </script>
+
+ <script src="../../swarminject.js"></script>
+</head>
+<body>
+ <div id="qunit"></div>
+</body>
+</html>
@@ -0,0 +1,10 @@
+test( "Loader attaches to DOM when running individually", function() {
+ var loader = $.mobile.loading( "show" );
+
+ deepEqual( $.contains( document, loader[ 0 ] ), true,
+ "Document contains the loader after it is shown" );
+
+ deepEqual( loader.is( ":visible" ), true, "Loader is visible when shown" );
+
+ $.mobile.loading( "hide" );
+});

0 comments on commit 005206f

Please sign in to comment.