Skip to content

Commit

Permalink
Add search feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
BSVino committed Aug 16, 2014
1 parent 8da99f3 commit 88f9162
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 1 deletion.
66 changes: 66 additions & 0 deletions compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,74 @@ def create_directory(dir):
footer_fp = open("html/footer.html")
footer = footer_fp.read()
footer_fp.close()

search_fp = open("html/docs.gl.search.js")
search = search_fp.read()
search_fp.close()
print "Done."

search_versions_commands = "var search_versions = {"
for version in opengl.version_commands:
if version[0:2] == "gl" and float(version[2:]) < 2.1:
continue

if version[0:2] == "es" and float(version[2:]) < 2.0:
continue

search_versions_commands += "'" + version + "': ["

for command in opengl.version_commands[version]:
search_versions_commands += "'" + command + "',"

for command in opengl.version_commands_flat[version]:
if not command in opengl.version_commands[version]:
search_versions_commands += "'" + command + "',"

search_versions_commands += "],"

search_versions_commands += "'all': ["
for command in opengl.commands_version:
major_versions = opengl.get_major_versions(opengl.commands_version[command])
for version in major_versions:
if int(version[2]) < 2:
continue
search_versions_commands += "'" + version[:3] + "/" + command + "',"

for command in opengl.commands_version_flat:
if command in opengl.commands_version:
continue

major_versions = opengl.get_major_versions(opengl.commands_version_flat[command])
for version in major_versions:
if int(version[2]) < 2:
continue
search_versions_commands += "'" + version[:3] + "/" + command + "',"

search_versions_commands += "]};"

search = search.replace("{$search_versions_commands}", search_versions_commands)

search_fp = open(output_dir + "/docs.gl.search.js", "w")
search_fp.write(search)
search_fp.close()

search_versions_options = ""
for version_option in opengl.version_commands.keys():
if version_option[0:2] == "gl" and float(version_option[2:]) < 2.1:
continue

if version_option[0:2] == "es" and float(version_option[2:]) < 2.0:
continue

if version_option[:2] == 'gl':
search_versions_options += "<option value='" + version_option + "'" + ">GL" + version_option[2:] + "</option>"
elif version_option[:2] == 'es':
search_versions_options += "<option value='" + version_option + "'" + ">GLES" + version_option[2:] + "</option>"

search_versions_options += "<option selected='selected' value='all'" + ">All</option>"

header = header.replace("{$search_versions}", search_versions_options)

unhandled_commands = opengl.commands_version_flat.keys()

def spew_category(name, commands, current_command):
Expand Down
2 changes: 1 addition & 1 deletion html/copy/docs.gl.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,4 @@ $(function() {
$("#style_dark").click();

$(".open_me span.bonsai_inner").trigger('click');
});
});
22 changes: 22 additions & 0 deletions html/copy/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ a {
border: 0px;
}

.ui-autocomplete .ui-state-focus {
border: 0px;
}

#header {
width: 100%;
background-color: #aaa;
Expand All @@ -105,6 +109,24 @@ a {
margin-right: auto;
}

#search_div {
float: right;
margin: 18px;
margin-top: 8px;
}

#search_button {
padding: 0em 0.3em;
margin-left: 5px;
position: relative;
top: -1px;
}

#search_versions-button {
position: relative;
top: 8px;
}

#styles {
float: right;
color: black;
Expand Down
5 changes: 5 additions & 0 deletions html/copy/style_dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@ a:hover {
background-color: #222;
}

.ui-autocomplete .ui-state-focus, .ui-state-default {
color: #fff;
background-color: #222;
}

4 changes: 4 additions & 0 deletions html/copy/style_light.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,7 @@ a:hover {
.ui-selectmenu-open ul .ui-state-focus, .ui-state-default {
background-color: #ddd;
}

.ui-autocomplete .ui-state-focus, .ui-state-default {
background-color: #ddd;
}
40 changes: 40 additions & 0 deletions html/docs.gl.search.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{$search_versions_commands}

$(function() {
search_fn = function(value) {
version = $("#search_versions").val();
if (!version || typeof version == 'undefined')
version = 'all';

if (search_versions[version].indexOf(value) < 0)
return;

if (version == 'all')
window.location.href = "../" + value;
else
window.location.href = "../" + version.substring(0, 3) + "/" + value;
}

$( "#search_button" ).button().click(function(event) {
search_fn($("#search").val());
});

$( "#search" ).autocomplete({
source: search_versions["all"],
minLength: 3,
select: function( event, ui ) {
search_fn(event.target.value);
},
});

$( "#search_versions" ).selectmenu({
change: function( event, ui ) {
$("#search").val("");
$("#search").autocomplete( "option", "source", search_versions[$("#search_versions").val()] );
},
width: 70,
});

if (typeof $.cookie("api_version") != 'undefined')
$("#search_versions").val($.cookie("api_version").substring(0, 3) + "." + $.cookie("api_version").substring(3, 4)).selectmenu('refresh');
});
2 changes: 2 additions & 0 deletions html/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
window.current_api = "{$current_api}"
</script>
<script src="../docs.gl.js"></script>
<script src="../docs.gl.search.js"></script>

</head>
<body>
Expand All @@ -29,6 +30,7 @@
<div id='header_inner'>
<a href="/"><img src="../logo.png" /></a>
<div id="styles"><a id="style_light">Light</a> | <a id="style_dark">Dark</a></div>
<div id="search_div"><label for="search">Search:</label> <select id="search_versions">{$search_versions}</select> <input id="search" /><input id="search_button" type="submit" value="Go" /></div>
</div>
</div>

Expand Down

0 comments on commit 88f9162

Please sign in to comment.