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.

stephan 2020-09-15 14:13 trunk
Commit db865174a03ee9d309e6a27386522037537bfa6b819de4f5d492506d17e0adce
+17 -5
--- src/forum.c
+++ src/forum.c
@@ -735,10 +735,23 @@
735735
736736
/* Clean up. */
737737
forumthread_delete(pThread);
738738
fossil_free(zQuery);
739739
}
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
+}
740753
741754
/*
742755
** WEBPAGE: forumpost
743756
**
744757
** Show a single forum posting. The posting is shown in context with
@@ -864,15 +877,11 @@
864877
/* Display the thread. */
865878
forum_display_thread(froot, fpid, mode, bUnf, bHist);
866879
867880
/* Emit Forum Javascript. */
868881
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();
874883
875884
/* Emit the page style. */
876885
style_footer();
877886
}
878887
@@ -1066,10 +1075,11 @@
10661075
@ <input type="hidden" name="noanon" value="1">
10671076
@ <input type="submit" value="Login">
10681077
@ </form>
10691078
@ <td>Log into an existing account
10701079
@ </table>
1080
+ forum_emit_js();
10711081
style_footer();
10721082
fossil_free(zGoto);
10731083
}
10741084
10751085
/*
@@ -1126,10 +1136,11 @@
11261136
@ <br><label><input type="checkbox" name="showqp" %s(PCK("showqp"))> \
11271137
@ Show query parameters</label>
11281138
@ </div>
11291139
}
11301140
@ </form>
1141
+ forum_emit_js();
11311142
style_footer();
11321143
}
11331144
11341145
/*
11351146
** WEBPAGE: forume2
@@ -1305,10 +1316,11 @@
13051316
@ <br><label><input type="checkbox" name="showqp" %s(PCK("showqp"))> \
13061317
@ Show query parameters</label>
13071318
@ </div>
13081319
}
13091320
@ </form>
1321
+ forum_emit_js();
13101322
style_footer();
13111323
}
13121324
13131325
/*
13141326
** WEBPAGE: forummain
13151327
--- 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
--- src/fossil.page.forumpost.js
+++ src/fossil.page.forumpost.js
@@ -2,10 +2,24 @@
22
"use strict";
33
/* JS code for /forumpage and friends. Requires fossil.dom
44
and can optionally use fossil.pikchr. */
55
const P = F.page, D = F.dom;
66
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
+ */
721
F.onPageLoad(function(){
822
const scrollbarIsVisible = (e)=>e.scrollHeight > e.clientHeight;
923
/* Returns an event handler which implements the post expand/collapse toggle
1024
on contentElem when the given widget is activated. */
1125
const getWidgetHandler = function(widget, contentElem){
@@ -31,11 +45,11 @@
3145
/* Adds an Expand/Collapse toggle to all div.forumPostBody
3246
elements which are deemed "too large" (those for which
3347
scrolling is currently activated because they are taller than
3448
their max-height). */
3549
document.querySelectorAll(
36
- 'div.forumHier, div.forumTime, div.forumHierRoot'
50
+ 'div.forumHier, div.forumTime, div.forumHierRoot, div.forumEdit'
3751
).forEach(function f(forumPostWrapper){
3852
const content = forumPostWrapper.querySelector('div.forumPostBody');
3953
if(!content || !scrollbarIsVisible(content)) return;
4054
const parent = content.parentElement,
4155
widget = D.addClass(
@@ -80,13 +94,13 @@
8094
forumPostWrapper.appendChild(widget);
8195
}
8296
content.appendChild(rightTapZone);
8397
rightTapZone.addEventListener('click', widgetEventHandler, false);
8498
refillTapZone();
85
- });
99
+ })/*F.onPageLoad()*/;
86100
87101
if(F.pikchr){
88102
F.pikchr.addSrcView();
89103
}
90104
})/*onload callback*/;
91105
92106
})(window.fossil);
93107
--- 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

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button