From a91d838aca2cb6b1330454a6e92616a73a2e1255 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 10 Jul 2013 13:24:36 +0200 Subject: [PATCH] Canvas list API fix: removing unnecessary lists if all items extracted --- modules/documentCanvas/canvas/canvas.js | 14 ++++++++----- modules/documentCanvas/canvas/canvas.test3.js | 21 +++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/modules/documentCanvas/canvas/canvas.js b/modules/documentCanvas/canvas/canvas.js index a274fa4..d883835 100644 --- a/modules/documentCanvas/canvas/canvas.js +++ b/modules/documentCanvas/canvas/canvas.js @@ -196,13 +196,17 @@ $.extend(Canvas.prototype.list, { last = item; }); - var secondList = documentElement.DocumentNodeElement.create({tag: 'div', klass:'list-items'}, this); + if(list.children().length === 0) + list.detach(); - last.after(secondList); + if(succeedingItems.length > 0) { + var secondList = documentElement.DocumentNodeElement.create({tag: 'div', klass:'list-items'}, this); + last.after(secondList); - succeedingItems.forEach(function(item) { - secondList.append(item); - }); + succeedingItems.forEach(function(item) { + secondList.append(item); + }); + } } }); diff --git a/modules/documentCanvas/canvas/canvas.test3.js b/modules/documentCanvas/canvas/canvas.test3.js index 9a549df..597fec2 100644 --- a/modules/documentCanvas/canvas/canvas.test3.js +++ b/modules/documentCanvas/canvas/canvas.test3.js @@ -485,6 +485,27 @@ describe('Canvas', function() { expect(list2.children().length).to.equal(1, 'second list has one child'); expect(list2.children()[0].children()[0].getText()).to.equal('3', 'first item of the second list is a last item of the original list'); }); + + it('removes list if all its items are extracted', function() { + var c = canvas.fromXML('\ +
\ +
\ +
some item
\ +
\ +
'), + list = c.doc().children()[0], + item = list.children()[0]; + + c.list.extractItems({element1: item, element2: item}); + + var section = c.doc(), + list1 = section.children()[0], + oldItem1 = section.children()[1], + oldItem2 = section.children()[2], + list2 = section.children()[3]; + + expect(section.children().length).to.equal(1, 'section contains one child'); + }); }); }); -- 2.20.1