Created by: IDisposable
Add the ability to set a binder in the Tooltip & Popover options
to support data-binding of the created DOM in setContent
. This allows having binding expressions in the template that will be applied as the tooltip/popover is created during the show event. This can be used by setting the dataBinder to a function that will apply bindings. Since the DOM elements are not created until the tooltip is shown, the best place for this seems to be set setContent
method.
An example of the use of this it for knockout binds, here we create a knockout binding that hooks itself up:
ko.bindingHandlers.popover = {
init: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
var options = $.extend({ disabled: false }, ko.toJS(valueAccessor()));
ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
$(element).popover('destroy');
});
},
update: function (element, valueAccessor, allBindings, viewModel, bindingContext) {
var $element = $(element);
var options = $.extend({ disabled: false }, ko.toJS(valueAccessor()));
$element.popover('destroy');
if (options.disabled)
return;
options.dataBinder = function ($tip) {
ko.cleanNode($tip[0]);
$tip.applyBindings(viewModel);
};
$element.popover(options);
}
};