Skip to content

Commit a4e09c8

Browse files
committed
target the page through the event, simplify the href selection, account for ajax page loads
1 parent c787743 commit a4e09c8

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

docs/_assets/js/jqm-docs.js

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -59,31 +59,19 @@ $(function(){
5959
if ( location.protocol.substr(0,4) === 'file' ||
6060
location.protocol.substr(0,11) === '*-extension' ||
6161
location.protocol.substr(0,6) === 'widget' ) {
62-
$( function() {
63-
// Check to see if ajax can be used. This does a quick ajax request and blocks the page until its done
64-
// Start with links with only the trailing slash, and then move on to the ones that start with ..
65-
$( "a" )
66-
.filter( "[href='/']" ).attr( "href", "/index.html" ).end()
67-
.filter( "[href^='..']" ).each(function() {
68-
var href = $( this ).attr( "href" ),
69-
append = "";
70-
71-
if ( href.substr(-2, 2) === '..' ) {
72-
append = "/index.html";
73-
}
74-
else if ( href.substr(-1, 1) === '/' ) {
75-
append = "index.html";
76-
}
77-
else if ( href.substr(-4, 4) !== 'html' ) {
78-
append = "/index.html";
79-
}
80-
else if ( href.substr(-2, 2) === '..' ) {
81-
append = "/index.html";
82-
}
83-
84-
this.href = href + append;
85-
});
86-
});
62+
63+
// Start with links with only the trailing slash and that aren't external links
64+
var fixLinks = function() {
65+
$( "a[href$='/'], a[href='.'], a[href='..']" ).not( "[rel='external']" ).each( function() {
66+
this.href = $( this ).attr( "href" ).replace( /\/$/, "" ) + "/index.html";
67+
});
68+
};
69+
70+
// fix the links for the initial page
71+
$(fixLinks);
72+
73+
// fix the links for subsequent ajax page loads
74+
$(document).bind( 'pagecreate', fixLinks );
8775

8876
// Check to see if ajax can be used. This does a quick ajax request and blocks the page until its done
8977
$.ajax({
@@ -96,16 +84,17 @@ if ( location.protocol.substr(0,4) === 'file' ||
9684
$.mobile.ajaxEnabled = false;
9785

9886
var message = $( '<div>' , {
99-
"class": "ui-footer ui-bar-e",
100-
"style": "overflow: auto"
101-
});
87+
'class': "ui-footer ui-bar-e",
88+
style: "overflow: auto; padding:10px 15px;",
89+
'data-ajax-warning': true
90+
});
10291

10392
message
10493
.append( "<h3>Note: Navigation may not work if viewed locally</h3>" )
10594
.append( "<p>The AJAX-based navigation used throughout the jQuery Mobile docs may need to be viewed on a web server to work in certain browsers such as Chrome. If you see an error message when you click a link, try a different browser or <a href='https://github.com/jquery/jquery-mobile/wiki/Downloadable-Docs-Help'>view help</a>.</p>" );
10695

107-
$( document ).bind( "pagecreate", function() {
108-
$( "div.ui-page" ).append( message );
96+
$( document ).bind( "pagecreate", function( event ) {
97+
$( event.target ).append( message );
10998
});
11099
});
111100
});

0 commit comments

Comments
 (0)