From c9f528a5445024f1b9d3b2d3a58939b00d580db2 Mon Sep 17 00:00:00 2001 From: m7r Date: Wed, 11 Mar 2015 23:31:59 +0100 Subject: [PATCH] fix(docs): run from file:// url again --- src/templates/index.tmpl | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/templates/index.tmpl b/src/templates/index.tmpl index 77d90ae..21ae83f 100644 --- a/src/templates/index.tmpl +++ b/src/templates/index.tmpl @@ -18,12 +18,18 @@ // before the base attribute is added, causing 404 and terribly slow loading of the docs app. (function() { var indexFile = (location.pathname.match(/\/(index[^\.]*\.html)/) || ['', ''])[1], - rUrl = /(#!\/|<%= sections %>|index[^\.]*\.html).*$/, - origin = location.origin || (window.location.protocol + "//" + window.location.hostname + (window.location.port ? ':' + window.location.port: '')), - baseUrl = origin + location.href.substr(origin.length).replace(rUrl, indexFile), + origin, baseUrl, rUrl = /(#!\/|<%= sections %>|index[^\.]*\.html).*$/, headEl = document.getElementsByTagName('head')[0], sync = true; + if (location.href.slice(0, 7) == 'file://') { + baseUrl = location.href.replace(rUrl, indexFile); + } else { + origin = location.origin || (window.location.protocol + "//" + window.location.hostname + + (window.location.port ? ':' + window.location.port: '')); + baseUrl = origin + location.href.substr(origin.length).replace(rUrl, indexFile); + } + addTag('base', {href: baseUrl}); addTag('link', {rel: 'stylesheet', href: 'css/bootstrap.min.css', type: 'text/css'}); addTag('link', {rel: 'stylesheet', href: 'css/font-awesome.css', type: 'text/css'});