Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions js/widgets/loader.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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" );
});