diff options
author | Scott Main <smain@google.com> | 2010-04-16 09:00:29 -0700 |
---|---|---|
committer | Scott Main <smain@google.com> | 2010-04-16 09:05:06 -0700 |
commit | 7a0090b316482a2dc6f232ea312e1db63a9e919c (patch) | |
tree | b56bc113e9bb46823baeeb32d1c3d15a878d0150 /tools/droiddoc | |
parent | fcc7cf779905613d6bd48344b5c3a994237c02bd (diff) | |
download | build-7a0090b316482a2dc6f232ea312e1db63a9e919c.zip build-7a0090b316482a2dc6f232ea312e1db63a9e919c.tar.gz build-7a0090b316482a2dc6f232ea312e1db63a9e919c.tar.bz2 |
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
Diffstat (limited to 'tools/droiddoc')
-rw-r--r-- | tools/droiddoc/templates/assets/android-developer-docs.js | 37 | ||||
-rw-r--r-- | tools/droiddoc/templates/assets/android-developer-reference.js | 138 | ||||
-rw-r--r-- | tools/droiddoc/templates/class.cs | 25 |
3 files changed, 117 insertions, 83 deletions
diff --git a/tools/droiddoc/templates/assets/android-developer-docs.js b/tools/droiddoc/templates/assets/android-developer-docs.js index 4f27e0e..4c59dd6 100644 --- a/tools/droiddoc/templates/assets/android-developer-docs.js +++ b/tools/droiddoc/templates/assets/android-developer-docs.js @@ -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) { var nodes = $("#header-tabs").find("."+lang); for (i=0; i < nodes.length; i++) { // for each node in this language diff --git a/tools/droiddoc/templates/assets/android-developer-reference.js b/tools/droiddoc/templates/assets/android-developer-reference.js index 6299596..daddde0 100644 --- a/tools/droiddoc/templates/assets/android-developer-reference.js +++ b/tools/droiddoc/templates/assets/android-developer-reference.js @@ -34,25 +34,25 @@ function buildApiLevelSelector() { $("#apiLevelCheckbox").attr("checked","checked"); $("#api-level-toggle label").removeClass("disabled"); } - + minLevel = $("body").attr("class"); var select = $("#apiLevelSelector").html("").change(changeApiLevel); for (var i = maxLevel-1; i >= 0; 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) - select.append(option); + select.append(option); } - + // get the DOM element and use setAttribute cuz IE6 fails when using jquery .attr('selected',true) - var selectedLevelItem = $("#apiLevelSelector option[value='"+userApiLevel+"']").get(0); - selectedLevelItem.setAttribute('selected',true); + var selectedLevelItem = $("#apiLevelSelector option[value='"+userApiLevel+"']").get(0); + selectedLevelItem.setAttribute('selected',true); } function changeApiLevel() { var maxLevel = SINCE_DATA.length; var userApiLevelEnabled = readCookie(API_LEVEL_ENABLED_COOKIE); - var selectedLevel = maxLevel; - + var selectedLevel = maxLevel; + if (userApiLevelEnabled == 0) { toggleVisisbleApis(selectedLevel, "body"); } else { @@ -78,17 +78,17 @@ function changeApiLevel() { } function toggleVisisbleApis(selectedLevel, context) { - var apis = $(".api",context); - apis.each(function(i) { - var obj = $(this); - var className = obj.attr("class"); - var apiLevelIndex = className.lastIndexOf("-")+1; - var apiLevelEndIndex = className.indexOf(" ", apiLevelIndex); - apiLevelEndIndex = apiLevelEndIndex != -1 ? apiLevelEndIndex : className.length; - var apiLevel = className.substring(apiLevelIndex, apiLevelEndIndex); - if (apiLevel > selectedLevel) obj.addClass("absent").attr("title","Requires API Level "+apiLevel+" or higher"); - else obj.removeClass("absent").removeAttr("title"); - }); + var apis = $(".api",context); + apis.each(function(i) { + var obj = $(this); + var className = obj.attr("class"); + var apiLevelIndex = className.lastIndexOf("-")+1; + var apiLevelEndIndex = className.indexOf(" ", apiLevelIndex); + apiLevelEndIndex = apiLevelEndIndex != -1 ? apiLevelEndIndex : className.length; + var apiLevel = className.substring(apiLevelIndex, apiLevelEndIndex); + if (apiLevel > selectedLevel) obj.addClass("absent").attr("title","Requires API Level "+apiLevel+" or higher"); + else obj.removeClass("absent").removeAttr("title"); + }); } /* NAVTREE */ @@ -185,8 +185,8 @@ function expand_node(me, node) node.plus_img.src = me.toroot + "assets/images/triangle-opened-small.png"; node.expanded = true; - // perform api level toggling because new nodes are new to the DOM - var selectedLevel = $("#apiLevelSelector option:selected").val(); + // perform api level toggling because new nodes are new to the DOM + var selectedLevel = $("#apiLevelSelector option:selected").val(); toggleVisisbleApis(selectedLevel, "#side-nav"); } } @@ -257,8 +257,8 @@ function load_navtree_data(toroot) { function init_default_navtree(toroot) { init_navtree("nav-tree", toroot, NAVTREE_DATA); - // perform api level toggling because because the whole tree is new to the DOM - var selectedLevel = $("#apiLevelSelector option:selected").val(); + // perform api level toggling because because the whole tree is new to the DOM + var selectedLevel = $("#apiLevelSelector option:selected").val(); 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(); + } +});
\ No newline at end of file diff --git a/tools/droiddoc/templates/class.cs b/tools/droiddoc/templates/class.cs index 89eb927..d2add18 100644 --- a/tools/droiddoc/templates/class.cs +++ b/tools/droiddoc/templates/class.cs @@ -3,29 +3,6 @@ <html> <?cs include:"head_tag.cs" ?> <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" ?> <div class="g-unit" id="doc-content"> @@ -102,7 +79,7 @@ Summary: <?cs if:linkcount ?>| <?cs /if ?><a href="#inhmethods">Inherited Methods</a> <?cs /if ?> <?cs if:inhattrs || inhconstants || inhfields || inhmethods || subcount(class.subclasses.direct) || subcount(class.subclasses.indirect) ?> -| <a href="#" onclick="return toggleAllSummaryInherited(this)">[Expand All]</a> +| <a href="#" onclick="return toggleAllClassInherited()" id="toggleAllClassInherited">[Expand All]</a> <?cs /if ?> </div><!-- end sum-details-links --> <div class="api-level"> |