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

Commit

Permalink
add namespace module, move navigation objects under $.mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
johnbender committed Jan 10, 2013
1 parent ec88ea2 commit 42477a5
Show file tree
Hide file tree
Showing 25 changed files with 153 additions and 130 deletions.
2 changes: 1 addition & 1 deletion js/events/navigate.js
Expand Up @@ -4,7 +4,7 @@
//>>group: Navigation

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

(function( $, undefined ) {
Expand Down
1 change: 1 addition & 0 deletions js/index.php
Expand Up @@ -6,6 +6,7 @@
// to revert to the pre async include, and should not be
// used in other build methods
'jquery.mobile.define.js',
'jquery.mobile.ns.js',
'jquery.ui.widget.js',
'jquery.mobile.widget.js',
'jquery.mobile.media.js',
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.mobile.core.js
Expand Up @@ -5,14 +5,14 @@
//>>css.structure: ../css/structure/jquery.mobile.core.css
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css

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

var nsNormalizeDict = {};

// jQuery.mobile configurable options
$.mobile = $.extend( {}, {
$.mobile = $.extend($.mobile, {

// Version of the jQuery Mobile Framework
version: __version__,
Expand Down
6 changes: 3 additions & 3 deletions js/jquery.mobile.init.js
Expand Up @@ -107,7 +107,7 @@ define([
// make sure to set initial popstate state if it exists
// so that navigation back to the initial page works properly
if( $.event.special.navigate.isPushStateEnabled() ) {
$.navigate.navigator.squash( path.parseLocation().href );
$.mobile.navigate.navigator.squash( path.parseLocation().href );
}

$.mobile.changePage( $.mobile.firstPage, {
Expand All @@ -124,8 +124,8 @@ define([
} else {
// TODO figure out how to simplify this interaction with the initial history entry
// at the bottom js/navigate/navigate.js
$.navigate.history.stack = [];
$.navigate( $.mobile.path.isPath( location.hash ) ? location.hash : location.href );
$.mobile.navigate.history.stack = [];
$.mobile.navigate( $.mobile.path.isPath( location.hash ) ? location.hash : location.href );
}
}
}
Expand Down
47 changes: 44 additions & 3 deletions js/jquery.mobile.navigation.js
Expand Up @@ -24,7 +24,48 @@ define( [
$html = $( 'html' ),
$head = $( 'head' ),

path = $.mobile.path,
// NOTE: path extensions dependent on core attributes. Moved here to remove deps from
// $.mobile.path definition
path = $.extend($.mobile.path, {

//return the substring of a filepath before the sub-page key, for making a server request
getFilePath: function( path ) {
var splitkey = '&' + $.mobile.subPageUrlKey;
return path && path.split( splitkey )[0].split( dialogHashKey )[0];
},

//check if the specified url refers to the first page in the main application document.
isFirstPageUrl: function( url ) {
// We only deal with absolute paths.
var u = path.parseUrl( path.makeUrlAbsolute( url, this.documentBase ) ),

// Does the url have the same path as the document?
samePath = u.hrefNoHash === this.documentUrl.hrefNoHash || ( this.documentBaseDiffers && u.hrefNoHash === this.documentBase.hrefNoHash ),

// Get the first page element.
fp = $.mobile.firstPage,

// Get the id of the first page element if it has one.
fpId = fp && fp[0] ? fp[0].id : undefined;

// The url refers to the first page if the path matches the document and
// it either has no hash value, or the hash is exactly equal to the id of the
// first page element.
return samePath && ( !u.hash || u.hash === "#" || ( fpId && u.hash.replace( /^#/, "" ) === fpId ) );
},

// Some embedded browsers, like the web view in Phone Gap, allow cross-domain XHR
// requests if the document doing the request was loaded via the file:// protocol.
// This is usually to allow the application to "phone home" and fetch app specific
// data. We normally let the browser handle external/cross-domain urls, but if the
// allowCrossDomainPages option is true, we will allow cross-domain http/https
// requests to go through our page loading logic.
isPermittedCrossDomainRequest: function( docUrl, reqUrl ) {
return $.mobile.allowCrossDomainPages &&
docUrl.protocol === "file:" &&
reqUrl.search( /^https?:/ ) !== -1;
}
}),

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

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

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

// TODO the property names here are just silly
$.navigate( url, {
$.mobile.navigate( url, {
transition: settings.transition,
title: pageTitle,
pageUrl: pageUrl,
Expand Down
10 changes: 10 additions & 0 deletions js/jquery.mobile.ns.js
@@ -0,0 +1,10 @@
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
//>>description: The core namespace for the mobile library
//>>label: Namespace
//>>group: Core
define([ "jquery" ], function( $ ) {
//>>excludeEnd("jqmBuildExclude");
$.mobile = {};
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
});
//>>excludeEnd("jqmBuildExclude");
3 changes: 1 addition & 2 deletions js/jquery.mobile.support.touch.js
Expand Up @@ -3,14 +3,13 @@
//>>label: Touch support test
//>>group: Core

define( [ "jquery" ], function( jQuery ) {
define( [ "jquery", "./jquery.mobile.ns" ], function( jQuery ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, undefined ) {
var support = {
touch: "ontouchend" in document
};

$.mobile = $.mobile || {};
$.mobile.support = $.mobile.support || {};
$.extend( $.support, support );
$.extend( $.mobile.support, support );
Expand Down
4 changes: 2 additions & 2 deletions js/jquery.mobile.widget.js
@@ -1,10 +1,10 @@
//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
//>>description: Widget factory extentions for mobile.
//>>label: Widget Factory
//>>label: Widget Factory
//>>group: Core
//>>css.theme: ../css/themes/default/jquery.mobile.theme.css

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

Expand Down
6 changes: 3 additions & 3 deletions js/navigation/history.js
Expand Up @@ -2,18 +2,18 @@
//>>description: History Manager
//>>label: AJAX Navigation System
//>>group: Navigation
define([ "jquery", "./path" ], function( $ ) {
define([ "jquery", "./../jquery.mobile.ns", "./path" ], function( $ ) {
//>>excludeEnd("jqmBuildExclude");

(function( $ ) {
var path = $.mobile.path;

$.History = function( stack, index ) {
$.mobile.History = function( stack, index ) {
this.stack = stack || [];
this.activeIndex = index || 0;
};

$.extend($.History.prototype, {
$.extend($.mobile.History.prototype, {
getActive: function() {
return this.stack[ this.activeIndex ];
},
Expand Down
10 changes: 5 additions & 5 deletions js/navigation/method.js
Expand Up @@ -9,19 +9,19 @@ define([ "jquery", "./path", "./history", "./navigator" ], function( $ ) {
// TODO consider queueing navigation activity until previous activities have completed
// so that end users don't have to think about it. Punting for now
// TODO !! move the event bindings into callbacks on the navigate event
$.navigate = function( url, data, noEvents ) {
$.navigate.navigator.go( url, data, noEvents );
$.mobile.navigate = function( url, data, noEvents ) {
$.mobile.navigate.navigator.go( url, data, noEvents );
};

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

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

var loc = $.mobile.path.parseLocation();
$.navigate.history.add( loc.href, {hash: loc.hash} );
$.mobile.navigate.history.add( loc.href, {hash: loc.hash} );
})( jQuery );

//>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
Expand Down
12 changes: 8 additions & 4 deletions js/navigation/navigator.js
Expand Up @@ -2,12 +2,16 @@
//>>description: Navigation Manager
//>>label: AJAX Navigation System
//>>group: Navigation
define([ "jquery", "../events/navigate", "./path", "./history" ], function( $ ) {
define(["jquery",
"./../jquery.mobile.ns",
"../events/navigate",
"./path",
"./history" ], function( $ ) {
//>>excludeEnd("jqmBuildExclude");
(function( $, undefined ) {
var path = $.mobile.path;

$.Navigator = function( history ) {
$.mobile.Navigator = function( history ) {
this.history = history;
this.ignoreInitialHashChange = true;

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

$.extend($.Navigator.prototype, {
$.extend($.mobile.Navigator.prototype, {
squash: function( url, data ) {
var state, href, hash = path.isPath(url) ? path.stripHash(url) : url;

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

// record the new hash as an additional history entry
// to match the browser's treatment of hash assignment
Expand Down
41 changes: 1 addition & 40 deletions js/navigation/path.js
Expand Up @@ -4,7 +4,7 @@
//>>group: Navigation
define([
"jquery",
"./../jquery.mobile.core" ], function( $ ) {
"./../jquery.mobile.ns" ], function( $ ) {
//>>excludeEnd("jqmBuildExclude");

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

//return the substring of a filepath before the sub-page key, for making a server request
getFilePath: function( path ) {
var splitkey = '&' + $.mobile.subPageUrlKey;
return path && path.split( splitkey )[0].split( dialogHashKey )[0];
},

//set location hash to path
set: function( path ) {
location.hash = path;
Expand Down Expand Up @@ -249,26 +243,6 @@ define([
return ( /^(:?\w+:)/ ).test( url );
},

//check if the specified url refers to the first page in the main application document.
isFirstPageUrl: function( url ) {
// We only deal with absolute paths.
var u = path.parseUrl( path.makeUrlAbsolute( url, this.documentBase ) ),

// Does the url have the same path as the document?
samePath = u.hrefNoHash === this.documentUrl.hrefNoHash || ( this.documentBaseDiffers && u.hrefNoHash === this.documentBase.hrefNoHash ),

// Get the first page element.
fp = $.mobile.firstPage,

// Get the id of the first page element if it has one.
fpId = fp && fp[0] ? fp[0].id : undefined;

// The url refers to the first page if the path matches the document and
// it either has no hash value, or the hash is exactly equal to the id of the
// first page element.
return samePath && ( !u.hash || u.hash === "#" || ( fpId && u.hash.replace( /^#/, "" ) === fpId ) );
},

isEmbeddedPage: function( url ) {
var u = path.parseUrl( url );

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


// Some embedded browsers, like the web view in Phone Gap, allow cross-domain XHR
// requests if the document doing the request was loaded via the file:// protocol.
// This is usually to allow the application to "phone home" and fetch app specific
// data. We normally let the browser handle external/cross-domain urls, but if the
// allowCrossDomainPages option is true, we will allow cross-domain http/https
// requests to go through our page loading logic.
isPermittedCrossDomainRequest: function( docUrl, reqUrl ) {
return $.mobile.allowCrossDomainPages &&
docUrl.protocol === "file:" &&
reqUrl.search( /^https?:/ ) !== -1;
},

squash: function( url, resolutionUrl ) {
var state, href, cleanedUrl, search, stateIndex,
isPath = this.isPath( url ),
Expand Down
2 changes: 1 addition & 1 deletion js/widgets/popup.js
Expand Up @@ -816,7 +816,7 @@ define( [
});

this.urlAltered = true;
$.navigate( url, {role: "dialog"} );
$.mobile.navigate( url, {role: "dialog"} );
},

close: function() {
Expand Down
9 changes: 7 additions & 2 deletions tests/jquery.testHelper.js
Expand Up @@ -122,14 +122,19 @@
},

reloadLib: function(libName){
var reload;

if(this.reloads[libName] === undefined) {
this.reloads[libName] = {
lib: $("script[src$='" + libName + "']"),
lib: $( "script[src$='" + libName + "']" ),
dataSrcLib: $( "script[data-src$='" + libName + "']"),
count: 0
};
}

var src = this.reloads[libName].lib.attr('src') + "?" + this.reloads[libName].count++;
reload = this.reloads[libName];

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

Expand Down
5 changes: 4 additions & 1 deletion tests/unit/core/core.js
Expand Up @@ -8,10 +8,13 @@
$.support.mediaquery = value;
$.mobile.browser.ie = version;
},
extendFn = $.extend;
extendFn = $.extend,
ns = $.mobile.ns;

module(libName, {
setup: function(){
$.mobile.ns = ns;

// NOTE reset for gradeA tests
$('html').removeClass('ui-mobile');

Expand Down
10 changes: 3 additions & 7 deletions tests/unit/core/index.html
Expand Up @@ -12,14 +12,10 @@
<script src="../../../external/qunit.js"></script>
<script>
$.testHelper.asyncLoad([
[
"jquery.mobile.core"
],
[ "jquery.mobile.core" ],
[ "jquery.mobile.init" ],
[
"core.js",
"core_scroll.js"
]
[ "core.js" ],
[ "core_scroll.js" ]
]);
</script>
<link rel="stylesheet" href="../../../css/themes/default/jquery.mobile.css" />
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/init/index.html
Expand Up @@ -11,8 +11,8 @@
<script src="init_core.js"></script>
<script src="../../../js/"></script>
<!-- added explicitly for library reloading (see testHelper ) -->
<script src="../../../js/jquery.mobile.init.js"></script>
<script src="../../../js/jquery.mobile.core.js"></script>
<script data-src="../../../js/jquery.mobile.init.js"></script>
<script data-src="../../../js/jquery.mobile.core.js"></script>
<link rel="stylesheet" href="../../../css/themes/default/jquery.mobile.css" />
<link rel="stylesheet" href="../../../external/qunit.css"/>

Expand Down

0 comments on commit 42477a5

Please sign in to comment.