docs: add checkbox to toggle the api level filter on and off;
this includes some function renaming for the related scripts. the checkbox will be unchecked by default, so any users that currently have an api level filter selected will now see all apis until they click the checkbox. the old api level cookie is still saved the same, but the selected value will only be applied if the checkbox is selected, which has its own cookie for on or off.
This commit is contained in:
parent
f1bac52fe2
commit
9b5fdb9c23
5 changed files with 68 additions and 34 deletions
|
@ -73,9 +73,10 @@ def:custom_masthead() ?>
|
||||||
call:default_search_box() ?><?cs
|
call:default_search_box() ?><?cs
|
||||||
if:reference ?>
|
if:reference ?>
|
||||||
<div id="api-level-toggle">
|
<div id="api-level-toggle">
|
||||||
<label for="apiLevelControl"><a href="<?cs var:toroot ?>guide/appendix/api-levels.html">Filter by API Level</a>: </label>
|
<input type="checkbox" id="apiLevelCheckbox" onclick="toggleApiLevelSelector(this)" />
|
||||||
<select id="apiLevelControl">
|
<label for="apiLevelCheckbox" class="disabled">Filter by API Level: </label>
|
||||||
<!-- option elements added by buildApiLevelToggle() -->
|
<select id="apiLevelSelector">
|
||||||
|
<!-- option elements added by buildApiLevelSelector() -->
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
|
@ -85,7 +86,7 @@ def:custom_masthead() ?>
|
||||||
if:!last(since) ?>, <?cs /if ?><?cs
|
if:!last(since) ?>, <?cs /if ?><?cs
|
||||||
/each
|
/each
|
||||||
?> ];
|
?> ];
|
||||||
buildApiLevelToggle();
|
buildApiLevelSelector();
|
||||||
</script><?cs
|
</script><?cs
|
||||||
/if ?>
|
/if ?>
|
||||||
</div><!-- headerRight -->
|
</div><!-- headerRight -->
|
||||||
|
|
|
@ -48,11 +48,12 @@ a:visited code {
|
||||||
}
|
}
|
||||||
|
|
||||||
input, select,
|
input, select,
|
||||||
textarea, option {
|
textarea, option, label {
|
||||||
font-family:inherit;
|
font-family:inherit;
|
||||||
font-size:inherit;
|
font-size:inherit;
|
||||||
padding:0;
|
padding:0;
|
||||||
margin:0;
|
margin:0;
|
||||||
|
vertical-align:middle;
|
||||||
}
|
}
|
||||||
|
|
||||||
option {
|
option {
|
||||||
|
|
|
@ -341,6 +341,9 @@ links to summary tables) */
|
||||||
#api-level-toggle {
|
#api-level-toggle {
|
||||||
padding:0 10px;
|
padding:0 10px;
|
||||||
font-size:11px;
|
font-size:11px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#api-level-toggle label.disabled {
|
||||||
color:#999;
|
color:#999;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,7 @@ function readCookie(cookie) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeCookie(cookie, val, section, expiration) {
|
function writeCookie(cookie, val, section, expiration) {
|
||||||
if (!val) return;
|
if (val==undefined) return;
|
||||||
section = section == null ? "_" : "_"+section+"_";
|
section = section == null ? "_" : "_"+section+"_";
|
||||||
if (expiration == null) {
|
if (expiration == null) {
|
||||||
var date = new Date();
|
var date = new Date();
|
||||||
|
|
|
@ -1,21 +1,41 @@
|
||||||
|
|
||||||
/* API LEVEL TOGGLE */
|
/* API LEVEL TOGGLE */
|
||||||
addLoadEvent(changeApiLevel);
|
addLoadEvent(changeApiLevel);
|
||||||
|
|
||||||
|
var API_LEVEL_ENABLED_COOKIE = "api_level_enabled";
|
||||||
var API_LEVEL_COOKIE = "api_level";
|
var API_LEVEL_COOKIE = "api_level";
|
||||||
var minLevel = 1;
|
var minLevel = 1;
|
||||||
|
|
||||||
function buildApiLevelToggle() {
|
function toggleApiLevelSelector(checkbox) {
|
||||||
|
var date = new Date();
|
||||||
|
date.setTime(date.getTime()+(10*365*24*60*60*1000)); // keep this for 10 years
|
||||||
|
var expiration = date.toGMTString();
|
||||||
|
if (checkbox.checked) {
|
||||||
|
$("#apiLevelSelector").removeAttr("disabled");
|
||||||
|
$("#api-level-toggle label").removeClass("disabled");
|
||||||
|
writeCookie(API_LEVEL_ENABLED_COOKIE, 1, null, expiration);
|
||||||
|
} else {
|
||||||
|
$("#apiLevelSelector").attr("disabled","disabled");
|
||||||
|
$("#api-level-toggle label").addClass("disabled");
|
||||||
|
writeCookie(API_LEVEL_ENABLED_COOKIE, 0, null, expiration);
|
||||||
|
}
|
||||||
|
changeApiLevel();
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildApiLevelSelector() {
|
||||||
var maxLevel = SINCE_DATA.length;
|
var maxLevel = SINCE_DATA.length;
|
||||||
|
var userApiLevelEnabled = readCookie(API_LEVEL_ENABLED_COOKIE);
|
||||||
var userApiLevel = readCookie(API_LEVEL_COOKIE);
|
var userApiLevel = readCookie(API_LEVEL_COOKIE);
|
||||||
|
|
||||||
if (userApiLevel != 0) {
|
if (userApiLevelEnabled == 0) {
|
||||||
selectedLevel = userApiLevel;
|
$("#apiLevelSelector").attr("disabled","disabled");
|
||||||
} else {
|
} else {
|
||||||
selectedLevel = maxLevel;
|
$("#apiLevelCheckbox").attr("checked","checked");
|
||||||
|
$("#api-level-toggle label").removeClass("disabled");
|
||||||
}
|
}
|
||||||
|
|
||||||
minLevel = $("body").attr("class");
|
minLevel = $("body").attr("class");
|
||||||
var select = $("#apiLevelControl").html("").change(changeApiLevel);
|
var select = $("#apiLevelSelector").html("").change(changeApiLevel);
|
||||||
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)
|
||||||
|
@ -23,17 +43,26 @@ function buildApiLevelToggle() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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)
|
||||||
var selectedLevelItem = $("#apiLevelControl option[value='"+selectedLevel+"']").get(0);
|
var selectedLevelItem = $("#apiLevelSelector option[value='"+userApiLevel+"']").get(0);
|
||||||
selectedLevelItem.setAttribute('selected',true);
|
selectedLevelItem.setAttribute('selected',true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeApiLevel() {
|
function changeApiLevel() {
|
||||||
var selectedLevel = $("#apiLevelControl option:selected").val();
|
var maxLevel = SINCE_DATA.length;
|
||||||
|
var userApiLevelEnabled = readCookie(API_LEVEL_ENABLED_COOKIE);
|
||||||
|
var selectedLevel = maxLevel;
|
||||||
|
|
||||||
|
if (userApiLevelEnabled == 0) {
|
||||||
|
toggleVisisbleApis(selectedLevel, "body");
|
||||||
|
} else {
|
||||||
|
selectedLevel = $("#apiLevelSelector option:selected").val();
|
||||||
toggleVisisbleApis(selectedLevel, "body");
|
toggleVisisbleApis(selectedLevel, "body");
|
||||||
|
|
||||||
var date = new Date();
|
var date = new Date();
|
||||||
date.setTime(date.getTime()+(50*365*24*60*60*1000)); // keep this for 50 years
|
date.setTime(date.getTime()+(10*365*24*60*60*1000)); // keep this for 10 years
|
||||||
writeCookie(API_LEVEL_COOKIE, selectedLevel, null, date);
|
var expiration = date.toGMTString();
|
||||||
|
writeCookie(API_LEVEL_COOKIE, selectedLevel, null, expiration);
|
||||||
|
}
|
||||||
|
|
||||||
if (selectedLevel < minLevel) {
|
if (selectedLevel < minLevel) {
|
||||||
var thing = ($("#jd-header").html().indexOf("package") != -1) ? "package" : "class";
|
var thing = ($("#jd-header").html().indexOf("package") != -1) ? "package" : "class";
|
||||||
|
@ -156,7 +185,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 = $("#apiLevelControl option:selected").val();
|
var selectedLevel = $("#apiLevelSelector option:selected").val();
|
||||||
toggleVisisbleApis(selectedLevel, "#side-nav");
|
toggleVisisbleApis(selectedLevel, "#side-nav");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,7 +257,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 = $("#apiLevelControl option:selected").val();
|
var selectedLevel = $("#apiLevelSelector option:selected").val();
|
||||||
toggleVisisbleApis(selectedLevel, "#side-nav");
|
toggleVisisbleApis(selectedLevel, "#side-nav");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue