I am using bootstrap in my mvc project. I have a problem with bootstrap popover widgets. I created a custom knockout binding for the popover widget, here is the code:
Check script
ko.bindingHandlers.popover = { init: function (element, valuesAccessor, allBindingsAccessor, viewModel, bindingContext) { var options = ko.utils.unwrapObservable(valuesAccessor() || {}); options.html = true; options.content = '<small class="text-info">' + 'Variable text goes here.Variable text goes here.Variable text goes here.Variable text goes here.Variable text goes here. ' + '</small>'; $(element).popover(options); }, update: function (element, valuesAccessor, allBindingsAccessor, viewModel, bindingContext) { var extraOptions = allBindingsAccessor().popoverOptions; $(element).popover(extraOptions.observable() ? "show" : "hide"); $(element).siblings('.popover').css({ width: '150px' });
I want to initialize a popover for any element with a variable text message and with a variable size. Everything goes fine, but when I change the default width by default than the first time it opens its position, this is wrong (check the behavior in the script).
There was some line of code in the fiddle that, if you uncomment this problem, solve it. But I feel like this is a hacky approach, do I need a better way to handle it, if any?
source share