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

Commit

Permalink
Loader: Attach to body when no $.mobile.pageContainer found
Browse files Browse the repository at this point in the history
Closes gh-7761
Fixes gh-7760
  • Loading branch information
Gabriel Schulhof committed Oct 24, 2014
1 parent 4ef44a6 commit de43d3f
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 5 deletions.
17 changes: 12 additions & 5 deletions js/widgets/loader.js
Expand Up @@ -3,7 +3,11 @@
//>>label: Loading Message
//>>group: Widgets

define( [ "jquery", "../core", "../widget" ], function( jQuery ) {
define( [
"jquery",
"../helpers",
"../defaults",
"../widget" ], function( jQuery ) {
//>>excludeEnd("jqmBuildExclude");

(function( $ ) {
Expand Down Expand Up @@ -114,8 +118,11 @@ define( [ "jquery", "../core", "../widget" ], function( jQuery ) {
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();
Expand All @@ -131,8 +138,8 @@ define( [ "jquery", "../core", "../widget" ], function( jQuery ) {
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 );
}
});

Expand Down
36 changes: 36 additions & 0 deletions tests/unit/individual-modules/loader-tests.html
@@ -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>
10 changes: 10 additions & 0 deletions tests/unit/individual-modules/loader_core.js
@@ -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 de43d3f

Please sign in to comment.