Fossil SCM
Added post expand/collapse JS to forum post create/edit pages and activated pikchr source/svg toggle on those pages. This is all nice-to-have JS, not required, so won't break non-JS-capable clients.
Commit
db865174a03ee9d309e6a27386522037537bfa6b819de4f5d492506d17e0adce
Parent
7da8813eefa123d…
2 files changed
+17
-5
+16
-2
+17
-5
| --- src/forum.c | ||
| +++ src/forum.c | ||
| @@ -735,10 +735,23 @@ | ||
| 735 | 735 | |
| 736 | 736 | /* Clean up. */ |
| 737 | 737 | forumthread_delete(pThread); |
| 738 | 738 | fossil_free(zQuery); |
| 739 | 739 | } |
| 740 | + | |
| 741 | +/* | |
| 742 | +** Emit Forum Javascript which applies (or optionally can apply) | |
| 743 | +** to all forum-related pages. It does not include page-specific | |
| 744 | +** code (e.g. "forum.js"). | |
| 745 | +*/ | |
| 746 | +static void forum_emit_js(void){ | |
| 747 | + if(!builtin_bundle_all_fossil_js_apis()){ | |
| 748 | + builtin_emit_fossil_js_apis("dom", "copybutton", | |
| 749 | + "pikchr", 0); | |
| 750 | + } | |
| 751 | + builtin_emit_fossil_js_apis("page.forumpost", 0); | |
| 752 | +} | |
| 740 | 753 | |
| 741 | 754 | /* |
| 742 | 755 | ** WEBPAGE: forumpost |
| 743 | 756 | ** |
| 744 | 757 | ** Show a single forum posting. The posting is shown in context with |
| @@ -864,15 +877,11 @@ | ||
| 864 | 877 | /* Display the thread. */ |
| 865 | 878 | forum_display_thread(froot, fpid, mode, bUnf, bHist); |
| 866 | 879 | |
| 867 | 880 | /* Emit Forum Javascript. */ |
| 868 | 881 | builtin_request_js("forum.js"); |
| 869 | - if(!builtin_bundle_all_fossil_js_apis()){ | |
| 870 | - builtin_emit_fossil_js_apis("dom", "copybutton", | |
| 871 | - "pikchr", 0); | |
| 872 | - } | |
| 873 | - builtin_emit_fossil_js_apis("page.forumpost", 0); | |
| 882 | + forum_emit_js(); | |
| 874 | 883 | |
| 875 | 884 | /* Emit the page style. */ |
| 876 | 885 | style_footer(); |
| 877 | 886 | } |
| 878 | 887 | |
| @@ -1066,10 +1075,11 @@ | ||
| 1066 | 1075 | @ <input type="hidden" name="noanon" value="1"> |
| 1067 | 1076 | @ <input type="submit" value="Login"> |
| 1068 | 1077 | @ </form> |
| 1069 | 1078 | @ <td>Log into an existing account |
| 1070 | 1079 | @ </table> |
| 1080 | + forum_emit_js(); | |
| 1071 | 1081 | style_footer(); |
| 1072 | 1082 | fossil_free(zGoto); |
| 1073 | 1083 | } |
| 1074 | 1084 | |
| 1075 | 1085 | /* |
| @@ -1126,10 +1136,11 @@ | ||
| 1126 | 1136 | @ <br><label><input type="checkbox" name="showqp" %s(PCK("showqp"))> \ |
| 1127 | 1137 | @ Show query parameters</label> |
| 1128 | 1138 | @ </div> |
| 1129 | 1139 | } |
| 1130 | 1140 | @ </form> |
| 1141 | + forum_emit_js(); | |
| 1131 | 1142 | style_footer(); |
| 1132 | 1143 | } |
| 1133 | 1144 | |
| 1134 | 1145 | /* |
| 1135 | 1146 | ** WEBPAGE: forume2 |
| @@ -1305,10 +1316,11 @@ | ||
| 1305 | 1316 | @ <br><label><input type="checkbox" name="showqp" %s(PCK("showqp"))> \ |
| 1306 | 1317 | @ Show query parameters</label> |
| 1307 | 1318 | @ </div> |
| 1308 | 1319 | } |
| 1309 | 1320 | @ </form> |
| 1321 | + forum_emit_js(); | |
| 1310 | 1322 | style_footer(); |
| 1311 | 1323 | } |
| 1312 | 1324 | |
| 1313 | 1325 | /* |
| 1314 | 1326 | ** WEBPAGE: forummain |
| 1315 | 1327 |
| --- src/forum.c | |
| +++ src/forum.c | |
| @@ -735,10 +735,23 @@ | |
| 735 | |
| 736 | /* Clean up. */ |
| 737 | forumthread_delete(pThread); |
| 738 | fossil_free(zQuery); |
| 739 | } |
| 740 | |
| 741 | /* |
| 742 | ** WEBPAGE: forumpost |
| 743 | ** |
| 744 | ** Show a single forum posting. The posting is shown in context with |
| @@ -864,15 +877,11 @@ | |
| 864 | /* Display the thread. */ |
| 865 | forum_display_thread(froot, fpid, mode, bUnf, bHist); |
| 866 | |
| 867 | /* Emit Forum Javascript. */ |
| 868 | builtin_request_js("forum.js"); |
| 869 | if(!builtin_bundle_all_fossil_js_apis()){ |
| 870 | builtin_emit_fossil_js_apis("dom", "copybutton", |
| 871 | "pikchr", 0); |
| 872 | } |
| 873 | builtin_emit_fossil_js_apis("page.forumpost", 0); |
| 874 | |
| 875 | /* Emit the page style. */ |
| 876 | style_footer(); |
| 877 | } |
| 878 | |
| @@ -1066,10 +1075,11 @@ | |
| 1066 | @ <input type="hidden" name="noanon" value="1"> |
| 1067 | @ <input type="submit" value="Login"> |
| 1068 | @ </form> |
| 1069 | @ <td>Log into an existing account |
| 1070 | @ </table> |
| 1071 | style_footer(); |
| 1072 | fossil_free(zGoto); |
| 1073 | } |
| 1074 | |
| 1075 | /* |
| @@ -1126,10 +1136,11 @@ | |
| 1126 | @ <br><label><input type="checkbox" name="showqp" %s(PCK("showqp"))> \ |
| 1127 | @ Show query parameters</label> |
| 1128 | @ </div> |
| 1129 | } |
| 1130 | @ </form> |
| 1131 | style_footer(); |
| 1132 | } |
| 1133 | |
| 1134 | /* |
| 1135 | ** WEBPAGE: forume2 |
| @@ -1305,10 +1316,11 @@ | |
| 1305 | @ <br><label><input type="checkbox" name="showqp" %s(PCK("showqp"))> \ |
| 1306 | @ Show query parameters</label> |
| 1307 | @ </div> |
| 1308 | } |
| 1309 | @ </form> |
| 1310 | style_footer(); |
| 1311 | } |
| 1312 | |
| 1313 | /* |
| 1314 | ** WEBPAGE: forummain |
| 1315 |
| --- src/forum.c | |
| +++ src/forum.c | |
| @@ -735,10 +735,23 @@ | |
| 735 | |
| 736 | /* Clean up. */ |
| 737 | forumthread_delete(pThread); |
| 738 | fossil_free(zQuery); |
| 739 | } |
| 740 | |
| 741 | /* |
| 742 | ** Emit Forum Javascript which applies (or optionally can apply) |
| 743 | ** to all forum-related pages. It does not include page-specific |
| 744 | ** code (e.g. "forum.js"). |
| 745 | */ |
| 746 | static void forum_emit_js(void){ |
| 747 | if(!builtin_bundle_all_fossil_js_apis()){ |
| 748 | builtin_emit_fossil_js_apis("dom", "copybutton", |
| 749 | "pikchr", 0); |
| 750 | } |
| 751 | builtin_emit_fossil_js_apis("page.forumpost", 0); |
| 752 | } |
| 753 | |
| 754 | /* |
| 755 | ** WEBPAGE: forumpost |
| 756 | ** |
| 757 | ** Show a single forum posting. The posting is shown in context with |
| @@ -864,15 +877,11 @@ | |
| 877 | /* Display the thread. */ |
| 878 | forum_display_thread(froot, fpid, mode, bUnf, bHist); |
| 879 | |
| 880 | /* Emit Forum Javascript. */ |
| 881 | builtin_request_js("forum.js"); |
| 882 | forum_emit_js(); |
| 883 | |
| 884 | /* Emit the page style. */ |
| 885 | style_footer(); |
| 886 | } |
| 887 | |
| @@ -1066,10 +1075,11 @@ | |
| 1075 | @ <input type="hidden" name="noanon" value="1"> |
| 1076 | @ <input type="submit" value="Login"> |
| 1077 | @ </form> |
| 1078 | @ <td>Log into an existing account |
| 1079 | @ </table> |
| 1080 | forum_emit_js(); |
| 1081 | style_footer(); |
| 1082 | fossil_free(zGoto); |
| 1083 | } |
| 1084 | |
| 1085 | /* |
| @@ -1126,10 +1136,11 @@ | |
| 1136 | @ <br><label><input type="checkbox" name="showqp" %s(PCK("showqp"))> \ |
| 1137 | @ Show query parameters</label> |
| 1138 | @ </div> |
| 1139 | } |
| 1140 | @ </form> |
| 1141 | forum_emit_js(); |
| 1142 | style_footer(); |
| 1143 | } |
| 1144 | |
| 1145 | /* |
| 1146 | ** WEBPAGE: forume2 |
| @@ -1305,10 +1316,11 @@ | |
| 1316 | @ <br><label><input type="checkbox" name="showqp" %s(PCK("showqp"))> \ |
| 1317 | @ Show query parameters</label> |
| 1318 | @ </div> |
| 1319 | } |
| 1320 | @ </form> |
| 1321 | forum_emit_js(); |
| 1322 | style_footer(); |
| 1323 | } |
| 1324 | |
| 1325 | /* |
| 1326 | ** WEBPAGE: forummain |
| 1327 |
+16
-2
| --- src/fossil.page.forumpost.js | ||
| +++ src/fossil.page.forumpost.js | ||
| @@ -2,10 +2,24 @@ | ||
| 2 | 2 | "use strict"; |
| 3 | 3 | /* JS code for /forumpage and friends. Requires fossil.dom |
| 4 | 4 | and can optionally use fossil.pikchr. */ |
| 5 | 5 | const P = F.page, D = F.dom; |
| 6 | 6 | |
| 7 | + /** | |
| 8 | + When the page is loaded, this handler does the following: | |
| 9 | + | |
| 10 | + - Installs expand/collapse UI elements on "long" posts and collapses | |
| 11 | + them. | |
| 12 | + | |
| 13 | + - Any pikchr-generated SVGs get a source-toggle button added to them | |
| 14 | + which activates when the mouse is over the image or it is tapped. | |
| 15 | + | |
| 16 | + This is a harmless no-op if the current page has neither forum | |
| 17 | + post constructs for (1) nor any pikchr images for (2), nor will | |
| 18 | + NOT running this code cause any breakage for clients with no JS | |
| 19 | + support: this is all "nice-to-have", not required functionality. | |
| 20 | + */ | |
| 7 | 21 | F.onPageLoad(function(){ |
| 8 | 22 | const scrollbarIsVisible = (e)=>e.scrollHeight > e.clientHeight; |
| 9 | 23 | /* Returns an event handler which implements the post expand/collapse toggle |
| 10 | 24 | on contentElem when the given widget is activated. */ |
| 11 | 25 | const getWidgetHandler = function(widget, contentElem){ |
| @@ -31,11 +45,11 @@ | ||
| 31 | 45 | /* Adds an Expand/Collapse toggle to all div.forumPostBody |
| 32 | 46 | elements which are deemed "too large" (those for which |
| 33 | 47 | scrolling is currently activated because they are taller than |
| 34 | 48 | their max-height). */ |
| 35 | 49 | document.querySelectorAll( |
| 36 | - 'div.forumHier, div.forumTime, div.forumHierRoot' | |
| 50 | + 'div.forumHier, div.forumTime, div.forumHierRoot, div.forumEdit' | |
| 37 | 51 | ).forEach(function f(forumPostWrapper){ |
| 38 | 52 | const content = forumPostWrapper.querySelector('div.forumPostBody'); |
| 39 | 53 | if(!content || !scrollbarIsVisible(content)) return; |
| 40 | 54 | const parent = content.parentElement, |
| 41 | 55 | widget = D.addClass( |
| @@ -80,13 +94,13 @@ | ||
| 80 | 94 | forumPostWrapper.appendChild(widget); |
| 81 | 95 | } |
| 82 | 96 | content.appendChild(rightTapZone); |
| 83 | 97 | rightTapZone.addEventListener('click', widgetEventHandler, false); |
| 84 | 98 | refillTapZone(); |
| 85 | - }); | |
| 99 | + })/*F.onPageLoad()*/; | |
| 86 | 100 | |
| 87 | 101 | if(F.pikchr){ |
| 88 | 102 | F.pikchr.addSrcView(); |
| 89 | 103 | } |
| 90 | 104 | })/*onload callback*/; |
| 91 | 105 | |
| 92 | 106 | })(window.fossil); |
| 93 | 107 |
| --- src/fossil.page.forumpost.js | |
| +++ src/fossil.page.forumpost.js | |
| @@ -2,10 +2,24 @@ | |
| 2 | "use strict"; |
| 3 | /* JS code for /forumpage and friends. Requires fossil.dom |
| 4 | and can optionally use fossil.pikchr. */ |
| 5 | const P = F.page, D = F.dom; |
| 6 | |
| 7 | F.onPageLoad(function(){ |
| 8 | const scrollbarIsVisible = (e)=>e.scrollHeight > e.clientHeight; |
| 9 | /* Returns an event handler which implements the post expand/collapse toggle |
| 10 | on contentElem when the given widget is activated. */ |
| 11 | const getWidgetHandler = function(widget, contentElem){ |
| @@ -31,11 +45,11 @@ | |
| 31 | /* Adds an Expand/Collapse toggle to all div.forumPostBody |
| 32 | elements which are deemed "too large" (those for which |
| 33 | scrolling is currently activated because they are taller than |
| 34 | their max-height). */ |
| 35 | document.querySelectorAll( |
| 36 | 'div.forumHier, div.forumTime, div.forumHierRoot' |
| 37 | ).forEach(function f(forumPostWrapper){ |
| 38 | const content = forumPostWrapper.querySelector('div.forumPostBody'); |
| 39 | if(!content || !scrollbarIsVisible(content)) return; |
| 40 | const parent = content.parentElement, |
| 41 | widget = D.addClass( |
| @@ -80,13 +94,13 @@ | |
| 80 | forumPostWrapper.appendChild(widget); |
| 81 | } |
| 82 | content.appendChild(rightTapZone); |
| 83 | rightTapZone.addEventListener('click', widgetEventHandler, false); |
| 84 | refillTapZone(); |
| 85 | }); |
| 86 | |
| 87 | if(F.pikchr){ |
| 88 | F.pikchr.addSrcView(); |
| 89 | } |
| 90 | })/*onload callback*/; |
| 91 | |
| 92 | })(window.fossil); |
| 93 |
| --- src/fossil.page.forumpost.js | |
| +++ src/fossil.page.forumpost.js | |
| @@ -2,10 +2,24 @@ | |
| 2 | "use strict"; |
| 3 | /* JS code for /forumpage and friends. Requires fossil.dom |
| 4 | and can optionally use fossil.pikchr. */ |
| 5 | const P = F.page, D = F.dom; |
| 6 | |
| 7 | /** |
| 8 | When the page is loaded, this handler does the following: |
| 9 | |
| 10 | - Installs expand/collapse UI elements on "long" posts and collapses |
| 11 | them. |
| 12 | |
| 13 | - Any pikchr-generated SVGs get a source-toggle button added to them |
| 14 | which activates when the mouse is over the image or it is tapped. |
| 15 | |
| 16 | This is a harmless no-op if the current page has neither forum |
| 17 | post constructs for (1) nor any pikchr images for (2), nor will |
| 18 | NOT running this code cause any breakage for clients with no JS |
| 19 | support: this is all "nice-to-have", not required functionality. |
| 20 | */ |
| 21 | F.onPageLoad(function(){ |
| 22 | const scrollbarIsVisible = (e)=>e.scrollHeight > e.clientHeight; |
| 23 | /* Returns an event handler which implements the post expand/collapse toggle |
| 24 | on contentElem when the given widget is activated. */ |
| 25 | const getWidgetHandler = function(widget, contentElem){ |
| @@ -31,11 +45,11 @@ | |
| 45 | /* Adds an Expand/Collapse toggle to all div.forumPostBody |
| 46 | elements which are deemed "too large" (those for which |
| 47 | scrolling is currently activated because they are taller than |
| 48 | their max-height). */ |
| 49 | document.querySelectorAll( |
| 50 | 'div.forumHier, div.forumTime, div.forumHierRoot, div.forumEdit' |
| 51 | ).forEach(function f(forumPostWrapper){ |
| 52 | const content = forumPostWrapper.querySelector('div.forumPostBody'); |
| 53 | if(!content || !scrollbarIsVisible(content)) return; |
| 54 | const parent = content.parentElement, |
| 55 | widget = D.addClass( |
| @@ -80,13 +94,13 @@ | |
| 94 | forumPostWrapper.appendChild(widget); |
| 95 | } |
| 96 | content.appendChild(rightTapZone); |
| 97 | rightTapZone.addEventListener('click', widgetEventHandler, false); |
| 98 | refillTapZone(); |
| 99 | })/*F.onPageLoad()*/; |
| 100 | |
| 101 | if(F.pikchr){ |
| 102 | F.pikchr.addSrcView(); |
| 103 | } |
| 104 | })/*onload callback*/; |
| 105 | |
| 106 | })(window.fossil); |
| 107 |