summaryrefslogtreecommitdiff
path: root/src/compiler/scala/tools/nsc/doc/html/resource/lib/index.js
diff options
context:
space:
mode:
authorDonna Malayeri <lindydonna@gmail.com>2011-04-19 15:30:26 +0000
committerDonna Malayeri <lindydonna@gmail.com>2011-04-19 15:30:26 +0000
commit7c47203ee24c0ec28ee303ca014e0378a86c8c2a (patch)
treefa8ffa1121addbd52823a0f6d6829c27c9a8ed6a /src/compiler/scala/tools/nsc/doc/html/resource/lib/index.js
parentacffc823df789bd0d446f0e3636378b277283e34 (diff)
downloadscala-7c47203ee24c0ec28ee303ca014e0378a86c8c2a.tar.gz
scala-7c47203ee24c0ec28ee303ca014e0378a86c8c2a.tar.bz2
scala-7c47203ee24c0ec28ee303ca014e0378a86c8c2a.zip
[scaladoc] Change URL when navigating Scaladoc,...
[scaladoc] Change URL when navigating Scaladoc, so as to allow linking to individual pages with the left frame intact. Patch submitted by Ruediger Keller. Closes #4473. No review.
Diffstat (limited to 'src/compiler/scala/tools/nsc/doc/html/resource/lib/index.js')
-rw-r--r--src/compiler/scala/tools/nsc/doc/html/resource/lib/index.js60
1 files changed, 58 insertions, 2 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) {