From cde239c97a31524622910e578c3ba4dfa9da6625 Mon Sep 17 00:00:00 2001 From: ansuz Date: Mon, 18 Jul 2016 20:57:53 +0200 Subject: [PATCH] implement row/column removal --- www/poll/table.js | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/www/poll/table.js b/www/poll/table.js index 79f385c18..bff2a6db0 100644 --- a/www/poll/table.js +++ b/www/poll/table.js @@ -37,10 +37,51 @@ define([ return $width.length; }; + var remove = function ($sel) { + $sel.fadeOut(750, function () { + $sel.remove(); + }); + }; + + var removeColumn = function (uid) { + //var I/ + var $col = $('th[data-rt-uid="' + uid + '"]'); + if (!$col.length) { return; } + + /* removing a column is difficult because the elements + all have different parents. */ + + // use the th + var th = $col[0]; + + // find its index in the tr + var index = Array.prototype.slice + .call(th.parentElement.children).indexOf(th); + + // remove it + remove($col); + + // remove all elements in the body which have the same index + $body.find('tr').each(function () { + var $this = $(this); + $this.find('td').eq(index).each(function () { + remove($(this)); + }); + }); + }; + + var removeRow = function (uid) { + var $row = $body.find('tr[data-rt-uid="' + uid + '"]'); + if (!$row.length) { return; } + remove($row); + }; + return { $: $t, addRow: addRow, addColumn: addColumn, + removeRow: removeRow, + removeColumn: removeColumn, }; }; return Table;