Closed douglas-srs closed 6 years ago
This is how I managed to do it, I saved every node "click" handler in an array, unbinded it and then binded my own click handler, asked for confirmation and if positive I bind the old click handler and trigger click again, I am sure this is not optimal but it works, now I just have to implement something to check if data has actually changed before popping up this confirmation dialog. I hope this helps someone else.
oldClickEvents = {};
firstClick = true;
newClickEvent = function (event, index, elem) {
if (firstClick == true){
if (confirm('You changed data, are you sure you want to continue?')) {
//YES
$(elem).bind( 'click', oldClickEvents[index].handler);
firstClick = false;
$(elem).triggerHandler('click');
} else {
//NO
firstClick = true;
$(elem).blur();
event.preventDefault();
}
} else {
firstClick = true;
$(elem).off('click');
$(elem).on('click', function (event) {
newClickEvent(event, index, elem);
});
}
};
$('#arvore-tree').find('.kv-node-detail').each(function (index) {
var oldClickEvent = jQuery._data(this, 'events').click[0];
oldClickEvents[index] = oldClickEvent;
$(this).off('click');
$(this).on('click', function (event) {
newClickEvent(event, index, this);
});
});
I have provided an enhancement for you to do an event.preventDefault
and abort events.
Thank you :)
I am trying to implement this without override the kv-tree.js itself, I tried this:
Anyway to implement this?