After studying this example, I attempted to incorporate a hidden callback function. While the show
callback is functioning perfectly, the hidden
callback seems to be ineffective. Can someone shed light on why this issue is occurring?
To showcase the problem, I have prepared this fiddle.
$(document).ready(function() {
var showCb = $.fn.popover.Constructor.prototype.show;
$.fn.popover.Constructor.prototype.show = function () {
showCb.call(this);
if (this.options.showCb) {
this.options.showCb();
}
}
var hiddenCb = $.fn.popover.Constructor.prototype.hidden;
$.fn.popover.Constructor.prototype.hidden = function () {
hiddenCb.call(this);
if (this.options.hiddenCb) {
this.options.hiddenCb();
}
}
$("[data-toggle=popover]").popover({
showCb: function() {
alert('showCb');
},
hiddenCb: function() {
alert('hiddenCb');
}
});
})
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<div class="container">
<h3>Popover Example</h3>
<a href="#" data-toggle="popover" title="Popover Header" data-content="Some content inside the popover">Toggle popover</a>
</div>
UPDATE
I've developed a new jsFiddle to demonstrate Christos's second code snippet applied to Bootstrap's jQBTK plugin. This plugin utilizes Bootstrap's Popovers to create a virtual keyboard. Issue: Events are linked to the dynamically formed object leading them to trigger multiple times. What strategies can be employed to optimize this scenario?