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);

0 commit comments

Comments
 (0)