diff options
| -rw-r--r-- | html.c | 54 |
1 files changed, 26 insertions, 28 deletions
| @@ -1988,25 +1988,27 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local, | |||
| 1988 | int left = xs_list_len(children); | 1988 | int left = xs_list_len(children); |
| 1989 | 1989 | ||
| 1990 | if (left) { | 1990 | if (left) { |
| 1991 | char *p, *cmd5; | 1991 | xs_html *ch_details = xs_html_tag("details", |
| 1992 | int older_open = 0; | 1992 | xs_html_attr("open", NULL), |
| 1993 | xs *ss = xs_str_new(NULL); | 1993 | xs_html_tag("summary", |
| 1994 | int n_children = 0; | 1994 | xs_html_text("..."))); |
| 1995 | 1995 | ||
| 1996 | ss = xs_str_cat(ss, "<details open><summary>...</summary><p>\n"); | 1996 | xs_html *ch_container = xs_html_tag("div", |
| 1997 | xs_html_attr("class", level < 4 ? "snac-children" : "snac-children-too-deep")); | ||
| 1997 | 1998 | ||
| 1998 | if (level < 4) | 1999 | xs_html_add(ch_details, |
| 1999 | ss = xs_str_cat(ss, "<div class=\"snac-children\">\n"); | 2000 | ch_container); |
| 2000 | else | ||
| 2001 | ss = xs_str_cat(ss, "<div>\n"); | ||
| 2002 | 2001 | ||
| 2002 | xs_html *ch_older = NULL; | ||
| 2003 | if (left > 3) { | 2003 | if (left > 3) { |
| 2004 | xs *s1 = xs_fmt("<details><summary>%s</summary>\n", L("Older...")); | 2004 | xs_html_add(ch_container, |
| 2005 | ss = xs_str_cat(ss, s1); | 2005 | ch_older = xs_html_tag("details", |
| 2006 | older_open = 1; | 2006 | xs_html_tag("summary", |
| 2007 | xs_html_text(L("Older..."))))); | ||
| 2007 | } | 2008 | } |
| 2008 | 2009 | ||
| 2009 | p = children; | 2010 | xs_list *p = children; |
| 2011 | char *cmd5; | ||
| 2010 | while (xs_list_iter(&p, &cmd5)) { | 2012 | while (xs_list_iter(&p, &cmd5)) { |
| 2011 | xs *chd = NULL; | 2013 | xs *chd = NULL; |
| 2012 | 2014 | ||
| @@ -2015,14 +2017,16 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local, | |||
| 2015 | else | 2017 | else |
| 2016 | object_get_by_md5(cmd5, &chd); | 2018 | object_get_by_md5(cmd5, &chd); |
| 2017 | 2019 | ||
| 2018 | if (older_open && left <= 3) { | ||
| 2019 | ss = xs_str_cat(ss, "</details>\n"); | ||
| 2020 | older_open = 0; | ||
| 2021 | } | ||
| 2022 | |||
| 2023 | if (chd != NULL && xs_is_null(xs_dict_get(chd, "name"))) { | 2020 | if (chd != NULL && xs_is_null(xs_dict_get(chd, "name"))) { |
| 2024 | ss = html_entry(user, ss, chd, local, level + 1, cmd5, hide_children); | 2021 | xs *s1 = xs_str_new(NULL); |
| 2025 | n_children++; | 2022 | s1 = html_entry(user, s1, chd, local, level + 1, cmd5, hide_children); |
| 2023 | |||
| 2024 | if (left > 3) | ||
| 2025 | xs_html_add(ch_older, | ||
| 2026 | xs_html_raw(s1)); | ||
| 2027 | else | ||
| 2028 | xs_html_add(ch_container, | ||
| 2029 | xs_html_raw(s1)); | ||
| 2026 | } | 2030 | } |
| 2027 | else | 2031 | else |
| 2028 | srv_debug(2, xs_fmt("cannot read child %s", cmd5)); | 2032 | srv_debug(2, xs_fmt("cannot read child %s", cmd5)); |
| @@ -2030,14 +2034,8 @@ xs_str *html_entry(snac *user, xs_str *os, const xs_dict *msg, int local, | |||
| 2030 | left--; | 2034 | left--; |
| 2031 | } | 2035 | } |
| 2032 | 2036 | ||
| 2033 | if (older_open) | 2037 | xs *s1 = xs_html_render(ch_details); |
| 2034 | ss = xs_str_cat(ss, "</details>\n"); | 2038 | s = xs_str_cat(s, s1); |
| 2035 | |||
| 2036 | ss = xs_str_cat(ss, "</div>\n"); | ||
| 2037 | ss = xs_str_cat(ss, "</details>\n"); | ||
| 2038 | |||
| 2039 | if (n_children) | ||
| 2040 | s = xs_str_cat(s, ss); | ||
| 2041 | } | 2039 | } |
| 2042 | } | 2040 | } |
| 2043 | 2041 | ||