Fossil SCM

chat: multi-line mode and chat-only-mode toggles are now locally persistent.

stephan 2020-12-30 05:15 trunk
Commit e29358468326095f1997152190693a1275230d83cef0efa25aab8760283e0729
1 file changed +26 -5
+26 -5
--- src/chat.js
+++ src/chat.js
@@ -160,10 +160,22 @@
160160
m.scrollTo( 0, sTop + (mh1-mh2));
161161
this.e.inputCurrent.value = old.value;
162162
old.value = '';
163163
return this;
164164
},
165
+ /**
166
+ If passed true or no arguments, switches to multi-line mode
167
+ if currently in single-line mode. If passed false, switches
168
+ to single-line mode if currently in multi-line mode. Returns
169
+ this.
170
+ */
171
+ inputMultilineMode: function(yes){
172
+ if(!arguments.length) yes = true;
173
+ if(yes && this.e.inputCurrent === this.e.inputMulti) return this;
174
+ else if(!yes && this.e.inputCurrent === this.e.inputSingle) return this;
175
+ else return this.inputToggleSingleMulti();
176
+ },
165177
/** Enables (if yes is truthy) or disables all elements in
166178
* this.disableDuringAjax. */
167179
enableAjaxComponents: function(yes){
168180
D[yes ? 'enable' : 'disable'](this.disableDuringAjax);
169181
return this;
@@ -340,14 +352,17 @@
340352
get: (k,dflt)=>F.storage.get(k,dflt),
341353
getBool: (k,dflt)=>F.storage.getBool(k,dflt),
342354
set: (k,v)=>F.storage.set(k,v),
343355
defaults:{
344356
"images-inline": !!F.config.chat.imagesInline,
345
- "monospace-messages": false
357
+ "edit-multiline": false,
358
+ "monospace-messages": false,
359
+ "chat-only-mode": false
346360
}
347361
}
348362
};
363
+ cs.e.inputCurrent = cs.e.inputSingle;
349364
/* Install default settings... */
350365
Object.keys(cs.settings.defaults).forEach(function(k){
351366
const v = cs.settings.get(k,cs);
352367
if(cs===v) cs.settings.set(k,cs.settings.defaults[k]);
353368
});
@@ -361,11 +376,12 @@
361376
cs.toggleNavButtons(false);
362377
}
363378
if(cs.settings.getBool('monospace-messages',false)){
364379
document.body.classList.add('monospace-messages');
365380
}
366
- cs.e.inputCurrent = cs.e.inputSingle;
381
+ cs.inputMultilineMode(cs.settings.getBool('edit-multiline',false));
382
+ cs.chatOnlyMode(cs.settings.getBool('chat-only-mode'));
367383
cs.pageTitleOrig = cs.e.pageTitle.innerText;
368384
369385
const qs = (e)=>document.querySelector(e);
370386
const argsToArray = function(args){
371387
return Array.prototype.slice.call(args,0);
@@ -795,24 +811,25 @@
795811
});
796812
/* Settings menu entries... */
797813
const settingsOps = [{
798814
label: "Multi-line input",
799815
boolValue: ()=>Chat.inputElement()===Chat.e.inputMulti,
816
+ persistentSetting: 'edit-multiline',
800817
callback: function(){
801818
Chat.inputToggleSingleMulti();
802819
}
803820
},{
804821
label: "Monospace message font",
805822
boolValue: ()=>document.body.classList.contains('monospace-messages'),
823
+ persistentSetting: 'monospace-messages',
806824
callback: function(){
807825
document.body.classList.toggle('monospace-messages');
808
- Chat.settings.set('monospace-messages',
809
- document.body.classList.contains('monospace-messages'));
810826
}
811827
},{
812828
label: "Chat-only mode",
813829
boolValue: ()=>Chat.isChatOnlyMode(),
830
+ persistentSetting: 'chat-only-mode',
814831
callback: function(){
815832
Chat.toggleChatOnlyMode();
816833
}
817834
},{
818835
label: "Left-align my posts",
@@ -825,10 +842,11 @@
825842
boolValue: ()=>!Chat.e.btnMsgHome.classList.contains('hidden'),
826843
callback: ()=>Chat.toggleNavButtons()
827844
},{
828845
label: "Images inline",
829846
boolValue: ()=>Chat.settings.getBool('images-inline'),
847
+ persistentSetting: 'images-inline',
830848
callback: function(){
831849
const v = Chat.settings.getBool('images-inline',true);
832850
Chat.settings.set('images-inline', !v);
833851
F.toast.message("Image mode set to "+(v ? "hyperlink" : "inline")+".");
834852
}
@@ -843,11 +861,14 @@
843861
settingsOps.forEach(function(op){
844862
const line = D.addClass(D.span(), 'menu-entry');
845863
const btn = D.append(D.addClass(D.span(), 'button'), op.label);
846864
const callback = function(ev){
847865
settingsPopup.hide();
848
- op.callback.call(this,ev);
866
+ op.callback(ev);
867
+ if(op.persistentSetting){
868
+ Chat.settings.set(op.persistentSetting, op.boolValue());
869
+ }
849870
};
850871
D.append(line, btn);
851872
if(op.hasOwnProperty('boolValue')){
852873
const check = D.attr(D.checkbox(1, op.boolValue()),
853874
'aria-label', op.label);
854875
--- src/chat.js
+++ src/chat.js
@@ -160,10 +160,22 @@
160 m.scrollTo( 0, sTop + (mh1-mh2));
161 this.e.inputCurrent.value = old.value;
162 old.value = '';
163 return this;
164 },
 
 
 
 
 
 
 
 
 
 
 
 
165 /** Enables (if yes is truthy) or disables all elements in
166 * this.disableDuringAjax. */
167 enableAjaxComponents: function(yes){
168 D[yes ? 'enable' : 'disable'](this.disableDuringAjax);
169 return this;
@@ -340,14 +352,17 @@
340 get: (k,dflt)=>F.storage.get(k,dflt),
341 getBool: (k,dflt)=>F.storage.getBool(k,dflt),
342 set: (k,v)=>F.storage.set(k,v),
343 defaults:{
344 "images-inline": !!F.config.chat.imagesInline,
345 "monospace-messages": false
 
 
346 }
347 }
348 };
 
349 /* Install default settings... */
350 Object.keys(cs.settings.defaults).forEach(function(k){
351 const v = cs.settings.get(k,cs);
352 if(cs===v) cs.settings.set(k,cs.settings.defaults[k]);
353 });
@@ -361,11 +376,12 @@
361 cs.toggleNavButtons(false);
362 }
363 if(cs.settings.getBool('monospace-messages',false)){
364 document.body.classList.add('monospace-messages');
365 }
366 cs.e.inputCurrent = cs.e.inputSingle;
 
367 cs.pageTitleOrig = cs.e.pageTitle.innerText;
368
369 const qs = (e)=>document.querySelector(e);
370 const argsToArray = function(args){
371 return Array.prototype.slice.call(args,0);
@@ -795,24 +811,25 @@
795 });
796 /* Settings menu entries... */
797 const settingsOps = [{
798 label: "Multi-line input",
799 boolValue: ()=>Chat.inputElement()===Chat.e.inputMulti,
 
800 callback: function(){
801 Chat.inputToggleSingleMulti();
802 }
803 },{
804 label: "Monospace message font",
805 boolValue: ()=>document.body.classList.contains('monospace-messages'),
 
806 callback: function(){
807 document.body.classList.toggle('monospace-messages');
808 Chat.settings.set('monospace-messages',
809 document.body.classList.contains('monospace-messages'));
810 }
811 },{
812 label: "Chat-only mode",
813 boolValue: ()=>Chat.isChatOnlyMode(),
 
814 callback: function(){
815 Chat.toggleChatOnlyMode();
816 }
817 },{
818 label: "Left-align my posts",
@@ -825,10 +842,11 @@
825 boolValue: ()=>!Chat.e.btnMsgHome.classList.contains('hidden'),
826 callback: ()=>Chat.toggleNavButtons()
827 },{
828 label: "Images inline",
829 boolValue: ()=>Chat.settings.getBool('images-inline'),
 
830 callback: function(){
831 const v = Chat.settings.getBool('images-inline',true);
832 Chat.settings.set('images-inline', !v);
833 F.toast.message("Image mode set to "+(v ? "hyperlink" : "inline")+".");
834 }
@@ -843,11 +861,14 @@
843 settingsOps.forEach(function(op){
844 const line = D.addClass(D.span(), 'menu-entry');
845 const btn = D.append(D.addClass(D.span(), 'button'), op.label);
846 const callback = function(ev){
847 settingsPopup.hide();
848 op.callback.call(this,ev);
 
 
 
849 };
850 D.append(line, btn);
851 if(op.hasOwnProperty('boolValue')){
852 const check = D.attr(D.checkbox(1, op.boolValue()),
853 'aria-label', op.label);
854
--- src/chat.js
+++ src/chat.js
@@ -160,10 +160,22 @@
160 m.scrollTo( 0, sTop + (mh1-mh2));
161 this.e.inputCurrent.value = old.value;
162 old.value = '';
163 return this;
164 },
165 /**
166 If passed true or no arguments, switches to multi-line mode
167 if currently in single-line mode. If passed false, switches
168 to single-line mode if currently in multi-line mode. Returns
169 this.
170 */
171 inputMultilineMode: function(yes){
172 if(!arguments.length) yes = true;
173 if(yes && this.e.inputCurrent === this.e.inputMulti) return this;
174 else if(!yes && this.e.inputCurrent === this.e.inputSingle) return this;
175 else return this.inputToggleSingleMulti();
176 },
177 /** Enables (if yes is truthy) or disables all elements in
178 * this.disableDuringAjax. */
179 enableAjaxComponents: function(yes){
180 D[yes ? 'enable' : 'disable'](this.disableDuringAjax);
181 return this;
@@ -340,14 +352,17 @@
352 get: (k,dflt)=>F.storage.get(k,dflt),
353 getBool: (k,dflt)=>F.storage.getBool(k,dflt),
354 set: (k,v)=>F.storage.set(k,v),
355 defaults:{
356 "images-inline": !!F.config.chat.imagesInline,
357 "edit-multiline": false,
358 "monospace-messages": false,
359 "chat-only-mode": false
360 }
361 }
362 };
363 cs.e.inputCurrent = cs.e.inputSingle;
364 /* Install default settings... */
365 Object.keys(cs.settings.defaults).forEach(function(k){
366 const v = cs.settings.get(k,cs);
367 if(cs===v) cs.settings.set(k,cs.settings.defaults[k]);
368 });
@@ -361,11 +376,12 @@
376 cs.toggleNavButtons(false);
377 }
378 if(cs.settings.getBool('monospace-messages',false)){
379 document.body.classList.add('monospace-messages');
380 }
381 cs.inputMultilineMode(cs.settings.getBool('edit-multiline',false));
382 cs.chatOnlyMode(cs.settings.getBool('chat-only-mode'));
383 cs.pageTitleOrig = cs.e.pageTitle.innerText;
384
385 const qs = (e)=>document.querySelector(e);
386 const argsToArray = function(args){
387 return Array.prototype.slice.call(args,0);
@@ -795,24 +811,25 @@
811 });
812 /* Settings menu entries... */
813 const settingsOps = [{
814 label: "Multi-line input",
815 boolValue: ()=>Chat.inputElement()===Chat.e.inputMulti,
816 persistentSetting: 'edit-multiline',
817 callback: function(){
818 Chat.inputToggleSingleMulti();
819 }
820 },{
821 label: "Monospace message font",
822 boolValue: ()=>document.body.classList.contains('monospace-messages'),
823 persistentSetting: 'monospace-messages',
824 callback: function(){
825 document.body.classList.toggle('monospace-messages');
 
 
826 }
827 },{
828 label: "Chat-only mode",
829 boolValue: ()=>Chat.isChatOnlyMode(),
830 persistentSetting: 'chat-only-mode',
831 callback: function(){
832 Chat.toggleChatOnlyMode();
833 }
834 },{
835 label: "Left-align my posts",
@@ -825,10 +842,11 @@
842 boolValue: ()=>!Chat.e.btnMsgHome.classList.contains('hidden'),
843 callback: ()=>Chat.toggleNavButtons()
844 },{
845 label: "Images inline",
846 boolValue: ()=>Chat.settings.getBool('images-inline'),
847 persistentSetting: 'images-inline',
848 callback: function(){
849 const v = Chat.settings.getBool('images-inline',true);
850 Chat.settings.set('images-inline', !v);
851 F.toast.message("Image mode set to "+(v ? "hyperlink" : "inline")+".");
852 }
@@ -843,11 +861,14 @@
861 settingsOps.forEach(function(op){
862 const line = D.addClass(D.span(), 'menu-entry');
863 const btn = D.append(D.addClass(D.span(), 'button'), op.label);
864 const callback = function(ev){
865 settingsPopup.hide();
866 op.callback(ev);
867 if(op.persistentSetting){
868 Chat.settings.set(op.persistentSetting, op.boolValue());
869 }
870 };
871 D.append(line, btn);
872 if(op.hasOwnProperty('boolValue')){
873 const check = D.attr(D.checkbox(1, op.boolValue()),
874 'aria-label', op.label);
875

Keyboard Shortcuts

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