Skip to content

Commit

Permalink
wmlunits: Make the sidebar and popup menus markup more proper (<ul>/<…
Browse files Browse the repository at this point in the history
…li>)

The language menu gets to stay as a <div> containing a table for now
since doing columns with lists is still not that well supported across
browsers (as well as the CSS columns spec as a whole -- too many legacy
browsers floating around).
  • Loading branch information
irydacea committed Aug 7, 2017
1 parent e9287e5 commit d4fb543
Showing 1 changed file with 44 additions and 25 deletions.
69 changes: 44 additions & 25 deletions data/tools/unit_tree/html_output.py
Expand Up @@ -8,6 +8,8 @@

pics_location = "../../pics"

html_entity_horizontal_bar = '&#8213;'

html_header = '''
<!DOCTYPE html>
Expand Down Expand Up @@ -344,7 +346,7 @@ def write(x): self.output.write(x)
<div class="navbar">
""")

write("<ul class=\"navbar\">")
write('<ul class="navbar" role="menu">')

def abbrev(name):
abbrev = name[0]
Expand All @@ -355,13 +357,28 @@ def abbrev(name):
return abbrev

def add_menu(id, name, class2=""):
write("""<li class="popuptrigger"
write("""<li class="popuptrigger" role="menuitem" aria-haspopup="true"
onclick="toggle_menu(this, '""" + id + """', 2)"
onmouseover="toggle_menu(this, '""" + id + """', 1)"
onmouseout="toggle_menu(this, '""" + id + """', 0)">""")
write('<a class="' + class2 + '">' + name + "</a>")
write('<ul class="popupmenu" id="' + id + '" role="menu" aria-label="' + name + '">')
write('<li>' + name + '</li>')

# FIXME: This is legacy code needed for the Language menu, since it's
# a table and we can't make it otherwise since CSS column
# support is still hit-or-miss for some browsers still in use.
def add_menu2(id, name, class2=""):
write("""<li class="popuptrigger" role="menuitem" aria-haspopup="true"
onclick="toggle_menu(this, '""" + id + """', 2)"
onmouseover="toggle_menu(this, '""" + id + """', 1)"
onmouseout="toggle_menu(this, '""" + id + """', 0)">""")
write('<a class="' + class2 + '">' + name + "</a>")
write('<div class="popupmenu" id="' + id + '">')
write("<div>" + name + "</div>")
write('<div class="popupmenu" id="' + id + '" role="menu" aria-label="' + name + '">')
write('<div>' + name + '</div>')

def end_menu():
write('</ul></li>\n')

# We may not have all the required info yet so defer writing the
# campaigns/eras navigation.
Expand All @@ -370,13 +387,13 @@ def add_menu(id, name, class2=""):
x = self.translate("addon_type^Campaign", "wesnoth")
add_menu("campaigns_menu", x)
write("PLACE CAMPAIGNS HERE\n")
write("</div></li>\n")
end_menu()

# Eras
x = self.translate("Era", "wesnoth")
add_menu("eras_menu", x)
write("PLACE ERAS HERE\n")
write("</div></li>\n")
end_menu()

# Races / Factions

Expand All @@ -389,7 +406,7 @@ def add_menu(id, name, class2=""):
x = self.translate("Race", "wesnoth-lib")
add_menu("races_menu", x)

write("<a href=\"mainline.html\">%s</a><br/>\n" % (
write('<li><a href="mainline.html" role="menuitem">%s</a></li>\n' % (
self.translate("all", "wesnoth-editor")))

r = {}, {}
Expand All @@ -412,12 +429,12 @@ def add_menu(id, name, class2=""):

for racename, rid in racenames:
if racename == "-":
write(" -<br/>")
write('<li>%s</li>' % html_entity_horizontal_bar)
else:
write(" <a href=\"%s#%s\">%s</a><br/>" % (
write('<li><a href="%s#%s" role="menuitem">%s</a></li>' % (
target, racename, racename))

write("</div></li>\n")
end_menu()
else:
x = self.translate("Factions", "wesnoth-help")
add_menu("races_menu", x)
Expand All @@ -429,10 +446,10 @@ def add_menu(id, name, class2=""):
if isinstance(un, helpers.GroupNode):
html = "../%s/%s.html" % (
self.isocode, self.campaign)
write(" <a href=\"%s#%s\">%s</a><br/>" % (
write('<li><a href="%s#%s" role="menuitem">%s</a></li>' % (
html, un.name, un.name))

write("</div></li>\n")
end_menu()

# Add entries for the races also to the navbar itself.
if not self.is_era:
Expand All @@ -454,14 +471,16 @@ class Entry: pass
got_menu = False
menuid = 0
for r in racelist:
if not r: continue
if got_menu: write("</div></li>\n")
if not r:
continue
if got_menu:
end_menu()
add_menu("units_menu" + str(menuid), r, "unitmenu")
menuid += 1
got_menu = True
c = self.campaign
if c == "units": c = "mainline"
write("<a href=\"%s#%s\">%s</a><br/>" % (
write('<li><a href="%s#%s" role="menuitem">%s</a></li>' % (
target, r, r))
for uid in races[r]:
un = self.wesnoth.unit_lookup[uid]
Expand All @@ -474,13 +493,13 @@ class Entry: pass
if not name:
error_message("Warning: Unit uid=" + uid + " has no name.\n")
name = uid
write("<a href=\"" + link + "\">" + name + "</a><br />")

if got_menu: write("</div></li>\n")
write('<li><a href="' + link + '" role="menuitem">' + name + '</a></li>')
if got_menu:
end_menu()

# Languages
x = self.translate("Language", "wesnoth")
add_menu("languages_menu", x)
add_menu2("languages_menu", x)
col = 0
maxcol = len(langlist) - 1
write("<table>")
Expand All @@ -492,11 +511,11 @@ class Entry: pass
#underscore = labb.find("_")
#if underscore > 0: labb = labb[:underscore]
if self.addon == "mainline":
write(" <a title=\"%s\" href=\"../%s/%s\">%s</a><br/>\n" % (
write('<a title="%s" href="../%s/%s" role="menuitem">%s</a>\n' % (
languages[lang], lang, self.target,
labb))
else:
write(" <a title=\"%s\" href=\"../%s/%s\">%s</a><br/>\n" % (
write('<a title="%s" href="../%s/%s">%s</a>\n' % (
languages[lang], lang, "mainline.html",
labb))
write("</td>")
Expand Down Expand Up @@ -1212,10 +1231,10 @@ def html_postprocess_file(filename, isocode, batchlist):
for campaign in campaigns:
addon, cname, campname, lang = campaign

chtml += " <a title=\"%s\" href=\"../../%s/%s/%s.html\">%s</a><br/>\n" % (
chtml += '<li><a title="%s" href="../../%s/%s/%s.html" role="menuitem">%s</a></li>\n' % (
campname, addon, lang, cname, campname)
if i == 0 and cids[1]:
chtml += "-<br/>\n"
chtml += '<li>%s</li>\n' % html_entity_horizontal_bar

eids = [[], []]
for addon in batchlist:
Expand All @@ -1238,10 +1257,10 @@ def html_postprocess_file(filename, isocode, batchlist):
for era in eras:
addon, eid, eraname, lang = era

ehtml += " <a title=\"%s\" href=\"../../%s/%s/%s.html\">%s</a><br/>" % (
ehtml += '<li><a title="%s" href="../../%s/%s/%s.html" role="menuitem">%s</a></li>\n' % (
eraname, addon, lang, eid, eraname)
if i == 0 and eids[1]:
ehtml += "-<br/>\n"
ehtml += '<li>%s</li>\n' % html_entity_horizontal_bar

f = open(filename, "r+b")
html = f.read().decode("utf8")
Expand Down

0 comments on commit d4fb543

Please sign in to comment.