// 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);
// 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.
}
}
ns.keys = function (obj) {
var result = [];
var key;
for (key in obj) {
result.push(key);
}
return result;
}
var hiddenPackages = {};
function subPackages(pack) {
return $.grep($('#tpl ol.packages'), function (element, index) {
var pack = $('li.pack > .tplshow', element).text();
return pack.indexOf(pack + '.') == 0;
});
}
ns.hidePackage = function (ol) {
var selected = $('li.pack > .tplshow', ol).text();
hiddenPackages[selected] = true;
$('ol.templates', ol).hide();
$.each(subPackages(selected), function (index, element) {
$(element).hide();
});
}
ns.showPackage = function (ol, state) {
var selected = $('li.pack > .tplshow', ol).text();
hiddenPackages[selected] = false;
$('ol.templates', ol).show();
$.each(subPackages(selected), function (index, element) {
$(element).show();
// When the filter is in "packs" state,
// we don't want to show the `.templates`
var key = $('li.pack > .tplshow', element).text();
if (hiddenPackages[key] || state == 'packs') {
$('ol.templates', element).hide();
}
});
}
})(Index);
function configureEntityList() {
kindFilterSync();
configureHideFilter();
configureFocusFilter();
textFilter();
}
/* Updates the list of entities (i.e. the content of the #tpl element) from the raw form generated by Scaladoc to a
form suitable for display. In particular, it adds class and object etc. icons, and it configures links to open in
the right frame. Furthermore, it sets the two reference top-level entities lists (topLevelTemplates and
topLevelPackages) to serve as reference for resetting the list when needed.
Be advised: this function should only be called once, on page load. */
function prepareEntityList() {
var classIcon = $("#library > img.class");
var traitIcon = $("#library > img.trait");
var objectIcon = $("#library > img.object");
var packageIcon = $("#library > img.package");
function compilePattern(query) {
var escaped = query.replace(/([\.\*\+\?\|\(\)\[\]\\])/g, '\\$1');
if (query.toLowerCase() != query) {
// Regexp that matches CamelCase subbits: "BiSe" is
// "[a-z]*Bi[a-z]*Se" and matches "BitSet", "ABitSet", ...
return new RegExp(escaped.replace(/([A-Z])/g,"[a-z]*$1"));
}
else { // if query is all lower case make a normal case insensitive search
return new RegExp(escaped, "i");
}
}
// Filters all focused templates and packages. This function should be made less-blocking.
// @param query The string of the query
function textFilter() {
scheduler.clear("filter");
$('#tpl').html('');
var query = $("#textfilter input").attr("value") || '';
var queryRegExp = compilePattern(query);
var index = 0;
var searchLoop = function () {
var packages = Index.keys(Index.PACKAGES).sort();
while (packages[index]) {
var pack = packages[index];
var children = Index.PACKAGES[pack];
index++;
/* Configures the hide tool by adding the hide link to all packages. */
function configureHideFilter() {
$('#tpl li.pack a.packhide').click(function () {
var packhide = $(this)
var action = packhide.text();
/* Configures the focus tool by adding the focus bar in the filter box (initially hidden), and by adding the focus
link to all packages. */
function configureFocusFilter() {
scheduler.add("init", function() {
focusFilterState = null;
if ($("#focusfilter").length == 0) {
$("#filter").append("<div id='focusfilter'>focused on <span class='focuscoll'></span> <a class='focusremove'><img class='icon' src='lib/remove.png'/></a></div>");
$("#focusfilter > .focusremove").click(function(event) {
textFilter();
/* Focuses the entity index on a specific package. To do so, it will copy the sub-templates and sub-packages of the
focuses package into the top-level templates and packages position of the index. The original top-level
@param package The <li> element that corresponds to the package in the entity index */
function focusFilter(package) {
scheduler.clear("filter");
function resizeFilterBlock() {
$("#tpl").css("top", $("#filter").outerHeight(true));
}
function printAlphabet() {
var html = '<a target="template" href="index/index-_.html">#</a>';
var c;
for (c = 'a'; c < 'z'; c = String.fromCharCode(c.charCodeAt(0) + 1)) {
html += [
'<a target="template" href="index/index-',
c,
'.html">',
c.toUpperCase(),
'</a>'
].join('');
}
$("#filter").append('<div id="letters">' + html + '</div>');
}