Fossil SCM
chat: multi-line mode and chat-only-mode toggles are now locally persistent.
Commit
e29358468326095f1997152190693a1275230d83cef0efa25aab8760283e0729
Parent
5d3ba8aa9005b1f…
1 file changed
+26
-5
+26
-5
| --- src/chat.js | ||
| +++ src/chat.js | ||
| @@ -160,10 +160,22 @@ | ||
| 160 | 160 | m.scrollTo( 0, sTop + (mh1-mh2)); |
| 161 | 161 | this.e.inputCurrent.value = old.value; |
| 162 | 162 | old.value = ''; |
| 163 | 163 | return this; |
| 164 | 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 | + }, | |
| 165 | 177 | /** Enables (if yes is truthy) or disables all elements in |
| 166 | 178 | * this.disableDuringAjax. */ |
| 167 | 179 | enableAjaxComponents: function(yes){ |
| 168 | 180 | D[yes ? 'enable' : 'disable'](this.disableDuringAjax); |
| 169 | 181 | return this; |
| @@ -340,14 +352,17 @@ | ||
| 340 | 352 | get: (k,dflt)=>F.storage.get(k,dflt), |
| 341 | 353 | getBool: (k,dflt)=>F.storage.getBool(k,dflt), |
| 342 | 354 | set: (k,v)=>F.storage.set(k,v), |
| 343 | 355 | defaults:{ |
| 344 | 356 | "images-inline": !!F.config.chat.imagesInline, |
| 345 | - "monospace-messages": false | |
| 357 | + "edit-multiline": false, | |
| 358 | + "monospace-messages": false, | |
| 359 | + "chat-only-mode": false | |
| 346 | 360 | } |
| 347 | 361 | } |
| 348 | 362 | }; |
| 363 | + cs.e.inputCurrent = cs.e.inputSingle; | |
| 349 | 364 | /* Install default settings... */ |
| 350 | 365 | Object.keys(cs.settings.defaults).forEach(function(k){ |
| 351 | 366 | const v = cs.settings.get(k,cs); |
| 352 | 367 | if(cs===v) cs.settings.set(k,cs.settings.defaults[k]); |
| 353 | 368 | }); |
| @@ -361,11 +376,12 @@ | ||
| 361 | 376 | cs.toggleNavButtons(false); |
| 362 | 377 | } |
| 363 | 378 | if(cs.settings.getBool('monospace-messages',false)){ |
| 364 | 379 | document.body.classList.add('monospace-messages'); |
| 365 | 380 | } |
| 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')); | |
| 367 | 383 | cs.pageTitleOrig = cs.e.pageTitle.innerText; |
| 368 | 384 | |
| 369 | 385 | const qs = (e)=>document.querySelector(e); |
| 370 | 386 | const argsToArray = function(args){ |
| 371 | 387 | return Array.prototype.slice.call(args,0); |
| @@ -795,24 +811,25 @@ | ||
| 795 | 811 | }); |
| 796 | 812 | /* Settings menu entries... */ |
| 797 | 813 | const settingsOps = [{ |
| 798 | 814 | label: "Multi-line input", |
| 799 | 815 | boolValue: ()=>Chat.inputElement()===Chat.e.inputMulti, |
| 816 | + persistentSetting: 'edit-multiline', | |
| 800 | 817 | callback: function(){ |
| 801 | 818 | Chat.inputToggleSingleMulti(); |
| 802 | 819 | } |
| 803 | 820 | },{ |
| 804 | 821 | label: "Monospace message font", |
| 805 | 822 | boolValue: ()=>document.body.classList.contains('monospace-messages'), |
| 823 | + persistentSetting: 'monospace-messages', | |
| 806 | 824 | callback: function(){ |
| 807 | 825 | document.body.classList.toggle('monospace-messages'); |
| 808 | - Chat.settings.set('monospace-messages', | |
| 809 | - document.body.classList.contains('monospace-messages')); | |
| 810 | 826 | } |
| 811 | 827 | },{ |
| 812 | 828 | label: "Chat-only mode", |
| 813 | 829 | boolValue: ()=>Chat.isChatOnlyMode(), |
| 830 | + persistentSetting: 'chat-only-mode', | |
| 814 | 831 | callback: function(){ |
| 815 | 832 | Chat.toggleChatOnlyMode(); |
| 816 | 833 | } |
| 817 | 834 | },{ |
| 818 | 835 | label: "Left-align my posts", |
| @@ -825,10 +842,11 @@ | ||
| 825 | 842 | boolValue: ()=>!Chat.e.btnMsgHome.classList.contains('hidden'), |
| 826 | 843 | callback: ()=>Chat.toggleNavButtons() |
| 827 | 844 | },{ |
| 828 | 845 | label: "Images inline", |
| 829 | 846 | boolValue: ()=>Chat.settings.getBool('images-inline'), |
| 847 | + persistentSetting: 'images-inline', | |
| 830 | 848 | callback: function(){ |
| 831 | 849 | const v = Chat.settings.getBool('images-inline',true); |
| 832 | 850 | Chat.settings.set('images-inline', !v); |
| 833 | 851 | F.toast.message("Image mode set to "+(v ? "hyperlink" : "inline")+"."); |
| 834 | 852 | } |
| @@ -843,11 +861,14 @@ | ||
| 843 | 861 | settingsOps.forEach(function(op){ |
| 844 | 862 | const line = D.addClass(D.span(), 'menu-entry'); |
| 845 | 863 | const btn = D.append(D.addClass(D.span(), 'button'), op.label); |
| 846 | 864 | const callback = function(ev){ |
| 847 | 865 | 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 | + } | |
| 849 | 870 | }; |
| 850 | 871 | D.append(line, btn); |
| 851 | 872 | if(op.hasOwnProperty('boolValue')){ |
| 852 | 873 | const check = D.attr(D.checkbox(1, op.boolValue()), |
| 853 | 874 | 'aria-label', op.label); |
| 854 | 875 |
| --- 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 |