Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Initial go at a preview mode for /chat. Still some UI/UX decisions to be made. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | chat-markdown |
| Files: | files | file ages | folders |
| SHA3-256: |
f33eefe2bb8bf14e00a61b9c8add780a |
| User & Date: | stephan 2021-09-21 11:20:38.771 |
Context
|
2021-09-21
| ||
| 11:32 | Moved the 350-ish lines/9k of chat-specific CSS into style.chat.css. ... (check-in: bd4dd24373 user: stephan tags: chat-markdown) | |
| 11:20 | Initial go at a preview mode for /chat. Still some UI/UX decisions to be made. ... (check-in: f33eefe2bb user: stephan tags: chat-markdown) | |
| 10:08 | Merge fixes from trunk ... (check-in: 3f2365fe26 user: drh tags: chat-markdown) | |
Changes
Changes to src/ajax.c.
| ︙ | ︙ | |||
262 263 264 265 266 267 268 |
*zFn = PD("filename",P("fn"));
if (*zFn) ++rc;
}
return rc;
}
/*
| | | > > | 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
*zFn = PD("filename",P("fn"));
if (*zFn) ++rc;
}
return rc;
}
/*
** AJAX route /ajax/preview-text
**
** Required query parameters:
**
** filename=name of content, for use in determining the
** mimetype/render mode.
**
** content=text
**
** Optional query parameters:
**
** render_mode=integer (AJAX_RENDER_xxx) (default=AJAX_RENDER_GUESS)
**
** ln=0 or 1 to disable/enable line number mode in
** AJAX_RENDER_PLAIN_TEXT mode.
|
| ︙ | ︙ | |||
363 364 365 366 367 368 369 |
int cmp_ajax_route_name(const void *a, const void *b){
const AjaxRoute * rA = (const AjaxRoute*)a;
const AjaxRoute * rB = (const AjaxRoute*)b;
return fossil_strcmp(rA->zName, rB->zName);
}
/*
| | | 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
int cmp_ajax_route_name(const void *a, const void *b){
const AjaxRoute * rA = (const AjaxRoute*)a;
const AjaxRoute * rB = (const AjaxRoute*)b;
return fossil_strcmp(rA->zName, rB->zName);
}
/*
** WEBPAGE: ajax hidden
**
** The main dispatcher for shared ajax-served routes. Requires the
** 'name' parameter be the main route's name (as defined in a list in
** this function), noting that fossil automatically assigns all path
** parts after "ajax" to "name", e.g. /ajax/foo/bar assigns
** name=foo/bar.
**
|
| ︙ | ︙ |
Changes to src/chat.c.
| ︙ | ︙ | |||
152 153 154 155 156 157 158 |
zAlert = mprintf("%s/builtin/%s", g.zBaseURL,
db_get("chat-alert-sound","alerts/plunk.wav"));
zProjectName = db_get("project-name","Unnamed project");
style_set_current_feature("chat");
style_header("Chat");
@ <form accept-encoding="utf-8" id="chat-form" autocomplete="off">
@ <div id='chat-input-area'>
| | > | | | > > > > > > > | | 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
zAlert = mprintf("%s/builtin/%s", g.zBaseURL,
db_get("chat-alert-sound","alerts/plunk.wav"));
zProjectName = db_get("project-name","Unnamed project");
style_set_current_feature("chat");
style_header("Chat");
@ <form accept-encoding="utf-8" id="chat-form" autocomplete="off">
@ <div id='chat-input-area'>
@ <div id='chat-input-line' class='single-line'>
@ <input type="text" name="msg" id="chat-input-single" \
@ placeholder="Type markdown-formatted message for %h(zProjectName)." \
@ autocomplete="off">
@ <textarea rows="8" id="chat-input-multi" \
@ placeholder="Type markdown-formatted message for %h(zProjectName). Ctrl-Enter sends it." \
@ class="hidden"></textarea>
@ <div id='chat-edit-buttons'>
@ <button id="chat-preview-button">Preview</button>
@ <span id="chat-settings-button" class="settings-icon" \
@ aria-label="Settings..." aria-haspopup="true" ></span>
@ <button id="chat-message-submit">Send</button>
@ </div>
@ </div>
@ <div id='chat-input-file-area'>
@ <div class='file-selection-wrapper'>
@ <div class='help-buttonlet'>
@ Select a file to upload, drag/drop a file into this spot,
@ or paste an image from the clipboard if supported by
@ your environment.
@ </div>
@ <input type="file" name="file" id="chat-input-file">
@ </div>
@ <div id="chat-drop-details"></div>
@ </div>
@ </div>
@ </form>
@ <div id='chat-preview' class='hidden'>
@ <header>Preview:</header>
@ <div id='chat-preview-content' class='message-widget-content'></div>
@ <div id='chat-preview-buttons'><button id='chat-preview-close'>Close Preview</button></div>
@ </div>
@ <div id='chat-config' class='hidden'>
@ <div id='chat-config-options'></div>
/* ^^^populated client-side */
@ <button>Close Settings</button>
@ </div>
@ <div id='chat-messages-wrapper'>
/* New chat messages get inserted immediately after this element */
@ <span id='message-inject-point'></span>
@ </div>
fossil_free(zProjectName);
builtin_fossil_js_bundle_or("popupwidget", "storage",
|
| ︙ | ︙ | |||
201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
@ /*^^^for skins which add their own BODY tag */;
@ window.fossil.config.chat = {
@ fromcli: %h(PB("cli")?"true":"false"),
@ alertSound: "%h(zAlert)",
@ initSize: %d(db_get_int("chat-initial-history",50)),
@ imagesInline: !!%d(db_get_boolean("chat-inline-images",1))
@ };
chat_emit_alert_list();
cgi_append_content(builtin_text("chat.js"),-1);
@ }, false);
@ </script>
style_finish_page();
}
| > | 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 |
@ /*^^^for skins which add their own BODY tag */;
@ window.fossil.config.chat = {
@ fromcli: %h(PB("cli")?"true":"false"),
@ alertSound: "%h(zAlert)",
@ initSize: %d(db_get_int("chat-initial-history",50)),
@ imagesInline: !!%d(db_get_boolean("chat-inline-images",1))
@ };
ajax_emit_js_preview_modes(0);
chat_emit_alert_list();
cgi_append_content(builtin_text("chat.js"),-1);
@ }, false);
@ </script>
style_finish_page();
}
|
| ︙ | ︙ |
Changes to src/chat.js.
| ︙ | ︙ | |||
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
verboseErrors: false /* if true then certain, mostly extraneous,
error messages may be sent to the console. */,
e:{/*map of certain DOM elements.*/
messageInjectPoint: E1('#message-inject-point'),
pageTitle: E1('head title'),
loadOlderToolbar: undefined /* the load-posts toolbar (dynamically created) */,
inputWrapper: E1("#chat-input-area"),
fileSelectWrapper: E1('#chat-input-file-area'),
messagesWrapper: E1('#chat-messages-wrapper'),
inputForm: E1('#chat-form'),
btnSubmit: E1('#chat-message-submit'),
inputSingle: E1('#chat-input-single'),
inputMulti: E1('#chat-input-multi'),
inputCurrent: undefined/*one of inputSingle or inputMulti*/,
inputFile: E1('#chat-input-file'),
contentDiv: E1('div.content'),
| > | > > > | 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
verboseErrors: false /* if true then certain, mostly extraneous,
error messages may be sent to the console. */,
e:{/*map of certain DOM elements.*/
messageInjectPoint: E1('#message-inject-point'),
pageTitle: E1('head title'),
loadOlderToolbar: undefined /* the load-posts toolbar (dynamically created) */,
inputWrapper: E1("#chat-input-area"),
inputLine: E1('#chat-input-line'),
fileSelectWrapper: E1('#chat-input-file-area'),
messagesWrapper: E1('#chat-messages-wrapper'),
inputForm: E1('#chat-form'),
btnSubmit: E1('#chat-message-submit'),
inputSingle: E1('#chat-input-single'),
inputMulti: E1('#chat-input-multi'),
inputCurrent: undefined/*one of inputSingle or inputMulti*/,
inputFile: E1('#chat-input-file'),
contentDiv: E1('div.content'),
configArea: E1('#chat-config'),
previewArea: E1('#chat-preview'),
previewContent: E1('#chat-preview-content'),
btnPreview: E1('#chat-preview-button')
},
me: F.user.name,
mxMsg: F.config.chat.initSize ? -F.config.chat.initSize : -50,
mnMsg: undefined/*lowest message ID we've seen so far (for history loading)*/,
pageIsActive: 'visible'===document.visibilityState,
changesSincePageHidden: 0,
notificationBubbleColor: 'white',
|
| ︙ | ︙ | |||
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
return this.e.inputCurrent;
},
/** Toggles between single- and multi-line edit modes. Returns this. */
inputToggleSingleMulti: function(){
const old = this.e.inputCurrent;
if(this.e.inputCurrent === this.e.inputSingle){
this.e.inputCurrent = this.e.inputMulti;
}else{
this.e.inputCurrent = this.e.inputSingle;
}
const m = this.e.messagesWrapper,
sTop = m.scrollTop,
mh1 = m.clientHeight;
D.addClass(old, 'hidden');
D.removeClass(this.e.inputCurrent, 'hidden');
const mh2 = m.clientHeight;
| > > | 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
return this.e.inputCurrent;
},
/** Toggles between single- and multi-line edit modes. Returns this. */
inputToggleSingleMulti: function(){
const old = this.e.inputCurrent;
if(this.e.inputCurrent === this.e.inputSingle){
this.e.inputCurrent = this.e.inputMulti;
this.e.inputLine.classList.remove('single-line');
}else{
this.e.inputCurrent = this.e.inputSingle;
this.e.inputLine.classList.add('single-line');
}
const m = this.e.messagesWrapper,
sTop = m.scrollTop,
mh1 = m.clientHeight;
D.addClass(old, 'hidden');
D.removeClass(this.e.inputCurrent, 'hidden');
const mh2 = m.clientHeight;
|
| ︙ | ︙ | |||
945 946 947 948 949 950 951 952 953 954 955 956 957 958 |
and/or the file attachment field to the server. If both are
empty, this is a no-op.
*/
Chat.submitMessage = function f(){
if(!f.spaces){
f.spaces = /\s+$/;
}
const fd = new FormData(this.e.inputForm)
/* ^^^^ we don't really want/need the FORM element, but when
FormData() is default-constructed here then the server
segfaults, and i have no clue why! */;
var msg = this.inputValue().trim();
if(msg && (msg.indexOf('\n')>0 || f.spaces.test(msg))){
/* Cosmetic: trim whitespace from the ends of lines to try to
| > | 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 |
and/or the file attachment field to the server. If both are
empty, this is a no-op.
*/
Chat.submitMessage = function f(){
if(!f.spaces){
f.spaces = /\s+$/;
}
this.revealPreview(false);
const fd = new FormData(this.e.inputForm)
/* ^^^^ we don't really want/need the FORM element, but when
FormData() is default-constructed here then the server
segfaults, and i have no clue why! */;
var msg = this.inputValue().trim();
if(msg && (msg.indexOf('\n')>0 || f.spaces.test(msg))){
/* Cosmetic: trim whitespace from the ends of lines to try to
|
| ︙ | ︙ | |||
1017 1018 1019 1020 1021 1022 1023 |
.replace('T',' ').replace(/\.\d+/,'').replace('Z', ' zulu');
};
(function(){/*Set up #chat-settings-button */
const settingsButton = document.querySelector('#chat-settings-button');
const optionsMenu = E1('#chat-config-options');
const cbToggle = function(){
| > > | > > > > | 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 |
.replace('T',' ').replace(/\.\d+/,'').replace('Z', ' zulu');
};
(function(){/*Set up #chat-settings-button */
const settingsButton = document.querySelector('#chat-settings-button');
const optionsMenu = E1('#chat-config-options');
const cbToggle = function(){
if(Chat.e.configArea.classList.contains('hidden')){
D.removeClass(Chat.e.configArea, 'hidden');
D.addClass([Chat.e.messagesWrapper, Chat.e.previewArea], 'hidden');
}else{
D.addClass(Chat.e.configArea, 'hidden');
D.removeClass(Chat.e.messagesWrapper, 'hidden');
}
};
D.attr(settingsButton, 'role', 'button').addEventListener('click', cbToggle, false);
Chat.e.configArea.querySelector('button').addEventListener('click', cbToggle, false);
/* Settings menu entries... */
const settingsOps = [{
label: "Multi-line input",
boolValue: ()=>Chat.inputElement()===Chat.e.inputMulti,
|
| ︙ | ︙ | |||
1059 1060 1061 1062 1063 1064 1065 |
callback: function(){
const v = Chat.settings.toggle('images-inline');
F.toast.message("Image mode set to "+(v ? "inline" : "hyperlink")+".");
}
}];
/** Set up selection list of notification sounds. */
| | < < < < < < < < < < < < < < < < < < < < < < < < < < < < < < | 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 |
callback: function(){
const v = Chat.settings.toggle('images-inline');
F.toast.message("Image mode set to "+(v ? "inline" : "hyperlink")+".");
}
}];
/** Set up selection list of notification sounds. */
if(1){
settingsOps.push({
label: "Audible alerts",
boolValue: ()=>Chat.settings.getBool('audible-alert'),
callback: function(){
const v = Chat.settings.toggle('audible-alert');
Chat.setNewMessageSound(v ? F.config.chat.alertSound : false);
if(v) setTimeout(()=>Chat.playNewMessageSound(), 50);
F.toast.message("Audio notifications "+(v ? "enabled" : "disabled")+".");
}
});
Chat.setNewMessageSound(
Chat.settings.getBool('audible-alert') ? F.config.chat.alertSound : false
);
}/*audio notification config*/
/**
Build list of options...
*/
settingsOps.forEach(function f(op){
const line = D.addClass(D.div(), 'menu-entry');
const btn = D.append(
|
| ︙ | ︙ | |||
1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 |
D.append(optionsMenu, line);
});
if(settingsOps.selectSound){
D.append(optionsMenu, settingsOps.selectSound);
}
//settingsButton.click()/*for for development*/;
})()/*#chat-settings-button setup*/;
/** Callback for poll() to inject new content into the page. jx ==
the response from /chat-poll. If atEnd is true, the message is
appended to the end of the chat list (for loading older
messages), else the beginning (the default). */
const newcontent = function f(jx,atEnd){
if(!f.processPost){
| > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 |
D.append(optionsMenu, line);
});
if(settingsOps.selectSound){
D.append(optionsMenu, settingsOps.selectSound);
}
//settingsButton.click()/*for for development*/;
})()/*#chat-settings-button setup*/;
(function(){/*set up message preview*/
const btnPreview = Chat.e.btnPreview;
Chat.setPreviewText = function(t){
this.revealPreview(true).e.previewContent.innerHTML = t;
};
/**
Reveals preview area if showIt is true, else hides it.
This also shows/hides other elements, "as appropriate."
*/
Chat.revealPreview = function(showIt){
if(showIt){
D.removeClass(Chat.e.previewArea, 'hidden');
D.addClass([Chat.e.messagesWrapper, Chat.e.configArea],
'hidden');
}else{
D.addClass(Chat.e.previewArea, 'hidden');
D.removeClass(Chat.e.messagesWrapper, 'hidden');
}
return this;
};
Chat.e.previewArea.querySelector('#chat-preview-close').
addEventListener('click', ()=>Chat.revealPreview(false), false);
let previewPending = false;
const elemsToEnable = [
btnPreview, Chat.e.btnSubmit,
Chat.e.inputSingle, Chat.e.inputMulti];
Chat.disableDuringAjax.push(btnPreview);
const submit = function(ev){
ev.preventDefault();
ev.stopPropagation();
if(previewPending) return false;
const txt = Chat.e.inputCurrent.value;
if(!txt){
Chat.setPreviewText('');
previewPending = false;
return false;
}
const fd = new FormData();
fd.append('content', txt);
fd.append('filename','chat.md'
/*filename needed for mimetype determination*/);
fd.append('render_mode',F.page.previewModes.wiki);
F.fetch('ajax/preview-text',{
payload: fd,
onload: (html)=>Chat.setPreviewText(html),
onerror: function(e){
F.fetch.onerror(e);
Chat.setPreviewText("ERROR: "+(
e.message || 'Unknown error fetching preview!'
));
},
beforesend: function(){
D.disable(elemsToEnable);
Chat.ajaxStart();
previewPending = true;
Chat.setPreviewText("Loading preview...");
},
aftersend:function(){
previewPending = false;
D.enable(elemsToEnable);
Chat.ajaxEnd();
}
});
return false;
};
btnPreview.addEventListener('click', submit, false);
})()/*message preview setup*/;
/** Callback for poll() to inject new content into the page. jx ==
the response from /chat-poll. If atEnd is true, the message is
appended to the end of the chat list (for loading older
messages), else the beginning (the default). */
const newcontent = function f(jx,atEnd){
if(!f.processPost){
|
| ︙ | ︙ |
Changes to src/default.css.
| ︙ | ︙ | |||
1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 |
body.chat.monospace-messages textarea,
body.chat.monospace-messages input[type=text]{
font-family: monospace;
}
body.chat .message-widget-content > * {
margin: 0;
padding: 0;
}
body.chat .message-widget-content > .markdown > *:first-child {
margin-top: 0;
}
body.chat .message-widget-content > .markdown > *:last-child {
margin-bottom: 0;
}
| > > > | 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 |
body.chat.monospace-messages textarea,
body.chat.monospace-messages input[type=text]{
font-family: monospace;
}
body.chat .message-widget-content > * {
margin: 0;
padding: 0;
}
body.chat .message-widget-content > pre {
white-space: pre-wrap;
}
body.chat .message-widget-content > .markdown > *:first-child {
margin-top: 0;
}
body.chat .message-widget-content > .markdown > *:last-child {
margin-bottom: 0;
}
|
| ︙ | ︙ | |||
1847 1848 1849 1850 1851 1852 1853 |
/* Widget holding the chat message input field, send button, and
settings button. */
body.chat #chat-input-line {
display: flex;
flex-direction: row;
margin-bottom: 0.25em;
| | | > > > > | > > | > > > | > | 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 |
/* Widget holding the chat message input field, send button, and
settings button. */
body.chat #chat-input-line {
display: flex;
flex-direction: row;
margin-bottom: 0.25em;
align-items: stretch;
}
body.chat #chat-edit-buttons {
display: flex;
flex-direction: column;
justify-content: space-between;
}
body.chat #chat-input-line.single-line {
flex-direction: column;
}
body.chat #chat-input-line.single-line #chat-edit-buttons {
flex-direction: row;
}
body.chat #chat-edit-buttons > * {
/*flex: 1 5 auto;*/
max-width: 6em;
margin: 0 0.25em;
}
body.chat #chat-input-line > button {
max-width: 4em;
}
body.chat #chat-input-line > #chat-settings-button{
margin: 0 0 0 0.25em;
max-width: 2em;
}
body.chat #chat-input-line > input[type=text],
body.chat #chat-input-line > textarea {
flex: 5 1 auto;
max-width: revert;
}
/* Widget holding the file selection control and preview */
body.chat #chat-input-file-area {
display: flex;
flex-direction: row;
align-items: center;
flex-wrap: wrap;
|
| ︙ | ︙ | |||
1909 1910 1911 1912 1913 1914 1915 |
font-family: monospace;
}
body.chat #chat-drop-details img {
max-width: 45%;
max-height: 45%;
}
| > | > < | < < < < | > > > > > > > > > > > > > > > > > > > > > > > > | 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 |
font-family: monospace;
}
body.chat #chat-drop-details img {
max-width: 45%;
max-height: 45%;
}
body.chat #chat-config,
body.chat #chat-preview {
/* /chat configuration widget */
display: flex;
flex-direction: column;
overflow: auto;
flex: 2 1 auto;
padding: 0;
margin: 0;
align-items: stretch;
min-height: 6em;
}
body.chat #chat-config #chat-config-options {
/* /chat config options go here */
flex: 1 1 auto;
display: flex;
flex-direction: column;
overflow: auto;
}
body.chat #chat-config #chat-config-options .menu-entry {
display: flex;
align-items: center;
flex-direction: row;
flex-wrap: wrap;
padding: 1em;
}
body.chat #chat-config #chat-config-options .menu-entry > *:first-child {
margin-right: 1em;
}
body.chat #chat-preview #chat-preview-content {
overflow: auto;
flex: 1 1 auto;
padding: 0.5em;
border: 1px dotted;
}
body.chat #chat-preview #chat-preview-content > * {
margin: 0;
padding: 0;
}
body.chat #chat-preview #chat-preview-buttons {
flex: 0 1 auto;
display: flex;
flex-direction: column;
}
body.chat #chat-config > button,
body.chat #chat-preview #chat-preview-buttons > button {
padding: 0.5em;
flex: 0 1 auto;
margin: 0.25em 0;
}
input[type="checkbox"].diff-toggle {
float: right;
}
body.branch .brlist > table > tbody > tr:hover:not(.selected),
body.branch .brlist > table > tbody > tr.selected {
background-color: #ffc;
|
| ︙ | ︙ |