docs: add script to capture the ctrl+f key event (initiates 'find' search

on the page) and expand all inherited members.

Also move the appropriate methods from -docs.js into -reference.js where
they belong and add some function documentation.

Change-Id: I421bbf27d3b41d377776b3d64a97380458fcebd6
This commit is contained in:
Scott Main
2010-04-16 09:00:29 -07:00
parent fcc7cf7799
commit 7a0090b316
3 changed files with 117 additions and 83 deletions

View File

@@ -434,43 +434,6 @@ function scrollIntoView(nav) {
} }
} }
function toggleAllInherited(linkObj, expand) {
var a = $(linkObj);
var table = $(a.parent().parent().parent());
var expandos = $(".jd-expando-trigger", table);
if ( (expand == null && a.text() == "[Expand]") || expand ) {
expandos.each(function(i) {
toggleInherited(this, true);
});
a.text("[Collapse]");
} else if ( (expand == null && a.text() == "[Collapse]") || (expand == false) ) {
expandos.each(function(i) {
toggleInherited(this, false);
});
a.text("[Expand]");
}
return false;
}
function toggleAllSummaryInherited(linkObj) {
var a = $(linkObj);
var content = $(a.parent().parent().parent());
var toggles = $(".toggle-all", content);
if (a.text() == "[Expand All]") {
toggles.each(function(i) {
toggleAllInherited(this, true);
});
a.text("[Collapse All]");
} else {
toggles.each(function(i) {
toggleAllInherited(this, false);
});
a.text("[Expand All]");
}
return false;
}
function changeTabLang(lang) { function changeTabLang(lang) {
var nodes = $("#header-tabs").find("."+lang); var nodes = $("#header-tabs").find("."+lang);
for (i=0; i < nodes.length; i++) { // for each node in this language for (i=0; i < nodes.length; i++) { // for each node in this language

View File

@@ -40,7 +40,7 @@ function buildApiLevelSelector() {
for (var i = maxLevel-1; i >= 0; i--) { for (var i = maxLevel-1; i >= 0; i--) {
var option = $("<option />").attr("value",""+SINCE_DATA[i]).append(""+SINCE_DATA[i]); var option = $("<option />").attr("value",""+SINCE_DATA[i]).append(""+SINCE_DATA[i]);
// if (SINCE_DATA[i] < minLevel) option.addClass("absent"); // always false for strings (codenames) // if (SINCE_DATA[i] < minLevel) option.addClass("absent"); // always false for strings (codenames)
select.append(option); select.append(option);
} }
// get the DOM element and use setAttribute cuz IE6 fails when using jquery .attr('selected',true) // get the DOM element and use setAttribute cuz IE6 fails when using jquery .attr('selected',true)
@@ -78,17 +78,17 @@ function changeApiLevel() {
} }
function toggleVisisbleApis(selectedLevel, context) { function toggleVisisbleApis(selectedLevel, context) {
var apis = $(".api",context); var apis = $(".api",context);
apis.each(function(i) { apis.each(function(i) {
var obj = $(this); var obj = $(this);
var className = obj.attr("class"); var className = obj.attr("class");
var apiLevelIndex = className.lastIndexOf("-")+1; var apiLevelIndex = className.lastIndexOf("-")+1;
var apiLevelEndIndex = className.indexOf(" ", apiLevelIndex); var apiLevelEndIndex = className.indexOf(" ", apiLevelIndex);
apiLevelEndIndex = apiLevelEndIndex != -1 ? apiLevelEndIndex : className.length; apiLevelEndIndex = apiLevelEndIndex != -1 ? apiLevelEndIndex : className.length;
var apiLevel = className.substring(apiLevelIndex, apiLevelEndIndex); var apiLevel = className.substring(apiLevelIndex, apiLevelEndIndex);
if (apiLevel > selectedLevel) obj.addClass("absent").attr("title","Requires API Level "+apiLevel+" or higher"); if (apiLevel > selectedLevel) obj.addClass("absent").attr("title","Requires API Level "+apiLevel+" or higher");
else obj.removeClass("absent").removeAttr("title"); else obj.removeClass("absent").removeAttr("title");
}); });
} }
/* NAVTREE */ /* NAVTREE */
@@ -186,7 +186,7 @@ function expand_node(me, node)
node.expanded = true; node.expanded = true;
// perform api level toggling because new nodes are new to the DOM // perform api level toggling because new nodes are new to the DOM
var selectedLevel = $("#apiLevelSelector option:selected").val(); var selectedLevel = $("#apiLevelSelector option:selected").val();
toggleVisisbleApis(selectedLevel, "#side-nav"); toggleVisisbleApis(selectedLevel, "#side-nav");
} }
} }
@@ -258,7 +258,7 @@ function init_default_navtree(toroot) {
init_navtree("nav-tree", toroot, NAVTREE_DATA); init_navtree("nav-tree", toroot, NAVTREE_DATA);
// perform api level toggling because because the whole tree is new to the DOM // perform api level toggling because because the whole tree is new to the DOM
var selectedLevel = $("#apiLevelSelector option:selected").val(); var selectedLevel = $("#apiLevelSelector option:selected").val();
toggleVisisbleApis(selectedLevel, "#side-nav"); toggleVisisbleApis(selectedLevel, "#side-nav");
} }
@@ -294,3 +294,97 @@ function init_navtree(navtree_id, toroot, root_nodes)
}); });
} }
} }
/* TOGGLE INHERITED MEMBERS */
/* Toggle an inherited class (arrow toggle)
* @param linkObj The link that was clicked.
* @param expand 'true' to ensure it's expanded. 'false' to ensure it's closed.
* 'null' to simply toggle.
*/
function toggleInherited(linkObj, expand) {
var base = linkObj.getAttribute("id");
var list = document.getElementById(base + "-list");
var summary = document.getElementById(base + "-summary");
var trigger = document.getElementById(base + "-trigger");
var a = $(linkObj);
if ( (expand == null && a.hasClass("closed")) || expand ) {
list.style.display = "none";
summary.style.display = "block";
trigger.src = toRoot + "assets/images/triangle-opened.png";
a.removeClass("closed");
a.addClass("opened");
} else if ( (expand == null && a.hasClass("opened")) || (expand == false) ) {
list.style.display = "block";
summary.style.display = "none";
trigger.src = toRoot + "assets/images/triangle-closed.png";
a.removeClass("opened");
a.addClass("closed");
}
return false;
}
/* Toggle all inherited classes in a single table (e.g. all inherited methods)
* @param linkObj The link that was clicked.
* @param expand 'true' to ensure it's expanded. 'false' to ensure it's closed.
* 'null' to simply toggle.
*/
function toggleAllInherited(linkObj, expand) {
var a = $(linkObj);
var table = $(a.parent().parent().parent()); // ugly way to get table/tbody
var expandos = $(".jd-expando-trigger", table);
if ( (expand == null && a.text() == "[Expand]") || expand ) {
expandos.each(function(i) {
toggleInherited(this, true);
});
a.text("[Collapse]");
} else if ( (expand == null && a.text() == "[Collapse]") || (expand == false) ) {
expandos.each(function(i) {
toggleInherited(this, false);
});
a.text("[Expand]");
}
return false;
}
/* Toggle all inherited members in the class (link in the class title)
*/
function toggleAllClassInherited() {
var a = $("#toggleAllClassInherited"); // get toggle link from class title
var toggles = $(".toggle-all", $("#doc-content"));
if (a.text() == "[Expand All]") {
toggles.each(function(i) {
toggleAllInherited(this, true);
});
a.text("[Collapse All]");
} else {
toggles.each(function(i) {
toggleAllInherited(this, false);
});
a.text("[Expand All]");
}
return false;
}
/* Expand all inherited members in the class. Used when initiating page search */
function ensureAllInheritedExpanded() {
var toggles = $(".toggle-all", $("#doc-content"));
toggles.each(function(i) {
toggleAllInherited(this, true);
});
$("#toggleAllClassInherited").text("[Collapse All]");
}
/* HANDLE KEY EVENTS
* - Listen for Ctrl+F (Cmd on Mac) and expand all inherited members (to aid page search)
*/
var agent = navigator['userAgent'].toLowerCase();
var mac = agent.indexOf("macintosh") != -1;
$(document).keydown( function(e) {
var control = mac ? e.metaKey && !e.ctrlKey : e.ctrlKey; // get ctrl key
if (control && e.which == 70) { // 70 is "F"
ensureAllInheritedExpanded();
}
});

