Browse Source

expanding sub-menu items for projects page.

Thomas B 4 months ago
parent
commit
b482df013f
3 changed files with 59 additions and 19 deletions
  1. 16
    0
      input/projects.md
  2. 21
    10
      macros.py
  3. 22
    9
      static/css/style.css

+ 16
- 0
input/projects.md View File

12
 <!--%
12
 <!--%
13
 printProjectsMenu()
13
 printProjectsMenu()
14
 %-->
14
 %-->
15
+
16
+<script>
17
+    var coll = document.getElementsByClassName("collapse_menu");
18
+    var i;
19
+    for (i = 0; i < coll.length; i++) {
20
+        coll[i].addEventListener("click", function() {
21
+            this.classList.toggle("collapseactive_menu");
22
+            var content = this.parentElement.nextElementSibling;
23
+            if (content.style.maxHeight) {
24
+                content.style.maxHeight = null;
25
+            } else {
26
+                content.style.maxHeight = content.scrollHeight + "px";
27
+            }
28
+        });
29
+    }
30
+</script>

+ 21
- 10
macros.py View File

165
             ret += ".svg?logo=git&style=flat\" /></a>"
165
             ret += ".svg?logo=git&style=flat\" /></a>"
166
     return ret
166
     return ret
167
 
167
 
168
-def printMenuItem(p, yearsAsHeading = False, showDateSpan = False, showOnlyStartDate = False, nicelyFormatFullDate = False, lastyear = "0", lang = "", showLastCommit = True, hide_description = False, updates_as_heading = False):
168
+def printMenuItem(p, yearsAsHeading = False, showDateSpan = False, showOnlyStartDate = False, nicelyFormatFullDate = False, lastyear = "0", lang = "", showLastCommit = True, hide_description = False, updates_as_heading = False, desc_has_collapse = False):
169
     title = p.title
169
     title = p.title
170
     if lang != "":
170
     if lang != "":
171
         if p.get("title_" + lang, "") != "":
171
         if p.get("title_" + lang, "") != "":
202
         if p.get("description", "") != "":
202
         if p.get("description", "") != "":
203
             description = p.get("description", "")
203
             description = p.get("description", "")
204
             if lang != "":
204
             if lang != "":
205
-                if p.get("description_" + lang, "") != "":
206
-                    description = p.get("description_" + lang, "")
207
-            print("<br><span class=\"listdesc\">" + description + "</span>")
205
+                description = p.get("description_" + lang, description)
206
+            if desc_has_collapse:
207
+                print("<br><span class=\"listdesc collapse_menu\">" + description + "</span>")
208
+            else:
209
+                print("<br><span class=\"listdesc\">" + description + "</span>")
208
 
210
 
209
     if showLastCommit:
211
     if showLastCommit:
210
         link = githubCommitBadge(p)
212
         link = githubCommitBadge(p)
251
     # prints all pages with parent 'projects' or 'stuff'.
253
     # prints all pages with parent 'projects' or 'stuff'.
252
     # first the ones without date, sorted by position.
254
     # first the ones without date, sorted by position.
253
     # this first section includes sub-headings for children
255
     # this first section includes sub-headings for children
256
+    # in a hidden div, expanding when clicking the description.
254
     # then afterwards those with date, split by year.
257
     # then afterwards those with date, split by year.
255
     # also supports blog posts with parent.
258
     # also supports blog posts with parent.
256
     enpages = [p for p in pages if p.lang == "en"]
259
     enpages = [p for p in pages if p.lang == "en"]
266
 
269
 
267
     # print all pages
270
     # print all pages
268
     for p in mpages:
271
     for p in mpages:
269
-        printMenuItem(p)
270
-
271
-        # print subpages for these top-level items
272
+        # fetch subpages for these top-level items
272
         subpages = [sub for sub in enpages if sub.get("parent", "none") == p.get("child-id", "unknown")]
273
         subpages = [sub for sub in enpages if sub.get("parent", "none") == p.get("child-id", "unknown")]
273
         order = p.get("sort-order", "date")
274
         order = p.get("sort-order", "date")
274
         if order == "position":
275
         if order == "position":
275
             subpages.sort(key=lambda p: p["position"])
276
             subpages.sort(key=lambda p: p["position"])
276
         else:
277
         else:
277
             subpages.sort(key=lambda p: p["date"], reverse = True)
278
             subpages.sort(key=lambda p: p["date"], reverse = True)
279
+
280
+        printMenuItem(p, False, False, False, False, "0", "", True, False, False, len(subpages) > 0)
281
+
282
+        # print subpages
278
         if len(subpages) > 0:
283
         if len(subpages) > 0:
284
+            print("<div class='collapsecontent_menu'>")
279
             print("<ul>")
285
             print("<ul>")
280
             for sp in subpages:
286
             for sp in subpages:
281
                 printMenuItem(sp, False, True, True, False, "0", "", False, True)
287
                 printMenuItem(sp, False, True, True, False, "0", "", False, True)
282
             print("</ul>")
288
             print("</ul>")
289
+            print("</div>")
283
 
290
 
284
     # slect pages with a date
