pad

minimal etherpad alternative  https://pad.ce9e.org
git clone https://git.ce9e.org/pad.git

commit
7473eebf20992a65cf4d6f5880c150308a243103
parent
8d7b0d54b0b01792881d257fdf5d83f4a5289807
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-05-06 04:08
use throttle instead of setInterval for sendChanges

Diffstat

M static/pad.js 13 ++++++-------

1 files changed, 6 insertions, 7 deletions


diff --git a/static/pad.js b/static/pad.js

@@ -29,6 +29,11 @@ var backup = utils.throttled(function() {
   29    29 	via.store(room, el.value, true);
   30    30 }, 10000);
   31    31 
   -1    32 var sendChanges = utils.throttled(function() {
   -1    33 	via.send(room, {sender: id, type: 'changes', data: localChanges});
   -1    34 	localChanges = [];
   -1    35 }, 500);
   -1    36 
   32    37 var applyChanges = function(changes) {
   33    38 	var text = el.value;
   34    39 	var selection = [el.selectionStart, el.selectionEnd];
@@ -42,6 +47,7 @@ el.addEventListener('input', function() {
   42    47 	var change = context.diff(old, el.value, 3);
   43    48 	context.pushChange(localChanges, change);
   44    49 	old = el.value;
   -1    50 	sendChanges();
   45    51 	backup();
   46    52 });
   47    53 
@@ -74,13 +80,6 @@ via.listen(room, function(msg) {
   74    80 	}
   75    81 });
   76    82 
   77    -1 setInterval(function() {
   78    -1 	if (localChanges.length) {
   79    -1 		via.send(room, {sender: id, type: 'changes', data: localChanges});
   80    -1 		localChanges = [];
   81    -1 	}
   82    -1 }, 500);
   83    -1 
   84    83 window.addEventListener('beforeunload', backup.unblock);
   85    84 window.addEventListener('offline', function() {
   86    85 	el.readOnly = true;