Last active
August 29, 2015 14:09
-
-
Save zaparker/447e682b873ec34c7bd8 to your computer and use it in GitHub Desktop.
Knockout Bootstrap Tooltip Binding
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ko.bindingHandlers.tooltip = { | |
init: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) { | |
var value = valueAccessor(); | |
var valueUnwrapped = ko.unwrap(value); | |
if (valueUnwrapped.text != null) | |
{ | |
$(element).attr('title', valueUnwrapped.text); | |
if (valueUnwrapped.alignment != null) { | |
$(element).attr('data-placement', valueUnwrapped.alignment); | |
} | |
} | |
else $(element).attr('title', valueUnwrapped); | |
$(element).tooltip(); | |
ko.utils.domNodeDisposal.addDisposeCallback(element, function () { | |
$(element).tooltip("destroy"); | |
}); | |
}, | |
update: function (element, valueAccessor, allBindingsAccessor, viewModel, bindingContext) { } | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment