mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-27 03:00:12 -04:00
Make tab panes URL-addressable.
This commit is contained in:
@@ -363,11 +363,15 @@ class NamedButton(NavButton):
|
||||
class JsButton(NavButton):
|
||||
"""A button which fires a JS event and thus has no path and cannot
|
||||
be in the 'selected' state"""
|
||||
def __init__(self, title, style = 'js', **kw):
|
||||
NavButton.__init__(self, title, '#', style = style, **kw)
|
||||
def __init__(self, title, style = 'js', tab_name = None, **kw):
|
||||
NavButton.__init__(self, title, '#', style = style, tab_name = tab_name,
|
||||
**kw)
|
||||
|
||||
def build(self, *a, **kw):
|
||||
self.path = 'javascript:void(0)'
|
||||
if self.tab_name:
|
||||
self.path = '#' + self.tab_name
|
||||
else:
|
||||
self.path = 'javascript:void(0)'
|
||||
|
||||
def is_selected(self):
|
||||
return False
|
||||
|
||||
@@ -2506,7 +2506,7 @@ class FlairPane(Templated):
|
||||
|
||||
Templated.__init__(
|
||||
self,
|
||||
tabs=TabbedPane(tabs),
|
||||
tabs=TabbedPane(tabs, linkable=True),
|
||||
flair_enabled=c.site.flair_enabled,
|
||||
flair_position=c.site.flair_position,
|
||||
link_flair_position=c.site.link_flair_position,
|
||||
@@ -3028,17 +3028,18 @@ class Roadblocks(Templated):
|
||||
else g.default_sr
|
||||
|
||||
class TabbedPane(Templated):
|
||||
def __init__(self, tabs):
|
||||
def __init__(self, tabs, linkable=False):
|
||||
"""Renders as tabbed area where you can choose which tab to
|
||||
render. Tabs is a list of tuples (tab_name, tab_pane)."""
|
||||
buttons = []
|
||||
for tab_name, title, pane in tabs:
|
||||
buttons.append(JsButton(title, onclick="return select_tab_menu(this, '%s');" % tab_name))
|
||||
onclick = "return select_tab_menu(this, '%s')" % tab_name
|
||||
buttons.append(JsButton(title, tab_name=tab_name, onclick=onclick))
|
||||
|
||||
self.tabmenu = JsNavMenu(buttons, type = 'tabmenu')
|
||||
self.tabs = tabs
|
||||
|
||||
Templated.__init__(self)
|
||||
Templated.__init__(self, linkable=linkable)
|
||||
|
||||
class LinkChild(object):
|
||||
def __init__(self, link, load = False, expand = False, nofollow = False):
|
||||
|
||||
@@ -124,9 +124,12 @@
|
||||
${"id='%s'" % thing._id if thing._id else ""}>
|
||||
%for i, option in enumerate(thing):
|
||||
<%
|
||||
option.selected = (option == thing.selected)
|
||||
li_id = (
|
||||
"id='tab-%s'" % option.tab_name if hasattr(option, 'tab_name')
|
||||
else "")
|
||||
li_class = "class='selected'" if option == thing.selected else ""
|
||||
%>
|
||||
<li ${"class='selected'" if option.selected else ""}>
|
||||
<li ${id_class} ${li_class}>
|
||||
${option}
|
||||
</li>
|
||||
%endfor
|
||||
|
||||
@@ -7,3 +7,15 @@ ${thing.tabmenu}
|
||||
</div>
|
||||
%endfor
|
||||
</div>
|
||||
%if thing.linkable:
|
||||
<script>
|
||||
$(function() {
|
||||
var target = "tab-" + $(window.location).attr("hash").substr(1);
|
||||
$(".tabmenu li").each(function() {
|
||||
if (this.id == target) {
|
||||
$(this).find("a").click();
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
%endif
|
||||
|
||||
Reference in New Issue
Block a user