Skip to content

Commit

Permalink
Merge pull request #1 from karlis-dreizis/master
Browse files Browse the repository at this point in the history
Bubble events
  • Loading branch information
Osvaldas Valutis authored Sep 30, 2019
2 parents 0e6d18b + a97c6a7 commit 569204e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const addFieldsHandler = (btn) => {
}

new_contents.forEach((node) => {
const event = new CustomEvent('cocoon:before-insert', {detail: node});
const event = new CustomEvent('cocoon:before-insert', {detail: node, bubbles: true, cancelable: true});
insertionNodeElem.dispatchEvent(event);

if(!event.defaultPrevented) {
Expand All @@ -100,7 +100,7 @@ const addFieldsHandler = (btn) => {

insertionNodeElem.insertAdjacentHTML(insertionMethod, node);
insertionNodeElem.dispatchEvent(
new CustomEvent('cocoon:after-insert', {detail: node})
new CustomEvent('cocoon:after-insert', {detail: node, bubbles: true, cancelable: true})
);
}
});
Expand All @@ -119,7 +119,7 @@ const removeFieldsHandler = (btn) => {
const nodeToDelete = btn.closest(`.${wrapperClass}`);
const triggerNode = nodeToDelete.parentNode;

const event = new CustomEvent('cocoon:before-remove', {detail: nodeToDelete});
const event = new CustomEvent('cocoon:before-remove', {detail: nodeToDelete, bubbles: true, cancelable: true});
triggerNode.dispatchEvent(event);

if(!event.defaultPrevented) {
Expand All @@ -139,7 +139,7 @@ const removeFieldsHandler = (btn) => {
}

triggerNode.dispatchEvent(
new CustomEvent('cocoon:after-remove', {detail: nodeToDelete})
new CustomEvent('cocoon:after-remove', {detail: nodeToDelete, bubbles: true, cancelable: true})
);
}, timeout);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cocoon-vanilla-js",
"version": "1.0.1",
"version": "1.0.2",
"description": "A vanilla JS replacement for (Rails) Cocoon's jQuery script",
"main": "index.js",
"engines": {
Expand Down

0 comments on commit 569204e

Please sign in to comment.