From ea5301be134d8891ee4d20c6995577ca64cd03c6 Mon Sep 17 00:00:00 2001 From: Pierre Bondoerffer Date: Thu, 13 Apr 2017 16:31:57 +0200 Subject: [PATCH] poll improved(tm) --- www/poll/main.js | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/www/poll/main.js b/www/poll/main.js index 41295caa5..ff90adcfd 100644 --- a/www/poll/main.js +++ b/www/poll/main.js @@ -211,7 +211,7 @@ define([ }; /* Any time the realtime object changes, call this function */ - var change = function (o, n, path, throttle) { + var change = function (o, n, path, throttle, cb) { if (path && !Cryptpad.isArray(path)) { return; } @@ -262,6 +262,11 @@ define([ Render.updateTable(table, displayedObj2, conf); updateDisplayedTable(); setFocus(f); + if (typeof(cb) === "function") + { + console.log("change cb"); + cb(); + } }; if (throttle) { @@ -273,7 +278,9 @@ define([ return; } - window.setTimeout(updateTable); + window.setTimeout(function() { + updateTable(); + }); }; var getRealtimeId = function (input) { @@ -332,11 +339,8 @@ define([ }); } else if (isEdit) { unlockRow(id, function () { - change(); - - setTimeout(function() { - var $newest = $('input[data-rt-id="' + id + '"]'); - $newest.focus(); + change(null, null, null, null, function() { + $('input[data-rt-id="' + id + '"]').focus(); }); }); } @@ -350,11 +354,8 @@ define([ }); } else if (isEdit) { unlockColumn(id, function () { - change(); - - setTimeout(function() { - var $newest = $('[data-rt-id="' + id + '"]'); - $newest.focus(); + change(null, null, null, null, function() { + $('input[data-rt-id="' + id + '"]').focus(); }); }); } @@ -365,8 +366,8 @@ define([ } }; - var hideInputs = function (e) { - if ($(e.target).is('[type="text"]')) { + var hideInputs = function (e, isKeyup) { + if (!isKeyup && $(e.target).is('[type="text"]')) { return; } $('.lock[data-rt-id!="' + APP.userid + '"]').html(lockHTML); @@ -400,6 +401,9 @@ define([ switch (nodeName) { case 'INPUT': handleInput(target); + if (isKeyup && (e.keyCode === 13 || e.keyCode === 27)) { + hideInputs(e, isKeyup); + } break; case 'SPAN': //case 'LABEL': @@ -558,19 +562,17 @@ define([ var $createRow = APP.$createRow = $('#create-option').click(function () { //console.error("BUTTON CLICKED! LOL"); Render.createRow(proxy, function (empty, id) { - unlockRow(id, function () { - change(); - - setTimeout(function() { - $('.edit[data-rt-id="' + id + '"]').click(); - }); + change(null, null, null, null, function() { + $('.edit[data-rt-id="' + id + '"]').click(); }); }); }); var $createCol = APP.$createCol = $('#create-user').click(function () { - Render.createColumn(proxy, function () { - change(); + Render.createColumn(proxy, function (empty, id) { + change(null, null, null, null, function() { + $('.edit[data-rt-id="' + id + '"]').click(); + }); }); });