Skip to content

Commit 42477a5

Browse files
committed
add namespace module, move navigation objects under $.mobile
1 parent ec88ea2 commit 42477a5

25 files changed

+153
-130
lines changed

js/events/navigate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//>>group: Navigation
55

66
// TODO break out pushstate support test so we don't depend on the whole thing
7-
define([ "jquery", "./../jquery.mobile.support" ], function( $ ) {
7+
define([ "jquery", "./../jquery.mobile.ns", "./../jquery.mobile.support" ], function( $ ) {
88
//>>excludeEnd("jqmBuildExclude");
99

1010
(function( $, undefined ) {

js/index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// to revert to the pre async include, and should not be
77
// used in other build methods
88
'jquery.mobile.define.js',
9+
'jquery.mobile.ns.js',
910
'jquery.ui.widget.js',
1011
'jquery.mobile.widget.js',
1112
'jquery.mobile.media.js',

js/jquery.mobile.core.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
//>>css.structure: ../css/structure/jquery.mobile.core.css
66
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css
77

8-
define( [ "jquery", "text!../version.txt" ], function( $, __version__ ) {
8+
define( [ "jquery", "./jquery.mobile.ns", "text!../version.txt" ], function( $, __version__ ) {
99
//>>excludeEnd("jqmBuildExclude");
1010
(function( $, window, undefined ) {
1111

1212
var nsNormalizeDict = {};
1313

1414
// jQuery.mobile configurable options
15-
$.mobile = $.extend( {}, {
15+
$.mobile = $.extend($.mobile, {
1616

1717
// Version of the jQuery Mobile Framework
1818
version: __version__,

js/jquery.mobile.init.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ define([
107107
// make sure to set initial popstate state if it exists
108108
// so that navigation back to the initial page works properly
109109
if( $.event.special.navigate.isPushStateEnabled() ) {
110-
$.navigate.navigator.squash( path.parseLocation().href );
110+
$.mobile.navigate.navigator.squash( path.parseLocation().href );
111111
}
112112

113113
$.mobile.changePage( $.mobile.firstPage, {
@@ -124,8 +124,8 @@ define([
124124
} else {
125125
// TODO figure out how to simplify this interaction with the initial history entry
126126
// at the bottom js/navigate/navigate.js
127-
$.navigate.history.stack = [];
128-
$.navigate( $.mobile.path.isPath( location.hash ) ? location.hash : location.href );
127+
$.mobile.navigate.history.stack = [];
128+
$.mobile.navigate( $.mobile.path.isPath( location.hash ) ? location.hash : location.href );
129129
}
130130
}
131131
}

js/jquery.mobile.navigation.js

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,48 @@ define( [
2424
$html = $( 'html' ),
2525
$head = $( 'head' ),
2626

27-
path = $.mobile.path,
27+
// NOTE: path extensions dependent on core attributes. Moved here to remove deps from
28+
// $.mobile.path definition
29+
path = $.extend($.mobile.path, {
30+
31+
//return the substring of a filepath before the sub-page key, for making a server request
32+
getFilePath: function( path ) {
33+
var splitkey = '&' + $.mobile.subPageUrlKey;
34+
return path && path.split( splitkey )[0].split( dialogHashKey )[0];
35+
},
36+
37+
//check if the specified url refers to the first page in the main application document.
38+
isFirstPageUrl: function( url ) {
39+
// We only deal with absolute paths.
40+
var u = path.parseUrl( path.makeUrlAbsolute( url, this.documentBase ) ),
41+
42+
// Does the url have the same path as the document?
43+
samePath = u.hrefNoHash === this.documentUrl.hrefNoHash || ( this.documentBaseDiffers && u.hrefNoHash === this.documentBase.hrefNoHash ),
44+
45+
// Get the first page element.
46+
fp = $.mobile.firstPage,
47+
48+
// Get the id of the first page element if it has one.
49+
fpId = fp && fp[0] ? fp[0].id : undefined;
50+
51+
// The url refers to the first page if the path matches the document and
52+
// it either has no hash value, or the hash is exactly equal to the id of the
53+
// first page element.
54+
return samePath && ( !u.hash || u.hash === "#" || ( fpId && u.hash.replace( /^#/, "" ) === fpId ) );
55+
},
56+
57+
// Some embedded browsers, like the web view in Phone Gap, allow cross-domain XHR
58+
// requests if the document doing the request was loaded via the file:// protocol.
59+
// This is usually to allow the application to "phone home" and fetch app specific
60+
// data. We normally let the browser handle external/cross-domain urls, but if the
61+
// allowCrossDomainPages option is true, we will allow cross-domain http/https
62+
// requests to go through our page loading logic.
63+
isPermittedCrossDomainRequest: function( docUrl, reqUrl ) {
64+
return $.mobile.allowCrossDomainPages &&
65+
docUrl.protocol === "file:" &&
66+
reqUrl.search( /^https?:/ ) !== -1;
67+
}
68+
}),
2869

2970
//will be defined when a link is clicked and given an active class
3071
$activeClickedLink = null,
@@ -34,7 +75,7 @@ define( [
3475

3576
//urlHistory is purely here to make guesses at whether the back or forward button was clicked
3677
//and provide an appropriate transition
37-
urlHistory = $.navigate.history,
78+
urlHistory = $.mobile.navigate.history,
3879

3980
//define first selector to receive focus when a page is shown
4081
focusable = "[tabindex],a,button:visible,select:visible,input",
@@ -850,7 +891,7 @@ define( [
850891
}
851892

852893
// TODO the property names here are just silly
853-
$.navigate( url, {
894+
$.mobile.navigate( url, {
854895
transition: settings.transition,
855896
title: pageTitle,
856897
pageUrl: pageUrl,

js/jquery.mobile.ns.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2+
//>>description: The core namespace for the mobile library
3+
//>>label: Namespace
4+
//>>group: Core
5+
define([ "jquery" ], function( $ ) {
6+
//>>excludeEnd("jqmBuildExclude");
7+
$.mobile = {};
8+
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
9+
});
10+
//>>excludeEnd("jqmBuildExclude");

js/jquery.mobile.support.touch.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,13 @@
33
//>>label: Touch support test
44
//>>group: Core
55

6-
define( [ "jquery" ], function( jQuery ) {
6+
define( [ "jquery", "./jquery.mobile.ns" ], function( jQuery ) {
77
//>>excludeEnd("jqmBuildExclude");
88
(function( $, undefined ) {
99
var support = {
1010
touch: "ontouchend" in document
1111
};
1212

13-
$.mobile = $.mobile || {};
1413
$.mobile.support = $.mobile.support || {};
1514
$.extend( $.support, support );
1615
$.extend( $.mobile.support, support );

js/jquery.mobile.widget.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
22
//>>description: Widget factory extentions for mobile.
3-
//>>label: Widget Factory
3+
//>>label: Widget Factory
44
//>>group: Core
55
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css
66

7-
define( [ "jquery", "depend!./jquery.ui.widget[jquery]" ], function( $ ) {
7+
define( [ "jquery", "./jquery.mobile.ns", "depend!./jquery.ui.widget[jquery]" ], function( $ ) {
88
//>>excludeEnd("jqmBuildExclude");
99
(function( $, undefined ) {
1010

js/navigation/history.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22
//>>description: History Manager
33
//>>label: AJAX Navigation System
44
//>>group: Navigation
5-
define([ "jquery", "./path" ], function( $ ) {
5+
define([ "jquery", "./../jquery.mobile.ns", "./path" ], function( $ ) {
66
//>>excludeEnd("jqmBuildExclude");
77

88
(function( $ ) {
99
var path = $.mobile.path;
1010

11-
$.History = function( stack, index ) {
11+
$.mobile.History = function( stack, index ) {
1212
this.stack = stack || [];
1313
this.activeIndex = index || 0;
1414
};
1515

16-
$.extend($.History.prototype, {
16+
$.extend($.mobile.History.prototype, {
1717
getActive: function() {
1818
return this.stack[ this.activeIndex ];
1919
},

js/navigation/method.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,19 @@ define([ "jquery", "./path", "./history", "./navigator" ], function( $ ) {
99
// TODO consider queueing navigation activity until previous activities have completed
1010
// so that end users don't have to think about it. Punting for now
1111
// TODO !! move the event bindings into callbacks on the navigate event
12-
$.navigate = function( url, data, noEvents ) {
13-
$.navigate.navigator.go( url, data, noEvents );
12+
$.mobile.navigate = function( url, data, noEvents ) {
13+
$.mobile.navigate.navigator.go( url, data, noEvents );
1414
};
1515

1616
// expose the history on the navigate method in anticipation of full integration with
1717
// existing navigation functionalty that is tightly coupled to the history information
18-
$.navigate.history = new $.History();
18+
$.mobile.navigate.history = new $.mobile.History();
1919

2020
// instantiate an instance of the navigator for use within the $.navigate method
21-
$.navigate.navigator = new $.Navigator( $.navigate.history );
21+
$.mobile.navigate.navigator = new $.mobile.Navigator( $.mobile.navigate.history );
2222

2323
var loc = $.mobile.path.parseLocation();
24-
$.navigate.history.add( loc.href, {hash: loc.hash} );
24+
$.mobile.navigate.history.add( loc.href, {hash: loc.hash} );
2525
})( jQuery );
2626

2727
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);

js/navigation/navigator.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
//>>description: Navigation Manager
33
//>>label: AJAX Navigation System
44
//>>group: Navigation
5-
define([ "jquery", "../events/navigate", "./path", "./history" ], function( $ ) {
5+
define(["jquery",
6+
"./../jquery.mobile.ns",
7+
"../events/navigate",
8+
"./path",
9+
"./history" ], function( $ ) {
610
//>>excludeEnd("jqmBuildExclude");
711
(function( $, undefined ) {
812
var path = $.mobile.path;
913

10-
$.Navigator = function( history ) {
14+
$.mobile.Navigator = function( history ) {
1115
this.history = history;
1216
this.ignoreInitialHashChange = true;
1317

@@ -23,7 +27,7 @@ define([ "jquery", "../events/navigate", "./path", "./history" ], function( $ )
2327
});
2428
};
2529

26-
$.extend($.Navigator.prototype, {
30+
$.extend($.mobile.Navigator.prototype, {
2731
squash: function( url, data ) {
2832
var state, href, hash = path.isPath(url) ? path.stripHash(url) : url;
2933

@@ -196,7 +200,7 @@ define([ "jquery", "../events/navigate", "./path", "./history" ], function( $ )
196200
// when the hash is adjacent to the active history entry
197201
if( !event.originalEvent.state ) {
198202
hash = path.parseLocation().hash;
199-
state = $.navigate.navigator.squash( hash );
203+
state = this.squash( hash );
200204

201205
// record the new hash as an additional history entry
202206
// to match the browser's treatment of hash assignment

js/navigation/path.js

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//>>group: Navigation
55
define([
66
"jquery",
7-
"./../jquery.mobile.core" ], function( $ ) {
7+
"./../jquery.mobile.ns" ], function( $ ) {
88
//>>excludeEnd("jqmBuildExclude");
99

1010
var path, documentBase, $base, dialogHashKey = "&ui-state=dialog";
@@ -198,12 +198,6 @@ define([
198198
return path.stripHash( newPath ).replace( /[^\/]*\.[^\/*]+$/, '' );
199199
},
200200

201-
//return the substring of a filepath before the sub-page key, for making a server request
202-
getFilePath: function( path ) {
203-
var splitkey = '&' + $.mobile.subPageUrlKey;
204-
return path && path.split( splitkey )[0].split( dialogHashKey )[0];
205-
},
206-
207201
//set location hash to path
208202
set: function( path ) {
209203
location.hash = path;
@@ -249,26 +243,6 @@ define([
249243
return ( /^(:?\w+:)/ ).test( url );
250244
},
251245

252-
//check if the specified url refers to the first page in the main application document.
253-
isFirstPageUrl: function( url ) {
254-
// We only deal with absolute paths.
255-
var u = path.parseUrl( path.makeUrlAbsolute( url, this.documentBase ) ),
256-
257-
// Does the url have the same path as the document?
258-
samePath = u.hrefNoHash === this.documentUrl.hrefNoHash || ( this.documentBaseDiffers && u.hrefNoHash === this.documentBase.hrefNoHash ),
259-
260-
// Get the first page element.
261-
fp = $.mobile.firstPage,
262-
263-
// Get the id of the first page element if it has one.
264-
fpId = fp && fp[0] ? fp[0].id : undefined;
265-
266-
// The url refers to the first page if the path matches the document and
267-
// it either has no hash value, or the hash is exactly equal to the id of the
268-
// first page element.
269-
return samePath && ( !u.hash || u.hash === "#" || ( fpId && u.hash.replace( /^#/, "" ) === fpId ) );
270-
},
271-
272246
isEmbeddedPage: function( url ) {
273247
var u = path.parseUrl( url );
274248

@@ -283,19 +257,6 @@ define([
283257
return ( /^#/ ).test( u.href );
284258
},
285259

286-
287-
// Some embedded browsers, like the web view in Phone Gap, allow cross-domain XHR
288-
// requests if the document doing the request was loaded via the file:// protocol.
289-
// This is usually to allow the application to "phone home" and fetch app specific
290-
// data. We normally let the browser handle external/cross-domain urls, but if the
291-
// allowCrossDomainPages option is true, we will allow cross-domain http/https
292-
// requests to go through our page loading logic.
293-
isPermittedCrossDomainRequest: function( docUrl, reqUrl ) {
294-
return $.mobile.allowCrossDomainPages &&
295-
docUrl.protocol === "file:" &&
296-
reqUrl.search( /^https?:/ ) !== -1;
297-
},
298-
299260
squash: function( url, resolutionUrl ) {
300261
var state, href, cleanedUrl, search, stateIndex,
301262
isPath = this.isPath( url ),

js/widgets/popup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ define( [
816816
});
817817

818818
this.urlAltered = true;
819-
$.navigate( url, {role: "dialog"} );
819+
$.mobile.navigate( url, {role: "dialog"} );
820820
},
821821

822822
close: function() {

tests/jquery.testHelper.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,19 @@
122122
},
123123

124124
reloadLib: function(libName){
125+
var reload;
126+
125127
if(this.reloads[libName] === undefined) {
126128
this.reloads[libName] = {
127-
lib: $("script[src$='" + libName + "']"),
129+
lib: $( "script[src$='" + libName + "']" ),
130+
dataSrcLib: $( "script[data-src$='" + libName + "']"),
128131
count: 0
129132
};
130133
}
131134

132-
var src = this.reloads[libName].lib.attr('src') + "?" + this.reloads[libName].count++;
135+
reload = this.reloads[libName];
136+
137+
var src = reload.lib.attr('src') || reload.dataSrcLib.attr( "data-src" ) + "?" + this.reloads[libName].count++;
133138
$.ajax( { url: src, dataType: "script", async: false } );
134139
},
135140

tests/unit/core/core.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@
88
$.support.mediaquery = value;
99
$.mobile.browser.ie = version;
1010
},
11-
extendFn = $.extend;
11+
extendFn = $.extend,
12+
ns = $.mobile.ns;
1213

1314
module(libName, {
1415
setup: function(){
16+
$.mobile.ns = ns;
17+
1518
// NOTE reset for gradeA tests
1619
$('html').removeClass('ui-mobile');
1720

tests/unit/core/index.html

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,10 @@
1212
<script src="../../../external/qunit.js"></script>
1313
<script>
1414
$.testHelper.asyncLoad([
15-
[
16-
"jquery.mobile.core"
17-
],
15+
[ "jquery.mobile.core" ],
1816
[ "jquery.mobile.init" ],
19-
[
20-
"core.js",
21-
"core_scroll.js"
22-
]
17+
[ "core.js" ],
18+
[ "core_scroll.js" ]
2319
]);
2420
</script>
2521
<link rel="stylesheet" href="../../../css/themes/default/jquery.mobile.css" />

tests/unit/init/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<script src="init_core.js"></script>
1212
<script src="../../../js/"></script>
1313
<!-- added explicitly for library reloading (see testHelper ) -->
14-
<script src="../../../js/jquery.mobile.init.js"></script>
15-
<script src="../../../js/jquery.mobile.core.js"></script>
14+
<script data-src="../../../js/jquery.mobile.init.js"></script>
15+
<script data-src="../../../js/jquery.mobile.core.js"></script>
1616
<link rel="stylesheet" href="../../../css/themes/default/jquery.mobile.css" />
1717
<link rel="stylesheet" href="../../../external/qunit.css"/>
1818

0 commit comments

Comments
 (0)