diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/doc/html/resource/lib/index.js | 60 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/doc/html/resource/lib/template.js | 8 |
2 files changed, 65 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/doc/html/resource/lib/index.js b/src/compiler/scala/tools/nsc/doc/html/resource/lib/index.js index 1a574a8752..60dcfcfe4b 100644 --- a/src/compiler/scala/tools/nsc/doc/html/resource/lib/index.js +++ b/src/compiler/scala/tools/nsc/doc/html/resource/lib/index.js @@ -9,7 +9,9 @@ var scheduler = undefined; var kindFilterState = undefined; var focusFilterState = undefined; -var title = $(document).attr('title') +var title = $(document).attr('title'); + +var lastHash = ""; $(document).ready(function() { $('body').layout({ west__size: '20%' }); @@ -17,10 +19,12 @@ $(document).ready(function() { center__paneSelector: ".ui-west-center" //,center__initClosed:true ,north__paneSelector: ".ui-west-north" - }); + }); $('iframe').bind("load", function(){ var subtitle = $(this).contents().find('title').text(); $(document).attr('title', (title ? title + " - " : "") + subtitle); + + setUrlFragmentFromFrameSrc(); }); // workaround for IE's iframe sizing lack of smartness @@ -43,8 +47,60 @@ $(document).ready(function() { configureKindFilter(); configureEntityList(); + setFrameSrcFromUrlFragment(); + + // If the url fragment changes, adjust the src of iframe "template". + $(window).bind('hashchange', function() { + if(lastFragment != window.location.hash) { + lastFragment = window.location.hash; + setFrameSrcFromUrlFragment(); + } + }); }); +// Set the iframe's src according to the fragment of the current url. +// fragment = "#scala.Either" => iframe url = "scala/Either.html" +// fragment = "#scala.Either@isRight:Boolean" => iframe url = "scala/Either.html#isRight:Boolean" +function setFrameSrcFromUrlFragment() { + var fragment = location.hash.slice(1); + if(fragment) { + var loc = fragment.split("@")[0].replace(/\./g, "/"); + if(loc.indexOf(".html") < 0) loc += ".html"; + if(fragment.indexOf('@') > 0) loc += ("#" + fragment.split("@", 2)[1]); + frames["template"].location.replace(loc); + } + else + frames["template"].location.replace("package.html"); +} + +// Set the url fragment according to the src of the iframe "template". +// iframe url = "scala/Either.html" => url fragment = "#scala.Either" +// iframe url = "scala/Either.html#isRight:Boolean" => url fragment = "#scala.Either@isRight:Boolean" +function setUrlFragmentFromFrameSrc() { + try { + var commonLength = location.pathname.lastIndexOf("/"); + var frameLocation = frames["template"].location; + var relativePath = frameLocation.pathname.slice(commonLength + 1); + + if(!relativePath || frameLocation.pathname.indexOf("/") < 0) + return; + + // Add #, remove ".html" and replace "/" with "." + fragment = "#" + relativePath.replace(/\.html$/, "").replace(/\//g, "."); + + // Add the frame's hash after an @ + if(frameLocation.hash) fragment += ("@" + frameLocation.hash.slice(1)); + + // Use replace to not add history items + lastFragment = fragment; + location.replace(fragment); + } + catch(e) { + // Chrome doesn't allow reading the iframe's location when + // used on the local file system. + } +} + var Index = {}; (function (ns) { diff --git a/src/compiler/scala/tools/nsc/doc/html/resource/lib/template.js b/src/compiler/scala/tools/nsc/doc/html/resource/lib/template.js index 14a5613015..2479945299 100644 --- a/src/compiler/scala/tools/nsc/doc/html/resource/lib/template.js +++ b/src/compiler/scala/tools/nsc/doc/html/resource/lib/template.js @@ -263,5 +263,11 @@ function filter() { function windowTitle() { - parent.document.title=document.title; + try { + parent.document.title=document.title; + } + catch(e) { + // Chrome doesn't allow settings the parent's title when + // used on the local file system. + } }; |