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

Allow local browsing of the docs without a web server #3117

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 60 additions & 2 deletions docs/_assets/js/jqm-docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ $('div').live('pagecreate',function(event){
//collapse page navs after use
$(function(){
$('body').delegate('.content-secondary .ui-collapsible-content', 'click', function(){
$(this).trigger("collapse")
$(this).trigger("collapse");
});
});

Expand All @@ -52,4 +52,62 @@ function setDefaultTransition(){
$(function(){
setDefaultTransition();
$( window ).bind( "throttledresize", setDefaultTransition );
});
});


// Turn off AJAX for local file browsing
if ( location.protocol.substr(0,4) === 'file' ||
location.protocol.substr(0,11) === '*-extension' ||
location.protocol.substr(0,6) === 'widget' ) {
$( function() {
// Check to see if ajax can be used. This does a quick ajax request and blocks the page until its done
// Start with links with only the trailing slash, and then move on to the ones that start with ..
$( "a" )
.filter( "[href='/']" ).attr( "href", "/index.html" ).end()
.filter( "[href^='..']" ).each(function() {
var href = $( this ).attr( "href" ),
append = "";

if ( href.substr(-2, 2) === '..' ) {
append = "/index.html";
}
else if ( href.substr(-1, 1) === '/' ) {
append = "index.html";
}
else if ( href.substr(-4, 4) !== 'html' ) {
append = "/index.html";
}
else if ( href.substr(-2, 2) === '..' ) {
append = "/index.html";
}

this.href = href + append;
});
});

// Check to see if ajax can be used. This does a quick ajax request and blocks the page until its done
$.ajax({
url: '.',
async: false,
isLocal: true
}).error(function() {
// Ajax doesn't work so turn it off
$( document ).bind( "mobileinit", function() {
$.mobile.ajaxEnabled = false;

var message = $( '<div>' , {
"class": "ui-footer ui-bar-e",
"style": "overflow: auto"
});

message
.append( "<h3>Note: Navigation may not work if viewed locally</h3>" )
.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>" );

$( document ).bind( "pagecreate", function() {
$( "div.ui-page" ).append( message );
});
});
});
}