Skip to content

Commit

Permalink
Fixed ready event
Browse files Browse the repository at this point in the history
Fixed issue with j2h ready event from being propagated to children
  • Loading branch information
moappi committed Mar 4, 2022
1 parent 1d9b8fc commit 8779f4e
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions json2html.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
if(!root.json2html) root.json2html = {};

//Current Version
root.json2html.version = "2.2.1";
root.json2html.version = "2.2.2";

//Render a json2html template
// obj : json object to render, or json string
Expand Down Expand Up @@ -407,7 +407,7 @@

//Trigger all the json2html.ready events
for(var i=0; i < events.length; i++)
events[i].trigger("j2h.ready");
events[i].trigger("j2h-ready");
}

//Add the ihtml object to the dom
Expand Down Expand Up @@ -438,7 +438,7 @@

//Make sure we have some events to attach
if(attach) {

//split by " " (can contain multiple events per element)
var _events = attach.split(" ");

Expand All @@ -462,18 +462,21 @@
//Sepcify that we'll need to trigger these later
ready.push($(this));

//rename the event to j2h.ready
event.type = "j2h.ready";
//rename the event to j2h-ready
event.type = "j2h-ready";
break;

//All other jquery events
default:
break;
}

//otherwise attach the events to the element
//Attach the events to the element
$(this).on(event.type,event.data,function(e){


//Disable j2h-ready events from being propagated
if(e.type === "j2h-ready") e.stopPropagation();

//attach the jquery event
e.data.event = e;

Expand All @@ -484,7 +487,7 @@
}

//remove the event attribute
$(this).removeAttr("-j2h-e");
//$(this).removeAttr("-j2h-e");
});

//Return the ready events
Expand Down

0 comments on commit 8779f4e

Please sign in to comment.