From 9a3ab5cedb873e0c06d626ae8a682d1a8d521fb8 Mon Sep 17 00:00:00 2001 From: Anselm Joseph Date: Wed, 10 Jul 2019 14:27:04 +0530 Subject: [PATCH] - Rename removeObject:index to removeObjectAtIndex - Added removeObjectWithUID --- dist/tea-plates.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/dist/tea-plates.js b/dist/tea-plates.js index 880da32..201ff06 100644 --- a/dist/tea-plates.js +++ b/dist/tea-plates.js @@ -158,7 +158,7 @@ class TeaPlates { ); } - removeObject(index, completion = () => {}) { + removeObjectAtIndex(index, completion = () => {}) { let element = this.insertedElements[index]; let elementStyle = window.getComputedStyle(element); let height = element.offsetHeight; @@ -174,6 +174,30 @@ class TeaPlates { }, this.animationTime, element, this, index); } + removeObjectWithUID(uid, completion = () => {}) { + let element = undefined; + let index = undefined; + this.insertedElements.forEach((ele, i) => { + if (ele.getAttribute('uid') == uid) { + element = ele; + index = i; + } + }); + if (element == undefined) return; + let elementStyle = window.getComputedStyle(element); + let height = element.offsetHeight; + let marginTop = index > 0 ? parseFloat(elementStyle.marginTop) : 0; + let rmMargin = -(height + marginTop); + element.classList.add("animate-out"); + element.style.marginTop = rmMargin + 'px'; + + setTimeout(() => { + this.insertedElements.splice(index, 1); + document.getElementById(this.wrapperId).removeChild(element); + completion(); + }, this.animationTime, element, this, index); + } + pTP_CreateElementFromString(htmlString, uid = -1) { var div = document.createElement('div'); div.innerHTML = htmlString;