291
     # slect pages with a date
285
     dpages = [p for p in enpages if p.get("date", "") != ""]
292
     dpages = [p for p in enpages if p.get("date", "") != ""]
291
     # print all pages
298
     # print all pages
292
     lastyear = "0"
299
     lastyear = "0"
293
     for p in mpages:
300
     for p in mpages:
294
-        lastyear = printMenuItem(p, True, True, False, False, lastyear)
295
-
296
-        # print subpages for these top-level items
301
+        # fetch subpages for these top-level items
297
         subpages = [sub for sub in enpages if sub.get("parent", "none") == p.get("child-id", "unknown")]
302
         subpages = [sub for sub in enpages if sub.get("parent", "none") == p.get("child-id", "unknown")]
298
         order = p.get("sort-order", "date")
303
         order = p.get("sort-order", "date")
299
         if order == "position":
304
         if order == "position":
300
             subpages.sort(key=lambda p: p["position"])
305
             subpages.sort(key=lambda p: p["position"])
301
         else:
306
         else:
302
             subpages.sort(key=lambda p: p["date"], reverse = True)
307
             subpages.sort(key=lambda p: p["date"], reverse = True)
308
+
309
+        lastyear = printMenuItem(p, True, True, False, False, lastyear, "", True, False, False, len(subpages) > 0)
310
+
311
+        # print subpages
303
         if len(subpages) > 0:
312
         if len(subpages) > 0:
313
+            print("<div class='collapsecontent_menu'>")
304
             print("<ul>")
314
             print("<ul>")
305
             for sp in subpages:
315
             for sp in subpages:
306
                 printMenuItem(sp, False, True, True, False, "0", "", False, True)
316
                 printMenuItem(sp, False, True, True, False, "0", "", False, True)
307
             print("</ul>")
317
             print("</ul>")
318
+            print("</div>")
308
 
319
 
309
     print("</ul>")
320
     print("</ul>")
310
 
321
 

+ 22
- 9
static/css/style.css View File

274
     cursor: zoom-in;
274
     cursor: zoom-in;
275
 }
275
 }
276
 
276
 
277
-.collapse {
277
+.collapse, .collapse_menu {
278
     cursor: pointer;
278
     cursor: pointer;
279
+}
280
+
281
+.collapse {
279
     padding: 15px;
282
     padding: 15px;
280
 }
283
 }
281
 
284
 
282
-.collapse:after {
285
+.collapse:after, .collapse_menu:before {
283
     content: '\002B';
286
     content: '\002B';
284
     font-weight: bold;
287
     font-weight: bold;
288
+}
289
+
290
+.collapse:after {
285
     float: right;
291
     float: right;
286
     margin-left: 5px;
292
     margin-left: 5px;
287
 }
293
 }
288
 
294
 
289
-.collapseactive:after {
295
+.collapse_menu:before {
296
+    margin-right: 5px;
297
+}
298
+
299
+.collapseactive:after, .collapseactive_menu:before {
290
     content: "\2212";
300
     content: "\2212";
291
 }
301
 }
292
 
302
 
293
-.collapsecontent {
303
+.collapsecontent, .collapsecontent_menu {
294
     padding: 0;
304
     padding: 0;
295
-    margin: 15px;
296
     max-height: 0;
305
     max-height: 0;
297
     overflow: hidden;
306
     overflow: hidden;
298
     transition: max-height 0.1s ease-out;
307
     transition: max-height 0.1s ease-out;
308
+}
309
+
310
+.collapsecontent {
311
+    margin: 15px;
299
     border-width: 0px;
312
     border-width: 0px;
300
     border-style: solid;
313
     border-style: solid;
301
     border-radius: 10px;
314
     border-radius: 10px;
412
     text-decoration-color: #FF0000;
425
     text-decoration-color: #FF0000;
413
 }
426
 }
414
 
427
 
415
-.releasecard, .collapse {
428
+.releasecard, .collapse, .collapse_menu:before {
416
     background-color: #C0C0C0;
429
     background-color: #C0C0C0;
417
 }
430
 }
418
 
431
 
425
     margin-left: 1em;
438
     margin-left: 1em;
426
 }
439
 }
427
 
440
 
428
-.collapseactive, .collapse:hover {
441
+.collapseactive, .collapse:hover, .collapse_menu:hover {
429
     background-color: #999999;
442
     background-color: #999999;
430
 }
443
 }
431
 
444
 
456
         color: #BA55D3;
469
         color: #BA55D3;
457
     }
470
     }
458
 
471
 
459
-    .releasecard, .collapse {
472
+    .releasecard, .collapse, .collapse_menu:before {
460
         background-color: #232323;
473
         background-color: #232323;
461
     }
474
     }
462
 
475
 
500
         color: #FFFFFF !important;
513
         color: #FFFFFF !important;
501
     }
514
     }
502
 
515
 
503
-    .collapseactive, .collapse:hover {
516
+    .collapseactive, .collapse:hover, .collapse_menu:hover {
504
         background-color: #424242;
517
         background-color: #424242;
505
     }
518
     }
506
 
519
 

Loading…
Cancel
Save