View File

@@ -3,29 +3,6 @@
<html> <html>
<?cs include:"head_tag.cs" ?> <?cs include:"head_tag.cs" ?>
<body class="<?cs var:class.since ?>"> <body class="<?cs var:class.since ?>">
<script type="text/javascript">
function toggleInherited(linkObj, expand) {
var base = linkObj.getAttribute("id");
var list = document.getElementById(base + "-list");
var summary = document.getElementById(base + "-summary");
var trigger = document.getElementById(base + "-trigger");
var a = $(linkObj);
if ( (expand == null && a.hasClass("closed")) || expand ) {
list.style.display = "none";
summary.style.display = "block";
trigger.src = "<?cs var:toroot ?>assets/images/triangle-opened.png";
a.removeClass("closed");
a.addClass("opened");
} else if ( (expand == null && a.hasClass("opened")) || (expand == false) ) {
list.style.display = "block";
summary.style.display = "none";
trigger.src = "<?cs var:toroot ?>assets/images/triangle-closed.png";
a.removeClass("opened");
a.addClass("closed");
}
return false;
}
</script>
<?cs include:"header.cs" ?> <?cs include:"header.cs" ?>
<div class="g-unit" id="doc-content"> <div class="g-unit" id="doc-content">
@@ -102,7 +79,7 @@ Summary:
<?cs if:linkcount ?>&#124; <?cs /if ?><a href="#inhmethods">Inherited Methods</a> <?cs if:linkcount ?>&#124; <?cs /if ?><a href="#inhmethods">Inherited Methods</a>
<?cs /if ?> <?cs /if ?>
<?cs if:inhattrs || inhconstants || inhfields || inhmethods || subcount(class.subclasses.direct) || subcount(class.subclasses.indirect) ?> <?cs if:inhattrs || inhconstants || inhfields || inhmethods || subcount(class.subclasses.direct) || subcount(class.subclasses.indirect) ?>
&#124; <a href="#" onclick="return toggleAllSummaryInherited(this)">[Expand All]</a> &#124; <a href="#" onclick="return toggleAllClassInherited()" id="toggleAllClassInherited">[Expand All]</a>
<?cs /if ?> <?cs /if ?>
</div><!-- end sum-details-links --> </div><!-- end sum-details-links -->
<div class="api-level"> <div class="api-level">