Skip to content

Commit 4bb3aeb

Browse files
committed
revert base tag merge and query param hash merge
1 parent fd8680a commit 4bb3aeb

File tree

5 files changed

+66
-173
lines changed

5 files changed

+66
-173
lines changed

js/jquery.mobile.core.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ define( [ "jquery", "text!../version.txt" ], function( $, __version__ ) {
8484
hoverDelay: 200
8585
},
8686

87-
// disable the alteration of the dynamic base tag or links in the case
88-
// that a dynamic base tag isn't supported
89-
dynamicBaseEnabled: true,
90-
9187
// TODO might be useful upstream in jquery itself ?
9288
keyCode: {
9389
ALT: 18,

js/jquery.mobile.navigation.js

Lines changed: 55 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -404,48 +404,22 @@ define( [
404404
getScreenHeight = $.mobile.getScreenHeight;
405405

406406
//base element management, defined depending on dynamic base tag support
407-
var base = {
407+
var base = $.support.dynamicBaseTag ? {
408+
408409
//define base element, for use in routing asset urls that are referenced in Ajax-requested markup
409410
element: ( $base.length ? $base : $( "<base>", { href: documentBase.hrefNoHash } ).prependTo( $head ) ),
410411

411-
linkSelector: "[src], link[href], a[rel='external'], :jqmData(ajax='false'), a[target]",
412-
413412
//set the generated BASE element's href attribute to a new page's base path
414-
set: function( href, page ) {
415-
// we should do nothing if the user wants to manage their url base manually
416-
if ( !$.mobile.dynamicBaseEnabled ){
417-
return;
418-
}
419-
420-
// we should use the base tag if we can manipulate it dynamically
421-
if ( $.support.dynamicBaseTag ){
422-
base.element.attr( "href", path.makeUrlAbsolute( href, documentBase ) );
423-
}
424-
425-
// otherwise rewrite src and href attrs to use a base url
426-
if ( !$.support.dynamicBaseTag && page ) {
427-
var newPath = path.get( href );
428-
page.find( base.linkSelector ).each(function( i, link ) {
429-
var thisAttr = $( link ).is( '[href]' ) ? 'href' : $( link ).is( '[src]' ) ? 'src' : 'action',
430-
thisUrl = $( link ).attr( thisAttr );
431-
432-
// XXX_jblas: We need to fix this so that it removes the document
433-
// base URL, and then prepends with the new page URL.
434-
//if full path exists and is same, chop it - helps IE out
435-
thisUrl = thisUrl.replace( location.protocol + '//' + location.host + location.pathname, '' );
436-
437-
if ( !/^(\w+:|#|\/)/.test( thisUrl ) ) {
438-
$( link ).attr( thisAttr, newPath + thisUrl );
439-
}
440-
});
441-
}
413+
set: function( href ) {
414+
base.element.attr( "href", path.makeUrlAbsolute( href, documentBase ) );
442415
},
443416

444417
//set the generated BASE element's href attribute to a new page's base path
445418
reset: function() {
446419
base.element.attr( "href", documentBase.hrefNoHash );
447420
}
448-
};
421+
422+
} : undefined;
449423

450424
/* internal utility functions */
451425

@@ -627,12 +601,6 @@ define( [
627601
$page.page();
628602
}
629603

630-
// determine the current base url
631-
function findBaseWithDefault() {
632-
var closestBase = ( $.mobile.activePage && getClosestBaseUrl( $.mobile.activePage ) );
633-
return closestBase || documentBase.hrefNoHash;
634-
}
635-
636604
/* exposed $.mobile methods */
637605

638606
//animation complete callback
@@ -658,6 +626,8 @@ define( [
658626

659627
$.mobile.dialogHashKey = dialogHashKey;
660628

629+
630+
661631
//enable cross-domain page support
662632
$.mobile.allowCrossDomainPages = false;
663633

@@ -710,6 +680,12 @@ define( [
710680
// page is loaded off the network.
711681
dupCachedPage = null,
712682

683+
// determine the current base url
684+
findBaseWithDefault = function() {
685+
var closestBase = ( $.mobile.activePage && getClosestBaseUrl( $.mobile.activePage ) );
686+
return closestBase || documentBase.hrefNoHash;
687+
},
688+
713689
// The absolute version of the URL passed into the function. This
714690
// version of the URL may contain dialog/subpage params in it.
715691
absUrl = path.makeUrlAbsolute( url, findBaseWithDefault() );
@@ -857,6 +833,10 @@ define( [
857833
url = fileUrl = path.getFilePath( $( "<div>" + RegExp.$1 + "</div>" ).text() );
858834
}
859835

836+
if ( base ) {
837+
base.set( fileUrl );
838+
}
839+
860840
//workaround to allow scripts to execute when included in page divs
861841
all.get( 0 ).innerHTML = html;
862842
page = all.find( ":jqmData(role='page'), :jqmData(role='dialog')" ).first();
@@ -873,7 +853,24 @@ define( [
873853
page.jqmData( "title", newPageTitle );
874854
}
875855

876-
base.set( fileUrl, page );
856+
//rewrite src and href attrs to use a base url
857+
if ( !$.support.dynamicBaseTag ) {
858+
var newPath = path.get( fileUrl );
859+
page.find( "[src], link[href], a[rel='external'], :jqmData(ajax='false'), a[target]" ).each(function() {
860+
var thisAttr = $( this ).is( '[href]' ) ? 'href' :
861+
$( this ).is( '[src]' ) ? 'src' : 'action',
862+
thisUrl = $( this ).attr( thisAttr );
863+
864+
// XXX_jblas: We need to fix this so that it removes the document
865+
// base URL, and then prepends with the new page URL.
866+
//if full path exists and is same, chop it - helps IE out
867+
thisUrl = thisUrl.replace( location.protocol + '//' + location.host + location.pathname, '' );
868+
869+
if ( !/^(\w+:|#|\/)/.test( thisUrl ) ) {
870+
$( this ).attr( thisAttr, newPath + thisUrl );
871+
}
872+
});
873+
}
877874

878875
//append to page and enhance
879876
// TODO taging a page with external to make sure that embedded pages aren't removed
@@ -897,6 +894,7 @@ define( [
897894
}
898895

899896
//bind pageHide to removePage after it's hidden, if the page options specify to do so
897+
900898
// Remove loading message.
901899
if ( settings.showLoadMsg ) {
902900
hideMsg();
@@ -914,7 +912,9 @@ define( [
914912
},
915913
error: function( xhr, textStatus, errorThrown ) {
916914
//set base back to current path
917-
base.set( path.get() );
915+
if ( base ) {
916+
base.set( path.get() );
917+
}
918918

919919
// Add error info to our triggerData.
920920
triggerData.xhr = xhr;
@@ -975,33 +975,18 @@ define( [
975975
return;
976976
}
977977

978-
var settings = $.extend( {}, $.mobile.changePage.defaults, options ), isString;
978+
var settings = $.extend( {}, $.mobile.changePage.defaults, options );
979979

980980
// Make sure we have a pageContainer to work with.
981981
settings.pageContainer = settings.pageContainer || $.mobile.pageContainer;
982982

983983
// Make sure we have a fromPage.
984984
settings.fromPage = settings.fromPage || $.mobile.activePage;
985985

986-
isString = (typeof toPage === "string");
987-
988986
var mpc = settings.pageContainer,
989987
pbcEvent = new $.Event( "pagebeforechange" ),
990988
triggerData = { toPage: toPage, options: settings };
991989

992-
// NOTE: preserve the original target as the dataUrl value will be simplified
993-
// eg, removing ui-state, and removing query params from the hash
994-
// this is so that users who want to use query params have access to them
995-
// in the event bindings for the page life cycle See issue #5085
996-
if ( isString ) {
997-
// if the toPage is a string simply convert it
998-
triggerData.absUrl = path.makeUrlAbsolute( toPage, findBaseWithDefault() );
999-
} else {
1000-
// if the toPage is a jQuery object grab the absolute url stored
1001-
// in the loadPage callback where it exists
1002-
triggerData.absUrl = toPage.data( 'absUrl' );
1003-
}
1004-
1005990
// Let listeners know we're about to change the current page.
1006991
mpc.trigger( pbcEvent, triggerData );
1007992

@@ -1025,15 +1010,17 @@ define( [
10251010
// to make sure it is loaded into the DOM. We'll listen
10261011
// to the promise object it returns so we know when
10271012
// it is done loading or if an error ocurred.
1028-
if ( isString ) {
1013+
if ( typeof toPage === "string" ) {
1014+
// preserve the original target as the dataUrl value will be simplified
1015+
// eg, removing ui-state, and removing query params from the hash
1016+
// this is so that users who want to use query params have access to them
1017+
// in the event bindings for the page life cycle See issue #5085
1018+
settings.target = toPage;
1019+
10291020
$.mobile.loadPage( toPage, settings )
10301021
.done(function( url, options, newPage, dupCachedPage ) {
10311022
isPageTransitioning = false;
10321023
options.duplicateCachedPage = dupCachedPage;
1033-
1034-
// store the original absolute url so that it can be provided
1035-
// to events in the triggerData of the subsequent changePage call
1036-
newPage.data( 'absUrl', triggerData.absUrl );
10371024
$.mobile.changePage( newPage, options );
10381025
})
10391026
.fail(function( url, options ) {
@@ -1186,7 +1173,6 @@ define( [
11861173
if ( alreadyThere ) {
11871174
urlHistory.activeIndex = Math.max( 0, urlHistory.activeIndex - 1 );
11881175
}
1189-
11901176
urlHistory.addNew( url, settings.transition, pageTitle, pageUrl, settings.role );
11911177
}
11921178

@@ -1237,8 +1223,9 @@ define( [
12371223
allowSamePageTransition: false
12381224
};
12391225

1240-
/* Event Bindings - hashchange, submit, and click */
1241-
function findClosestLink( ele ) {
1226+
/* Event Bindings - hashchange, submit, and click */
1227+
function findClosestLink( ele )
1228+
{
12421229
while ( ele ) {
12431230
// Look for the closest element with a nodeName of "a".
12441231
// Note that we are checking if we have a valid nodeName
@@ -1256,16 +1243,17 @@ define( [
12561243
}
12571244

12581245
// The base URL for any given element depends on the page it resides in.
1259-
function getClosestBaseUrl( ele ) {
1246+
function getClosestBaseUrl( ele )
1247+
{
12601248
// Find the closest page and extract out its url.
12611249
var url = $( ele ).closest( ".ui-page" ).jqmData( "url" ),
12621250
base = documentBase.hrefNoHash;
12631251

1264-
if ( !$.mobile.dynamicBaseEnabled || !url || !path.isPath( url ) ) {
1252+
if ( !url || !path.isPath( url ) ) {
12651253
url = base;
12661254
}
12671255

1268-
return path.makeUrlAbsolute( url, base );
1256+
return path.makeUrlAbsolute( url, base);
12691257
}
12701258

12711259
//The following event bindings should be bound after mobileinit has been triggered

tests/unit/navigation/base-tests.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1">
66
<title>jQuery Mobile Navigation Test Suite</title>
77

8-
<script>
8+
<script>
9+
910
// This unit test requires a base tag to be set within the file.
1011
// Most browsers require a base tag with an @href URL that is absolute.
1112
// We need to dynamically inject the base tag so we can prefix it with

tests/unit/navigation/navigation_base.js

Lines changed: 9 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
(function($){
55
var baseDir = $.mobile.path.parseUrl($("base").attr("href")).directory,
66
contentDir = $.mobile.path.makePathAbsolute("../content/", baseDir),
7-
home = location.pathname + location.search,
8-
baseTagEnabled = $.mobile.dynamicBaseTagEnabled,
9-
baseTagSupported = $.support.dynamicBaseTag;
7+
home = location.pathname + location.search;
108

119
module('jquery.mobile.navigation.js - base tag', {
1210
setup: function(){
13-
$.testHelper.navReset( home );
14-
15-
// reset the value to prevent test collision
16-
$.mobile.dynamicBaseTagEnabled = baseTagEnabled;
17-
$.support.dynamicBaseTag = baseTagSupported;
11+
if ( location.hash ) {
12+
stop();
13+
$(document).one("pagechange", function() {
14+
start();
15+
} );
16+
location.hash = "";
17+
}
1818
}
1919
});
2020

@@ -201,69 +201,6 @@
201201
});
202202

203203
start();
204-
}
205-
]);
206-
});
207-
208-
var testBaseTagAlteration = function( assertions ) {
209-
$.testHelper.pageSequence([
210-
function(){
211-
$.mobile.changePage( "../../base-change.html" );
212-
},
213-
214-
function(){
215-
assertions();
216-
window.history.back();
217-
},
218-
219-
function() {
220-
start();
221-
}
222-
]);
223-
224-
};
225-
226-
asyncTest( "disabling base tag changes should prevent base href value changes", function() {
227-
var baseHref = $( "base" ).attr( "href" );
228-
$.mobile.dynamicBaseEnabled = false;
229-
230-
testBaseTagAlteration(function() {
231-
if ( $.support.dynamicBaseTag ) {
232-
equal( baseHref, $( "base" ).attr( "href" ), "the base href value should be unchanged" );
233-
} else {
234-
equal( $.mobile.activePage.find( "#base-change-link" ).attr( "href" ), "foo", "the link href's remain unchanged" );
235-
}
236-
});
237-
});
238-
239-
asyncTest( "enabling base tag changes should enable base href value changes", function() {
240-
var baseHref = $( "base" ).attr( "href" );
241-
$.mobile.dynamicBaseEnabled = true;
242-
$.support.dynamicBaseTag = true;
243-
244-
testBaseTagAlteration(function() {
245-
ok( baseHref !== $( "base" ).attr( "href" ), "the base href value should be changed" );
246-
});
247-
});
248-
249-
asyncTest( "enabling base tag changes when a dynamic base isn't supported should alter links", function() {
250-
$.mobile.dynamicBaseEnabled = true;
251-
$.support.dynamicBaseTag = false;
252-
253-
testBaseTagAlteration(function() {
254-
var linkHref = $.mobile.activePage.find( "#base-change-link" ).attr( "href" );
255-
256-
if ( $.support.pushState ) {
257-
equal( linkHref,
258-
$.mobile.path.get( location.href ) + "foo",
259-
"the link's href is changed" );
260-
} else {
261-
// compare the pathname of the links href with the directory of the current
262-
// location + foo
263-
equal( $.mobile.path.parseUrl( linkHref ).pathname,
264-
$.mobile.path.parseUrl( location.href ).directory + "foo",
265-
"the link's href is changed" );
266-
}
267-
});
204+
}]);
268205
});
269206
})(jQuery);

tests/unit/navigation/navigation_core.js

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,33 +1312,4 @@
13121312
}
13131313
]);
13141314
});
1315-
1316-
1317-
var absHomeUrl = $.mobile.path.parseLocation().hrefNoHash,
1318-
homeDomain = $.mobile.path.parseLocation().domain;
1319-
1320-
asyncTest( "page load events are providided with the absolute url for the content", function() {
1321-
var requestPath;
1322-
1323-
expect( 3 );
1324-
1325-
$( document ).one( "pagebeforechange", function( event, data ) {
1326-
equal( data.absUrl, absHomeUrl + "#bar");
1327-
});
1328-
1329-
$( document ).one( "pagechange", function( event, data ) {
1330-
equal( data.absUrl, absHomeUrl + "#bar" );
1331-
});
1332-
1333-
$.mobile.changePage( "#bar" );
1334-
1335-
requestPath = "/theres/no/way/this/page/exists.html";
1336-
1337-
$( document ).one( "pagechangefailed", function( event, data ) {
1338-
equal( data.absUrl, homeDomain + requestPath );
1339-
start();
1340-
});
1341-
1342-
$.mobile.changePage( requestPath );
1343-
});
13441315
})(jQuery);

0 commit comments

Comments
 (0)