diff options
author | Scott Main <smain@google.com> | 2011-07-27 18:20:34 -0700 |
---|---|---|
committer | Scott Main <smain@google.com> | 2011-07-27 18:31:32 -0700 |
commit | 70e606653a26f519d42673890c487b397603572a (patch) | |
tree | 69b0ecb29ca6f039a189da2aef8c8cb637a3d5a1 /tools | |
parent | 44067211572126ab39456580059cac6cdd0228f6 (diff) | |
download | build-70e606653a26f519d42673890c487b397603572a.zip build-70e606653a26f519d42673890c487b397603572a.tar.gz build-70e606653a26f519d42673890c487b397603572a.tar.bz2 |
docs: update api filtering to support provisional APIs (api levels that are string names)
Change-Id: I2df890739054e4130e455c9dcf5540a9c39f5ee3
Diffstat (limited to 'tools')
-rw-r--r-- | tools/droiddoc/templates-sdk/assets/android-developer-reference.js | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/tools/droiddoc/templates-sdk/assets/android-developer-reference.js b/tools/droiddoc/templates-sdk/assets/android-developer-reference.js index 31a702b..5561cc9 100644 --- a/tools/droiddoc/templates-sdk/assets/android-developer-reference.js +++ b/tools/droiddoc/templates-sdk/assets/android-developer-reference.js @@ -5,6 +5,7 @@ addLoadEvent(changeApiLevel); var API_LEVEL_ENABLED_COOKIE = "api_level_enabled"; var API_LEVEL_COOKIE = "api_level"; var minLevel = 1; +var maxLevel = 1; function toggleApiLevelSelector(checkbox) { var date = new Date(); @@ -23,9 +24,9 @@ function toggleApiLevelSelector(checkbox) { } function buildApiLevelSelector() { - var maxLevel = SINCE_DATA.length; + maxLevel = SINCE_DATA.length; var userApiLevelEnabled = readCookie(API_LEVEL_ENABLED_COOKIE); - var userApiLevel = readCookie(API_LEVEL_COOKIE); + var userApiLevel = parseInt(readCookie(API_LEVEL_COOKIE)); userApiLevel = userApiLevel == 0 ? maxLevel : userApiLevel; // If there's no cookie (zero), use the max by default if (userApiLevelEnabled == 0) { @@ -34,41 +35,45 @@ function buildApiLevelSelector() { $("#apiLevelCheckbox").attr("checked","checked"); $("#api-level-toggle label").removeClass("disabled"); } - - minLevel = $("body").attr("class"); + + minLevel = parseInt($("body").attr("class")); + // Handle provisional api levels; the provisional level will always be the highest possible level + if (isNaN(minLevel)) { + minLevel = maxLevel; + } 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); } - + // 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); } function changeApiLevel() { - var maxLevel = SINCE_DATA.length; + maxLevel = SINCE_DATA.length; var userApiLevelEnabled = readCookie(API_LEVEL_ENABLED_COOKIE); var selectedLevel = maxLevel; - + if (userApiLevelEnabled == 0) { toggleVisisbleApis(selectedLevel, "body"); } else { selectedLevel = parseInt($("#apiLevelSelector option:selected").val()); toggleVisisbleApis(selectedLevel, "body"); - + var date = new Date(); date.setTime(date.getTime()+(10*365*24*60*60*1000)); // keep this for 10 years var expiration = date.toGMTString(); writeCookie(API_LEVEL_COOKIE, selectedLevel, null, expiration); } - + if (selectedLevel < minLevel) { var thing = ($("#jd-header").html().indexOf("package") != -1) ? "package" : "class"; $("#naMessage").show().html("<div><p><strong>This " + thing + " is not available with API Level " + selectedLevel + ".</strong></p>" - + "<p>To use this " + thing + ", your application must specify API Level " + minLevel + " or higher in its manifest " + + "<p>To use this " + thing + ", your application must specify API Level \"" + $("body").attr("class") + "\" or higher in its manifest " + "and be compiled against a version of the Android library that supports an equal or higher API Level. To reveal this " + "document, change the value of the API Level filter above.</p>" + "<p><a href='" +toRoot+ "guide/appendix/api-levels.html'>What is the API Level?</a></p></div>"); @@ -86,7 +91,21 @@ function toggleVisisbleApis(selectedLevel, context) { 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"); + if (apiLevel.length == 0) { // for odd cases when the since data is actually missing, just bail + return; + } + apiLevel = parseInt(apiLevel); + + // Handle provisional api levels; if this item's level is the provisional one, set it to the max + var selectedLevelNum = parseInt(selectedLevel) + var apiLevelNum = parseInt(apiLevel); + if (isNaN(apiLevelNum)) { + apiLevelNum = maxLevel; + } + + // Grey things out that aren't available and give a tooltip title + if (apiLevelNum > selectedLevelNum) obj.addClass("absent").attr("title","Requires API Level \"" + + apiLevel + "\" or higher"); else obj.removeClass("absent").removeAttr("title"); }); } @@ -184,7 +203,7 @@ 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(); toggleVisisbleApis(selectedLevel, "#side-nav"); |