Skip to content

Commit

Permalink
- Rename removeObject:index to removeObjectAtIndex
Browse files Browse the repository at this point in the history
- Added removeObjectWithUID
  • Loading branch information
Anselm Joseph authored and Anselm Joseph committed Jul 10, 2019
1 parent dbad7f8 commit 9a3ab5c
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion dist/tea-plates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 9a3ab5c

Please sign in to comment.