Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

r42858 was not enough in order to take in account base element in loa…

…ded or initial page.

We have so store it in variable in case of browser not allow to change it dynamically,
and also to store it in page loaded in order to be able to retrieve it when re-displaying from memory (back navigation)

More over, finding base element in loaded page needs Regexp as it is lost when page injected in <div></div> in Safari.

git-svn-id: svn://zone.spip.org/spip-zone/_squelettes_/mobi.spip@43021 ac52e18a-acf5-0310-9fe8-c4428f23b10a
  • Loading branch information...
commit 7abc8664dd83c84ff8c2eac9e69286f08295e284 1 parent 52fb82c
@Cerdic authored
Showing with 27 additions and 11 deletions.
  1. +27 −11 mobile/js/jquery.mobile.js
View
38 mobile/js/jquery.mobile.js
@@ -2982,10 +2982,10 @@ $.fn.grid = function(options){
$metaViewport = $.mobile.metaViewportContent ? $("<meta>", { name: "viewport", content: $.mobile.metaViewportContent}).prependTo( $head ) : undefined,
//define baseUrl for use in relative url management
- baseUrl = getPathDir( location.protocol + '//' + location.host + location.pathname ),
+ baseUrl = $('base',$head).length ? $('base',$head).attr('href') : getPathDir( location.protocol + '//' + location.host + location.pathname ),
//define base element, for use in routing asset urls that are referenced in Ajax-requested markup
- $base = $.support.dynamicBaseTag ? $("<base>", { href: baseUrl }).prependTo( $head ) : undefined,
+ $base = $.support.dynamicBaseTag ? ( $('base',$head).length ? $('base',$head) : $("<base>", { href: baseUrl }).prependTo( $head ) ) : undefined,
//will be defined as first page element in DOM
$startPage,
@@ -3049,17 +3049,24 @@ $.fn.grid = function(options){
return newPath.join('/') + (newPath.length ? '/' : '');
}
+ var dynamiqueBaseUrl = '';
function getBaseURL( nonHashPath ){
- return getPathDir( nonHashPath || location.hash );
+ if (nonHashPath)
+ nonHashPath = nonHashPath.replace( location.protocol + "//" + location.host, "");
+ return getPathDir( nonHashPath || dynamiqueBaseUrl || location.hash );
}
- var setBaseURL = !$.support.dynamicBaseTag ? $.noop : function( nonHashPath ){
- //set base url for new page assets
- $base.attr('href', baseUrl + getBaseURL( nonHashPath ));
+ var setBaseURL = function( nonHashPath ){
+ dynamiqueBaseUrl = nonHashPath.replace( location.protocol + "//" + location.host, "");
+ if ($.support.dynamicBaseTag)
+ //set base url for new page assets
+ $base.attr('href', baseUrl + getBaseURL( nonHashPath ));
}
- var resetBaseURL = !$.support.dynamicBaseTag ? $.noop : function(){
- $base.attr('href', baseUrl);
+ var resetBaseURL = function(){
+ dynamiqueBaseUrl = baseUrl.replace( location.protocol + "//" + location.host, "");
+ if ($.support.dynamicBaseTag)
+ $base.attr('href', baseUrl);
}
//set base href to pathname
@@ -3328,8 +3335,9 @@ $.fn.grid = function(options){
// find the "to" page, either locally existing in the dom or by creating it through ajax
if ( to.length && !isFormRequest ) {
- if( fileUrl ){
- setBaseURL(fileUrl);
+ var base = to.attr('data-base') || fileUrl;
+ if( base ){
+ setBaseURL(base);
}
enhancePage();
transitionPages();
@@ -3351,7 +3359,13 @@ $.fn.grid = function(options){
//workaround to allow scripts to execute when included in page divs
all.get(0).innerHTML = html;
var base = all.find('base');
- base = ((base.length?base.attr('href'):'') || fileUrl);
+ if (base.length)
+ base = base.attr('href');
+ else
+ // workaround : safari deletes head section when injecting in <div></div>
+ if (base=html.match(/<base [^>]*href=["']([^"']+)["']/i))
+ base = base[1];
+ base = (base || fileUrl);
setBaseURL(base);
to = all.find('[data-role="page"]');
@@ -3371,6 +3385,8 @@ $.fn.grid = function(options){
});
}
+ to.attr('data-base',base);
+
//preserve ID on a retrieved page
if ( to.attr('id') ) {
to = wrapNewPage( to );
Please sign in to comment.
Something went wrong with that request. Please try again.