Following this example, i tried to implement a hidden callback function but while show
callback works perfectly, there's no way to make hidden
callback work. Can someone explain why this happens?
I've created this fiddle to replicate the problem.
$(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 created a new jsFiddle to show Christos's second snippet applied to Bootstrap's jQBTK plugin. This plugin takes advantage of Bootstrap's Popovers to create a virtual keyboard. Problem: events are bind to the dynamically created object and so they fires multiple times. How can this be optimized?